Skip to content

Commit

Permalink
Making TestInetLayer an executable tool (project-chip#33985)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
Alami-Amine and restyled-commits authored Jun 19, 2024
1 parent b194ca5 commit ab42d43
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 334 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") {
"${chip_root}/examples/shell/standalone:chip-shell",
"${chip_root}/src/app/tests/integration:chip-im-initiator",
"${chip_root}/src/app/tests/integration:chip-im-responder",
"${chip_root}/src/inet/tests:inet-layer-test-tool",
"${chip_root}/src/lib/address_resolve:address-resolve-tool",
"${chip_root}/src/messaging/tests/echo:chip-echo-requester",
"${chip_root}/src/messaging/tests/echo:chip-echo-responder",
Expand Down
5 changes: 3 additions & 2 deletions build/chip/tests.gni
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

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

declare_args() {
Expand All @@ -40,6 +41,6 @@ declare_args() {
}

declare_args() {
# Enable use of nlfaultinjection.
chip_with_nlfaultinjection = chip_build_tests
# Enable use of nlfaultinjection when building tests or when building tools.
chip_with_nlfaultinjection = chip_build_tests || chip_build_tools
}
1 change: 1 addition & 0 deletions config/common/cmake/chip_gn.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ macro(matter_build target)
${CHIP_ROOT}/src/include
${CHIP_ROOT}/third_party/nlassert/repo/include
${CHIP_ROOT}/third_party/nlio/repo/include
${CHIP_ROOT}/third_party/nlfaultinjection/include
${CHIP_ROOT}/zzz_generated/app-common
${CMAKE_CURRENT_BINARY_DIR}/gen/include
)
Expand Down
75 changes: 42 additions & 33 deletions src/inet/tests/BUILD.gn
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@

import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")
import("//build_overrides/nlfaultinjection.gni")
import("//build_overrides/pigweed.gni")

import("${chip_root}/build/chip/chip_test_suite.gni")
import("${chip_root}/build/chip/tests.gni")
import("${chip_root}/build/chip/tools.gni")
import("${chip_root}/src/platform/device.gni")
import("${chip_root}/src/system/system.gni")

if (chip_build_tests) {
import("${chip_root}/build/chip/chip_test_suite.gni")
}

config("tests_config") {
include_dirs = [ "." ]
}
Expand All @@ -40,55 +45,59 @@ static_library("helpers") {
"TestSetupSignallingPosix.cpp",
]

if (current_os != "mbed") {
sources += [ "TestInetLayer.cpp" ]
}
cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/inet",
"${chip_root}/src/lib/core",
"${chip_root}/src/platform",
]

if (chip_with_nlfaultinjection) {
sources += [
"TestSetupFaultInjection.h",
"TestSetupFaultInjectionPosix.cpp",
]
}
}

cflags = [ "-Wconversion" ]
if (chip_build_tests) {
chip_test_suite("tests") {
output_name = "libInetLayerTests"

public_deps = [
"${chip_root}/src/inet",
"${chip_root}/src/lib/core",
"${chip_root}/src/platform",
]
public_configs = [ ":tests_config" ]

public_deps = [
":helpers",
"${chip_root}/src/inet",
"${chip_root}/src/lib/core",
]
test_sources = [
"TestBasicPacketFilters.cpp",
"TestInetAddress.cpp",
"TestInetErrorStr.cpp",
]
sources = []

if (chip_system_config_use_sockets && current_os != "zephyr") {
test_sources += [ "TestInetEndPoint.cpp" ]
}

cflags = [ "-Wconversion" ]
}
}

