2 * Copyright (c) 2018 Jiří Zárevúcky
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <str_error.h>
38 static errno_t
run_test(const char *logfile
, const char *logmode
,
39 const char *path
, const char *const args
[], task_exit_t
*ex
, int *retval
)
41 FILE *f
= fopen(logfile
, logmode
);
43 fprintf(stderr
, "Can't open file %s: %s\n",
44 logfile
, str_error(errno
));
49 errno_t rc
= vfs_fhandle(f
, &h
);
51 fprintf(stderr
, "Error getting file handle: %s\n",
60 rc
= task_spawnvf(&id
, &wait
, path
, args
, -1, h
, h
);
62 fprintf(stderr
, "Task spawning failed: %s\n",
68 rc
= task_wait(&wait
, ex
, retval
);
70 fprintf(stderr
, "Task wait failed: %s\n",
76 // TODO: check that we are managing resources correctly
81 static void run_tester(const char *logfile
)
83 const char *const tests
[] = {
103 // FIXME: malloc2 doesn't work as expected
112 int tests_count
= sizeof(tests
) / sizeof(const char *);
118 const char *app
= "/app/tester";
120 for (int i
= 0; i
< tests_count
; i
++) {
121 const char *const args
[] = { app
, tests
[i
], NULL
};
122 errno_t rc
= run_test(logfile
, "a", app
, args
, &ex
, &retval
);
124 /* Reason already printed in run_test(). */
128 if (ex
!= TASK_EXIT_NORMAL
) {
129 fprintf(stderr
, "tester %s CRASHED\n",
136 printf("tester %s ok\n", tests
[i
]);
138 printf("tester %s FAILED\n", tests
[i
]);
143 printf("tester: %d failed tests\n", failed
);
146 static void run_tester_fault(const char *logfile
)
151 const char *app
= "/app/tester";
152 const char *const args
[] = { app
, "fault1", NULL
};
153 errno_t rc
= run_test(logfile
, "w", app
, args
, &ex
, &retval
);
155 /* Reason already printed in run_test(). */
159 if (ex
!= TASK_EXIT_UNEXPECTED
) {
160 fprintf(stderr
, "`tester fault1` unexpectedly"
161 " didn't terminate unexpectedly\n");
165 printf("`tester fault1`: terminated as expected\n");
168 static void run_pcut_tests(void)
170 printf("Running all pcut tests...\n");
172 DIR *d
= opendir("/test");
178 while ((e
= readdir(d
))) {
179 if (str_lcmp(e
->d_name
, "test-", 5) != 0)
186 if (asprintf(&bin
, "/test/%s", e
->d_name
) < 0) {
187 fprintf(stderr
, "out of memory\n");
192 if (asprintf(&logfile
, "/data/web/result-%s.txt", e
->d_name
) < 0) {
193 fprintf(stderr
, "out of memory\n");
197 const char *const args
[] = { bin
, NULL
};
198 errno_t rc
= run_test(logfile
, "w", bin
, args
, &ex
, &retval
);
203 /* Reason already printed in run_test(). */
207 if (ex
!= TASK_EXIT_NORMAL
) {
208 fprintf(stderr
, "%s CRASHED\n", e
->d_name
);
213 printf("%s ok\n", e
->d_name
);
215 printf("%s FAILED\n", e
->d_name
);
222 static void gen_index(const char *fname
)
224 FILE *f
= fopen(fname
, "w");
226 fprintf(stderr
, "Can't open %s for writing: %s\n", fname
,
227 str_error_name(errno
));
231 fprintf(f
, "<html><head><title>HelenOS test results"
232 "</title></head><body>\n");
233 fprintf(f
, "<h1>HelenOS test results</h1><ul>\n");
235 fprintf(f
, "<li><a href=\"result-tester.txt\">tester</a></li>\n");
237 DIR *d
= opendir("/test");
241 while ((e
= readdir(d
))) {
242 if (str_lcmp(e
->d_name
, "test-", 5) != 0)
245 fprintf(f
, "<li><a href=\"result-%s.txt\">%s"
246 "</a></li>\n", e
->d_name
, e
->d_name
);
250 fprintf(f
, "</ul></body></html>\n");
254 int main(int argc
, char **argv
)
256 run_tester("/data/web/result-tester.txt");
257 run_tester_fault("/tmp/tester_fault.log");
260 const char *fname
= "/data/web/test.html";
261 printf("Generating HTML report in %s\n", fname
);