Skip to content

Commit ab42d43

Browse files
Making TestInetLayer an executable tool (#33985)
* making TestInetLayer an executable tool * allowing chip_with_nlfaultinjection for chip_build_tools * Restyled by clang-format * adding nlfaultinjection to CMake includes --------- Co-authored-by: Restyled.io <commits@restyled.io>
1 parent b194ca5 commit ab42d43

File tree

8 files changed

+77
-334
lines changed

8 files changed

+77
-334
lines changed

BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
161161
"${chip_root}/examples/shell/standalone:chip-shell",
162162
"${chip_root}/src/app/tests/integration:chip-im-initiator",
163163
"${chip_root}/src/app/tests/integration:chip-im-responder",
164+
"${chip_root}/src/inet/tests:inet-layer-test-tool",
164165
"${chip_root}/src/lib/address_resolve:address-resolve-tool",
165166
"${chip_root}/src/messaging/tests/echo:chip-echo-requester",
166167
"${chip_root}/src/messaging/tests/echo:chip-echo-responder",

build/chip/tests.gni

100644100755
+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
1717

18+
import("${chip_root}/build/chip/tools.gni")
1819
import("${chip_root}/src/platform/device.gni")
1920

2021
declare_args() {
@@ -40,6 +41,6 @@ declare_args() {
4041
}
4142

4243
declare_args() {
43-
# Enable use of nlfaultinjection.
44-
chip_with_nlfaultinjection = chip_build_tests
44+
# Enable use of nlfaultinjection when building tests or when building tools.
45+
chip_with_nlfaultinjection = chip_build_tests || chip_build_tools
4546
}

config/common/cmake/chip_gn.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ macro(matter_build target)
158158
${CHIP_ROOT}/src/include
159159
${CHIP_ROOT}/third_party/nlassert/repo/include
160160
${CHIP_ROOT}/third_party/nlio/repo/include
161+
${CHIP_ROOT}/third_party/nlfaultinjection/include
161162
${CHIP_ROOT}/zzz_generated/app-common
162163
${CMAKE_CURRENT_BINARY_DIR}/gen/include
163164
)

src/inet/tests/BUILD.gn

100644100755
+42-33
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414

1515
import("//build_overrides/build.gni")
1616
import("//build_overrides/chip.gni")
17+
import("//build_overrides/nlfaultinjection.gni")
1718
import("//build_overrides/pigweed.gni")
1819

19-
import("${chip_root}/build/chip/chip_test_suite.gni")
2020
import("${chip_root}/build/chip/tests.gni")
21+
import("${chip_root}/build/chip/tools.gni")
2122
import("${chip_root}/src/platform/device.gni")
2223
import("${chip_root}/src/system/system.gni")
2324

25+
if (chip_build_tests) {
26+
import("${chip_root}/build/chip/chip_test_suite.gni")
27+
}
28+
2429
config("tests_config") {
2530
include_dirs = [ "." ]
2631
}
@@ -40,55 +45,59 @@ static_library("helpers") {
4045
"TestSetupSignallingPosix.cpp",
4146
]
4247

43-
if (current_os != "mbed") {
44-
sources += [ "TestInetLayer.cpp" ]
45-
}
48+
cflags = [ "-Wconversion" ]
49+
50+
public_deps = [
51+
"${chip_root}/src/inet",
52+
"${chip_root}/src/lib/core",
53+
"${chip_root}/src/platform",
54+
]
4655

4756
if (chip_with_nlfaultinjection) {
4857
sources += [
4958
"TestSetupFaultInjection.h",
5059
"TestSetupFaultInjectionPosix.cpp",
5160
]
5261
}
62+
}
5363

54-
cflags = [ "-Wconversion" ]
64+
if (chip_build_tests) {
65+
chip_test_suite("tests") {
66+
output_name = "libInetLayerTests"
5567

56-
public_deps = [
57-
"${chip_root}/src/inet",
58-
"${chip_root}/src/lib/core",
59-
"${chip_root}/src/platform",
60-
]
68+
public_configs = [ ":tests_config" ]
69+
70+
public_deps = [
71+
":helpers",
72+
"${chip_root}/src/inet",
73+
"${chip_root}/src/lib/core",
74+
]
75+
test_sources = [
76+
"TestBasicPacketFilters.cpp",
77+
"TestInetAddress.cpp",
78+
"TestInetErrorStr.cpp",
79+
]
80+
sources = []
81+
82+
if (chip_system_config_use_sockets && current_os != "zephyr") {
83+
test_sources += [ "TestInetEndPoint.cpp" ]
84+
}
85+
86+
cflags = [ "-Wconversion" ]
87+
}
6188
}
6289

63-
chip_test_suite("tests") {
64-
output_name = "libInetLayerTests"
90+
executable("inet-layer-test-tool") {
91+
sources = [ "inet-layer-test-tool.cpp" ]
6592

66-
public_configs = [ ":tests_config" ]
93+
cflags = [ "-Wconversion" ]
6794

6895
public_deps = [
6996
":helpers",
7097
"${chip_root}/src/inet",
7198
"${chip_root}/src/lib/core",
99+
"${chip_root}/src/platform",
72100
]
73-
test_sources = [
74-
"TestBasicPacketFilters.cpp",
75-
"TestInetAddress.cpp",
76-
"TestInetErrorStr.cpp",
77-
]
78-
sources = []
79-
80-
if (chip_system_config_use_sockets && current_os != "zephyr") {
81-
test_sources += [ "TestInetEndPoint.cpp" ]
82-
}
83101

84-
# This fails on Raspberry Pi (Linux arm64), so only enable on Linux
85-
# x64.
86-
if (current_os != "mac" && current_os != "zephyr" &&
87-
chip_device_platform != "esp32" && current_cpu == "x64" &&
88-
chip_device_platform != "ameba") {
89-
# TODO: This test does not seem executed
90-
sources += [ "TestLwIPDNS.cpp" ]
91-
}
92-
93-
cflags = [ "-Wconversion" ]
102+
output_dir = root_out_dir
94103
}

src/inet/tests/TestInetCommonOptions.cpp

+27-36
Original file line numberDiff line numberDiff line change
@@ -198,43 +198,36 @@ bool NetworkOptions::HandleOption(const char * progName, OptionSet * optSet, int
198198

199199
FaultInjectionOptions::FaultInjectionOptions()
200200
{
201-
static OptionDef optionDefs[] = {
202-
#if CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
203-
{ "faults", kArgumentRequired, kToolCommonOpt_FaultInjection },
204-
{ "iterations", kArgumentRequired, kToolCommonOpt_FaultTestIterations },
205-
{ "debug-resource-usage", kNoArgument, kToolCommonOpt_DebugResourceUsage },
206-
{ "print-fault-counters", kNoArgument, kToolCommonOpt_PrintFaultCounters },
207-
{ "extra-cleanup-time", kArgumentRequired, kToolCommonOpt_ExtraCleanupTime },
208-
#endif
209-
{}
210-
};
211-
OptionDefs = optionDefs;
201+
static OptionDef optionDefs[] = { { "faults", kArgumentRequired, kToolCommonOpt_FaultInjection },
202+
{ "iterations", kArgumentRequired, kToolCommonOpt_FaultTestIterations },
203+
{ "debug-resource-usage", kNoArgument, kToolCommonOpt_DebugResourceUsage },
204+
{ "print-fault-counters", kNoArgument, kToolCommonOpt_PrintFaultCounters },
205+
{ "extra-cleanup-time", kArgumentRequired, kToolCommonOpt_ExtraCleanupTime },
206+
{} };
207+
OptionDefs = optionDefs;
212208

213209
HelpGroupName = "FAULT INJECTION OPTIONS";
214210

215-
OptionHelp =
216-
#if CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
217-
" --faults <fault-string>\n"
218-
" Inject specified fault(s) into the operation of the tool at runtime.\n"
219-
"\n"
220-
" --iterations <int>\n"
221-
" Execute the program operation the given number of times\n"
222-
"\n"
223-
" --debug-resource-usage\n"
224-
" Print all stats counters before exiting.\n"
225-
"\n"
226-
" --print-fault-counters\n"
227-
" Print the fault-injection counters before exiting.\n"
228-
"\n"
229-
" --extra-cleanup-time\n"
230-
" Allow extra time before asserting resource leaks; this is useful when\n"
231-
" running fault-injection tests to let the system free stale ExchangeContext\n"
232-
" instances after RMP has exhausted all retransmission; a failed RMP transmission\n"
233-
" should fail a normal happy-sequence test, but not necessarily a fault-injection test.\n"
234-
" The value is in milliseconds; a common value is 10000.\n"
235-
"\n"
236-
#endif
237-
"";
211+
OptionHelp = " --faults <fault-string>\n"
212+
" Inject specified fault(s) into the operation of the tool at runtime.\n"
213+
"\n"
214+
" --iterations <int>\n"
215+
" Execute the program operation the given number of times\n"
216+
"\n"
217+
" --debug-resource-usage\n"
218+
" Print all stats counters before exiting.\n"
219+
"\n"
220+
" --print-fault-counters\n"
221+
" Print the fault-injection counters before exiting.\n"
222+
"\n"
223+
" --extra-cleanup-time\n"
224+
" Allow extra time before asserting resource leaks; this is useful when\n"
225+
" running fault-injection tests to let the system free stale ExchangeContext\n"
226+
" instances after RMP has exhausted all retransmission; a failed RMP transmission\n"
227+
" should fail a normal happy-sequence test, but not necessarily a fault-injection test.\n"
228+
" The value is in milliseconds; a common value is 10000.\n"
229+
"\n"
230+
"";
238231

239232
// Defaults
240233
TestIterations = 1;
@@ -253,7 +246,6 @@ bool FaultInjectionOptions::HandleOption(const char * progName, OptionSet * optS
253246

254247
switch (id)
255248
{
256-
#if CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
257249
case kToolCommonOpt_FaultInjection: {
258250
chip::Platform::ScopedMemoryString mutableArg(arg, strlen(arg));
259251
assert(mutableArg);
@@ -285,7 +277,6 @@ bool FaultInjectionOptions::HandleOption(const char * progName, OptionSet * optS
285277
return false;
286278
}
287279
break;
288-
#endif // CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
289280
default:
290281
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", progName, name);
291282
return false;

src/inet/tests/TestInetLayerCommon.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ extern bool IsSender();
126126
extern bool IsTesting(const TestStatus & aTestStatus);
127127
extern bool WasSuccessful(const TestStatus & aTestStatus);
128128

129-
extern chip::System::PacketBufferHandle MakeDataBuffer(uint16_t aDesiredLength, uint8_t aFirstValue);
130-
extern chip::System::PacketBufferHandle MakeDataBuffer(uint16_t aDesiredLength);
129+
extern chip::System::PacketBufferHandle MakeDataBuffer(size_t aDesiredLength, uint8_t aFirstValue);
130+
extern chip::System::PacketBufferHandle MakeDataBuffer(size_t aDesiredLength);
131131
extern chip::System::PacketBufferHandle MakeICMPv4DataBuffer(uint16_t aDesiredUserLength);
132132
extern chip::System::PacketBufferHandle MakeICMPv6DataBuffer(uint16_t aDesiredUserLength);
133133

0 commit comments

Comments
 (0)