| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "preamble.h" |
| 18 |
|
| 19 |
struct aws_allocator *aws_default_allocator() |
| 20 |
_(ensures \wrapped(\result)) |
| 21 |
; |
| 22 |
|
| 23 |
uint64_t next_timestamp(); |
| 24 |
|
| 25 |
int clock(uint64_t *timestamp) |
| 26 |
_(writes timestamp) |
| 27 |
{ |
| 28 |
*timestamp = next_timestamp(); |
| 29 |
return AWS_OP_SUCCESS; |
| 30 |
} |
| 31 |
|
| 32 |
void test_new_destroy() |
| 33 |
{ |
| 34 |
struct aws_allocator *alloc = aws_default_allocator(); |
| 35 |
_(ghost \claim c_mutex) |
| 36 |
struct aws_event_loop *event_loop = aws_event_loop_new_default(alloc, clock, _(out c_mutex)); |
| 37 |
if (!event_loop) return; |
| 38 |
_(ghost \claim c_event_loop;) |
| 39 |
_(ghost c_event_loop = \make_claim({event_loop}, event_loop->\closed);) |
| 40 |
s_start_destroy(event_loop _(ghost c_event_loop) _(ghost c_mutex)); |
| 41 |
s_complete_destroy(event_loop _(ghost c_event_loop) _(ghost c_mutex)); |
| 42 |
} |
| 43 |
|
| 44 |
void on_event( |
| 45 |
struct aws_event_loop *event_loop, |
| 46 |
struct aws_io_handle *handle, |
| 47 |
int events, |
| 48 |
void *user_data _(ghost \claim(c)) |
| 49 |
); |
| 50 |
|
| 51 |
void test_subscribe_unsubscribe(struct aws_event_loop *event_loop |
| 52 |
_(ghost \claim(c_event_loop)) |
| 53 |
_(ghost \claim(c_mutex)) |
| 54 |
) |
| 55 |
_(always c_event_loop, event_loop->\closed) |
| 56 |
_(requires \wrapped(c_mutex) && \claims_object(c_mutex, &(epoll_loop_of(event_loop)->task_pre_queue_mutex))) |
| 57 |
_(writes event_loop) |
| 58 |
_(updates &epoll_loop_of(event_loop)->scheduler) |
| 59 |
{ |
| 60 |
struct aws_io_handle *handle = malloc(sizeof(struct aws_io_handle)); |
| 61 |
if (!handle) return; |
| 62 |
handle->data.fd = 1; |
| 63 |
_(wrap handle) |
| 64 |
int err = s_subscribe_to_io_events(event_loop, handle, 0, on_event, NULL, _(ghost c_event_loop)); |
| 65 |
if (err) { |
| 66 |
return; |
| 67 |
} |
| 68 |
_(assert wf_cio_handle(handle)) |
| 69 |
_(assert \wrapped((struct epoll_event_data *)handle->additional_data)) |
| 70 |
_(assert ((struct epoll_event_data *)handle->additional_data)->\owner == \me) |
| 71 |
s_unsubscribe_from_io_events(event_loop, handle _(ghost c_event_loop) _(ghost c_mutex)); |
| 72 |
} |
| 73 |
|
| 74 |
void task_fn(struct aws_task *task, void *arg, enum aws_task_status) { |
| 75 |
(void)task; |
| 76 |
(void)arg; |
| 77 |
} |
| 78 |
|
| 79 |
void test_schedule_cancel(struct aws_event_loop *event_loop |
| 80 |
_(ghost \claim(c_event_loop)) |
| 81 |
_(ghost \claim(c_mutex)) |
| 82 |
) |
| 83 |
_(requires \wrapped(event_loop)) |
| 84 |
_(always c_event_loop, event_loop->\closed) |
| 85 |
_(requires \wrapped(c_mutex) && \claims_object(c_mutex, &(epoll_loop_of(event_loop)->task_pre_queue_mutex))) |
| 86 |
_(updates &epoll_loop_of(event_loop)->scheduler) |
| 87 |
{ |
| 88 |
struct aws_task *task = malloc(sizeof(struct aws_task)); |
| 89 |
if (!task) return; |
| 90 |
aws_task_init(task, task_fn, NULL, "test_task"); |
| 91 |
s_schedule_task_now(event_loop, task _(ghost c_event_loop) _(ghost c_mutex)); |
| 92 |
s_cancel_task(event_loop, task); |
| 93 |
} |
| 94 |
|