Skip to content

Commit d6706d1

Browse files
author
Antti Kauppila
committed
Unittest configuration mechanism improved
Earlier all unittests ended up having all flags in common from all unittest targets. This is now improved by using googletest provided mechanism to set build time compile options All cmake files have been modified to reflect changes (when needed) Could not figure out a syntax for {0x00, 0x00, ..., 0x00} intitializer list yet, so those needs to be setup by updating C/CXX flags.
1 parent 8d246d8 commit d6706d1

File tree

36 files changed

+341
-175
lines changed

36 files changed

+341
-175
lines changed

UNITTESTS/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ foreach(testfile ${unittest-file-list})
158158
set(unittest-includes ${unittest-includes-base})
159159
set(unittest-sources)
160160
set(unittest-test-sources)
161+
set(unittest-test-flags)
161162

162163
# Get source files
163164
include("${testfile}")
@@ -184,6 +185,8 @@ foreach(testfile ${unittest-file-list})
184185
add_library("${TEST_SUITE_NAME}.${LIB_NAME}" STATIC ${unittest-sources})
185186
target_include_directories("${TEST_SUITE_NAME}.${LIB_NAME}" PRIVATE
186187
${unittest-includes})
188+
target_compile_options("${TEST_SUITE_NAME}.${LIB_NAME}" PRIVATE
189+
${unittest-test-flags})
187190
set(LIBS_TO_BE_LINKED ${LIBS_TO_BE_LINKED} "${TEST_SUITE_NAME}.${LIB_NAME}")
188191

189192
# Append lib build directory to list
@@ -195,6 +198,8 @@ foreach(testfile ${unittest-file-list})
195198
add_executable(${TEST_SUITE_NAME} ${unittest-test-sources})
196199
target_include_directories(${TEST_SUITE_NAME} PRIVATE
197200
${unittest-includes})
201+
target_compile_options(${TEST_SUITE_NAME} PRIVATE
202+
${unittest-test-flags})
198203

199204
# Link the executable with the libraries.
200205
target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED})

UNITTESTS/drivers/PwmOut/unittest.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ set(unittest-test-sources
2323
stubs/pwmout_api_stub.c
2424
)
2525

26-
# defines
27-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDEVICE_PWMOUT")
28-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEVICE_PWMOUT")
26+
set(unittest-test-flags
27+
-DDEVICE_PWMOUT
28+
)
29+

