Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move src/transport/tests to auto-test-driver generation #3999

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# Build System
out/
/src/test_driver/nrfconnect/build/

# Temporary Directories
.tmp/
Expand Down
34 changes: 24 additions & 10 deletions scripts/tests/esp32_qemu_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

set -e
set -o pipefail
set -x

here=$(cd "$(dirname "$0")" && pwd)
chip_dir="$here"/../..
Expand All @@ -41,31 +42,44 @@ if [ $? -ne 0 ]; then
fi

really_run_suite() {
idf scripts/tools/qemu_run_test.sh src/test_driver/esp32/build/chip "$1"
idf scripts/tools/qemu_run_test.sh src/test_driver/esp32/build/chip "$1" "$2"
}

run_suite() {
if [[ -d "${log_dir}" ]]; then
suite=${1%.a}
suite=${suite#lib}
really_run_suite "$1" |& tee "$log_dir/$suite.log"
really_run_suite "$1" "$2" |& tee "$log_dir/$suite.log"
else
really_run_suite "$1"
really_run_suite "$1" "$2"
fi
}

# Currently only crypto, inet, and system tests are configured to run on QEMU.
# The specific qualifiers will be removed, once all CHIP unit tests are
# updated to run on QEMU.
SUITES=(
libInetLayerTests.a
libSystemLayerTests.a
libTransportLayerTests.a
)

for suite in "${SUITES[@]}"; do
run_suite "$suite"
done
run_suite libAppTests.a
run_suite libASN1Tests.a
run_suite libBleLayerTests.a
run_suite libCoreTests.a
run_suite libInetLayerTests.a
run_suite libRetransmitTests.a
run_suite libSystemLayerTests.a

# TODO: Transport layer tests do not link:
# - getpid undefined
# - ArgParser for IPAddresses are not linked in
# - std::__throw_bad_alloc() linker errors
# run_suite libRawTransportTests.a "-lNetworkTestHelpers -lInetTestHelpers"

# TODO: Transport layer tests do not link:
# - getpid undefined
# - ArgParser for IPAddresses are not linked in
# - std::__throw_bad_alloc() linker errors
# run_suite libTransportLayerTests.a "-lNetworkTestHelpers -lInetTestHelpers"

# TODO - Fix crypto tests.
run_suite libChipCryptoTests.a || true
# run_suite libChipCryptoTests.a || true
4 changes: 3 additions & 1 deletion scripts/tools/qemu_run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#

set -e
set -x

die() {
echo "${me:?}: *** ERROR: " "${*}"
Expand All @@ -32,10 +33,11 @@ BUILD_DIR="$1"
shift
QEMU_TEST_TARGET="$1"
shift
EXTRA_COMPILE_ARGUMENTS="$*" # generally -lFooHelperLibrary

# shellcheck source=/dev/null
source "$BUILD_DIR"/env.sh
bash "$BUILD_DIR"/esp32_elf_builder.sh "$BUILD_DIR/lib/$QEMU_TEST_TARGET"
bash "$BUILD_DIR"/esp32_elf_builder.sh "$BUILD_DIR/lib/$QEMU_TEST_TARGET" "$EXTRA_COMPILE_ARGUMENTS"

flash_image_file=$(mktemp)
log_file=$(mktemp)
Expand Down
15 changes: 7 additions & 8 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ if (chip_build_tests) {
"${chip_root}/src/app/tests",
"${chip_root}/src/crypto/tests",
"${chip_root}/src/inet/tests",
"${chip_root}/src/lib/asn1/tests",
"${chip_root}/src/lib/core/tests",
"${chip_root}/src/lib/mdns/minimal/tests",
"${chip_root}/src/lib/support/tests",
"${chip_root}/src/messaging/tests",
"${chip_root}/src/protocols/bdx/tests",
"${chip_root}/src/setup_payload/tests",
"${chip_root}/src/system/tests",
"${chip_root}/src/transport/raw/tests",
"${chip_root}/src/transport/retransmit/tests",
Expand All @@ -54,16 +59,10 @@ if (chip_build_tests) {
}

if (chip_device_platform != "esp32") {
deps += [
"${chip_root}/src/lib/asn1/tests",
"${chip_root}/src/lib/core/tests",
"${chip_root}/src/lib/support/tests",
"${chip_root}/src/platform/tests",
"${chip_root}/src/setup_payload/tests",
]
deps += [ "${chip_root}/src/platform/tests" ]
}

if (chip_config_network_layer_ble && chip_device_platform != "esp32") {
if (chip_config_network_layer_ble) {
deps += [ "${chip_root}/src/ble/tests" ]
}

Expand Down
40 changes: 30 additions & 10 deletions src/inet/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,9 @@ config("tests_config") {
include_dirs = [ "." ]
}

chip_test_suite("tests") {
output_name = "libInetLayerTests"

test_sources = [
"TestInetAddress.cpp",
"TestInetEndPoint.cpp",
"TestInetErrorStr.cpp",
]
static_library("helpers") {
output_name = "libInetTestHelpers"
output_dir = "${root_out_dir}/lib"

sources = [
"TestInetCommon.cpp",
Expand All @@ -49,19 +44,44 @@ chip_test_suite("tests") {
]
}

cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/inet",
"${chip_root}/src/lib/core",
"${nlunit_test_root}:nlunit-test",
]
}

chip_test_suite("tests") {
output_name = "libInetLayerTests"

public_configs = [ ":tests_config" ]

public_deps = [
":helpers",
"${chip_root}/src/inet",
"${chip_root}/src/lib/core",
"${nlunit_test_root}:nlunit-test",
]

test_sources = [
"TestInetAddress.cpp",
"TestInetErrorStr.cpp",
]
sources = []

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

# This fails on Raspberry Pi (Linux arm64), so only enable on Linux
# x64.
if (current_os != "mac" && chip_device_platform != "esp32" &&
current_cpu == "x64") {
if (current_os != "mac" && current_os != "zephyr" &&
chip_device_platform != "esp32" && current_cpu == "x64") {
test_sources += [ "TestInetLayerDNS.cpp" ]

# TODO: This test does not seem executed
sources += [ "TestLwIPDNS.cpp" ]
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/inet/tests/TestInetCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,10 @@ void DumpMemory(const uint8_t * mem, uint32_t len, const char * prefix)

static void RebootCallbackFn()
{
int i;
int j = 0;
size_t i;
size_t j = 0;
chip::Platform::ScopedMemoryBuffer<char *> lArgv;
if (!lArgv.Alloc(sRestartCallbackCtx.mArgc + 2))
if (!lArgv.Alloc(static_cast<size_t>(sRestartCallbackCtx.mArgc + 2)))
{
printf("** failed to allocate memory **\n");
ExitNow();
Expand All @@ -697,19 +697,19 @@ static void RebootCallbackFn()

lArgv[j] = nullptr;

for (i = 0; lArgv[i] != nullptr; i++)
for (size_t idx = 0; lArgv[idx] != nullptr; idx++)
{
printf("argv[%d]: %s\n", i, lArgv[i]);
printf("argv[%d]: %s\n", static_cast<int>(idx), lArgv[idx]);
}

// Need to close any open file descriptor above stdin/out/err.
// There is no portable way to get the max fd number.
// Given that CHIP's test apps don't open a large number of files,
// FD_SETSIZE should be a reasonable upper bound (see the documentation
// of select).
for (i = 3; i < FD_SETSIZE; i++)
for (int fd = 3; fd < FD_SETSIZE; fd++)
{
close(i);
close(fd);
}

printf("********** Restarting *********\n");
Expand Down
8 changes: 4 additions & 4 deletions src/inet/tests/TestInetLayerCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ static PacketBufferHandle MakeICMPDataBuffer(uint16_t aDesiredUserLength, uint16
// To ensure there is enough room for the user data and the ICMP
// header, include both the user data size and the ICMP header length.

lBuffer = MakeDataBuffer(aDesiredUserLength + aHeaderLength, aPatternStartOffset);
lBuffer = MakeDataBuffer(static_cast<uint16_t>(aDesiredUserLength + aHeaderLength), aPatternStartOffset);

if (!lBuffer.IsNull())
{
Expand All @@ -210,7 +210,7 @@ static PacketBufferHandle MakeICMPDataBuffer(uint16_t aDesiredUserLength, uint16
lHeader->mType = aType;
lHeader->mCode = 0;
lHeader->mChecksum = 0;
lHeader->mID = rand() & UINT16_MAX;
lHeader->mID = static_cast<uint16_t>(rand() & UINT16_MAX);
lHeader->mSequenceNumber = nlByteOrderSwap16HostToBig(lSequenceNumber++);
}

Expand Down Expand Up @@ -268,8 +268,8 @@ static bool HandleDataReceived(const PacketBufferHandle & aBuffer, TransferStats
VerifyOrExit(lStatus == true, );
}

lTotalDataLength += lBuffer->DataLength();
aFirstValue += lBuffer->DataLength();
lTotalDataLength = static_cast<uint16_t>(lTotalDataLength + lBuffer->DataLength());
aFirstValue = static_cast<uint8_t>(aFirstValue + lBuffer->DataLength());
}

// If we are accumulating stats by packet rather than by size,
Expand Down
2 changes: 1 addition & 1 deletion src/messaging/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ chip_test_suite("tests") {
cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/inet/tests:tests_common",
"${chip_root}/src/inet/tests:helpers",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/messaging",
Expand Down
11 changes: 7 additions & 4 deletions src/test_driver/esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ PROJECT_NAME := chip-tests

CXXFLAGS += -DCHIP_SUPPORT_FOREIGN_TEST_DRIVERS -DCHIP_TARGET_STYLE_EMBEDDED -Wno-deprecated-declarations

CXXFLAGS += -DLWIP_IPV6_SCOPES=0
CXXFLAGS += -DLWIP_IPV6_SCOPES=0 -std=gnu++14
CPPFLAGS += -DLWIP_IPV6_SCOPES=0 -DCHIP_HAVE_CONFIG_H
CFLAGS += -DLWIP_IPV6_SCOPES=0
CFLAGS += -DLWIP_IPV6_SCOPES=0 -std=gnu11

EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/third_party/connectedhomeip/config/esp32/components

include $(IDF_PATH)/make/project.mk

esp32_elf_builder: all
mkdir -p build/chip/
echo $(CC) -L$(PROJECT_PATH)/build/chip/lib -Wl,--whole-archive '$$1' -Wl,--no-whole-archive \
-lnlunit-test $(LDFLAGS) -lnlfaultinjection -o $(PROJECT_PATH)/build/chip-tests.elf -Wl,-Map=$(APP_MAP) > build/chip/esp32_elf_builder.sh
echo "#!/bin/sh" > build/chip/esp32_elf_builder.sh
echo set -e >> build/chip/esp32_elf_builder.sh
echo set -x >> build/chip/esp32_elf_builder.sh
echo $(CXX) $(CXXFLAGS) $(CPPFLAGS) -L$(PROJECT_PATH)/build/chip/lib -Wl,--whole-archive '$$1' -Wl,--no-whole-archive \
-lnlunit-test $(LDFLAGS) -lnlfaultinjection '$$2' -o $(PROJECT_PATH)/build/chip-tests.elf -Wl,-Map=$(APP_MAP) >> build/chip/esp32_elf_builder.sh
echo $(ESPTOOLPY) elf2image $(ESPTOOL_FLASH_OPTIONS) $(ESPTOOL_ELF2IMAGE_OPTIONS) \
-o $(PROJECT_PATH)/build/chip/chip-tests.bin $(PROJECT_PATH)/build/chip-tests.elf >> build/chip/esp32_elf_builder.sh
ln -sf $(PROJECT_PATH)/build/partitions.bin $(PROJECT_PATH)/build/chip/partitions.bin
Expand Down
19 changes: 15 additions & 4 deletions src/test_driver/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,28 @@ set(CHIP_COMMON_FLAGS

set(CHIP_LIBRARIES
-lCHIP
-lInetLayerTests
-lInetTestHelpers
-lNetworkTestHelpers
-lnlunit-test
)

set(CHIP_TESTS
-lSupportTests
# TODO: this list is hard to maintain manually (and currently incomplete).
# An automated way that includes figuring out dependencies would be much better
-lAppTests
-lASN1Tests
-lBleLayerTests
-lChipCryptoTests
-lCoreTests
-lInetLayerTests
-lMessagingLayerTests
-lPlatformTests
# TODO: raw transport tests fail by running out of TCP/UDP endpoints
# -lRawTransportTests
-lRetransmitTests
-lSupportTests
-lSystemLayerTests
-lTransportLayerTests
-lChipCryptoTests
-lPlatformTests
)

# ==================================================
Expand Down
5 changes: 3 additions & 2 deletions src/transport/raw/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import("${chip_root}/build/chip/chip_test_suite.gni")

static_library("helpers") {
output_name = "libNetworkTestHelpers"
output_dir = "${root_out_dir}/lib"

sources = [
"NetworkTestHelpers.cpp",
Expand All @@ -28,7 +29,7 @@ static_library("helpers") {

cflags = [ "-Wconversion" ]

public_deps = [ "${chip_root}/src/inet/tests:tests_common" ]
public_deps = [ "${chip_root}/src/inet/tests:helpers" ]
}

chip_test_suite("tests") {
Expand All @@ -45,7 +46,7 @@ chip_test_suite("tests") {

public_deps = [
":helpers",
"${chip_root}/src/inet/tests:tests_common",
"${chip_root}/src/inet/tests:helpers",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/transport/raw",
Expand Down
2 changes: 1 addition & 1 deletion src/transport/raw/tests/NetworkTestHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "NetworkTestHelpers.h"

#include "TestInetCommon.h"
#include <inet/tests/TestInetCommon.h>

#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
Expand Down
12 changes: 2 additions & 10 deletions src/transport/tests/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,22 @@ import("${chip_root}/build/chip/chip_test_suite.gni")
chip_test_suite("tests") {
output_name = "libTransportLayerTests"

sources = [
test_sources = [
"TestPeerConnections.cpp",
"TestSecurePairingSession.cpp",
"TestSecureSession.cpp",
"TestSecureSessionMgr.cpp",
"TestTransportLayer.h",
]

cflags = [ "-Wconversion" ]

public_deps = [
"${chip_root}/src/inet/tests:tests_common",
"${chip_root}/src/inet/tests:helpers",
"${chip_root}/src/lib/core",
"${chip_root}/src/lib/support",
"${chip_root}/src/transport",
"${chip_root}/src/transport/raw/tests:helpers",
"${nlio_root}:nlio",
"${nlunit_test_root}:nlunit-test",
]

tests = [
"TestPeerConnections",
"TestSecurePairingSession",
"TestSecureSession",
"TestSecureSessionMgr",
]
}
Loading