QUIC SRTM: Add test
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22612)
This commit is contained in:
parent
d742badc3b
commit
90a1115799
@ -328,6 +328,10 @@ IF[{- !$disabled{tests} -}]
|
||||
INCLUDE[quic_txpim_test]=../include ../apps/include
|
||||
DEPEND[quic_txpim_test]=../libcrypto.a ../libssl.a libtestutil.a
|
||||
|
||||
SOURCE[quic_srtm_test]=quic_srtm_test.c
|
||||
INCLUDE[quic_srtm_test]=../include ../apps/include
|
||||
DEPEND[quic_srtm_test]=../libcrypto.a ../libssl.a libtestutil.a
|
||||
|
||||
SOURCE[quic_fifd_test]=quic_fifd_test.c cc_dummy.c
|
||||
INCLUDE[quic_fifd_test]=../include ../apps/include
|
||||
DEPEND[quic_fifd_test]=../libcrypto.a ../libssl.a libtestutil.a
|
||||
@ -1129,6 +1133,7 @@ ENDIF
|
||||
IF[{- !$disabled{'quic'} -}]
|
||||
PROGRAMS{noinst}=quic_wire_test quic_ackm_test quic_record_test
|
||||
PROGRAMS{noinst}=quic_fc_test quic_stream_test quic_cfq_test quic_txpim_test
|
||||
PROGRAMS{noinst}=quic_srtm_test
|
||||
PROGRAMS{noinst}=quic_fifd_test quic_txp_test quic_tserver_test
|
||||
PROGRAMS{noinst}=quic_client_test quic_cc_test quic_multistream_test
|
||||
ENDIF
|
||||
|
84
test/quic_srtm_test.c
Normal file
84
test/quic_srtm_test.c
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
* in the file LICENSE in the source distribution or at
|
||||
* https://www.openssl.org/source/license.html
|
||||
*/
|
||||
|
||||
#include "internal/quic_srtm.h"
|
||||
#include "testutil.h"
|
||||
|
||||
static char ptrs[8];
|
||||
|
||||
static const QUIC_STATELESS_RESET_TOKEN token_1 = {{
|
||||
0x01, 0x02, 0x03, 0x04
|
||||
}};
|
||||
|
||||
static const QUIC_STATELESS_RESET_TOKEN token_2 = {{
|
||||
0x01, 0x02, 0x03, 0x05
|
||||
}};
|
||||
|
||||
static int test_srtm(void)
|
||||
{
|
||||
int testresult = 0;
|
||||
QUIC_SRTM *srtm;
|
||||
void *opaque = NULL;
|
||||
uint64_t seq_num = 0;
|
||||
|
||||
if (!TEST_ptr(srtm = ossl_quic_srtm_new(NULL, NULL)))
|
||||
goto err;
|
||||
|
||||
if (!TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 0, &token_1))
|
||||
|| !TEST_false(ossl_quic_srtm_add(srtm, ptrs + 0, 0, &token_1))
|
||||
|| !TEST_false(ossl_quic_srtm_remove(srtm, ptrs + 0, 1))
|
||||
|| !TEST_false(ossl_quic_srtm_remove(srtm, ptrs + 3, 0))
|
||||
|| !TEST_true(ossl_quic_srtm_cull(srtm, ptrs + 3))
|
||||
|| !TEST_true(ossl_quic_srtm_cull(srtm, ptrs + 3))
|
||||
|| !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 1, &token_1))
|
||||
|| !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 2, &token_1))
|
||||
|| !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 0, 3, &token_1))
|
||||
|| !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 1, 0, &token_1))
|
||||
|| !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 2, 0, &token_2))
|
||||
|| !TEST_true(ossl_quic_srtm_add(srtm, ptrs + 3, 3, &token_2))
|
||||
|| !TEST_true(ossl_quic_srtm_remove(srtm, ptrs + 3, 3))
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 0, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 1)
|
||||
|| !TEST_uint64_t_eq(seq_num, 0)
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 1, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 0)
|
||||
|| !TEST_uint64_t_eq(seq_num, 3)
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 2, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 0)
|
||||
|| !TEST_uint64_t_eq(seq_num, 2)
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 3, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 0)
|
||||
|| !TEST_uint64_t_eq(seq_num, 1)
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 4, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 0)
|
||||
|| !TEST_uint64_t_eq(seq_num, 0)
|
||||
|| !TEST_false(ossl_quic_srtm_lookup(srtm, &token_1, 5, &opaque, &seq_num))
|
||||
|| !TEST_true(ossl_quic_srtm_cull(srtm, ptrs + 0))
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_1, 0, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 1)
|
||||
|| !TEST_uint64_t_eq(seq_num, 0)
|
||||
|| !TEST_true(ossl_quic_srtm_lookup(srtm, &token_2, 0, &opaque, &seq_num))
|
||||
|| !TEST_ptr_eq(opaque, ptrs + 2)
|
||||
|| !TEST_uint64_t_eq(seq_num, 0)
|
||||
|| !TEST_true(ossl_quic_srtm_remove(srtm, ptrs + 2, 0))
|
||||
|| !TEST_false(ossl_quic_srtm_lookup(srtm, &token_2, 0, &opaque, &seq_num))
|
||||
)
|
||||
goto err;
|
||||
|
||||
testresult = 1;
|
||||
err:
|
||||
ossl_quic_srtm_free(srtm);
|
||||
return testresult;
|
||||
}
|
||||
|
||||
int setup_tests(void)
|
||||
{
|
||||
ADD_TEST(test_srtm);
|
||||
return 1;
|
||||
}
|
19
test/recipes/70-test_quic_srtm.t
Normal file
19
test/recipes/70-test_quic_srtm.t
Normal file
@ -0,0 +1,19 @@
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
use OpenSSL::Test;
|
||||
use OpenSSL::Test::Utils;
|
||||
|
||||
setup("test_quic_srtm");
|
||||
|
||||
plan skip_all => "QUIC protocol is not supported by this OpenSSL build"
|
||||
if disabled('quic');
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
ok(run(test(["quic_srtm_test"])));
|
Loading…
x
Reference in New Issue
Block a user