]>
git.ipfire.org Git - thirdparty/openssl.git/blob - test/event_queue_test.c
2 * Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 #include "internal/event_queue.h"
11 #include "internal/nelem.h"
14 static OSSL_TIME cur_time
= { 100 };
16 OSSL_TIME
ossl_time_now(void)
21 #define PAYLOAD(s) s, strlen(s) + 1
23 static int event_test(void)
27 OSSL_EVENT
*e1
, *e2
, e3
, *e4
= NULL
, *ep
= NULL
;
28 OSSL_EVENT_QUEUE
*q
= NULL
;
30 static char payload
[] = "payload";
32 /* Create an event queue and add some events */
33 if (!TEST_ptr(q
= ossl_event_queue_new())
34 || !TEST_ptr(e1
= ossl_event_queue_add_new(q
, 1, 10,
35 ossl_ticks2time(1100),
38 || !TEST_ptr(e2
= ossl_event_queue_add_new(q
, 2, 5,
39 ossl_ticks2time(1100),
42 || !TEST_true(ossl_event_queue_add(q
, &e3
, 3, 20,
43 ossl_ticks2time(1200), "ctx 3",
44 PAYLOAD("more data")))
45 || !TEST_ptr(e4
= ossl_event_queue_add_new(q
, 2, 5,
46 ossl_ticks2time(1150),
50 /* Verify some event details */
51 || !TEST_uint_eq(ossl_event_get_type(e1
), 1)
52 || !TEST_uint_eq(ossl_event_get_priority(e1
), 10)
53 || !TEST_uint64_t_eq(ossl_time2ticks(ossl_event_get_when(e1
))
55 || !TEST_str_eq(ossl_event_get0_ctx(e1
), "ctx 1")
56 || !TEST_ptr(p
= ossl_event_get0_payload(e1
, &len
))
57 || !TEST_str_eq((char *)p
, payload
)
58 || !TEST_uint64_t_eq(ossl_time2ticks(ossl_event_time_until(&e3
)),
60 || !TEST_uint64_t_eq(ossl_time2ticks(ossl_event_queue_time_until_next(q
)),
63 /* Modify an event's time */
64 || !TEST_true(ossl_event_queue_postpone_until(q
, e1
,
65 ossl_ticks2time(1200)))
66 || !TEST_uint64_t_eq(ossl_time2ticks(ossl_event_get_when(e1
)), 1200)
67 || !TEST_true(ossl_event_queue_remove(q
, e4
)))
71 /* Execute the queue */
72 cur_time
= ossl_ticks2time(1000);
73 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
74 || !TEST_ptr_null(ep
))
76 cur_time
= ossl_ticks2time(1100);
77 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
78 || !TEST_ptr_eq(ep
, e2
))
82 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
83 || !TEST_ptr_null(ep
))
86 cur_time
= ossl_ticks2time(1250);
87 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
88 || !TEST_ptr_eq(ep
, &e3
))
92 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
93 || !TEST_ptr_eq(ep
, e1
))
97 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
98 || !TEST_ptr_null(ep
))
104 ossl_event_queue_free(q
);
108 int setup_tests(void)
110 ADD_TEST(event_test
);