chip_test_suite("tests") {
output_name = "libInetLayerTests"
executable("inet-layer-test-tool") {
sources = [ "inet-layer-test-tool.cpp" ]

public_configs = [ ":tests_config" ]
cflags = [ "-Wconversion" ]

public_deps = [
":helpers",
"${chip_root}/src/inet",
"${chip_root}/src/lib/core",
"${chip_root}/src/platform",
]
test_sources = [
"TestBasicPacketFilters.cpp",
"TestInetAddress.cpp",
"TestInetErrorStr.cpp",
]
sources = []

if (chip_system_config_use_sockets && current_os != "zephyr") {
test_sources += [ "TestInetEndPoint.cpp" ]
}

# This fails on Raspberry Pi (Linux arm64), so only enable on Linux
# x64.
if (current_os != "mac" && current_os != "zephyr" &&
chip_device_platform != "esp32" && current_cpu == "x64" &&
chip_device_platform != "ameba") {
# TODO: This test does not seem executed
sources += [ "TestLwIPDNS.cpp" ]
}

cflags = [ "-Wconversion" ]
output_dir = root_out_dir
}
63 changes: 27 additions & 36 deletions src/inet/tests/TestInetCommonOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,43 +198,36 @@ bool NetworkOptions::HandleOption(const char * progName, OptionSet * optSet, int

FaultInjectionOptions::FaultInjectionOptions()
{
static OptionDef optionDefs[] = {
#if CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
{ "faults", kArgumentRequired, kToolCommonOpt_FaultInjection },
{ "iterations", kArgumentRequired, kToolCommonOpt_FaultTestIterations },
{ "debug-resource-usage", kNoArgument, kToolCommonOpt_DebugResourceUsage },
{ "print-fault-counters", kNoArgument, kToolCommonOpt_PrintFaultCounters },
{ "extra-cleanup-time", kArgumentRequired, kToolCommonOpt_ExtraCleanupTime },
#endif
{}
};
OptionDefs = optionDefs;
static OptionDef optionDefs[] = { { "faults", kArgumentRequired, kToolCommonOpt_FaultInjection },
{ "iterations", kArgumentRequired, kToolCommonOpt_FaultTestIterations },
{ "debug-resource-usage", kNoArgument, kToolCommonOpt_DebugResourceUsage },
{ "print-fault-counters", kNoArgument, kToolCommonOpt_PrintFaultCounters },
{ "extra-cleanup-time", kArgumentRequired, kToolCommonOpt_ExtraCleanupTime },
{} };
OptionDefs = optionDefs;

HelpGroupName = "FAULT INJECTION OPTIONS";

OptionHelp =
#if CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
" --faults <fault-string>\n"
" Inject specified fault(s) into the operation of the tool at runtime.\n"
"\n"
" --iterations <int>\n"
" Execute the program operation the given number of times\n"
"\n"
" --debug-resource-usage\n"
" Print all stats counters before exiting.\n"
"\n"
" --print-fault-counters\n"
" Print the fault-injection counters before exiting.\n"
"\n"
" --extra-cleanup-time\n"
" Allow extra time before asserting resource leaks; this is useful when\n"
" running fault-injection tests to let the system free stale ExchangeContext\n"
" instances after RMP has exhausted all retransmission; a failed RMP transmission\n"
" should fail a normal happy-sequence test, but not necessarily a fault-injection test.\n"
" The value is in milliseconds; a common value is 10000.\n"
"\n"
#endif
"";
OptionHelp = " --faults <fault-string>\n"
" Inject specified fault(s) into the operation of the tool at runtime.\n"
"\n"
" --iterations <int>\n"
" Execute the program operation the given number of times\n"
"\n"
" --debug-resource-usage\n"
" Print all stats counters before exiting.\n"
"\n"
" --print-fault-counters\n"
" Print the fault-injection counters before exiting.\n"
"\n"
" --extra-cleanup-time\n"
" Allow extra time before asserting resource leaks; this is useful when\n"
" running fault-injection tests to let the system free stale ExchangeContext\n"
" instances after RMP has exhausted all retransmission; a failed RMP transmission\n"
" should fail a normal happy-sequence test, but not necessarily a fault-injection test.\n"
" The value is in milliseconds; a common value is 10000.\n"
"\n"
"";

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

switch (id)
{
#if CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
case kToolCommonOpt_FaultInjection: {
chip::Platform::ScopedMemoryString mutableArg(arg, strlen(arg));
assert(mutableArg);
Expand Down Expand Up @@ -285,7 +277,6 @@ bool FaultInjectionOptions::HandleOption(const char * progName, OptionSet * optS
return false;
}
break;
#endif // CHIP_CONFIG_TEST || CHIP_SYSTEM_CONFIG_TEST || INET_CONFIG_TEST
default:
PrintArgError("%s: INTERNAL ERROR: Unhandled option: %s\n", progName, name);
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/inet/tests/TestInetLayerCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ extern bool IsSender();
extern bool IsTesting(const TestStatus & aTestStatus);
extern bool WasSuccessful(const TestStatus & aTestStatus);

extern chip::System::PacketBufferHandle MakeDataBuffer(uint16_t aDesiredLength, uint8_t aFirstValue);
extern chip::System::PacketBufferHandle MakeDataBuffer(uint16_t aDesiredLength);
extern chip::System::PacketBufferHandle MakeDataBuffer(size_t aDesiredLength, uint8_t aFirstValue);
extern chip::System::PacketBufferHandle MakeDataBuffer(size_t aDesiredLength);
extern chip::System::PacketBufferHandle MakeICMPv4DataBuffer(uint16_t aDesiredUserLength);
extern chip::System::PacketBufferHandle MakeICMPv6DataBuffer(uint16_t aDesiredUserLength);

Expand Down
Loading

0 comments on commit ab42d43

Please sign in to comment.