7 #include <arch/atomic.h>
9 int main(int argc, char** argv)
11 /* this program should only be started from the kernel for tests */
12 printf("[user] Attempting to read ucq messages from test_ucq(). "
13 "Don't call this manually.\n");
14 /* Map into a known, extremely ghetto location. The kernel knows to look
16 struct ucq *ucq = mmap((void*)USTACKTOP, PGSIZE, PROT_WRITE | PROT_READ,
18 assert((uintptr_t)ucq == USTACKTOP);
20 uintptr_t two_pages = (uintptr_t)mmap(0, PGSIZE * 2, PROT_WRITE | PROT_READ,
21 MAP_POPULATE | MAP_ANONYMOUS, -1, 0);
23 ucq_init_raw(ucq, two_pages, two_pages + PGSIZE);
24 printf("[user] UCQ %08p initialized\n", ucq);
25 /* try to get a simple message */
27 /* 1: Spin til we can get a message (0 on success breaks) */
28 while (get_ucq_msg(ucq, &msg))
30 printf("[user] Got simple message type %d(7) with A2 %08p(0xdeadbeef)\n",
31 msg.ev_type, msg.ev_arg2);
33 for (int i = 0; i < 5000; i++) {
34 while (get_ucq_msg(ucq, &msg))
36 assert(msg.ev_type == i);
38 printf("[user] #2 Received a bunch! Last one was %d(4999), "
39 "extra pages %d(6, if #3 is 1000 and was blasted already)\n",
40 msg.ev_type, atomic_read(&ucq->nr_extra_pgs));
41 /* 3: test chaining */
42 while (atomic_read(&ucq->nr_extra_pgs) < 2)
44 printf("[user] #3 There's now a couple pages (%d), trying to receive...\n",
45 atomic_read(&ucq->nr_extra_pgs));
46 /* this assumes 1000 is enough for a couple pages */
47 for (int i = 0; i < 1000; i++) {
48 while (get_ucq_msg(ucq, &msg))
50 assert(msg.ev_type == i);
52 printf("[user] Done, extra pages: %d(0)\n", atomic_read(&ucq->nr_extra_pgs));
54 while (!get_ucq_msg(ucq, &msg)) {
55 printf("[user] got %d extra messages in the ucq, type %d\n", ++extra,
58 printf("[user] Spinning...\n");