UNITTESTS/drivers/Watchdog/unittest.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ set(unittest-sources
1717

1818
# Test files
1919
set(unittest-test-sources
20-
drivers/Watchdog/test_watchdog.cpp
21-
stubs/mbed_critical_stub.c
20+
drivers/Watchdog/test_watchdog.cpp
21+
stubs/mbed_critical_stub.c
2222
stubs/mbed_assert_stub.cpp
2323
stubs/watchdog_api_stub.c
2424
)
2525

26-
# defines
27-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDEVICE_WATCHDOG -DMBED_WDOG_ASSERT=1")
28-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEVICE_WATCHDOG -DMBED_WDOG_ASSERT=1")
26+
set(unittest-test-flags
27+
-DDEVICE_WATCHDOG
28+
-DMBED_WDOG_ASSERT=1
29+
)

UNITTESTS/empty_baseline/unittest.cmake

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,78 @@ set(unittest-includes ${unittest-includes}
1212
)
1313

1414
set(unittest-sources
15-
../features/device_key/source/DeviceKey.cpp
16-
../components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp
17-
../components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp
18-
../components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp
19-
../components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
20-
../components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.cpp
21-
../components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
22-
../components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp
23-
../features/storage/filesystem/Dir.cpp
24-
../features/storage/filesystem/FileSystem.cpp
25-
../features/storage/filesystem/File.cpp
26-
../features/storage/kvstore/global_api/kvstore_global_api.cpp
27-
../features/storage/kvstore/securestore/SecureStore.cpp
28-
../features/storage/kvstore/kv_map/KVMap.cpp
29-
../features/storage/kvstore/tdbstore/TDBStore.cpp
30-
../features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp
31-
../features/storage/kvstore/conf/kv_config.cpp
32-
../features/storage/kvstore/filesystemstore/FileSystemStore.cpp
33-
../features/storage/system_storage/SystemStorage.cpp
34-
../features/storage/blockdevice/ChainingBlockDevice.cpp
35-
../features/storage/blockdevice/ReadOnlyBlockDevice.cpp
36-
../features/storage/blockdevice/SlicingBlockDevice.cpp
37-
../features/storage/blockdevice/MBRBlockDevice.cpp
38-
../features/storage/blockdevice/HeapBlockDevice.cpp
39-
../features/storage/blockdevice/FlashSimBlockDevice.cpp
40-
../features/storage/blockdevice/ObservingBlockDevice.cpp
41-
../features/storage/blockdevice/ProfilingBlockDevice.cpp
42-
../features/storage/blockdevice/BufferedBlockDevice.cpp
43-
../features/storage/blockdevice/ExhaustibleBlockDevice.cpp
15+
../features/device_key/source/DeviceKey.cpp
16+
../components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp
17+
../components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp
18+
../components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp
19+
../components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
20+
../components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.cpp
21+
../components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
22+
../components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp
23+
../features/storage/filesystem/Dir.cpp
24+
../features/storage/filesystem/FileSystem.cpp
25+
../features/storage/filesystem/File.cpp
26+
../features/storage/kvstore/global_api/kvstore_global_api.cpp
27+
../features/storage/kvstore/securestore/SecureStore.cpp
28+
../features/storage/kvstore/kv_map/KVMap.cpp
29+
../features/storage/kvstore/tdbstore/TDBStore.cpp
30+
../features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp
31+
../features/storage/kvstore/conf/kv_config.cpp
32+
../features/storage/kvstore/filesystemstore/FileSystemStore.cpp
33+
../features/storage/system_storage/SystemStorage.cpp
34+
../features/storage/blockdevice/ChainingBlockDevice.cpp
35+
../features/storage/blockdevice/ReadOnlyBlockDevice.cpp
36+
../features/storage/blockdevice/SlicingBlockDevice.cpp
37+
../features/storage/blockdevice/MBRBlockDevice.cpp
38+
../features/storage/blockdevice/HeapBlockDevice.cpp
39+
../features/storage/blockdevice/FlashSimBlockDevice.cpp
40+
../features/storage/blockdevice/ObservingBlockDevice.cpp
41+
../features/storage/blockdevice/ProfilingBlockDevice.cpp
42+
../features/storage/blockdevice/BufferedBlockDevice.cpp
43+
../features/storage/blockdevice/ExhaustibleBlockDevice.cpp
4444
)
4545

4646
set(unittest-test-sources
4747
empty_baseline/empty_baseline.cpp
4848
)
4949

50-
set(DEVICE_FLAGS "-DDEVICE_ANALOGIN -DDEVICE_ANALOGOUT -DDEVICE_CAN -DDEVICE_ETHERNET -DDEVICE_FLASH -DDEVICE_I2C -DDEVICE_I2CSLAVE -DDEVICE_I2C_ASYNCH -DDEVICE_INTERRUPTIN -DDEVICE_LPTICKER -DDEVICE_PORTIN -DDEVICE_PORTINOUT -DDEVICE_PORTOUT -DDEVICE_PWMOUT -DDEVICE_QSPI -DDEVICE_SERIAL -DDEVICE_SERIAL_ASYNCH -DDEVICE_SERIAL_FC -DDEVICE_SPI -DDEVICE_SPISLAVE -DDEVICE_SPI_ASYNCH -DDEVICE_FLASH -DCOMPONENT_FLASHIAP")
51-
set(CONF_FLAGS "-DMBED_CONF_PLATFORM_CTHUNK_COUNT_MAX=10 -DMBED_CONF_DATAFLASH_SPI_FREQ=1 -DMBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS=0 -DMBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE=0 -DMBED_CONF_QSPIF_QSPI_FREQ=1 -DMBED_CONF_QSPIF_QSPI_MIN_READ_SIZE=1 -DMBED_CONF_QSPIF_QSPI_MIN_PROG_SIZE=1 -DMBED_LFS_READ_SIZE=64 -DMBED_LFS_PROG_SIZE=64 -DMBED_LFS_BLOCK_SIZE=512 -DMBED_LFS_LOOKAHEAD=512 -DFLASHIAP_APP_ROM_END_ADDR=0x80000 -DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE=1024 -DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS=0x80000 -DMBED_CONF_STORAGE_STORAGE_TYPE=default")
52-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
53-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
50+
set(unittest-test-flags
51+
-DDEVICE_ANALOGIN
52+
-DDEVICE_ANALOGOUT
53+
-DDEVICE_CAN
54+
-DDEVICE_ETHERNET
55+
-DDEVICE_FLASH
56+
-DDEVICE_I2C
57+
-DDEVICE_I2CSLAVE
58+
-DDEVICE_I2C_ASYNCH
59+
-DDEVICE_INTERRUPTIN
60+
-DDEVICE_LPTICKER
61+
-DDEVICE_PORTIN
62+
-DDEVICE_PORTINOUT
63+
-DDEVICE_PORTOUT
64+
-DDEVICE_PWMOUT
65+
-DDEVICE_QSPI
66+
-DDEVICE_SERIAL
67+
-DDEVICE_SERIAL_ASYNCH
68+
-DDEVICE_SERIAL_FC
69+
-DDEVICE_SPI
70+
-DDEVICE_SPISLAVE
71+
-DDEVICE_SPI_ASYNCH
72+
-DCOMPONENT_FLASHIAP
73+
-DMBED_CONF_PLATFORM_CTHUNK_COUNT_MAX=10
74+
-DMBED_CONF_DATAFLASH_SPI_FREQ=1
75+
-DMBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS=0
76+
-DMBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE=0
77+
-DMBED_CONF_QSPIF_QSPI_FREQ=1
78+
-DMBED_CONF_QSPIF_QSPI_MIN_READ_SIZE=1
79+
-DMBED_CONF_QSPIF_QSPI_MIN_PROG_SIZE=1
80+
-DMBED_LFS_READ_SIZE=64
81+
-DMBED_LFS_PROG_SIZE=64
82+
-DMBED_LFS_BLOCK_SIZE=512
83+
-DMBED_LFS_LOOKAHEAD=512
84+
-DFLASHIAP_APP_ROM_END_ADDR=0x80000
85+
-DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE=1024
86+
-DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS=0x80000
87+
-DMBED_CONF_STORAGE_STORAGE_TYPE=default
88+
-DMBED_CONF_FAT_CHAN_FF_MAX_SS=4096
89+
)

UNITTESTS/events/equeue/unittest.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,8 @@ set(unittest-test-sources
2020
stubs/EqueuePosix_stub.c
2121
)
2222

23-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -DEQUEUE_PLATFORM_POSIX")
24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -DEQUEUE_PLATFORM_POSIX")
23+
set(unittest-test-flags
24+
-pthread
25+
-DEQUEUE_PLATFORM_POSIX
26+
)
27+

UNITTESTS/features/cellular/framework/AT/at_cellularcontext/unittest.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ set(unittest-test-sources
4545
stubs/ConditionVariable_stub.cpp
4646
stubs/Mutex_stub.cpp
4747
)
48+
49+
set(unittest-test-flags
50+
-DDEVICE_SERIAL=1
51+
-DDEVICE_INTERRUPTIN=1
52+
-DMBED_CONF_CELLULAR_USE_SMS=1
53+
-DMBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL
54+
)

UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,17 @@ set(unittest-test-sources
4848
stubs/Mutex_stub.cpp
4949
)
5050

51-
# defines
52-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DDEVICE_SERIAL=1 -DDEVICE_INTERRUPTIN=1 -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN=NULL")
53-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMDMTXD=NC -DMDMRXD=NC -DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200")
54-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEVICE_SERIAL=1 -DDEVICE_INTERRUPTIN=1 -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN=NULL -DMBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN=NULL")
55-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMDMTXD=NC -DMDMRXD=NC -DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200")
51+
set(unittest-test-flags
52+
-DDEVICE_SERIAL=1
53+
-DDEVICE_INTERRUPTIN=1
54+
-DMBED_CONF_NSAPI_DEFAULT_CELLULAR_APN=NULL
55+
-DMBED_CONF_NSAPI_DEFAULT_CELLULAR_USERNAME=NULL
56+
-DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PASSWORD=NULL
57+
-DMBED_CONF_NSAPI_DEFAULT_CELLULAR_PLMN=NULL
58+
-DMBED_CONF_NSAPI_DEFAULT_CELLULAR_SIM_PIN=NULL
59+
-DMDMTXD=NC
60+
-DMDMRXD=NC
61+
-DMBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE=115200
62+
-DMBED_CONF_CELLULAR_USE_SMS=1
63+
)
5664

UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ set(unittest-test-sources
3232
stubs/Mutex_stub.cpp
3333
)
3434

35-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")
36-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_USE_SMS=1")
37-
38-
35+
set(unittest-test-flags
36+
-DMBED_CONF_CELLULAR_USE_SMS=1
37+
)

UNITTESTS/features/cellular/framework/AT/athandler/athandlertest.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,32 @@ TEST_F(TestATHandler, test_ATHandler_read_int)
947947

948948
ret = at.read_int();
949949
EXPECT_TRUE(2 == ret);
950+
at.resp_stop();
951+
at.clear_error();
952+
953+
char table3[] = "\"9223372036854775808,\"OK\r\n\0";
954+
filehandle_stub_table = table3;
955+
filehandle_stub_table_pos = 0;
956+
mbed_poll_stub::revents_value = POLLIN;
957+
mbed_poll_stub::int_value = strlen(table3);
958+
959+
at.resp_start();
960+
ret = at.read_int();
961+
EXPECT_TRUE(-1 == ret);
962+
at.resp_stop();
963+
at.clear_error();
964+
965+
char table4[] = "\"-9223372036854775809,\"OK\r\n\0";
966+
filehandle_stub_table = table4;
967+
filehandle_stub_table_pos = 0;
968+
mbed_poll_stub::revents_value = POLLIN;
969+
mbed_poll_stub::int_value = strlen(table4);
970+
971+
at.resp_start();
972+
ret = at.read_int();
973+
EXPECT_TRUE(-1 == ret);
974+
at.resp_stop();
975+
at.clear_error();
950976
}
951977

952978
TEST_F(TestATHandler, test_ATHandler_resp_start)

UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set(unittest-includes ${unittest-includes}
1010
../features/cellular/framework/common
1111
../features/cellular/framework/AT
1212
../features/frameworks/mbed-client-randlib/mbed-client-randlib
13-
13+
1414
)
1515

1616
# Source files
@@ -41,5 +41,9 @@ set(unittest-test-sources
4141
stubs/rtx_mutex_stub.c
4242
)
4343

44-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
45-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
44+
set(unittest-test-flags
45+
-DMBED_CONF_CELLULAR_DEBUG_AT=true
46+
-DOS_STACK_SIZE=2048
47+
-DDEVICE_SERIAL=1
48+
-DDEVICE_INTERRUPTIN=1
49+
)

0 commit comments

Comments
 (0)