Commit 25cea284 authored by Geir Istad's avatar Geir Istad

Introduction of CUTest Framework

This framework is header only which is the main reason it was chosen.
More information about it (not that much really!) can be found in [1].
The license is MIT and the copyright notice is included in the header
cutest.h so I think putting the file in our repo is OK wrt licensing.

Location of new files and structure for unit tests are up for discussion.
Note that I am including "srtp.c" in "test_srtp.c" in order to test it's
internal (static) functions.
Alternatively we could try to test from public API, however that is
already done in for example /test/srtp_driver.c which functions more
like an integration/module test.
The purpose of the unit tests are (for now) testing of lower level
functions that are not exposed
in the public API.

Alternative layout could be to put the unit tests in a /test/ folder in
the root directory of the file that is being tested.

Alternative frameworks considered:

cmocka [2] does not require external tools and have support for mocking.
It does however require more than a header to run. This seems like the
best bet if we do want to introduce a unit test system that supports more
advanced functionality.

CTest [3] introduces a dependency on cmake - depending on both make and
cmake seems kind of annoying.

Google Test [4] requires a C++98 compatible compiler, requiring this for
a C library seems excessive.

[1] https://github.com/mity/cutest
[2] https://cmocka.org/
[3] https://cmake.org/cmake/help/v3.0/manual/ctest.1.html
[4] https://github.com/google/googletest
parent 50afc951
......@@ -47,3 +47,4 @@ test/roc_driver
test/rtp_decoder
test/rtpw
test/srtp_driver
test/test_srtp
......@@ -24,6 +24,7 @@ runtest: test
@echo "running libsrtp2 test applications..."
crypto/test/cipher_driver$(EXE) -v >/dev/null
crypto/test/kernel_driver$(EXE) -v >/dev/null
test/test_srtp$(EXE) >/dev/null
test/rdbx_driver$(EXE) -v >/dev/null
test/srtp_driver$(EXE) -v >/dev/null
test/roc_driver$(EXE) -v >/dev/null
......@@ -153,7 +154,7 @@ crypto_testapp = $(AES_CALC) crypto/test/cipher_driver$(EXE) \
testapp = $(crypto_testapp) test/srtp_driver$(EXE) test/replay_driver$(EXE) \
test/roc_driver$(EXE) test/rdbx_driver$(EXE) test/rtpw$(EXE) \
test/dtls_srtp_driver$(EXE)
test/dtls_srtp_driver$(EXE) test/test_srtp$(EXE)
ifeq (1, $(HAVE_PCAP))
testapp += test/rtp_decoder$(EXE)
......@@ -174,6 +175,9 @@ endif
crypto/test/aes_calc$(EXE): crypto/test/aes_calc.c test/util.c
$(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
test/test_srtp$(EXE): test/test_srtp.c
$(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
crypto/test/datatypes_driver$(EXE): crypto/test/datatypes_driver.c test/util.c
$(COMPILE) -I$(srcdir)/test $(LDFLAGS) -o $@ $^ $(LIBS) $(SRTPLIB)
......
This diff is collapsed.
/*
* Tests specific.
*/
#include "cutest.h"
/*
* libSRTP specific.
*/
#include "../srtp/srtp.c" // Get access to static functions
/*
* Standard library
*/
/*
*Forward declaration of all tests
*/
void srtp_calc_aead_iv_srtcp_zero_happy_case();
// void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param();
/*
* NULL terminated array of tests.
*/
TEST_LIST = {{"srtp_calc_aead_iv_srtcp_zero_happy_case()",
srtp_calc_aead_iv_srtcp_zero_happy_case},
/* {"srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param()",
srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param}, */
{NULL} /* End of tests */};
/*
* Implementation
*/
void srtp_calc_aead_iv_srtcp_zero_happy_case()
{
// Preconditions
srtp_session_keys_t session_keys;
v128_t init_vector;
srtcp_hdr_t header;
uint32_t sequence_num;
// Postconditions
const v128_t zero_vector;
memset((v128_t *)&zero_vector, 0, sizeof(v128_t));
// Given
memset(&session_keys, 0, sizeof(srtp_session_keys_t));
memset(&init_vector, 0, sizeof(v128_t));
memset(&header, 0, sizeof(srtcp_hdr_t));
sequence_num = 0x0;
// When
srtp_calc_aead_iv_srtcp(&session_keys, &init_vector, sequence_num, &header);
// Then
TEST_CHECK(memcmp(&zero_vector, &init_vector, sizeof(v128_t)) == 0);
}
/*
void srtp_calc_aead_iv_srtcp_seq_num_over_0x7FFFFFFF_bad_param()
{
// Preconditions
srtp_session_keys_t session_keys;
v128_t init_vector;
srtcp_hdr_t header;
uint32_t sequence_num;
// Postconditions
srtp_err_status_t status
// Given
memset(&session_keys, 0, sizeof(srtp_session_keys_t));
memset(&init_vector, 0, sizeof(v128_t));
memset(&header, 0, sizeof(srtcp_hdr_t));
sequence_num = 0x7FFFFFFF + 0x1;
// When
srtp_err_status_t status = srtp_calc_aead_iv_srtcp(
&session_keys, &init_vector, sequence_num, &header);
// Then
TEST_CHECK(status == srtp_err_status_bad_param);
}
*/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment