Skip to content

Commit 3cc96a1

Browse files
authored
Replace nl-unit-test with pigweed for protocols/secure_channel (#33499)
* secure channel tests to pigweed * Remove nlunit tests dependency * Update conversion to pigweed * Relocate class * Revert old implementation * Restore * Move definition of TEST_F_FROM_FIXTURE to UnitTest * Fix test error * Add missing deps * Revert order change * Restyle * Revert * Add missing header * Add UnitTestPigweedUtils * IoT SDK update tests list * Remove unused define * Change target type * license * Assert * rollback * cleanup * Change function to method * Restyle * Fix dependency between tests * Fix merge * Fix * Review fix * Fix typo * Fix review issues * Fix review issues
1 parent f350172 commit 3cc96a1

15 files changed

+694
-1117
lines changed

src/BUILD.gn

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ if (chip_build_tests) {
101101
"${chip_root}/src/lib/format/tests",
102102
"${chip_root}/src/lib/support/tests",
103103
"${chip_root}/src/protocols/secure_channel/tests",
104-
"${chip_root}/src/protocols/secure_channel/tests:tests_nltest",
105104
"${chip_root}/src/system/tests",
106105
"${chip_root}/src/transport/tests",
107106
]

src/lib/support/tests/BUILD.gn

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ import("//build_overrides/pigweed.gni")
1919

2020
import("${chip_root}/build/chip/chip_test_suite.gni")
2121

22+
pw_source_set("pw-test-macros") {
23+
output_dir = "${root_out_dir}/lib"
24+
public_deps = [
25+
"$dir_pw_log:impl",
26+
"$dir_pw_unit_test",
27+
]
28+
sources = [ "ExtraPwTestMacros.h" ]
29+
}
30+
2231
chip_test_suite("tests") {
2332
output_name = "libSupportTests"
2433

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
#pragma once
19+
20+
/*
21+
* Run Fixture's class function as a test.
22+
* It is used to execute test cases that need to use private members of a particular class.
23+
* Unlike the pigweed macro `FRIEND_TEST`, this approach allows you to define the entire
24+
* test_fixture class as a friend, rather than having to define each testcase as a friend.
25+
*
26+
* @param test_fixture - the fixture class.
27+
*
28+
* @param test_name - the name of the test function.
29+
*
30+
* Example:
31+
* class Foo // class to be tested
32+
* {
33+
* friend class TestCtx;
34+
* private:
35+
* bool privateFunction();
36+
* };
37+
*
38+
* class TestCtx: public ::testing::Test
39+
* {
40+
* public:
41+
* void testFunction();
42+
* };
43+
*
44+
* TEST_F_FROM_FIXTURE(TestCtx, testFunction)
45+
* {
46+
* Foo foo;
47+
* EXPECT_TRUE(foo.privateFunction());
48+
* }
49+
*
50+
*/
51+
#define TEST_F_FROM_FIXTURE(test_fixture, test_name) \
52+
TEST_F(test_fixture, test_name) \
53+
{ \
54+
test_name(); \
55+
} \
56+
void test_fixture::test_name()

src/protocols/secure_channel/tests/BUILD.gn

+9-29
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,15 @@
11
import("//build_overrides/build.gni")
22
import("//build_overrides/chip.gni")
3-
import("//build_overrides/nlunit_test.gni")
43
import("${chip_root}/build/chip/chip_test_suite.gni")
54
import("${chip_root}/src/app/icd/icd.gni")
65

76
chip_test_suite("tests") {
87
output_name = "libSecureChannelTests"
98

109
test_sources = [
10+
"TestCASESession.cpp",
1111
"TestCheckInCounter.cpp",
1212
"TestCheckinMsg.cpp",
13-
]
14-
15-
sources = [ "CheckIn_Message_test_vectors.h" ]
16-
17-
cflags = [ "-Wconversion" ]
18-
public_deps = [
19-
"${chip_root}/src/app/icd/server:icd-server-config",
20-
"${chip_root}/src/credentials/tests:cert_test_vectors",
21-
"${chip_root}/src/lib/core",
22-
"${chip_root}/src/lib/support",
23-
"${chip_root}/src/lib/support:test_utils",
24-
"${chip_root}/src/lib/support:testing",
25-
"${chip_root}/src/protocols/secure_channel",
26-
"${chip_root}/src/protocols/secure_channel:check-in-counter",
27-
"${dir_pw_unit_test}",
28-
]
29-
}
30-
31-
chip_test_suite_using_nltest("tests_nltest") {
32-
# Renamed ouput during the transition away from nltest
33-
output_name = "libSecureChannelTestsNL"
34-
35-
test_sources = [
36-
"TestCASESession.cpp",
3713
"TestDefaultSessionResumptionStorage.cpp",
3814
"TestPASESession.cpp",
3915
"TestPairingSession.cpp",
@@ -44,22 +20,26 @@ chip_test_suite_using_nltest("tests_nltest") {
4420
# "TestMessageCounterManager.cpp",
4521
]
4622

23+
sources = [ "CheckIn_Message_test_vectors.h" ]
24+
25+
cflags = [ "-Wconversion" ]
4726
public_deps = [
27+
"${chip_root}/src/app/icd/server:icd-server-config",
28+
"${chip_root}/src/credentials/tests:cert_test_vectors",
4829
"${chip_root}/src/crypto/tests:tests.lib",
4930
"${chip_root}/src/lib/core",
5031
"${chip_root}/src/lib/support",
5132
"${chip_root}/src/lib/support:test_utils",
5233
"${chip_root}/src/lib/support:testing",
53-
"${chip_root}/src/lib/support:testing_nlunit",
34+
"${chip_root}/src/lib/support/tests:pw-test-macros",
5435
"${chip_root}/src/messaging/tests:helpers",
5536
"${chip_root}/src/protocols",
5637
"${chip_root}/src/protocols/secure_channel",
38+
"${chip_root}/src/protocols/secure_channel:check-in-counter",
5739
"${chip_root}/src/transport/raw/tests:helpers",
58-
"${nlunit_test_root}:nlunit-test",
40+
"${dir_pw_unit_test}",
5941
]
6042

61-
cflags = [ "-Wconversion" ]
62-
6343
if (chip_enable_icd_server) {
6444
public_deps += [ "${chip_root}/src/app/icd/server:configuration-data" ]
6545
}

0 commit comments

Comments
 (0)