blob: 4cd1c20c6026823e20ab8982754f95eeaafd27aa [file] [log] [blame]
Jeremy Kerrc9775ce2017-02-07 16:25:34 +08001
2#include <stdlib.h>
3#include <stdint.h>
4#include <stdio.h>
5
6#include "ringbuffer.c"
7#include "ringbuffer-test-utils.c"
8
9void test_boundary_poll(void)
10{
11 uint8_t in_buf[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
Andrew Jefferyb70f8712023-04-19 12:53:34 +093012 struct rb_test_ctx _ctx;
13 struct rb_test_ctx *ctx = &_ctx;
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080014 struct ringbuffer *rb;
15 int rc;
16
17 ringbuffer_test_context_init(ctx);
18
19 rb = ringbuffer_init(10);
20
Andrew Jefferya72711a2023-04-18 18:19:41 +093021 ctx->rbc = ringbuffer_consumer_register(rb, ringbuffer_poll_append_all,
22 ctx);
Jeremy Kerrc9775ce2017-02-07 16:25:34 +080023
24 /* don't consume initial data in the poll callback */
25 ctx->ignore_poll = true;
26
27 /* queue and dequeue, so our tail is non-zero */
28 ringbuffer_queue(rb, in_buf, sizeof(in_buf));
29 ringbuffer_dequeue_commit(ctx->rbc, sizeof(in_buf));
30
31 /* start queueing data */
32 ctx->ignore_poll = false;
33
34 /* ensure we're getting the second batch of data back */
35 in_buf[0] = 'A';
36
37 rc = ringbuffer_queue(rb, in_buf, sizeof(in_buf));
38 assert(!rc);
39
40 assert(ctx->count == 1);
41 assert(ctx->len == sizeof(in_buf));
42 assert(!memcmp(in_buf, ctx->data, ctx->len));
43
44 ringbuffer_fini(rb);
45 ringbuffer_test_context_fini(ctx);
46}
47
48int main(void)
49{
50 test_boundary_poll();
51 return EXIT_SUCCESS;
52}