-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathk_test_async.c
More file actions
153 lines (128 loc) · 5.22 KB
/
Copy pathk_test_async.c
File metadata and controls
153 lines (128 loc) · 5.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Testing cos_rcv and cos_asnd
* The test uses 2 thds, ine that sends and one that rcvs
* asend with a 0 ARG is NON_BLOCKING.
*/
#include <stdint.h>
#include "kernel_tests.h"
static volatile arcvcap_t rcc_global[NUM_CPU], rcp_global[NUM_CPU];
static volatile asndcap_t scp_global[NUM_CPU];
static int async_test_flag_[NUM_CPU] = { 0 };
static int failure = 0;
#define TEST_TIMEOUT_MS 1
static void
async_thd_fn(void *thdcap)
{
thdcap_t tc = (thdcap_t)thdcap;
arcvcap_t rc = rcc_global[cos_cpuid()];
int pending, rcvd, ret;
pending = cos_rcv(rc, RCV_NON_BLOCKING, NULL);
if (EXPECT_LL_NEQ(3, pending, "Test Async Endpoints")) failure = 1;
pending = cos_rcv(rc, RCV_NON_BLOCKING | RCV_ALL_PENDING, &rcvd);
if (EXPECT_LL_NEQ(0, pending, "Test Async Endpoints")) failure = 1;
pending = cos_rcv(rc, RCV_ALL_PENDING, &rcvd);
/* switch */
if (EXPECT_LL_NEQ(0, pending, "Test Async Endpoints")) failure = 1;
pending = cos_rcv(rc, 0, NULL);
/* switch */
if (EXPECT_LL_NEQ(0, pending, "Test Async Endpoints")) failure = 1;
pending = cos_rcv(rc, 0, NULL);
/* switch */
if (EXPECT_LL_NEQ(0, pending, "Test Async Endpoints")) failure = 1;
pending = cos_rcv(rc, RCV_NON_BLOCKING, NULL);
if (EXPECT_LL_NEQ(pending, -EAGAIN, "Test Async Endpoints")) failure = 1;
pending = cos_rcv(rc, 0, NULL);
/* switch */
if (EXPECT_LL_NEQ(0, 1, "Test Async Endpoints")) failure = 1;
ret = cos_thd_switch(tc);
if (EXPECT_LL_NEQ(0, ret, "COS Switch Error") ||
EXPECT_LL_NEQ(0, 1, "Test Async Endpoints")) {
failure = 1;
}
while (1) cos_thd_switch(tc);
}
static void
async_thd_parent(void *thdcap)
{
thdcap_t tc = (thdcap_t)thdcap;
arcvcap_t rc = rcp_global[cos_cpuid()];
asndcap_t sc = scp_global[cos_cpuid()];
int ret;
thdid_t tid;
int blocked, rcvd;
cycles_t cycles;
tcap_time_t thd_timeout;
/* NON_BLOCKING ASND with 0 as arg*/
ret = cos_asnd(sc, 0);
ret = cos_asnd(sc, 0);
ret = cos_asnd(sc, 0);
ret = cos_asnd(sc, 1);
/* switch */
/* child blocked at this point, parent is using child's tcap, this call yields to the child */
ret = cos_asnd(sc, 0);
/* switch */
ret = cos_asnd(sc, 0);
if (EXPECT_LL_NEQ(0, ret, "Test Async Endpoints")) failure = 1;
/* switch */
ret = cos_asnd(sc, 1);
if (EXPECT_LL_NEQ(0, ret, "Test Async Endpoints")) failure = 1;
/* switch */
cos_sched_rcv(rc, RCV_ALL_PENDING, 0, &rcvd, &tid, &blocked, &cycles, &thd_timeout);
async_test_flag_[cos_cpuid()] = 0;
while (1) cos_thd_switch(tc);
}
void
test_async_endpoints(void)
{
thdcap_t tcp, tcc;
tcap_t tccp, tccc;
arcvcap_t rcp, rcc;
asndcap_t scr;
/* parent rcv capabilities */
tcp = cos_thd_alloc(&booter_info, booter_info.comp_cap, async_thd_parent,
(void *)BOOT_CAPTBL_SELF_INITTHD_CPU_BASE, 0, 0);
if (EXPECT_LL_LT(1, tcp, "Test Async Endpoints")) {
return;
}
tccp = cos_tcap_alloc(&booter_info);
if (EXPECT_LL_LT(1, tccp, "Test Async Endpoints")) {
return;
}
rcp = cos_arcv_alloc(&booter_info, tcp, tccp, booter_info.comp_cap, BOOT_CAPTBL_SELF_INITRCV_CPU_BASE);
if (EXPECT_LL_LT(1, rcp, "Test Async Endpoints")) {
return;
}
if (EXPECT_LL_NEQ(0,cos_tcap_transfer(rcp, BOOT_CAPTBL_SELF_INITTCAP_CPU_BASE, TCAP_RES_INF, TCAP_PRIO_MAX),
"Test Async Endpoints")) {
return;
}
/* child rcv capabilities */
tcc = cos_thd_alloc(&booter_info, booter_info.comp_cap, async_thd_fn, (void *)tcp, 0, 0);
if (EXPECT_LL_LT(1, tcc, "Test Async Endpoints")) {
return;
}
tccc = cos_tcap_alloc(&booter_info);
if (EXPECT_LL_LT(1, tccc, "Test Async Endpoints")) {
return;
}
rcc = cos_arcv_alloc(&booter_info, tcc, tccc, booter_info.comp_cap, rcp);
if (EXPECT_LL_LT(1, rcc, "Test Async Endpoints")) {
return;
}
if (EXPECT_LL_NEQ(0,cos_tcap_transfer(rcc, BOOT_CAPTBL_SELF_INITTCAP_CPU_BASE, TCAP_RES_INF,
TCAP_PRIO_MAX + 1), "Test Async Endpoints")) {
return;
}
/* make the snd channel to the child */
scp_global[cos_cpuid()] = cos_asnd_alloc(&booter_info, rcc, booter_info.captbl_cap);
if (EXPECT_LL_EQ(0, scp_global[cos_cpuid()], "Test Async Endpoints")) return;
scr = cos_asnd_alloc(&booter_info, rcp, booter_info.captbl_cap);
if (EXPECT_LL_EQ(0, scr, "Test Async Endpoints")) return;
rcc_global[cos_cpuid()] = rcc;
rcp_global[cos_cpuid()] = rcp;
async_test_flag_[cos_cpuid()] = 1;
while (async_test_flag_[cos_cpuid()]) cos_asnd(scr, 1);
CHECK_STATUS_FLAG();
PRINTC("\t%s: \t\tSuccess\n", "Asynchronous Endpoints");
EXIT_FN();
}