From fe78fd2701f9a1d0fd8fb746b3f66252840381f9 Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Tue, 23 Jun 2020 08:25:35 -0700 Subject: [PATCH] Integrate transport tests to QEMU (#1200) * Integrate transport tests to QEMU * Restyled by clang-format Co-authored-by: Restyled.io --- scripts/tests/esp32_qemu_tests.sh | 1 + src/transport/tests/Makefile.am | 52 ++++++++++++++----- src/transport/tests/TestMessageHeader.cpp | 7 +++ src/transport/tests/TestPeerConnections.cpp | 9 +++- .../tests/TestPeerConnectionsDriver.cpp | 2 +- src/transport/tests/TestSecureSession.cpp | 6 +++ src/transport/tests/TestSecureSessionMgr.cpp | 2 +- src/transport/tests/TestTransportLayer.h | 2 +- src/transport/tests/TestUDP.cpp | 2 +- src/transport/tests/qemu_transport_tests.sh | 1 + 10 files changed, 65 insertions(+), 19 deletions(-) create mode 120000 src/transport/tests/qemu_transport_tests.sh diff --git a/scripts/tests/esp32_qemu_tests.sh b/scripts/tests/esp32_qemu_tests.sh index 3c0999fe22531b..0e3dd682d621f2 100755 --- a/scripts/tests/esp32_qemu_tests.sh +++ b/scripts/tests/esp32_qemu_tests.sh @@ -32,3 +32,4 @@ source "$chip_dir"/src/test_driver/esp32/idf.sh idf make V=1 -C "$chip_dir"/src/test_driver/esp32/build/chip/src/crypto check idf make V=1 -C "$chip_dir"/src/test_driver/esp32/build/chip/src/inet check idf make V=1 -C "$chip_dir"/src/test_driver/esp32/build/chip/src/system check +idf make V=1 -C "$chip_dir"/src/test_driver/esp32/build/chip/src/transport check diff --git a/src/transport/tests/Makefile.am b/src/transport/tests/Makefile.am index 044cd45bd5321b..33f81518a6a467 100644 --- a/src/transport/tests/Makefile.am +++ b/src/transport/tests/Makefile.am @@ -76,34 +76,58 @@ COMMON_LDADD = \ libTransportLayerTests.a \ $(COMMON_LDFLAGS) \ $(CHIP_LDADD) \ - $(NLFAULTINJECTION_LDFLAGS) $(NLFAULTINJECTION_LIBS) \ + $(NLFAULTINJECTION_LDFLAGS) \ + $(NLFAULTINJECTION_LIBS) \ $(NLUNIT_TEST_LDFLAGS) $(NLUNIT_TEST_LIBS) \ $(LWIP_LDFLAGS) $(LWIP_LIBS) \ $(SOCKETS_LDFLAGS) $(SOCKETS_LIBS) \ $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) \ $(NULL) +# The additional environment variables and their values that will be +# made available to all programs and scripts in TESTS. + +TESTS_ENVIRONMENT = \ + $(NULL) + # Test applications that should be run when the 'check' target is run. -check_PROGRAMS = \ - TestMessageHeader \ - TestPeerConnections \ - TestSecureSessionMgr \ - TestSecureSession \ - TestUDP \ +check_PROGRAMS = \ $(NULL) -# Test applications and scripts that should be built and run when the -# 'check' target is run. +check_SCRIPTS = \ + $(NULL) -TESTS = \ - $(check_PROGRAMS) \ +if CHIP_DEVICE_LAYER_TARGET_ESP32 + +check_SCRIPTS += \ + qemu_transport_tests.sh \ $(NULL) -# The additional environment variables and their values that will be -# made available to all programs and scripts in TESTS. +TESTS_ENVIRONMENT += \ + abs_top_srcdir='$(abs_top_srcdir)' \ + abs_top_builddir='$(abs_top_builddir)' \ + QEMU_TEST_TARGET=libTransportLayerTests.a \ + $(NULL) + +else # CHIP_DEVICE_LAYER_TARGET_ESP32 + +check_PROGRAMS += \ + TestMessageHeader \ + TestPeerConnections \ + TestSecureSessionMgr \ + TestSecureSession \ + TestUDP \ + $(NULL) + +endif # CHIP_DEVICE_LAYER_TARGET_ESP32 + +# Test applications and scripts that should be built and run when the +# 'check' target is run. -TESTS_ENVIRONMENT = \ +TESTS = \ + $(check_PROGRAMS) \ + $(check_SCRIPTS) \ $(NULL) # Source, compiler, and linker options for test programs. diff --git a/src/transport/tests/TestMessageHeader.cpp b/src/transport/tests/TestMessageHeader.cpp index bfffb0b20b326d..c700ef9ac705c4 100644 --- a/src/transport/tests/TestMessageHeader.cpp +++ b/src/transport/tests/TestMessageHeader.cpp @@ -24,7 +24,9 @@ */ #include "TestTransportLayer.h" +#include #include +#include #include #include @@ -148,3 +150,8 @@ int TestMessageHeader(void) nlTestRunner(&theSuite, NULL); return nlTestRunnerStats(&theSuite); } + +static void __attribute__((constructor)) TestMessageHeaderCtor(void) +{ + VerifyOrDie(RegisterUnitTests(&TestMessageHeader) == CHIP_NO_ERROR); +} diff --git a/src/transport/tests/TestPeerConnections.cpp b/src/transport/tests/TestPeerConnections.cpp index b71b7b417e83d5..5d4d711443baf4 100644 --- a/src/transport/tests/TestPeerConnections.cpp +++ b/src/transport/tests/TestPeerConnections.cpp @@ -24,7 +24,9 @@ */ #include "TestTransportLayer.h" +#include #include +#include #include #include @@ -236,9 +238,14 @@ static const nlTest sTests[] = }; // clang-format on -int TestPeerConnections(void) +int TestPeerConnectionsFn(void) { nlTestSuite theSuite = { "Transport-PeerConnections", &sTests[0], NULL, NULL }; nlTestRunner(&theSuite, NULL); return nlTestRunnerStats(&theSuite); } + +static void __attribute__((constructor)) TestPeerConnectionsCtor(void) +{ + VerifyOrDie(RegisterUnitTests(&TestPeerConnectionsFn) == CHIP_NO_ERROR); +} diff --git a/src/transport/tests/TestPeerConnectionsDriver.cpp b/src/transport/tests/TestPeerConnectionsDriver.cpp index 75ec048bc3a7bd..818ee8288e8c63 100644 --- a/src/transport/tests/TestPeerConnectionsDriver.cpp +++ b/src/transport/tests/TestPeerConnectionsDriver.cpp @@ -30,5 +30,5 @@ int main(void) { nlTestSetOutputStyle(OUTPUT_CSV); - return TestPeerConnections(); + return TestPeerConnectionsFn(); } diff --git a/src/transport/tests/TestSecureSession.cpp b/src/transport/tests/TestSecureSession.cpp index e772ac7f1c89bc..73cd6617f9c5a8 100644 --- a/src/transport/tests/TestSecureSession.cpp +++ b/src/transport/tests/TestSecureSession.cpp @@ -31,6 +31,7 @@ #include #include +#include using namespace chip; @@ -208,6 +209,11 @@ int TestSecureSession() return (nlTestRunnerStats(&sSuite)); } +static void __attribute__((constructor)) TestSecureSessionCtor(void) +{ + VerifyOrDie(RegisterUnitTests(&TestSecureSession) == CHIP_NO_ERROR); +} + namespace chip { namespace Logging { void LogV(uint8_t module, uint8_t category, const char * format, va_list argptr) diff --git a/src/transport/tests/TestSecureSessionMgr.cpp b/src/transport/tests/TestSecureSessionMgr.cpp index 88b449be7ed589..f7325c27f499ba 100644 --- a/src/transport/tests/TestSecureSessionMgr.cpp +++ b/src/transport/tests/TestSecureSessionMgr.cpp @@ -117,7 +117,7 @@ static void DriveIO(TestContext & ctx) #endif } -CHIP_ERROR InitLayers(System::Layer & systemLayer, InetLayer & inetLayer) +static CHIP_ERROR InitLayers(System::Layer & systemLayer, InetLayer & inetLayer) { CHIP_ERROR err = CHIP_NO_ERROR; // Initialize the CHIP System Layer. diff --git a/src/transport/tests/TestTransportLayer.h b/src/transport/tests/TestTransportLayer.h index 293397ffd615b4..285feeb814f0d2 100644 --- a/src/transport/tests/TestTransportLayer.h +++ b/src/transport/tests/TestTransportLayer.h @@ -30,7 +30,7 @@ extern "C" { #endif int TestMessageHeader(void); -int TestPeerConnections(void); +int TestPeerConnectionsFn(void); int TestSecureSession(void); int TestSecureSessionMgr(void); int TestUDP(void); diff --git a/src/transport/tests/TestUDP.cpp b/src/transport/tests/TestUDP.cpp index ab03afd791ca93..edc9daf2a21eb2 100644 --- a/src/transport/tests/TestUDP.cpp +++ b/src/transport/tests/TestUDP.cpp @@ -112,7 +112,7 @@ void DriveIO(TestContext & ctx) } // namespace -CHIP_ERROR InitLayers(System::Layer & systemLayer, InetLayer & inetLayer) +static CHIP_ERROR InitLayers(System::Layer & systemLayer, InetLayer & inetLayer) { CHIP_ERROR err = CHIP_NO_ERROR; // Initialize the CHIP System Layer. diff --git a/src/transport/tests/qemu_transport_tests.sh b/src/transport/tests/qemu_transport_tests.sh new file mode 120000 index 00000000000000..8fbe617c97a267 --- /dev/null +++ b/src/transport/tests/qemu_transport_tests.sh @@ -0,0 +1 @@ +../../../scripts/tools/qemu_run_test.sh \ No newline at end of file