mpsc_queue: Make tests more verbose in case of failure
[libnbds.git] / test / mpsc_queue_s.c
blob07027155f9aadc3cdf5db45f1d0c6a9af9cf837b
1 /*
2 libnbds
3 Copyright (C) 2014 Paweł Dziepak
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <stdint.h>
21 #include "mpsc_queue.h"
23 struct mpsc_queue queue;
25 #define SIZE 1024u
27 int main(int argc, char** argv)
29 uintptr_t i, val;
30 int error;
32 (void)argc;
33 (void)argv;
35 error = mpsc_queue_init(&queue);
36 if (error)
37 return 1;
39 if (mpsc_queue_dequeue(&queue))
40 return 1;
42 for (i = 1; i < SIZE; i++) {
43 error = mpsc_queue_enqueue(&queue, (void*)i);
44 if (error)
45 return 1;
48 for (i = 1; i < SIZE; i++) {
49 val = (uintptr_t)mpsc_queue_dequeue(&queue);
50 if (val != i)
51 return 1;
54 if (mpsc_queue_dequeue(&queue))
55 return 1;
57 for (i = 1; i < SIZE; i++) {
58 mpsc_queue_enqueue(&queue,(void*)i);
59 if ((uintptr_t)mpsc_queue_dequeue(&queue) != i)
60 return 1;
63 if (mpsc_queue_dequeue(&queue))
64 return 1;
66 mpsc_queue_destroy(&queue);
67 error = mpsc_queue_init(&queue);
68 if (error)
69 return 1;
71 for (i = 1; i < SIZE; i++) {
72 error = mpsc_queue_enqueue(&queue, (void*)i);
73 if (error)
74 return 1;
77 mpsc_queue_destroy(&queue);
78 error = mpsc_queue_init(&queue);
79 if (error)
80 return 1;
82 if (mpsc_queue_dequeue(&queue))
83 return 1;
85 mpsc_queue_destroy(&queue);