mirror of
https://github.com/OpenVPN/openvpn.git
synced 2024-09-20 03:52:28 +02:00
Add unit test for reliable_get_num_output_sequenced_available
Patch v4: rebase Signed-off-by: Arne Schwabe <arne@rfc2549.org> Acked-by: Frank Lichtenheld <frank@lichtenheld.com> Message-Id: <20220921104930.3452270-3-arne@rfc2549.org> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25292.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
This commit is contained in:
parent
4e9e25a9e5
commit
a5a30ec311
@ -61,7 +61,10 @@ packet_id_testdriver_SOURCES = test_packet_id.c mock_msg.c mock_msg.h \
|
||||
$(openvpn_srcdir)/buffer.c \
|
||||
$(openvpn_srcdir)/otime.c \
|
||||
$(openvpn_srcdir)/packet_id.c \
|
||||
$(openvpn_srcdir)/platform.c
|
||||
$(openvpn_srcdir)/platform.c \
|
||||
$(openvpn_srcdir)/reliable.c \
|
||||
$(openvpn_srcdir)/session_id.c
|
||||
|
||||
|
||||
pkt_testdriver_CFLAGS = @TEST_CFLAGS@ \
|
||||
-I$(openvpn_includedir) -I$(compat_srcdir) -I$(openvpn_srcdir)
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <setjmp.h>
|
||||
#include <stdint.h>
|
||||
#include <cmocka.h>
|
||||
|
||||
unsigned long
|
||||
@ -34,3 +35,12 @@ get_random(void)
|
||||
/* rand() is not very random, but it's C99 and this is just for testing */
|
||||
return rand();
|
||||
}
|
||||
|
||||
void
|
||||
prng_bytes(uint8_t *output, int len)
|
||||
{
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
output[i] = rand();
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <cmocka.h>
|
||||
|
||||
#include "packet_id.h"
|
||||
#include "reliable.h"
|
||||
|
||||
#include "mock_msg.h"
|
||||
|
||||
@ -156,6 +157,59 @@ test_packet_id_write_long_wrap(void **state)
|
||||
assert_true(data->test_buf_data.buf_time == htonl(now));
|
||||
}
|
||||
|
||||
static void
|
||||
test_get_num_output_sequenced_available(void **state)
|
||||
{
|
||||
|
||||
struct reliable *rel = malloc(sizeof(struct reliable));
|
||||
reliable_init(rel, 100, 50, 8, false);
|
||||
|
||||
rel->array[5].active = true;
|
||||
rel->array[5].packet_id = 100;
|
||||
|
||||
rel->packet_id = 103;
|
||||
|
||||
assert_int_equal(5, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
rel->array[6].active = true;
|
||||
rel->array[6].packet_id = 97;
|
||||
assert_int_equal(2, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
/* test ids close to int/unsigned int barrier */
|
||||
|
||||
rel->array[5].active = true;
|
||||
rel->array[5].packet_id = (0x80000000u -3);
|
||||
rel->array[6].active = false;
|
||||
rel->packet_id = (0x80000000u -1);
|
||||
|
||||
assert_int_equal(6, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
rel->array[5].active = true;
|
||||
rel->array[5].packet_id = (0x80000000u -3);
|
||||
rel->packet_id = 0x80000001u;
|
||||
|
||||
assert_int_equal(4, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
|
||||
/* test wrapping */
|
||||
rel->array[5].active = true;
|
||||
rel->array[5].packet_id = (0xffffffffu -3);
|
||||
rel->array[6].active = false;
|
||||
rel->packet_id = (0xffffffffu - 1);
|
||||
|
||||
assert_int_equal(6, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
rel->array[2].packet_id = 0;
|
||||
rel->array[2].active = true;
|
||||
|
||||
assert_int_equal(6, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
rel->packet_id = 3;
|
||||
assert_int_equal(1, reliable_get_num_output_sequenced_available(rel));
|
||||
|
||||
reliable_free(rel);
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
@ -178,6 +232,7 @@ main(void)
|
||||
cmocka_unit_test_setup_teardown(test_packet_id_write_long_wrap,
|
||||
test_packet_id_write_setup,
|
||||
test_packet_id_write_teardown),
|
||||
cmocka_unit_test(test_get_num_output_sequenced_available)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests_name("packet_id tests", tests, NULL, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user