example code and tests
This commit is contained in:
parent
42122decef
commit
7a8dd4f4d2
|
@ -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)
|
|
@ -0,0 +1,7 @@
|
|||
add_library(led_driver STATIC
|
||||
led_driver.c
|
||||
)
|
||||
|
||||
target_include_directories(led_driver PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef LED_DRIVER
|
||||
#define LED_DRIVER
|
||||
|
||||
#include <inttypes.h>
|
||||
//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
|
|
@ -0,0 +1,10 @@
|
|||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
printf("cmake functional\n");
|
||||
return 0;
|
||||
}
|
|
@ -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()
|
|
@ -0,0 +1,2 @@
|
|||
add_subdirectory(simple_test)
|
||||
add_subdirectory(wrap)
|
|
@ -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}")
|
|
@ -0,0 +1,18 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
/* 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);
|
||||
}
|
|
@ -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}")
|
|
@ -0,0 +1,19 @@
|
|||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdint.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
/* 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);
|
||||
}
|
|
@ -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}")
|
Loading…
Reference in New Issue