2000-10-31 Philip Blundell <philb@gnu.org>
[binutils.git] / ld / testsuite / ld-empic / runtest1.c
blobf9ab6eb66817c54aca0251ab6a4c26a5309bb4ca
1 /* First C source file for actual execution test. */
3 /* The main point of this test is to make sure that the code and data
4 are truly position independent. We statically initialize several
5 global variables, and make sure that they are correctly adjusted at
6 runtime. */
8 int i = 1;
9 int j = 0;
10 extern int k;
11 int l;
12 char small_buf[] = "aaaa";
13 char *small_pointer = small_buf;
14 char big_buf[] = "aaaaaaaaaaaaaaaa";
15 char *big_pointer = big_buf;
17 extern int bar ();
18 int (*pbar) () = bar;
20 static int
21 foo2 (arg)
22 int arg;
24 l = arg;
25 return i + j;
28 int (*pfoo2) () = foo2;
30 int
31 chkstr (z, c)
32 char *z;
33 int c;
35 /* Switch statements need extra effort to be position independent,
36 so we run one here, even though most of the cases will never be
37 taken. */
38 switch (c)
40 case 1:
41 case 2:
42 case 3:
43 return i - 1;
44 case 4:
45 break;
46 case 5:
47 case 6:
48 case 7:
49 case 8:
50 case 9:
51 return i * j;
52 case 10:
53 case 11:
54 case 12:
55 case 13:
56 case 14:
57 case 15:
58 return j;
59 case 16:
60 break;
61 default:
62 return 0;
65 while (c-- != 0)
66 if (*z++ != 'a')
67 return 0;
69 return *z == '\0';
72 /* This function is called by the assembler startup routine. It tries
73 to test that everything was correctly initialized. It returns 0 on
74 success, something else on failure. */
76 int
77 foo ()
79 if (i != 1)
80 return 1;
81 if (j != 0)
82 return 2;
83 if (! chkstr (small_buf, 4))
84 return 3;
85 if (! chkstr (small_pointer, 4))
86 return 4;
87 if (! chkstr (big_buf, 16))
88 return 5;
89 if (! chkstr (big_pointer, 16))
90 return 6;
92 if (l != 0)
93 return 7;
94 if (foo2 (1) != 1)
95 return 8;
96 if (l != 1)
97 return 9;
98 if ((*pfoo2) (2) != 1)
99 return 10;
100 if (l != 2)
101 return 11;
103 if (bar (1) != 0)
104 return 12;
105 if (bar (-1) != 1)
106 return 13;
107 if ((*pbar) (0xa5a5a5a5) != -1)
108 return 14;
109 if (k != 0xa5a5a5a5)
110 return 15;
111 if ((*pbar) (0) != 0xa5a5a5a5)
112 return 16;
113 if (k != 0)
114 return 17;
116 return 0;