Skip to content

Commit

Permalink
Integrate transport tests to QEMU (project-chip#1200)
Browse files Browse the repository at this point in the history
* Integrate transport tests to QEMU

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
pan-apple and restyled-commits authored Jun 23, 2020
1 parent aa82588 commit fe78fd2
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 19 deletions.
1 change: 1 addition & 0 deletions scripts/tests/esp32_qemu_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
52 changes: 38 additions & 14 deletions src/transport/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions src/transport/tests/TestMessageHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
#include "TestTransportLayer.h"

#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/TestUtils.h>
#include <transport/MessageHeader.h>

#include <nlunit-test.h>
Expand Down Expand Up @@ -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);
}
9 changes: 8 additions & 1 deletion src/transport/tests/TestPeerConnections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/
#include "TestTransportLayer.h"

#include <support/CodeUtils.h>
#include <support/ErrorStr.h>
#include <support/TestUtils.h>
#include <transport/PeerConnections.h>

#include <nlunit-test.h>
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/transport/tests/TestPeerConnectionsDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
int main(void)
{
nlTestSetOutputStyle(OUTPUT_CSV);
return TestPeerConnections();
return TestPeerConnectionsFn();
}
6 changes: 6 additions & 0 deletions src/transport/tests/TestSecureSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <stdarg.h>
#include <support/CodeUtils.h>
#include <support/TestUtils.h>

using namespace chip;

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/transport/tests/TestSecureSessionMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/transport/tests/TestTransportLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/transport/tests/TestUDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/transport/tests/qemu_transport_tests.sh

0 comments on commit fe78fd2

Please sign in to comment.