1 |
/* |
2 |
* Copyright (C) 2004-2005 Anders Gavare. All rights reserved. |
3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
6 |
* |
7 |
* 1. Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* 3. The name of the author may not be used to endorse or promote products |
13 |
* derived from this software without specific prior written permission. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
* |
28 |
* $Id: do_tests.c,v 1.12 2005/06/26 11:36:30 debug Exp $ |
29 |
* |
30 |
* This program assembles, links, and runs all regression tests. |
31 |
*/ |
32 |
|
33 |
#include <dirent.h> |
34 |
#include <stdio.h> |
35 |
#include <stdlib.h> |
36 |
#include <string.h> |
37 |
#include <sys/types.h> |
38 |
#include <sys/stat.h> |
39 |
|
40 |
|
41 |
static char *progname; |
42 |
static char *invoke_cc, *invoke_as, *invoke_ld, *invoke_gxemul; |
43 |
|
44 |
#define MAX_WAYS 1 |
45 |
static char *way_args[MAX_WAYS] = { "-E testmips" }; |
46 |
|
47 |
|
48 |
/* |
49 |
* usage(): |
50 |
*/ |
51 |
void usage(void) |
52 |
{ |
53 |
fprintf(stderr, "usage: %s how_to_invoke_cc how_to_invoke_as " |
54 |
"how_to_invoke_ld\n", progname); |
55 |
fprintf(stderr, "For example, when using GCC compiled for the " |
56 |
"mips64-unknown-elf target:\n"); |
57 |
fprintf(stderr, " %s \"mips64-unknown-elf-gcc -g -O3 -fno-builtin " |
58 |
"-fschedule-insns -mips4 -mabi=64\"\n" |
59 |
" \"mips64-unknown-elf-as\"\n" |
60 |
" \"mips64-unknown-elf-ld -Ttext 0xffffffff80030000 -e " |
61 |
"main --oformat=elf64-bigmips\"\n", progname); |
62 |
} |
63 |
|
64 |
|
65 |
/* |
66 |
* do_tests(): |
67 |
* |
68 |
* Returns 0 if ALL tests passed. |
69 |
* Returns non-zero otherwise. |
70 |
*/ |
71 |
int do_tests(void) |
72 |
{ |
73 |
int test_nr = 0, way = 0; |
74 |
int tests_passed = 0, tests_failed = 0; |
75 |
DIR *dirp; |
76 |
char *args; |
77 |
char fname[200], oname[200], ename[200], gname[200]; |
78 |
struct stat st; |
79 |
struct dirent *dp; |
80 |
int res; |
81 |
|
82 |
dirp = opendir("."); |
83 |
printf("\nStarting tests:\n"); |
84 |
|
85 |
for (;;) { |
86 |
if (way == 0) { |
87 |
dp = readdir(dirp); |
88 |
if (dp == NULL) |
89 |
break; |
90 |
|
91 |
if (strncmp(dp->d_name, "test_", 5) != 0 || |
92 |
strlen(dp->d_name) < 6 || |
93 |
strcmp(dp->d_name + strlen(dp->d_name) - 2, ".S") |
94 |
!= 0) |
95 |
continue; |
96 |
|
97 |
snprintf(fname, sizeof(fname), dp->d_name); |
98 |
|
99 |
strlcpy(oname, fname, sizeof(oname)); |
100 |
strlcpy(ename, oname, sizeof(ename)); |
101 |
strlcpy(gname, oname, sizeof(gname)); |
102 |
|
103 |
/* Remove the 'S': */ |
104 |
oname[strlen(oname)-1] = '\0'; |
105 |
ename[strlen(ename)-1] = '\0'; |
106 |
gname[strlen(gname)-1] = '\0'; |
107 |
|
108 |
strlcat(oname, "o", sizeof(oname)); |
109 |
strlcat(ename, "out", sizeof(ename)); |
110 |
/* ename = MIPS executable */ |
111 |
strlcat(gname, "good", sizeof(gname)); |
112 |
} |
113 |
|
114 |
args = way_args[way]; |
115 |
printf(" %s (%s)\n", fname, args); |
116 |
|
117 |
res = stat(fname, &st); |
118 |
if (res == 0) { |
119 |
char s[10000]; |
120 |
/* File exists, let's assemble it: */ |
121 |
snprintf(s, sizeof(s), "%s %s -o %s", invoke_as, |
122 |
fname, oname); |
123 |
res = system(s); |
124 |
if (res != 0) { |
125 |
printf("%05i: ERROR when invoking assembler, " |
126 |
"error code %i\n", test_nr, res); |
127 |
tests_failed ++; |
128 |
} else { |
129 |
snprintf(s, sizeof(s), |
130 |
"%s test_common.o %s -o %s", |
131 |
invoke_ld, oname, ename); |
132 |
res = system(s); |
133 |
if (res != 0) { |
134 |
printf("%05i: ERROR when invoking " |
135 |
"linker, error code %i\n", |
136 |
test_nr, res); |
137 |
tests_failed ++; |
138 |
} else { |
139 |
char *t = tmpnam(NULL); |
140 |
/* printf("t = %s\n", t); */ |
141 |
snprintf(s, sizeof(s), |
142 |
"%s -q %s %s > %s", |
143 |
invoke_gxemul, args, ename, t); |
144 |
res = system(s); |
145 |
if (res != 0) { |
146 |
printf("%05i: ERROR when " |
147 |
"invoking gxemul, error" |
148 |
" code %i\n", test_nr, res); |
149 |
tests_failed ++; |
150 |
} else { |
151 |
/* Compare the output to a |
152 |
known good test result: */ |
153 |
snprintf(s, sizeof(s), |
154 |
"cmp -s %s %s", gname, t); |
155 |
res = system(s); |
156 |
if (res != 0) { |
157 |
printf("%05i: ERROR " |
158 |
"when comparing cur" |
159 |
"rent output to kno" |
160 |
"wn good output\n", |
161 |
test_nr); |
162 |
snprintf(s, sizeof(s), |
163 |
"cat %s\n", gname); |
164 |
printf("%s\n", s); |
165 |
system(s); |
166 |
snprintf(s, sizeof(s), |
167 |
"cat %s\n", t); |
168 |
printf("%s\n", s); |
169 |
system(s); |
170 |
tests_failed ++; |
171 |
} else { |
172 |
tests_passed ++; |
173 |
} |
174 |
remove(t); |
175 |
} |
176 |
} |
177 |
} |
178 |
} else |
179 |
break; |
180 |
|
181 |
way = (way + 1) % MAX_WAYS; |
182 |
|
183 |
test_nr ++; |
184 |
} |
185 |
|
186 |
closedir(dirp); |
187 |
|
188 |
printf("\nDone. (%i tests done)\n", test_nr); |
189 |
printf(" PASS: %6i\n", tests_passed); |
190 |
printf(" FAIL: %6i\n", tests_failed); |
191 |
|
192 |
if (tests_failed != 0) { |
193 |
printf("\n*** ONE OR MORE TESTS FAILED!!! ***\n\n"); |
194 |
return 1; |
195 |
} else if (tests_failed + tests_passed != test_nr) { |
196 |
printf("\n*** INTERNAL ERROR IN do_tests.c ***\n\n"); |
197 |
return 1; |
198 |
} else { |
199 |
printf("\n\n----------------\n\n" |
200 |
" All tests OK\n\n----------------\n\n"); |
201 |
} |
202 |
|
203 |
return 0; |
204 |
} |
205 |
|
206 |
|
207 |
/* |
208 |
* main(): |
209 |
*/ |
210 |
int main(int argc, char *argv[]) |
211 |
{ |
212 |
char s[10000]; |
213 |
|
214 |
progname = argv[0]; |
215 |
|
216 |
if (argc != 5) { |
217 |
usage(); |
218 |
exit(1); |
219 |
} |
220 |
|
221 |
invoke_cc = argv[1]; |
222 |
invoke_as = argv[2]; |
223 |
invoke_ld = argv[3]; |
224 |
invoke_gxemul = argv[4]; |
225 |
|
226 |
/* fprintf(stderr, "%s: debug:\n" |
227 |
" invoke_cc = '%s'\n" |
228 |
" invoke_as = '%s'\n" |
229 |
" invoke_ld = '%s'\n" |
230 |
" invoke_gxemul = '%s'\n", |
231 |
progname, invoke_cc, invoke_as, invoke_ld, invoke_gxemul); */ |
232 |
|
233 |
return do_tests(); |
234 |
} |
235 |
|