diff --git a/inc/.git_inc_dir b/inc/.git_inc_dir new file mode 100644 index 0000000..e69de29 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..50e5749 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,12 @@ +add_executable(main PUBLIC + main.c +) +set_target_properties(main PROPERTIES VERSION 1.0 SOVERSION 1) +target_include_directories(main PUBLIC + ${PROJECT_SOURCE_DIR}/inc + ${CMAKE_CURRENT_SOURCE_DIR} +) + + +add_subdirectory(wrap) +add_subdirectory(led_driver) diff --git a/src/led_driver/CMakeLists.txt b/src/led_driver/CMakeLists.txt new file mode 100644 index 0000000..49da348 --- /dev/null +++ b/src/led_driver/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(led_driver STATIC + led_driver.c +) + +target_include_directories(led_driver PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) diff --git a/src/led_driver/led_driver.c b/src/led_driver/led_driver.c new file mode 100644 index 0000000..f845ab6 --- /dev/null +++ b/src/led_driver/led_driver.c @@ -0,0 +1,21 @@ +#include "led_driver.h" + +uint8_t internal_led_state = 0x00; +uint8_t *led_state = &internal_led_state; + +void init_led_driver(void) +{ + led_state = &internal_led_state; +} + +uint8_t get_led_state(void) +{ + return *led_state; +} + +void set_led_state(uint8_t state) +{ + *led_state = state; +} + + diff --git a/src/led_driver/led_driver.h b/src/led_driver/led_driver.h new file mode 100644 index 0000000..7001114 --- /dev/null +++ b/src/led_driver/led_driver.h @@ -0,0 +1,12 @@ +#ifndef LED_DRIVER +#define LED_DRIVER + +#include +//extern volatile uint8_t *led_state; + + +uint8_t get_led_state(void); +void set_led_state(uint8_t state); +void init_led_driver(void); + +#endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..716a10e --- /dev/null +++ b/src/main.c @@ -0,0 +1,10 @@ +#include +#include + + + +int main(int argc, char **argv) +{ + printf("cmake functional\n"); + return 0; +} diff --git a/src/wrap/CMakeLists.txt b/src/wrap/CMakeLists.txt new file mode 100644 index 0000000..a1c2a3f --- /dev/null +++ b/src/wrap/CMakeLists.txt @@ -0,0 +1,40 @@ +# An example for building and testing a shared library +# that can also depends on another shared library + + +set_target_properties(wrap PROPERTIES VERSION 1.0 SOVERSION 1) + +target_include_directories(camera_handler PUBLIC + ${PROJECT_SOURCE_DIR}/wrap/ + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_library(wrap SHARED + wrap.c +) + + +if(UNIT_TESTING) + + # ############################# + # Settings for the mocked lib + # ############################# + + set(WRAPPED_FUNCS "") + list(APPEND WRAPPED_FUNCS + "test_mock" + "arm_missiles" + "luanch_missiles" + ) + set(WRAPPED_STR "") + list(JOIN WRAPPED_FUNCS ",--wrap=" WRAPPED_STR) + message("WRAPPED_STR: ${WRAPPED_STR}") + + set_target_properties(camera_handler + PROPERTIES + LINK_FLAGS "-Wl,--wrap=${WRAPPED_STR}" + ) + +else() + # Nothing for now +endif() diff --git a/src/wrap/wrap.c b/src/wrap/wrap.c new file mode 100644 index 0000000..e69de29 diff --git a/src/wrap/wrap.h b/src/wrap/wrap.h new file mode 100644 index 0000000..e69de29 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..524ee31 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(simple_test) +add_subdirectory(wrap) diff --git a/tests/led_driver/CMakeLists.txt b/tests/led_driver/CMakeLists.txt new file mode 100644 index 0000000..b20ff1b --- /dev/null +++ b/tests/led_driver/CMakeLists.txt @@ -0,0 +1,13 @@ +# The led_driver module tests +list(APPEND TEST_LIBS "${CMOCKA_LIBRARIES}") +list(APPEND TEST_LIBS led_driver) + +list(APPEND TEST_DIRS "${CMOCKA_INCLUDE_DIRS}") +list(APPEND TEST_DIRS "${PROJECT_SOURCE_DIR}/src") + +add_cmocka_test(test_led_driver + SOURCES test_led_driver.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES "${TEST_LIBS}") +add_cmocka_test_environment(test_led_driver) +target_include_directories(test_led_driver PUBLIC "${TEST_DIRS}") diff --git a/tests/led_driver/test_led_driver.c b/tests/led_driver/test_led_driver.c new file mode 100644 index 0000000..7d47c40 --- /dev/null +++ b/tests/led_driver/test_led_driver.c @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include + +/* A test case that does nothing and succeeds. */ +static void null_test_success(void **state) { + (void) state; /* unused */ +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(null_test_success), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/tests/simple_test/CMakeLists.txt b/tests/simple_test/CMakeLists.txt new file mode 100644 index 0000000..63e5b69 --- /dev/null +++ b/tests/simple_test/CMakeLists.txt @@ -0,0 +1,7 @@ +# Test the logic for the PMG formating code +add_cmocka_test(test_pgm + SOURCES test_pgm.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES "${CMOCKA_LIBRARIES}") +add_cmocka_test_environment(test_pgm) +target_include_directories(test_pgm PUBLIC "${CMOCKA_INCLUDE_DIRS}") diff --git a/tests/simple_test/simple_test.c b/tests/simple_test/simple_test.c new file mode 100644 index 0000000..c8c52ff --- /dev/null +++ b/tests/simple_test/simple_test.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include + +/* A test case that does nothing and succeeds. */ +static void null_test_success(void **state) { + (void) state; /* unused */ +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test(null_test_success), + }; + +return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/tests/wrap/CMakeLists.txt b/tests/wrap/CMakeLists.txt new file mode 100644 index 0000000..0c21365 --- /dev/null +++ b/tests/wrap/CMakeLists.txt @@ -0,0 +1,13 @@ +# The wrap module tests +list(APPEND TEST_LIBS "${CMOCKA_LIBRARIES}") +list(APPEND TEST_LIBS wrap) + +list(APPEND TEST_DIRS "${CMOCKA_INCLUDE_DIRS}") +list(APPEND TEST_DIRS "${PROJECT_SOURCE_DIR}/src") + +add_cmocka_test(test_wrap + SOURCES test_wrap.c + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} + LINK_LIBRARIES "${TEST_LIBS}") +add_cmocka_test_environment(test_wrap) +target_include_directories(test_wrap PUBLIC "${TEST_DIRS}") diff --git a/tests/wrap/test_wrap.c b/tests/wrap/test_wrap.c new file mode 100644 index 0000000..e69de29