diff options
author | marcus <marcus> | 2005-02-09 04:12:31 +0000 |
---|---|---|
committer | marcus <marcus> | 2005-02-09 04:12:31 +0000 |
commit | f8af6bac914b79c6e79b07f628634feeb41cc2fc (patch) | |
tree | 21b8eb8ae427f43c58afa25c3a5b72d605261654 | |
parent | f2ca115249930202ee192eb3f10ecc606a240c4e (diff) |
2005-02-09 Marcus Brinkmann <marcus@gnu.org>
* configure.ac (AC_CONFIG_FILES): Add libl4/tests/Makefile.
libl4/
2005-02-09 Marcus Brinkmann <marcus@gnu.org>
* tests/Makefile.am: New file.
* tests/environment.h: New file.
* tests/t-l4-kip.c: New file.
* Makefile.am (SUBDIRS): Add tests.
* ia32/l4/bits/syscall.h (_L4_kernel_interface)
[_L4_TEST_ENVIRONMENT]: Replace function body with
_L4_TEST_KERNEL_INTERFACE_IMPL.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | libl4/ChangeLog | 10 | ||||
-rw-r--r-- | libl4/Makefile.am | 2 | ||||
-rw-r--r-- | libl4/README | 5 | ||||
-rw-r--r-- | libl4/TODO | 1 | ||||
-rw-r--r-- | libl4/ia32/l4/bits/syscall.h | 5 | ||||
-rw-r--r-- | libl4/tests/Makefile.am | 27 | ||||
-rw-r--r-- | libl4/tests/environment.h | 157 | ||||
-rw-r--r-- | libl4/tests/t-l4-kip.c | 108 |
10 files changed, 319 insertions, 3 deletions
@@ -1,3 +1,7 @@ +2005-02-09 Marcus Brinkmann <marcus@gnu.org> + + * configure.ac (AC_CONFIG_FILES): Add libl4/tests/Makefile. + 2005-01-31 Marcus Brinkmann <marcus@gnu.org> * README: Revert last change for now. diff --git a/configure.ac b/configure.ac index df89a0c..bafb487 100644 --- a/configure.ac +++ b/configure.ac @@ -168,7 +168,8 @@ fi # Checks for library functions. AC_CONFIG_FILES([Makefile - libl4/ia32/Makefile libl4/powerpc/Makefile libl4/Makefile + libl4/ia32/Makefile libl4/powerpc/Makefile + libl4/tests/Makefile libl4/Makefile platform/alpha/Makefile platform/amd64/Makefile platform/ia32/Makefile platform/ia64/Makefile platform/powerpc/Makefile platform/powerpc64/Makefile diff --git a/libl4/ChangeLog b/libl4/ChangeLog index b410a55..b053c6f 100644 --- a/libl4/ChangeLog +++ b/libl4/ChangeLog @@ -1,3 +1,13 @@ +2005-02-09 Marcus Brinkmann <marcus@gnu.org> + + * tests/Makefile.am: New file. + * tests/environment.h: New file. + * tests/t-l4-kip.c: New file. + * Makefile.am (SUBDIRS): Add tests. + * ia32/l4/bits/syscall.h (_L4_kernel_interface) + [_L4_TEST_ENVIRONMENT]: Replace function body with + _L4_TEST_KERNEL_INTERFACE_IMPL. + 2005-02-08 Marcus Brinkmann <marcus@gnu.org> * l4/ipc.h: Major overhaul. Avoid breaking struct aliasing rules. diff --git a/libl4/Makefile.am b/libl4/Makefile.am index 13262b8..ffad6fb 100644 --- a/libl4/Makefile.am +++ b/libl4/Makefile.am @@ -24,7 +24,7 @@ endif if ARCH_POWERPC ARCH_SUBDIR = powerpc endif -SUBDIRS = $(ARCH_SUBDIR) +SUBDIRS = $(ARCH_SUBDIR) tests # Header files that must be provided by all interfaces. common_headers := ipc.h kip.h message.h misc.h schedule.h space.h \ diff --git a/libl4/README b/libl4/README index 0dfc34f..1e40de5 100644 --- a/libl4/README +++ b/libl4/README @@ -95,6 +95,11 @@ requirements are: endianess of the architecture into a single word, and the bits within the individual bit-fields in the same order. +* Your compiler must provide a __builtin_memcpy that optimizes copies + of fixed small size (one or two machine words). The memcpy's are + necessary to not break strict aliasing rules. (But on the plus + side, you can use strict aliasing optimization). + What is the status of the library? ---------------------------------- @@ -26,6 +26,7 @@ * GNU interface ** Implement the cache hint support functions. ** Implement l4_thread_was_* functions. +** l4/globals.h should be moved to l4/gnu/globals.h. * Compatibility interface ** Implement more of the inofficial extensions to the official libl4 diff --git a/libl4/ia32/l4/bits/syscall.h b/libl4/ia32/l4/bits/syscall.h index 9dd0655..8473a8e 100644 --- a/libl4/ia32/l4/bits/syscall.h +++ b/libl4/ia32/l4/bits/syscall.h @@ -26,12 +26,12 @@ /* Return the pointer to the kernel interface page, the API version, the API flags, and the kernel ID. */ - static inline _L4_kip_t _L4_attribute_always_inline _L4_attribute_const _L4_kernel_interface (_L4_api_version_t *api_version, _L4_api_flags_t *api_flags, _L4_kernel_id_t *kernel_id) { +#ifndef _L4_TEST_ENVIRONMENT void *kip; /* The KernelInterface system call is invoked by "lock; nop" and @@ -43,6 +43,9 @@ _L4_kernel_interface (_L4_api_version_t *api_version, "=d" (*api_flags), "=S" (*kernel_id)); return kip; +#else + _L4_TEST_KERNEL_INTERFACE_IMPL +#endif /* _L4_TEST_ENVIRONMENT */ } diff --git a/libl4/tests/Makefile.am b/libl4/tests/Makefile.am new file mode 100644 index 0000000..f18d3bf --- /dev/null +++ b/libl4/tests/Makefile.am @@ -0,0 +1,27 @@ +# Makefile.am - Makefile template for libl4/tests. +# Copyright (C) 2005 Free Software Foundation, Inc. +# Written by Marcus Brinkmann. +# +# This file is part of the GNU Hurd. +# +# The GNU Hurd is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# The GNU Hurd 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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 + +noinst_HEADERS = environment.h + +AM_CPPFLAGS = -I$(top_builddir)/include + +noinst_PROGRAMS = $(TESTS) diff --git a/libl4/tests/environment.h b/libl4/tests/environment.h new file mode 100644 index 0000000..471d2c3 --- /dev/null +++ b/libl4/tests/environment.h @@ -0,0 +1,157 @@ +/* environment.h - Fake test environment for testing libl4. + */ + + +/* A type that behaves like char * alias-wise, but has the width of + the system word size. */ +#ifdef __i386__ +typedef unsigned int __attribute__((__mode__ (__SI__), __may_alias__)) + big_char_like; +#else +#error not ported to this architecture +#endif + +/* Our kernel interface page. */ +#ifdef __i386__ +static const big_char_like environment_kip[] = + { + 0x4be6344c, 0x84050000, 0x00000000, 0x00000130, + 0x0014fab0, 0xf0129720, 0x00000000, 0x00000000, + 0x00000000, 0x00041c70, 0x00040000, 0x000483a0, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00300000, 0x00300000, 0x0030ba90, + 0x00000000, 0x01c00007, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00100200, 0x0014f000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x00000000, 0x000c2401, 0x0000000c, + 0x00000000, 0x00000000, 0x00032600, 0x00000120, + 0x00000000, 0x03001011, 0x00401006, 0x40000000, + 0x00000910, 0x000008e0, 0x00000930, 0x00000940, + 0x00000800, 0x00000830, 0x000008d0, 0x00000860, + 0x00000870, 0x000008b0, 0x000008c0, 0x00000000, + + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000950, 0x00000000, 0x00000000, 0x00000000, + 0x00000000, 0x002addde, 0x00000000, 0x00000000, + 0x04020000, 0x00000a36, 0x00040000, 0x20614b55, + 0x614b344c, 0x69503a3a, 0x63617473, 0x206f6968, + 0x7562202d, 0x20746c69, 0x4a206e6f, 0x32206e61, + 0x30322032, 0x30203530, 0x36323a32, 0x2034313a, + 0x6d207962, 0x75637261, 0x6c754073, 0x65737379, + 0x73752073, 0x20676e69, 0x20636367, 0x73726576, + 0x206e6f69, 0x2e332e33, 0x44282034, 0x61696265, + 0x3a31206e, 0x2e332e33, 0x33312d34, 0x00000029, + 0x00000000, 0x00000000, 0x00000000, 0x00000000, + 0x00000004, 0xfffffc00, 0x00000001, 0x0009f800, + 0x00100001, 0x07fffc00, 0x000a0004, 0x000efc00, + 0x07000002, 0x08000000, 0x00000201, 0xbffffc00, + 0x00100002, 0x0014ec00, 0x00000000, 0x00000000 + + /* The rest in the real KIP are 0x00, until offset 0x800, which + contains the system call stubs. */ + }; + +unsigned int environment_api_version = 0x84050000; +unsigned int environment_api_flags = 0x00000000; +unsigned int environment_kernel_id = 0x04020000; + +#else +#error not ported to this architecture +#endif + + +#define _L4_TEST_KERNEL_INTERFACE_IMPL \ + *api_version = environment_api_version; \ + *api_flags = environment_api_flags; \ + *kernel_id = environment_kernel_id; \ + return (_L4_kip_t) environment_kip; + + +/* This signals to libl4 that we are running in a fake test + environment. */ +#define _L4_TEST_ENVIRONMENT 1 + + +/* Enable all interfaces. */ +#define _L4_INTERFACE_L4 1 +#define _L4_INTERFACE_GNU 1 + + +#include <l4/features.h> + + +#ifdef _L4_INTERFACE_GNU + +/* Include the global variables that need to be available in every + program. They are initialized by INIT. */ +#include <l4/globals.h> + +#endif /* _L4_INTERFACE_GNU */ + + +/* Be verbose. */ +static int verbose = 1; + +/* Do not exit if errors occur. */ +static int keep_going = 1; + + +/* True if a check failed. */ +static int failed; + + +/* Initialize the fake environment. */ +void +static inline environment_init (int argc, char *argv[]) +{ +#if _L4_INTERFACE_GNU + __l4_kip = (_L4_kip_t) environment_kip; +#endif +} + + +/* Support macros. */ + +#include <stdio.h> +#include <stdlib.h> + +#define check(prefix,msg,cond,...) \ + do \ + { \ + if (verbose) \ + printf ("%s Checking %s... ", prefix, msg); \ + if (cond) \ + { \ + if (verbose) \ + printf ("OK\n"); \ + } \ + else \ + { \ + if (verbose) \ + printf ("failed\n"); \ + fprintf (stderr, "FAIL: %s ", prefix); \ + fprintf (stderr, __VA_ARGS__); \ + failed = 1; \ + if (!keep_going) \ + exit (1); \ + } \ + } \ + while (0) + + + +void test (void); + + +int +main (int argc, char *argv[]) +{ + /* Initialize the test environment. */ + environment_init (argc, argv); + + test (); + + return failed ? 1 : 0; +} diff --git a/libl4/tests/t-l4-kip.c b/libl4/tests/t-l4-kip.c new file mode 100644 index 0000000..08e2c59 --- /dev/null +++ b/libl4/tests/t-l4-kip.c @@ -0,0 +1,108 @@ +/* t-l4-kip.c - A test for the KIP related code in libl4. + Copyright (C) 2005 Free Software Foundation, Inc. + Written by 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. */ + +/* This must be included before anything else. */ +#include "environment.h" + + +#include <l4/kip.h> + + +/* Test the various ways to get a pointer to the kernel interface + page, and the magic bytes at the beginning. */ +void +test_magic () +{ + /* This is our atom. We can't check it except by looking at the + magic, and we set it in our faked environment anyway. */ + _L4_api_version_t api_version; + _L4_api_flags_t api_flags; + _L4_kernel_id_t kernel_id; + _L4_kip_t kip = _L4_kernel_interface (&api_version, &api_flags, &kernel_id); + + /* Verify that our fake KIP is actually there. */ + check ("[intern]", "if fake KIP is installed", + + (kip->magic[0] == 'L' && kip->magic[1] == '4' + && kip->magic[2] == (char) 0xe6 && kip->magic[3] == 'K'), + + "_L4_kernel_interface kip magic == %c%c%c%c != L4\xe6K\n", + kip->magic[0], kip->magic[1], kip->magic[2], kip->magic[3]); + + + /* Verify the other values returned by _L4_kernel_interface. This + is basically an internal consistency check. */ + check ("[intern]", "if fake API version matches KIP", + (api_version == kip->api_version.raw), + "_L4_kernel_interface api_version == 0x%x != 0x%x\n", + api_version, kip->api_version.raw); + check ("[intern]", "if fake API flags matches KIP", + (api_flags == kip->api_flags.raw), + "_L4_kernel_interface api_flags == 0x%x != 0x%x\n", + api_flags, kip->api_flags.raw); + check ("[intern]", "if fake kernel ID flags matches KIP", + (kernel_id == _L4_kernel_desc (kip)->id.raw), + "_L4_kernel_interface kernel_id == 0x%x != 0x%x\n", + kernel_id, _L4_kernel_desc (kip)->id.raw); + +#ifdef _L4_INTERFACE_GNU + { + /* Some other ways to get the same information. */ + l4_kip_t kip_gnu = l4_kip (); + + check ("[GNU]", "if l4_kip() returns the KIP", + (kip_gnu == kip), + "kip_gnu == %p != %p\n", kip_gnu, kip); + } +#endif + +#ifdef _L4_INTERFACE_L4 + { + L4_Word_t api_version_l4; + L4_Word_t api_flags_l4; + L4_Word_t kernel_id_l4; + + void *kip_l4 = L4_KernelInterface (&api_version_l4, &api_flags_l4, + &kernel_id_l4); + + check ("[L4]", "if L4_KernelInterface returns the KIP", + (kip_l4 == kip), + "kip_l4 == %p != %p\n", kip_l4, kip); + + check ("[L4]", "if L4 API version matches KIP", + (api_version_l4 == api_version), + "api_version_l4 == 0x%x != 0x%x\n", api_version_l4, api_version); + check ("[L4]", "if L4 API flags matches KIP", + (api_flags_l4 == api_flags), + "api_flags_l4 == 0x%x != 0x%x\n", api_flags_l4, api_flags); + check ("[L4]", "if L4 kernel ID flags matches KIP", + (kernel_id_l4 == kernel_id), + "kip_l4 == 0x%x != 0x%x\n", kernel_id_l4, kernel_id); + } +#endif +} + + +void +test (void) +{ + test_magic (); +} |