]>
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, 1100, "ctx 1",
36 || !TEST_ptr(e2
= ossl_event_queue_add_new(q
, 2, 5, 1100, "ctx 2",
38 || !TEST_true(ossl_event_queue_add(q
, &e3
, 3, 20, 1200, "ctx 3",
39 PAYLOAD("more data")))
40 || !TEST_ptr(e4
= ossl_event_queue_add_new(q
, 2, 5, 1150, "ctx 2",
43 /* Verify some event details */
44 || !TEST_uint_eq(ossl_event_get_type(e1
), 1)
45 || !TEST_uint_eq(ossl_event_get_priority(e1
), 10)
46 || !TEST_uint64_t_eq(ossl_event_get_when(e1
), 1100)
47 || !TEST_str_eq(ossl_event_get0_ctx(e1
), "ctx 1")
48 || !TEST_ptr(p
= ossl_event_get0_payload(e1
, &len
))
49 || !TEST_str_eq((char *)p
, payload
)
50 || !TEST_uint64_t_eq(ossl_event_time_until(&e3
), 1100)
51 || !TEST_uint64_t_eq(ossl_event_queue_time_until_next(q
), 1000)
53 /* Modify an event's time */
54 || !TEST_true(ossl_event_queue_postpone_until(q
, e1
, 1200))
55 || !TEST_uint64_t_eq(ossl_event_get_when(e1
), 1200)
56 || !TEST_true(ossl_event_queue_remove(q
, e4
)))
60 /* Execute the queue */
62 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
63 || !TEST_ptr_null(ep
))
66 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
67 || !TEST_ptr_eq(ep
, e2
))
71 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
72 || !TEST_ptr_null(ep
))
76 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
77 || !TEST_ptr_eq(ep
, &e3
))
81 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
82 || !TEST_ptr_eq(ep
, e1
))
86 if (!TEST_true(ossl_event_queue_get1_next_event(q
, &ep
))
87 || !TEST_ptr_null(ep
))
93 ossl_event_queue_free(q
);