From b9d7666057b7771efc4936ec8c5b9a17494a871a Mon Sep 17 00:00:00 2001 From: Maksymilian Knust Date: Fri, 19 Apr 2024 11:04:11 +0200 Subject: [PATCH 1/4] Replaced nlunit-test with pw_unit_test in src/lib/shell/ --- src/lib/shell/tests/BUILD.gn | 5 +-- .../shell/tests/TestShellStreamerStdio.cpp | 33 ++++--------------- src/lib/shell/tests/TestShellTokenizeLine.cpp | 33 ++++--------------- 3 files changed, 13 insertions(+), 58 deletions(-) diff --git a/src/lib/shell/tests/BUILD.gn b/src/lib/shell/tests/BUILD.gn index 12c15d84c531c7..0b5f7d5fd43222 100644 --- a/src/lib/shell/tests/BUILD.gn +++ b/src/lib/shell/tests/BUILD.gn @@ -14,11 +14,10 @@ import("//build_overrides/build.gni") import("//build_overrides/chip.gni") -import("//build_overrides/nlunit_test.gni") import("${chip_root}/build/chip/chip_test_suite.gni") -chip_test_suite_using_nltest("tests") { +chip_test_suite("tests") { output_name = "libTestShell" test_sources = [ @@ -31,7 +30,5 @@ chip_test_suite_using_nltest("tests") { public_deps = [ "${chip_root}/src/lib/core", "${chip_root}/src/lib/shell", - "${chip_root}/src/lib/support:testing_nlunit", - "${nlunit_test_root}:nlunit-test", ] } diff --git a/src/lib/shell/tests/TestShellStreamerStdio.cpp b/src/lib/shell/tests/TestShellStreamerStdio.cpp index 170fc377e36e95..5436500a974fe2 100644 --- a/src/lib/shell/tests/TestShellStreamerStdio.cpp +++ b/src/lib/shell/tests/TestShellStreamerStdio.cpp @@ -15,11 +15,11 @@ * limitations under the License. */ -#include +#include #include #include -#include + #include #include @@ -48,7 +48,7 @@ static const struct test_streamer_vector test_vector_streamer_out[] = { // Unit tests // ================================= -static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext) +TEST(TestShellStreamerStdio, TestStreamer_Output) { int numOfTestVectors = ArraySize(test_vector_streamer_out); int numOfTestsRan = 0; @@ -64,29 +64,8 @@ static void TestStreamer_Output(nlTestSuite * inSuite, void * inContext) num_chars = streamer_write(streamer_get(), output, strlen(output)); // Let's assume that all our output lengths fit in ssize_t. - NL_TEST_ASSERT(inSuite, num_chars == static_cast(strlen(output))); + EXPECT_EQ(num_chars, static_cast(strlen(output))); numOfTestsRan++; } - NL_TEST_ASSERT(inSuite, numOfTestsRan > 0); -} - -/** - * Test Suite. It lists all the test functions. - */ -static const nlTest sTests[] = { - - NL_TEST_DEF("Test Shell: TestStreamer_Output", TestStreamer_Output), - - NL_TEST_SENTINEL() -}; - -int TestStreamerStdio() -{ - nlTestSuite theSuite = { "Test Shell: Streamer", &sTests[0], nullptr, nullptr }; - - // Run test suite against one context. - nlTestRunner(&theSuite, nullptr); - return nlTestRunnerStats(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestStreamerStdio) + EXPECT_GT(numOfTestsRan, 0); +} \ No newline at end of file diff --git a/src/lib/shell/tests/TestShellTokenizeLine.cpp b/src/lib/shell/tests/TestShellTokenizeLine.cpp index cbd0d751344670..b52c52cad8e87a 100644 --- a/src/lib/shell/tests/TestShellTokenizeLine.cpp +++ b/src/lib/shell/tests/TestShellTokenizeLine.cpp @@ -15,10 +15,10 @@ * limitations under the License. */ -#include +#include #include -#include + // Include entire C++ file to have access to functions-under-test // such as TokenizeLine despite them being declared within an anonymous namespace. @@ -99,7 +99,7 @@ static const struct test_shell_vector test_vector_shell_tokenizer[] = { // Unit tests // ================================= -static void TestShell_Tokenizer(nlTestSuite * inSuite, void * inContext) +TEST(TestShellTokenizeLine, TestShell_Tokenizer) { int numOfTestVectors = ArraySize(test_vector_shell_tokenizer); int numOfTestsRan = 0; @@ -115,34 +115,13 @@ static void TestShell_Tokenizer(nlTestSuite * inSuite, void * inContext) char * argv[TEST_SHELL_MAX_TOKENS]; int argc = TokenizeLine(line, argv, TEST_SHELL_MAX_TOKENS); - NL_TEST_ASSERT(inSuite, argc == test_params->argc); + EXPECT_EQ(argc, test_params->argc); for (int i = 0; i < argc; i++) { - NL_TEST_ASSERT(inSuite, strcmp(argv[i], test_params->argv[i]) == 0); + EXPECT_EQ(strcmp(argv[i], test_params->argv[i]), 0); } numOfTestsRan++; } - NL_TEST_ASSERT(inSuite, numOfTestsRan > 0); + EXPECT_GT(numOfTestsRan, 0); } - -/** - * Test Suite. It lists all the test functions. - */ -static const nlTest sTests[] = { - - NL_TEST_DEF("Test Shell: TestShell_Tokenizer", TestShell_Tokenizer), - - NL_TEST_SENTINEL() -}; - -int TestShellTokenizeLine() -{ - nlTestSuite theSuite = { "Test Shell: MainLoop", &sTests[0], nullptr, nullptr }; - - // Run test suite against one context. - nlTestRunner(&theSuite, nullptr); - return nlTestRunnerStats(&theSuite); -} - -CHIP_REGISTER_TEST_SUITE(TestShellTokenizeLine) From 55f232b246f2b36295bd8b886f16c6c2bc51f859 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 19 Apr 2024 09:06:02 +0000 Subject: [PATCH 2/4] Restyled by whitespace --- src/lib/shell/tests/TestShellStreamerStdio.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/shell/tests/TestShellStreamerStdio.cpp b/src/lib/shell/tests/TestShellStreamerStdio.cpp index 5436500a974fe2..46eaeb40f78b56 100644 --- a/src/lib/shell/tests/TestShellStreamerStdio.cpp +++ b/src/lib/shell/tests/TestShellStreamerStdio.cpp @@ -68,4 +68,4 @@ TEST(TestShellStreamerStdio, TestStreamer_Output) numOfTestsRan++; } EXPECT_GT(numOfTestsRan, 0); -} \ No newline at end of file +} From 0ed932347d378c887e987654df76e2e5fcf95848 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Fri, 19 Apr 2024 09:06:04 +0000 Subject: [PATCH 3/4] Restyled by clang-format --- src/lib/shell/tests/TestShellStreamerStdio.cpp | 1 - src/lib/shell/tests/TestShellTokenizeLine.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/lib/shell/tests/TestShellStreamerStdio.cpp b/src/lib/shell/tests/TestShellStreamerStdio.cpp index 46eaeb40f78b56..dde770c950183c 100644 --- a/src/lib/shell/tests/TestShellStreamerStdio.cpp +++ b/src/lib/shell/tests/TestShellStreamerStdio.cpp @@ -20,7 +20,6 @@ #include #include - #include #include #include diff --git a/src/lib/shell/tests/TestShellTokenizeLine.cpp b/src/lib/shell/tests/TestShellTokenizeLine.cpp index b52c52cad8e87a..8ed6c0eecde779 100644 --- a/src/lib/shell/tests/TestShellTokenizeLine.cpp +++ b/src/lib/shell/tests/TestShellTokenizeLine.cpp @@ -19,7 +19,6 @@ #include - // Include entire C++ file to have access to functions-under-test // such as TokenizeLine despite them being declared within an anonymous namespace. #include "../MainLoopDefault.cpp" From 0ffe9128a737f99e51e7a6772e2923fd18575738 Mon Sep 17 00:00:00 2001 From: Maksymilian Knust Date: Fri, 19 Apr 2024 12:59:12 +0200 Subject: [PATCH 4/4] Update openiot test components --- src/test_driver/openiotsdk/unit-tests/test_components.txt | 1 + src/test_driver/openiotsdk/unit-tests/test_components_nl.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test_driver/openiotsdk/unit-tests/test_components.txt b/src/test_driver/openiotsdk/unit-tests/test_components.txt index bc9d77e48d075f..159b0e0f7bc3c9 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components.txt @@ -1,2 +1,3 @@ accesstest PlatformTests +TestShell diff --git a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt index 0e012ff3354f02..b12fa582e0d732 100644 --- a/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt +++ b/src/test_driver/openiotsdk/unit-tests/test_components_nl.txt @@ -17,6 +17,5 @@ SecureChannelTests SetupPayloadTests SupportTests SystemLayerTests -TestShell TransportLayerTests UserDirectedCommissioningTests