From 1c0e48a2cebadb6601dfbe8d1d68909e4d54d730 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 24 Feb 2021 18:37:46 +0100 Subject: [PATCH] New test suite: net A place to put tests for the net_sockets module (MBEDTLS_NET_C feature). Start with a context smoke test. Signed-off-by: Gilles Peskine --- tests/CMakeLists.txt | 1 + tests/suites/test_suite_net.data | 6 ++++++ tests/suites/test_suite_net.function | 28 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/suites/test_suite_net.data create mode 100644 tests/suites/test_suite_net.function diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e2bc42018..fb604271d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -134,6 +134,7 @@ add_test_suite(md) add_test_suite(mdx) add_test_suite(memory_buffer_alloc) add_test_suite(mpi) +add_test_suite(net) add_test_suite(nist_kw) add_test_suite(oid) add_test_suite(pem) diff --git a/tests/suites/test_suite_net.data b/tests/suites/test_suite_net.data new file mode 100644 index 000000000..98da8d99e --- /dev/null +++ b/tests/suites/test_suite_net.data @@ -0,0 +1,6 @@ +Context init-free-free +context_init_free:0 + +Context init-free-init-free +context_init_free:1 + diff --git a/tests/suites/test_suite_net.function b/tests/suites/test_suite_net.function new file mode 100644 index 000000000..03b4bd36f --- /dev/null +++ b/tests/suites/test_suite_net.function @@ -0,0 +1,28 @@ +/* BEGIN_HEADER */ + +#include "mbedtls/net_sockets.h" + +/* END_HEADER */ + +/* BEGIN_DEPENDENCIES + * depends_on:MBEDTLS_NET_C + * END_DEPENDENCIES + */ + +/* BEGIN_CASE */ +void context_init_free( int reinit ) +{ + mbedtls_net_context ctx; + + mbedtls_net_init( &ctx ); + mbedtls_net_free( &ctx ); + + if( reinit ) + mbedtls_net_init( &ctx ); + mbedtls_net_free( &ctx ); + + /* This test case always succeeds, functionally speaking. A plausible + * bug might trigger an invalid pointer dereference or a memory leak. */ + goto exit; +} +/* END_CASE */