summaryrefslogtreecommitdiff
path: root/libl4/tests/environment.h
blob: 8a699ff5469f152a6d81682aa8076f8b7c3b406c (plain)
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
/* 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);
extern void exit (int status) __attribute__ ((__noreturn__));


/* 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__))) word_t;
typedef word_t __attribute__((__may_alias__)) word_ma_t;
#else
#error not ported to this architecture
#endif

/* Our kernel interface page.  */
#ifdef __i386__
static const word_ma_t environment_kip[] = 
  {
    /* 0x0000 */ 0x4be6344c, 0x84050000, 0x00000000, 0x00000140,
    /* 0x0010 */ 0x0014fab0, 0xf0129720, 0x00000000, 0x00000000,
    /* 0x0020 */ 0x00000000, 0x00041c70, 0x00040000, 0x000483a0,
    /* 0x0030 */ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    /* 0x0040 */ 0x00000000, 0x00300000, 0x00300000, 0x0030ba90,
    /* 0x0050 */ 0x00000000, 0x01d00007, 0x00000000, 0x00000000,
    /* 0x0060 */ 0x00000000, 0x00000000, 0x00100200, 0x0014f000,
    /* 0x0070 */ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    /* 0x0080 */ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    /* 0x0090 */ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    /* 0x00a0 */ 0x00000000, 0x00000000, 0x000c2401, 0x0000000c,
    /* 0x00b0 */ 0x00000000, 0x00000000, 0x00032600, 0x00000120,
    /* 0x00c0 */ 0x00000000, 0x03001011, 0x00401006, 0x40000001,
    /* 0x00d0 */ 0x00000910, 0x000008e0, 0x00000930, 0x00000940,
    /* 0x00e0 */ 0x00000800, 0x00000830, 0x000008d0, 0x00000860,
    /* 0x00f0 */ 0x00000870, 0x000008b0, 0x000008c0, 0x00000000,

    /* 0x0100 */ 0x00000000, 0x00000000, 0x00000000, 0x00000000,
    /* 0x0110 */ 0x00000950, 0x00000000, 0x00000000, 0x00000000,
    /* 0x0120 */ 0x00000000, 0x002addde, 0x00000000, 0x00000000,
    /* 0x0130 */ 0x00000000, 0x002adddf, 0x00000000, 0x00000000,
    /* 0x0140 */ 0x04020000, 0x00000a36, 0x00040000, 0x20614b55,
    /* 0x0150 */ 0x614b344c, 0x69503a3a, 0x63617473, 0x206f6968,
    /* 0x0160 */ 0x7562202d, 0x20746c69, 0x4a206e6f, 0x32206e61,
    /* 0x0170 */ 0x30322032, 0x30203530, 0x36323a32, 0x2034313a,
    /* 0x0180 */ 0x6d207962, 0x75637261, 0x6c754073, 0x65737379,
    /* 0x0190 */ 0x73752073, 0x20676e69, 0x20636367, 0x73726576,
    /* 0x01a0 */ 0x206e6f69, 0x2e332e33, 0x44282034, 0x61696265,
    /* 0x01b0 */ 0x3a31206e, 0x2e332e33, 0x33312d34, 0x6d730029,
    /* 0x01c0 */ 0x736c6c61, 0x65636170, 0x00000073, 0x00000000,
    /* 0x01d0 */ 0x00000004, 0xfffffc00, 0x00000001, 0x0009f800,
    /* 0x01e0 */ 0x00100001, 0x07fffc00, 0x000a0004, 0x000efc00,
    /* 0x01f0 */ 0x07000002, 0x08000000, 0x00000201, 0xbffffc00,
    /* 0x0200 */ 0x00100002, 0x0014ec00, 0x00000000, 0x00000000

    /* The rest in the real KIP are 0x00, until offset 0x800, which
       contains the system call stubs.  */
  };

static word_t __attribute__((__unused__)) environment_api_version = 0x84050000;
static word_t __attribute__((__unused__)) environment_api_flags = 0x00000000;
static word_t __attribute__((__unused__)) environment_kernel_id = 0x04020000;

/* 64 MRs forwards, 16 UTCB words and 33 BRs backwards.  */
static word_t environment_utcb[64 + 16 + 33];
static word_t *environment_utcb_address = &environment_utcb[33 + 16];
#else
#error not ported to this architecture
#endif


#ifdef _L4_TEST_EXTERNAL_LIBL4

#warning Add support for your external libl4 here.

/* Only check the official interface.  */
#undef _L4_INTERFACE_INTERN
#undef _L4_INTERFACE_GNU
#define _L4_INTERFACE_L4	1

#else	/* _L4_TEST_EXTERNAL_LIBL4 */

/* This signals to libl4 that we are running in a fake test
   environment.  */
#define _L4_TEST_ENVIRONMENT	1

/* Our implementation of the kernel interface system call.  */
#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;

/* Our implementation of the "get utcb address" function.  */
#define _L4_TEST_UTCB_IMPL \
  return (_L4_word_t *) environment_utcb_address;

/* Enable all interfaces.  */
#define _L4_INTERFACE_INTERN	1
#define _L4_INTERFACE_L4	1
#define _L4_INTERFACE_GNU	1

#include <l4/features.h>

/* If you want to test if you wrote the tests for the various
   interfaces independently of each other, enable one of these.  */
#if 0
/* Only the official interface.  */
#undef _L4_INTERFACE_INTERN
#undef _L4_INTERFACE_GNU
#elsif 0
/* Only the GNU interface.  */
#undef _L4_INTERFACE_INTERN
#undef _L4_INTERFACE_L4
#elsif 0
/* Only the internal interface.  */
#undef _L4_INTERFACE_GNU
#undef _L4_INTERFACE_L4
#endif

#endif	/* _L4_TEST_EXTERNAL_LIBL4 */


#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 opt_verbose;

/* Do not exit if errors occur.  */
static int opt_keep_going;


/* True if a check failed.  */
static int failed;


/* Initialize the fake environment.  */
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++;
	  }
    }
}


/* Support macros.  */

#include <stdio.h>

#define check(prefix,msg,cond,...) \
  do								\
    {								\
      if (opt_verbose)						\
        printf ("%s Checking %s... ", prefix, msg);		\
      if (cond)							\
        {							\
          if (opt_verbose)					\
            printf ("OK\n");					\
        }							\
      else							\
        {							\
          if (opt_verbose)					\
            printf ("failed\n");				\
          fprintf (stderr, "FAIL: %s ", prefix);		\
          fprintf (stderr, __VA_ARGS__);			\
          fprintf (stderr, "\n");				\
          failed = 1;						\
          if (!opt_keep_going)					\
	    exit (1);						\
        }							\
    }								\
  while (0)

#define check_nr(prefix,msg,val1,val2) \
  do								\
    {								\
      _L4_word_t v1 = (val1);					\
      _L4_word_t v2 = (val2);					\
								\
      check (prefix, msg, (v1 == v2), #val1 " == 0x%x != 0x%x",	\
	     v1, v2);						\
    }								\
  while (0)


void test (void);


int
main (int argc, char *argv[])
{
  /* Initialize the test environment.  */
  environment_init (argc, argv);

  test ();

  return failed ? 1 : 0;
}