unit-tests: Add asserts against SAs (e.g. their states)
This commit is contained in:
@@ -27,6 +27,7 @@ exchange_tests_SOURCES = \
|
|||||||
utils/exchange_test_helper.h utils/exchange_test_helper.c \
|
utils/exchange_test_helper.h utils/exchange_test_helper.c \
|
||||||
utils/mock_ipsec.h utils/mock_ipsec.c \
|
utils/mock_ipsec.h utils/mock_ipsec.c \
|
||||||
utils/mock_sender.h utils/mock_sender.c \
|
utils/mock_sender.h utils/mock_sender.c \
|
||||||
|
utils/sa_asserts.h \
|
||||||
exchange_tests.h exchange_tests.c
|
exchange_tests.h exchange_tests.c
|
||||||
|
|
||||||
exchange_tests_CFLAGS = \
|
exchange_tests_CFLAGS = \
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Tobias Brunner
|
||||||
|
* HSR Hochschule fuer Technik Rapperswil
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License as published by the
|
||||||
|
* Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Special assertions against IKE_SAs and CHILD_SAs (e.g. regarding their
|
||||||
|
* state).
|
||||||
|
*
|
||||||
|
* @defgroup sa_asserts sa_asserts
|
||||||
|
* @{ @ingroup test_utils_c
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SA_ASSERTS_H_
|
||||||
|
#define SA_ASSERTS_H_
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that there exists a specific number of CHILD_SAs.
|
||||||
|
*/
|
||||||
|
#define assert_child_sa_count(ike_sa, count) \
|
||||||
|
({ \
|
||||||
|
typeof(ike_sa) _sa = ike_sa; \
|
||||||
|
typeof(count) _count = count; \
|
||||||
|
test_assert_msg(_count == _sa->get_child_count(_sa), "unexpected number " \
|
||||||
|
"of CHILD_SAs in IKE_SA %s (%d != %d)", #ike_sa, _count, \
|
||||||
|
_sa->get_child_count(_sa)); \
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the CHILD_SA with the given inbound SPI is in the expected state.
|
||||||
|
*/
|
||||||
|
#define assert_child_sa_state(ike_sa, spi, state) \
|
||||||
|
({ \
|
||||||
|
typeof(ike_sa) _sa = ike_sa; \
|
||||||
|
typeof(spi) _spi = spi; \
|
||||||
|
typeof(state) _state = state; \
|
||||||
|
child_sa_t *_child = _sa->get_child_sa(_sa, PROTO_ESP, _spi, TRUE); \
|
||||||
|
test_assert_msg(_child, "CHILD_SA with SPI %.8x does not exist", \
|
||||||
|
ntohl(_spi)); \
|
||||||
|
test_assert_msg(_state == _child->get_state(_child), "%N != %N", \
|
||||||
|
child_sa_state_names, _state, \
|
||||||
|
child_sa_state_names, _child->get_state(_child)); \
|
||||||
|
})
|
||||||
|
|
||||||
|
#endif /** SA_ASSERTS_H_ @}*/
|
||||||
Reference in New Issue
Block a user