From 3e7ee6c4d1f31a3fcfb875b85b84ce5f898d981f Mon Sep 17 00:00:00 2001 From: Lari-Matias Orjala Date: Mon, 17 Sep 2018 15:37:11 +0300 Subject: [PATCH 1/3] add auto-naming of unit test suites --- UNITTESTS/CMakeLists.txt | 18 ++++++++++++------ .../AT/at_cellularbase/unittest.cmake | 3 --- .../framework/common/util/unittest.cmake | 3 --- .../netsocket/InternetSocket/unittest.cmake | 3 --- .../netsocket/NetworkInterface/unittest.cmake | 3 --- .../netsocket/TCPSocket/unittest.cmake | 3 --- .../netsocket/UDPSocket/unittest.cmake | 3 --- .../platform/CircularBuffer/unittest.cmake | 3 --- 8 files changed, 12 insertions(+), 27 deletions(-) diff --git a/UNITTESTS/CMakeLists.txt b/UNITTESTS/CMakeLists.txt index 76a0fddf4a..a50455c689 100644 --- a/UNITTESTS/CMakeLists.txt +++ b/UNITTESTS/CMakeLists.txt @@ -147,11 +147,17 @@ foreach(testfile ${unittest-file-list}) # Get source files include("${testfile}") - if(TEST_SUITE_NAME) - set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME}) - else() - message(FATAL_ERROR "No TEST_SUITE_NAME found in test file. Add it to ${testfile}.") - endif() + get_filename_component(TEST_SUITE_DIR ${testfile} DIRECTORY) + + file(RELATIVE_PATH + TEST_SUITE_NAME # output + ${PROJECT_SOURCE_DIR} # root + ${TEST_SUITE_DIR} #abs dirpath + ) + + string(REGEX REPLACE "/|\\\\" "-" TEST_SUITE_NAME ${TEST_SUITE_NAME}) + + set(TEST_SUITES ${TEST_SUITES} ${TEST_SUITE_NAME}) set(LIBS_TO_BE_LINKED gmock_main) @@ -178,7 +184,7 @@ foreach(testfile ${unittest-file-list}) # Link the executable with the libraries. target_link_libraries(${TEST_SUITE_NAME} ${LIBS_TO_BE_LINKED}) - add_test(NAME "${TEST_SUITE_NAME}UnitTests" COMMAND ${TEST_SUITE_NAME}) + add_test(NAME "${TEST_SUITE_NAME}" COMMAND ${TEST_SUITE_NAME}) # Append test build directory to list list(APPEND BUILD_DIRECTORIES "./CMakeFiles/${TEST_SUITE_NAME}.dir") diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake index b842f53743..eab77c34eb 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularbase/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "cellular-framework-AT-AT_CellularBase") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/AT/AT_CellularBase diff --git a/UNITTESTS/features/cellular/framework/common/util/unittest.cmake b/UNITTESTS/features/cellular/framework/common/util/unittest.cmake index cefe41bb1c..5a51c7f42c 100644 --- a/UNITTESTS/features/cellular/framework/common/util/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/common/util/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "cellular-framework-common-util") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake b/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake index a8a79bf90e..3d4297e530 100644 --- a/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/InternetSocket/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "features-netsocket-InternetSocket") - set(unittest-sources ../features/netsocket/SocketAddress.cpp ../features/netsocket/NetworkStack.cpp diff --git a/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake b/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake index b89cd580b0..cab0725e05 100644 --- a/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake +++ b/UNITTESTS/features/netsocket/NetworkInterface/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "features-netsocket-NetworkInterface") - # Source files set(unittest-sources ../features/netsocket/NetworkInterface.cpp diff --git a/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake b/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake index 4128378d8c..0265ca19b0 100644 --- a/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/TCPSocket/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "features-netsocket-TCPSocket") - set(unittest-sources ../features/netsocket/SocketAddress.cpp ../features/netsocket/InternetSocket.cpp diff --git a/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake b/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake index e8a8c828ed..b57c38e6f4 100644 --- a/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake +++ b/UNITTESTS/features/netsocket/UDPSocket/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "features-netsocket-UDPSocket") - set(unittest-sources ../features/netsocket/SocketAddress.cpp ../features/netsocket/NetworkStack.cpp diff --git a/UNITTESTS/platform/CircularBuffer/unittest.cmake b/UNITTESTS/platform/CircularBuffer/unittest.cmake index 8beeb88efb..34187f4f95 100644 --- a/UNITTESTS/platform/CircularBuffer/unittest.cmake +++ b/UNITTESTS/platform/CircularBuffer/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "platform-CircularBuffer") - set(unittest-sources ) From e0e759e0a4efeccb5fab52980cc7df087dd9eb52 Mon Sep 17 00:00:00 2001 From: Lari-Matias Orjala Date: Mon, 17 Sep 2018 15:59:05 +0300 Subject: [PATCH 2/3] update test file generator --- UNITTESTS/README.md | 3 --- UNITTESTS/template/unittest.cmake.template | 3 --- UNITTESTS/unit_test/new.py | 5 +---- 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/UNITTESTS/README.md b/UNITTESTS/README.md index 0ae44996f1..a405baceed 100644 --- a/UNITTESTS/README.md +++ b/UNITTESTS/README.md @@ -203,7 +203,6 @@ Each class to be tested requires two files for unit testing: A unit test definition file `unittest.cmake` requires variables to be set for a test to be configured. File source paths in `unittest.cmake` files need to be relative to the unit test folder and `CMakeLists.txt`. -* **TEST_SUITE_NAME** - Identifier for the test suite. Use naming convention *PATH_TO_THE_TESTABLE_FILE* e.g. *features-netsocket-InternetSocket* * **unittest-includes** - Include paths for headers needed to build the tests in addition to the base include paths listed in [CMakeLists.txt](CMakeLists.txt). Optional. * **unittest-sources** - Mbed OS source files and stubs included for the build. * **unittest-test-sources** - Unit test source files. @@ -225,8 +224,6 @@ For example to create a unit test for `rtos/Semaphore.cpp`: 1. Create a directory for unit test files in `UNITTESTS/rtos/Semaphore`. 2. Create a test definition file `UNITTESTS/rtos/Semaphore/unittest.cmake` with the following content: ``` -set(TEST_SUITE_NAME "rtos-Semaphore") - set(unittest-sources stubs/mbed_assert.c ../rtos/Semaphore.cpp diff --git a/UNITTESTS/template/unittest.cmake.template b/UNITTESTS/template/unittest.cmake.template index bd463665df..a5f0301525 100644 --- a/UNITTESTS/template/unittest.cmake.template +++ b/UNITTESTS/template/unittest.cmake.template @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "suitename") - set(unittest-includes ${unittest-includes} headerfile ) diff --git a/UNITTESTS/unit_test/new.py b/UNITTESTS/unit_test/new.py index f9fb748d85..772e310696 100644 --- a/UNITTESTS/unit_test/new.py +++ b/UNITTESTS/unit_test/new.py @@ -28,7 +28,7 @@ class UnitTestGeneratorTool(object): Generator tool to create new unit tests from template """ - def _replace_content(self, template_content, dirname, classname, suite_name, extension): + def _replace_content(self, template_content, dirname, classname, extension): if extension == "h": content = re.sub(r"cppfile", "", @@ -41,7 +41,6 @@ class UnitTestGeneratorTool(object): content = re.sub(r"headerfile", "../dirname/template.h", content) content = re.sub(r"dirname", dirname, content) content = re.sub(r"template", classname, content) - content = re.sub(r"suitename", suite_name, content) return content @@ -111,7 +110,6 @@ class UnitTestGeneratorTool(object): content = self._replace_content(template_content, dir_name, class_name, - suite_name, file_extension) output_file.writelines(content) @@ -130,7 +128,6 @@ class UnitTestGeneratorTool(object): content = self._replace_content(template_content, dir_name, class_name, - suite_name, file_extension) output_file.writelines(content) From 8f340b195322e5e41f4a29126950ee5ef1667a8f Mon Sep 17 00:00:00 2001 From: Lari-Matias Orjala Date: Wed, 19 Sep 2018 11:19:27 +0300 Subject: [PATCH 3/3] remove test suite names from cellular tests --- .../cellular/framework/AT/at_cellulardevice/unittest.cmake | 3 --- .../framework/AT/at_cellularinformation/unittest.cmake | 3 --- .../cellular/framework/AT/at_cellularnetwork/unittest.cmake | 3 --- .../cellular/framework/AT/at_cellularpower/unittest.cmake | 3 --- .../cellular/framework/AT/at_cellularsim/unittest.cmake | 3 --- .../cellular/framework/AT/at_cellularsms/unittest.cmake | 3 --- .../cellular/framework/AT/at_cellularstack/unittest.cmake | 3 --- .../features/cellular/framework/AT/athandler/unittest.cmake | 3 --- 8 files changed, 24 deletions(-) diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake index 36b69e0dbe..a259abbaff 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellulardevice/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_device_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake index 0a64cf5242..9a0a7435ce 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularinformation/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_information_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake index e41cf3c6de..194109d8d2 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularnetwork/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_network_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake index 118bdac47c..bf177affd9 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularpower/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_power_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake index ab4f3c0763..d3a6709606 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsim/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_sim_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake index ba6c5b52c8..e9816c2ea3 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularsms/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_sms_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake index 32ed822154..5087e2f82e 100644 --- a/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/at_cellularstack/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_cellular_stack_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util diff --git a/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake b/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake index 6f9c05df34..6fbe35d4aa 100644 --- a/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake +++ b/UNITTESTS/features/cellular/framework/AT/athandler/unittest.cmake @@ -3,9 +3,6 @@ # UNIT TESTS #################### -# Unit test suite name -set(TEST_SUITE_NAME "at_handler_unit") - # Add test specific include paths set(unittest-includes ${unittest-includes} features/cellular/framework/common/util