/[gxemul]/upstream/0.3.2/tests/do_tests.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.3.2/tests/do_tests.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations)
Mon Oct 8 16:18:06 2007 UTC (11 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 5983 byte(s)
0.3.2
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.8 2005/03/05 12:05:31 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 2
45 static char *way_args[MAX_WAYS] = { "-E testmips", "-E testmips -b" };
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 strcpy(oname, fname); oname[strlen(oname)-1] = '\0';
100 strcpy(ename, oname);
101 strcpy(gname, oname);
102
103 strcat(oname, "o");
104 strcat(ename, "out"); /* MIPS executable */
105 strcat(gname, "good");
106 }
107
108 args = way_args[way];
109 printf(" %s (%s)\n", fname, args);
110
111 res = stat(fname, &st);
112 if (res == 0) {
113 char s[10000];
114 /* File exists, let's assemble it: */
115 sprintf(s, "%s %s -o %s", invoke_as, fname, oname);
116 res = system(s);
117 if (res != 0) {
118 printf("%05i: ERROR when invoking assembler, "
119 "error code %i\n", test_nr, res);
120 tests_failed ++;
121 } else {
122 sprintf(s, "%s test_common.o %s -o %s",
123 invoke_ld, oname, ename);
124 res = system(s);
125 if (res != 0) {
126 printf("%05i: ERROR when invoking "
127 "linker, error code %i\n",
128 test_nr, res);
129 tests_failed ++;
130 } else {
131 char *t = tmpnam(NULL);
132 /* printf("t = %s\n", t); */
133 sprintf(s, "%s -q %s %s > %s",
134 invoke_gxemul, args, ename, t);
135 res = system(s);
136 if (res != 0) {
137 printf("%05i: ERROR when "
138 "invoking gxemul, error"
139 " code %i\n", test_nr, res);
140 tests_failed ++;
141 } else {
142 /* Compare the output to a
143 known good test result: */
144 sprintf(s, "cmp -s %s %s",
145 gname, t);
146 res = system(s);
147 if (res != 0) {
148 printf("%05i: ERROR "
149 "when comparing cur"
150 "rent output to kno"
151 "wn good output\n",
152 test_nr);
153 sprintf(s, "cat %s\n",
154 gname);
155 printf("%s\n", s);
156 system(s);
157 sprintf(s, "cat %s\n",
158 t);
159 printf("%s\n", s);
160 system(s);
161 tests_failed ++;
162 } else {
163 tests_passed ++;
164 }
165 remove(t);
166 }
167 }
168 }
169 } else
170 break;
171
172 way = (way + 1) % MAX_WAYS;
173
174 test_nr ++;
175 }
176
177 closedir(dirp);
178
179 printf("\nDone. (%i tests done)\n", test_nr);
180 printf(" PASS: %6i\n", tests_passed);
181 printf(" FAIL: %6i\n", tests_failed);
182
183 if (tests_failed != 0) {
184 printf("\n*** ONE OR MORE TESTS FAILED!!! ***\n\n");
185 return 1;
186 } else if (tests_failed + tests_passed != test_nr) {
187 printf("\n*** INTERNAL ERROR IN do_tests.c ***\n\n");
188 return 1;
189 } else {
190 printf("\n\n----------------\n\n"
191 " All tests OK\n\n----------------\n\n");
192 }
193
194 return 0;
195 }
196
197
198 /*
199 * main():
200 */
201 int main(int argc, char *argv[])
202 {
203 char s[10000];
204
205 progname = argv[0];
206
207 if (argc != 5) {
208 usage();
209 exit(1);
210 }
211
212 invoke_cc = argv[1];
213 invoke_as = argv[2];
214 invoke_ld = argv[3];
215 invoke_gxemul = argv[4];
216
217 /* fprintf(stderr, "%s: debug:\n"
218 " invoke_cc = '%s'\n"
219 " invoke_as = '%s'\n"
220 " invoke_ld = '%s'\n"
221 " invoke_gxemul = '%s'\n",
222 progname, invoke_cc, invoke_as, invoke_ld, invoke_gxemul); */
223
224 return do_tests();
225 }
226

  ViewVC Help
Powered by ViewVC 1.1.26