diff options
author | marcus <marcus> | 2005-02-15 18:27:45 +0000 |
---|---|---|
committer | marcus <marcus> | 2005-02-15 18:27:45 +0000 |
commit | ac8427463493edc96a390e7089598f93c303426f (patch) | |
tree | 49ec82d8654fc672061841b260b34b63719e6ac7 /libl4/tests | |
parent | 4fbb56b511d1546ba7e9fbbbc360eec99ce7715c (diff) |
2005-02-15 Marcus Brinkmann <marcus@gnu.org>
* ia32/l4/bits/vregs.h (_L4_utcb) [_L4_TEST_ENVIRONMENT]: Use
_L4_TEST_UTCB_IMPL instead real implementation.
* tests/Makefile.am (TESTS): Add l4-message.
* tests/t-l4-message.c: New file.
* tests/environment.h: Include stdio.h.
(getenv): Define prototype (can't include stdlib.h, urgs).
(environment_utcb, environment_utcb_address): New global
variables.
(_L4_TEST_UTCB_IMPL): New macro.
(environment_init): Parse arguments and TESTOPTS environment
variable.
(vebose): Rename to ...
(opt_verbose): ... this and initialize to 0.
(keep_going): Rename to ...
(keep_going): ... this and initialize to 0.
Diffstat (limited to 'libl4/tests')
-rw-r--r-- | libl4/tests/Makefile.am | 2 | ||||
-rw-r--r-- | libl4/tests/environment.h | 72 | ||||
-rw-r--r-- | libl4/tests/t-l4-kip.c | 2 | ||||
-rw-r--r-- | libl4/tests/t-l4-message.c | 388 |
4 files changed, 453 insertions, 11 deletions
diff --git a/libl4/tests/Makefile.am b/libl4/tests/Makefile.am index f18d3bf..1b1419e 100644 --- a/libl4/tests/Makefile.am +++ b/libl4/tests/Makefile.am @@ -18,7 +18,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -TESTS = t-l4-kip +TESTS = t-l4-kip t-l4-message noinst_HEADERS = environment.h diff --git a/libl4/tests/environment.h b/libl4/tests/environment.h index 3f54448..8d174be 100644 --- a/libl4/tests/environment.h +++ b/libl4/tests/environment.h @@ -1,6 +1,13 @@ /* environment.h - Fake test environment for testing libl4. */ +#include <stdio.h> + +/* FIXME: We can not include stdlib.h, as this wants to suck in the + whole libl4 headers via pthread (which currently fails as pthread + doesn't include the header files). Ouch! */ +extern char *getenv (const char *name); + /* A type that behaves like char * alias-wise, but has the width of the system word size. */ @@ -54,10 +61,13 @@ static const big_char_like environment_kip[] = contains the system call stubs. */ }; -unsigned int environment_api_version = 0x84050000; -unsigned int environment_api_flags = 0x00000000; -unsigned int environment_kernel_id = 0x04020000; +static unsigned int environment_api_version = 0x84050000; +static unsigned int environment_api_flags = 0x00000000; +static unsigned int environment_kernel_id = 0x04020000; +/* 64 MRs forwards, 16 UTCB words and 33 BRs backwards. */ +static big_char_like environment_utcb[64 + 16 + 33]; +static big_char_like *environment_utcb_address = &environment_utcb[33 + 16]; #else #error not ported to this architecture #endif @@ -69,6 +79,8 @@ unsigned int environment_kernel_id = 0x04020000; *kernel_id = environment_kernel_id; \ return (_L4_kip_t) environment_kip; +#define _L4_TEST_UTCB_IMPL \ + return (_L4_word_t *) environment_utcb_address; /* This signals to libl4 that we are running in a fake test environment. */ @@ -93,10 +105,10 @@ unsigned int environment_kernel_id = 0x04020000; /* Be verbose. */ -static int verbose = 1; +static int opt_verbose; /* Do not exit if errors occur. */ -static int keep_going = 1; +static int opt_keep_going; /* True if a check failed. */ @@ -107,9 +119,51 @@ static int failed; void static inline environment_init (int argc, char *argv[]) { + int i; + #if _L4_INTERFACE_GNU __l4_kip = (_L4_kip_t) environment_kip; #endif + + for (i = 0; i < argc; i++) + { + char *arg; + + if (i == 0) + { + arg = getenv ("TESTOPTS"); + if (!arg) + continue; + } + else + { + arg = argv[i]; + + if (arg[0] != '-') + continue; + arg++; + } + + while (*arg) + { + switch (*arg) + { + case 'v': + opt_verbose = 1; + break; + + case 'k': + opt_keep_going = 1; + break; + + default: + fprintf (stderr, "%s: warning: ignoring unknown option -%c\n", + argv[0], *arg); + break; + } + arg++; + } + } } @@ -121,22 +175,22 @@ static inline environment_init (int argc, char *argv[]) #define check(prefix,msg,cond,...) \ do \ { \ - if (verbose) \ + if (opt_verbose) \ printf ("%s Checking %s... ", prefix, msg); \ if (cond) \ { \ - if (verbose) \ + if (opt_verbose) \ printf ("OK\n"); \ } \ else \ { \ - if (verbose) \ + if (opt_verbose) \ printf ("failed\n"); \ fprintf (stderr, "FAIL: %s ", prefix); \ fprintf (stderr, __VA_ARGS__); \ fprintf (stderr, "\n"); \ failed = 1; \ - if (!keep_going) \ + if (!opt_keep_going) \ exit (1); \ } \ } \ diff --git a/libl4/tests/t-l4-kip.c b/libl4/tests/t-l4-kip.c index 98b18ee..ff239e3 100644 --- a/libl4/tests/t-l4-kip.c +++ b/libl4/tests/t-l4-kip.c @@ -22,7 +22,7 @@ #include <string.h> #include <stddef.h> -/* This must be included before anything else. */ +/* This must be included before any libl4 header. */ #include "environment.h" diff --git a/libl4/tests/t-l4-message.c b/libl4/tests/t-l4-message.c new file mode 100644 index 0000000..8700ffe --- /dev/null +++ b/libl4/tests/t-l4-message.c @@ -0,0 +1,388 @@ +/* t-vregs.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> + + +/* Test the message register MR with value VAL_OK. */ +void +test_one_mr (int mr, _L4_word_t val_ok) +{ + { + _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); + } + +#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) +{ + { + _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]); + } + } + +#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; + _L4_word_t values[L4_NUM_MRS]; + } 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; + + check_nr ("[intern]", "_L4_NUM_MRS", _L4_NUM_MRS, 64); +#ifdef _L4_INTERFACE_GNU + check_nr ("[GNU]", "L4_NUM_MRS", L4_NUM_MRS, 64); +#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) +{ + { + _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); + } + +#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) +{ + { + _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]); + } + } + +#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; + _L4_word_t values[L4_NUM_BRS]; + } 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; + + check_nr ("[intern]", "_L4_NUM_BRS", _L4_NUM_BRS, 33); +#ifdef _L4_INTERFACE_GNU + check_nr ("[GNU]", "L4_NUM_BRS", L4_NUM_BRS, 33); +#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 (); +} |