/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
#include "ssltestlib.h"
#include "testutil.h"
-#include "test_main_custom.h"
static char *cert = NULL;
static char *privkey = NULL;
+static unsigned int timer_cb_count;
#define NUM_TESTS 2
#define RECORD_SEQUENCE 10
+static unsigned int timer_cb(SSL *s, unsigned int timer_us)
+{
+ ++timer_cb_count;
+
+ if (timer_us == 0)
+ return 1000000;
+ else
+ return 2 * timer_us;
+}
+
static int test_dtls_unprocessed(int testidx)
{
SSL_CTX *sctx = NULL, *cctx = NULL;
BIO *c_to_s_fbio, *c_to_s_mempacket;
int testresult = 0;
- printf("Starting Test %d\n", testidx);
+ timer_cb_count = 0;
- if (!create_ssl_ctx_pair(DTLS_server_method(), DTLS_client_method(), &sctx,
- &cctx, cert, privkey)) {
- printf("Unable to create SSL_CTX pair\n");
+ if (!TEST_true(create_ssl_ctx_pair(DTLS_server_method(),
+ DTLS_client_method(),
+ DTLS1_VERSION, DTLS_MAX_VERSION,
+ &sctx, &cctx, cert, privkey)))
return 0;
- }
- if (!SSL_CTX_set_cipher_list(cctx, "AES128-SHA")) {
- printf("Failed setting cipher list\n");
- }
+ if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA")))
+ goto end;
c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());
- if (c_to_s_fbio == NULL) {
- printf("Failed to create filter BIO\n");
+ if (!TEST_ptr(c_to_s_fbio))
goto end;
- }
/* BIO is freed by create_ssl_connection on error */
- if (!create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1, NULL,
- c_to_s_fbio)) {
- printf("Unable to create SSL objects\n");
- ERR_print_errors_fp(stdout);
+ if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,
+ NULL, c_to_s_fbio)))
goto end;
- }
+
+ DTLS_set_timer_cb(clientssl1, timer_cb);
if (testidx == 1)
certstatus[RECORD_SEQUENCE] = 0xff;
mempacket_test_inject(c_to_s_mempacket, (char *)certstatus,
sizeof(certstatus), 1, INJECT_PACKET_IGNORE_REC_SEQ);
- if (!create_ssl_connection(serverssl1, clientssl1)) {
- printf("Unable to create SSL connection\n");
- ERR_print_errors_fp(stdout);
+ if (!TEST_true(create_ssl_connection(serverssl1, clientssl1,
+ SSL_ERROR_NONE)))
+ goto end;
+
+ if (timer_cb_count == 0) {
+ printf("timer_callback was not called.\n");
goto end;
}
return testresult;
}
-int test_main(int argc, char *argv[])
+int setup_tests(void)
{
- int testresult = 1;
-
- if (argc != 3) {
- printf("Invalid argument count\n");
- return 1;
- }
-
- cert = argv[1];
- privkey = argv[2];
+ if (!TEST_ptr(cert = test_get_argument(0))
+ || !TEST_ptr(privkey = test_get_argument(1)))
+ return 0;
ADD_ALL_TESTS(test_dtls_unprocessed, NUM_TESTS);
+ return 1;
+}
- testresult = run_tests(argv[0]);
-
+void cleanup_tests(void)
+{
bio_f_tls_dump_filter_free();
bio_s_mempacket_test_free();
-
- return testresult;
}