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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
/* t-message.c - A test for the interfaces to the L4 message registers.
Copyright (C) 2005 Free Software Foundation, Inc.
Written by Matthieu Lemerre <racin@free.fr> and
Marcus Brinkmann <marcus@gnu.org>.
This file is part of the GNU L4 library.
The GNU L4 library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
The GNU L4 library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU L4 library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stddef.h>
#include <stdio.h>
/* This must be included before any libl4 header. */
#include "environment.h"
#include <l4/message.h>
#define L4_NUM_MRS_OK 64
#define L4_NUM_BRS_OK 33
/* Test the message register MR with value VAL_OK. */
void
test_one_mr (int mr, word_t val_ok)
{
#ifdef _L4_INTERFACE_INTERN
{
_L4_word_t val;
char *msg;
/* Clear all MRs. */
memset (environment_utcb, ~(val_ok & 0xff), sizeof (environment_utcb));
asprintf (&msg, "_L4_load_mr and _L4_store_mr with MR%02i and value 0x%x",
mr, val_ok);
_L4_load_mr (mr, val_ok);
_L4_store_mr (mr, &val);
check_nr ("[intern]", msg, val, val_ok);
}
#endif
#ifdef _L4_INTERFACE_GNU
{
l4_word_t val;
char *msg;
/* Clear all MRs. */
memset (environment_utcb, ~(val_ok & 0xff), sizeof (environment_utcb));
asprintf (&msg, "l4_load_mr and l4_store_mr with MR%02i and value 0x%x",
mr, val_ok);
l4_load_mr (mr, val_ok);
l4_store_mr (mr, &val);
check_nr ("[GNU]", msg, val, val_ok);
}
#endif
#ifdef _L4_INTERFACE_L4
{
L4_Word_t val;
char *msg;
/* Clear all MRs. */
memset (environment_utcb, ~(val_ok & 0xff), sizeof (environment_utcb));
asprintf (&msg, "L4_LoadMR and L4_StoreMR with MR%02i and value 0x%x",
mr, val_ok);
L4_LoadMR (mr, val_ok);
L4_StoreMR (mr, &val);
check_nr ("[L4]", msg, val, val_ok);
}
#endif
}
/* Test the message registers START_MR to START_MR + NUM - 1
with the values VALUES_OK. */
void
test_many_mrs (int start_mr, int nr, _L4_word_t *values_ok)
{
#ifdef _L4_INTERFACE_INTERN
{
_L4_word_t values[nr];
int i;
/* Clear all MRs with a pattern that is unlike the test pattern. */
memset (environment_utcb,
~((values_ok[0] & 0x0f) | (values_ok[nr - 1] & 0xf0)),
sizeof (environment_utcb));
_L4_load_mrs (start_mr, nr, values_ok);
_L4_store_mrs (start_mr, nr, values);
for (i = 0; i < nr; i++)
{
char *msg;
asprintf (&msg,
"_L4_load_mrs, _L4_store_mrs MR%02i-%02i (MR%02i, 0x%x)",
start_mr, start_mr + nr - 1, start_mr + i, values_ok[i]);
check_nr ("[intern]", msg, values[i], values_ok[i]);
}
}
#endif
#ifdef _L4_INTERFACE_GNU
{
l4_word_t values[nr];
int i;
/* Clear all MRs with a pattern that is unlike the test pattern. */
memset (environment_utcb,
~((values_ok[0] & 0x0f) | (values_ok[nr - 1] & 0xf0)),
sizeof (environment_utcb));
l4_load_mrs (start_mr, nr, values_ok);
l4_store_mrs (start_mr, nr, values);
for (i = 0; i < nr; i++)
{
char *msg;
asprintf (&msg,
"l4_load_mrs, l4_store_mrs MR%02i-%02i (MR%02i, 0x%x)",
start_mr, start_mr + nr - 1, start_mr + i, values_ok[i]);
check_nr ("[GNU]", msg, values[i], values_ok[i]);
}
}
#endif
#ifdef _L4_INTERFACE_L4
{
L4_Word_t values[nr];
int i;
/* Clear all MRs with a pattern that is unlike the test pattern. */
memset (environment_utcb,
~((values_ok[0] & 0x0f) | (values_ok[nr - 1] & 0xf0)),
sizeof (environment_utcb));
L4_LoadMRs (start_mr, nr, values_ok);
L4_StoreMRs (start_mr, nr, values);
for (i = 0; i < nr; i++)
{
char *msg;
asprintf (&msg,
"L4_LoadMRs, L4_StoreMRs MR%02i-%02i (MR%02i, 0x%x)",
start_mr, start_mr + nr - 1, start_mr + i, values_ok[i]);
check_nr ("[L4]", msg, values[i], values_ok[i]);
}
}
#endif
}
void
test_mrs (void)
{
static struct
{
int start_mr;
int nr;
word_t values[L4_NUM_MRS_OK];
} tests[] =
{
{ 0, 1, { 22 } },
{ 63, 1, { 23 } },
{ 5, 3, { 1, 2, 3 } },
{ 0, 64, { -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 } }
};
int nr = sizeof (tests) / sizeof (tests[0]);
int i;
#ifdef _L4_INTERFACE_INTERN
check_nr ("[intern]", "_L4_NUM_MRS", _L4_NUM_MRS, L4_NUM_MRS_OK);
#endif
#ifdef _L4_INTERFACE_GNU
check_nr ("[GNU]", "L4_NUM_MRS", L4_NUM_MRS, L4_NUM_MRS_OK);
#endif
/* FIXME: There is no L4 interface for this. */
for (i = 0; i < nr; i++)
if (tests[i].nr == 1)
test_one_mr (tests[i].start_mr, tests[i].values[0]);
else
test_many_mrs (tests[i].start_mr, tests[i].nr, &tests[i].values[0]);
}
/* Test the message register BR with value VAL_OK. */
void
test_one_br (int br, _L4_word_t val_ok)
{
#ifdef _L4_INTERFACE_INTERN
{
_L4_word_t val;
char *msg;
/* Clear all BRs. */
memset (environment_utcb, ~(val_ok & 0xff), sizeof (environment_utcb));
asprintf (&msg, "_L4_load_br and _L4_store_br with BR%02i and value 0x%x",
br, val_ok);
_L4_load_br (br, val_ok);
_L4_store_br (br, &val);
check_nr ("[intern]", msg, val, val_ok);
}
#endif
#ifdef _L4_INTERFACE_GNU
{
l4_word_t val;
char *msg;
/* Clear all BRs. */
memset (environment_utcb, ~(val_ok & 0xff), sizeof (environment_utcb));
asprintf (&msg, "l4_load_br and l4_store_br with BR%02i and value 0x%x",
br, val_ok);
l4_load_br (br, val_ok);
l4_store_br (br, &val);
check_nr ("[GNU]", msg, val, val_ok);
}
#endif
#ifdef _L4_INTERFACE_L4
{
L4_Word_t val;
char *msg;
/* Clear all BRs. */
memset (environment_utcb, ~(val_ok & 0xff), sizeof (environment_utcb));
asprintf (&msg, "L4_LoadBR and L4_StoreBR with BR%02i and value 0x%x",
br, val_ok);
L4_LoadBR (br, val_ok);
L4_StoreBR (br, &val);
check_nr ("[L4]", msg, val, val_ok);
}
#endif
}
/* Test the message registers START_BR to START_BR + NUM - 1
with the values VALUES_OK. */
void
test_many_brs (int start_br, int nr, _L4_word_t *values_ok)
{
#ifdef _L4_INTERFACE_INTERN
{
_L4_word_t values[nr];
int i;
/* Clear all BRs with a pattern that is unlike the test pattern. */
memset (environment_utcb,
~((values_ok[0] & 0x0f) | (values_ok[nr - 1] & 0xf0)),
sizeof (environment_utcb));
_L4_load_brs (start_br, nr, values_ok);
_L4_store_brs (start_br, nr, values);
for (i = 0; i < nr; i++)
{
char *msg;
asprintf (&msg,
"_L4_load_brs, _L4_store_brs BR%02i-%02i (BR%02i, 0x%x)",
start_br, start_br + nr - 1, start_br + i, values_ok[i]);
check_nr ("[intern]", msg, values[i], values_ok[i]);
}
}
#endif
#ifdef _L4_INTERFACE_GNU
{
l4_word_t values[nr];
int i;
/* Clear all BRs with a pattern that is unlike the test pattern. */
memset (environment_utcb,
~((values_ok[0] & 0x0f) | (values_ok[nr - 1] & 0xf0)),
sizeof (environment_utcb));
l4_load_brs (start_br, nr, values_ok);
l4_store_brs (start_br, nr, values);
for (i = 0; i < nr; i++)
{
char *msg;
asprintf (&msg,
"l4_load_brs, l4_store_brs BR%02i-%02i (BR%02i, 0x%x)",
start_br, start_br + nr - 1, start_br + i, values_ok[i]);
check_nr ("[GNU]", msg, values[i], values_ok[i]);
}
}
#endif
#ifdef _L4_INTERFACE_L4
{
L4_Word_t values[nr];
int i;
/* Clear all BRs with a pattern that is unlike the test pattern. */
memset (environment_utcb,
~((values_ok[0] & 0x0f) | (values_ok[nr - 1] & 0xf0)),
sizeof (environment_utcb));
L4_LoadBRs (start_br, nr, values_ok);
L4_StoreBRs (start_br, nr, values);
for (i = 0; i < nr; i++)
{
char *msg;
asprintf (&msg,
"L4_LoadBRs, L4_StoreBRs BR%02i-%02i (BR%02i, 0x%x)",
start_br, start_br + nr - 1, start_br + i, values_ok[i]);
check_nr ("[L4]", msg, values[i], values_ok[i]);
}
}
#endif
}
void
test_brs (void)
{
static struct
{
int start_br;
int nr;
word_t values[L4_NUM_BRS_OK];
} tests[] =
{
{ 0, 1, { 24 } },
{ 63, 1, { 25 } },
{ 5, 3, { 4, 5, 6 } },
{ 0, 34, { -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 } }
};
int nr = sizeof (tests) / sizeof (tests[0]);
int i;
#ifdef _L4_INTERFACE_INTERN
check_nr ("[intern]", "_L4_NUM_BRS", _L4_NUM_BRS, L4_NUM_BRS_OK);
#endif
#ifdef _L4_INTERFACE_GNU
check_nr ("[GNU]", "L4_NUM_BRS", L4_NUM_BRS, L4_NUM_BRS_OK);
#endif
/* FIXME: There is no L4 interface for this. */
for (i = 0; i < nr; i++)
if (tests[i].nr == 1)
test_one_br (tests[i].start_br, tests[i].values[0]);
else
test_many_brs (tests[i].start_br, tests[i].nr, &tests[i].values[0]);
}
void
test (void)
{
test_mrs ();
test_brs ();
}
|