1a563ca70SAlex Hornung /*
2a563ca70SAlex Hornung * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>.
3a563ca70SAlex Hornung * All rights reserved.
4a563ca70SAlex Hornung *
5a563ca70SAlex Hornung * Redistribution and use in source and binary forms, with or without
6a563ca70SAlex Hornung * modification, are permitted provided that the following conditions
7a563ca70SAlex Hornung * are met:
8a563ca70SAlex Hornung *
9a563ca70SAlex Hornung * 1. Redistributions of source code must retain the above copyright
10a563ca70SAlex Hornung * notice, this list of conditions and the following disclaimer.
11a563ca70SAlex Hornung * 2. Redistributions in binary form must reproduce the above copyright
12a563ca70SAlex Hornung * notice, this list of conditions and the following disclaimer in
13a563ca70SAlex Hornung * the documentation and/or other materials provided with the
14a563ca70SAlex Hornung * distribution.
15a563ca70SAlex Hornung *
16a563ca70SAlex Hornung * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a563ca70SAlex Hornung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a563ca70SAlex Hornung * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19a563ca70SAlex Hornung * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20a563ca70SAlex Hornung * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21a563ca70SAlex Hornung * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22a563ca70SAlex Hornung * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23a563ca70SAlex Hornung * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24a563ca70SAlex Hornung * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25a563ca70SAlex Hornung * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26a563ca70SAlex Hornung * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a563ca70SAlex Hornung * SUCH DAMAGE.
28a563ca70SAlex Hornung */
29a563ca70SAlex Hornung
30a563ca70SAlex Hornung #include <sys/resource.h>
31a563ca70SAlex Hornung #include <sys/time.h>
32a563ca70SAlex Hornung #include <sys/types.h>
33a563ca70SAlex Hornung #include <sys/wait.h>
34a563ca70SAlex Hornung
35a563ca70SAlex Hornung #include <errno.h>
368135efafSAlex Hornung #include <limits.h>
37a563ca70SAlex Hornung #include <signal.h>
38a563ca70SAlex Hornung #include <stdio.h>
39a563ca70SAlex Hornung #include <stdlib.h>
40a563ca70SAlex Hornung #include <stdint.h>
41a563ca70SAlex Hornung #include <string.h>
42a563ca70SAlex Hornung #include <unistd.h>
43a563ca70SAlex Hornung #include <pwd.h>
44a563ca70SAlex Hornung
45a563ca70SAlex Hornung #include <err.h>
46a563ca70SAlex Hornung
47a563ca70SAlex Hornung #include <libprop/proplib.h>
48a563ca70SAlex Hornung
49a563ca70SAlex Hornung #include "parser.h"
50a563ca70SAlex Hornung #include "testcase.h"
51a563ca70SAlex Hornung #include "runlist.h"
52a563ca70SAlex Hornung #include <dfregress.h>
53a563ca70SAlex Hornung
54a563ca70SAlex Hornung
55a563ca70SAlex Hornung static void
usage(void)56a563ca70SAlex Hornung usage(void)
57a563ca70SAlex Hornung {
581eee3ce6SAlex Hornung fprintf(stderr, "Usage: dfregress [options] <input runlist>\n"
591eee3ce6SAlex Hornung "Valid options are:\n"
601eee3ce6SAlex Hornung " -o <output results plist file>\n"
61a563ca70SAlex Hornung " -t <testcase directory>\n"
621eee3ce6SAlex Hornung " -p <pre/post command directory>\n");
63a563ca70SAlex Hornung exit(1);
64a563ca70SAlex Hornung }
65a563ca70SAlex Hornung
66a563ca70SAlex Hornung int
main(int argc,char * argv[])67a563ca70SAlex Hornung main(int argc, char *argv[])
68a563ca70SAlex Hornung {
698135efafSAlex Hornung char runlist_file[PATH_MAX];
701eee3ce6SAlex Hornung char *p, *s;
711eee3ce6SAlex Hornung int oflag = 0;
721eee3ce6SAlex Hornung int tflag = 0;
73a563ca70SAlex Hornung int ch;
74a563ca70SAlex Hornung
751eee3ce6SAlex Hornung while ((ch = getopt(argc, argv, "h?o:t:p:")) != -1) {
76a563ca70SAlex Hornung switch (ch) {
77a563ca70SAlex Hornung case 'o':
788135efafSAlex Hornung if ((p = realpath(optarg, output_file)) == NULL)
798135efafSAlex Hornung err(1, "realpath(%s)", optarg);
801eee3ce6SAlex Hornung oflag = 1;
81a563ca70SAlex Hornung break;
82a563ca70SAlex Hornung
83a563ca70SAlex Hornung case 't':
848135efafSAlex Hornung if ((p = realpath(optarg, testcase_dir)) == NULL)
858135efafSAlex Hornung err(1, "realpath(%s)", optarg);
861eee3ce6SAlex Hornung tflag = 1;
87a563ca70SAlex Hornung break;
88a563ca70SAlex Hornung
89a563ca70SAlex Hornung case 'p':
908135efafSAlex Hornung if ((p = realpath(optarg, prepost_dir)) == NULL)
918135efafSAlex Hornung err(1, "realpath(%s)", optarg);
92a563ca70SAlex Hornung break;
93a563ca70SAlex Hornung
94a563ca70SAlex Hornung case '?':
95a563ca70SAlex Hornung case 'h':
96a563ca70SAlex Hornung usage();
97a563ca70SAlex Hornung /* NOTREACHED */
98a563ca70SAlex Hornung break;
99a563ca70SAlex Hornung }
100a563ca70SAlex Hornung }
101a563ca70SAlex Hornung
102a563ca70SAlex Hornung argc -= optind;
103a563ca70SAlex Hornung argv += optind;
104a563ca70SAlex Hornung
1051eee3ce6SAlex Hornung if (argc != 1)
1061eee3ce6SAlex Hornung usage();
1071eee3ce6SAlex Hornung /* NOTREACHED */
1081eee3ce6SAlex Hornung
1091eee3ce6SAlex Hornung if ((p = realpath(argv[0], runlist_file)) == NULL)
110ac87931eSAlex Hornung err(1, "realpath(%s)", argv[0]);
1111eee3ce6SAlex Hornung
1121eee3ce6SAlex Hornung if (!tflag) {
1131eee3ce6SAlex Hornung /*
1141eee3ce6SAlex Hornung * No explicit testcase directory:
1151eee3ce6SAlex Hornung * Use default testcase directory - the directory where the
1161eee3ce6SAlex Hornung * runlist is.
1171eee3ce6SAlex Hornung */
1181eee3ce6SAlex Hornung strcpy(testcase_dir, runlist_file);
1191eee3ce6SAlex Hornung p = strrchr(testcase_dir, '/');
1201eee3ce6SAlex Hornung if (p == NULL) {
1211eee3ce6SAlex Hornung fprintf(stderr, "Unknown error while determining "
1221eee3ce6SAlex Hornung "default testcase directory. testcase_dir = %s\n",
1231eee3ce6SAlex Hornung testcase_dir);
1241eee3ce6SAlex Hornung exit(1);
1251eee3ce6SAlex Hornung /* NOTREACHED */
1261eee3ce6SAlex Hornung }
1271eee3ce6SAlex Hornung
1281eee3ce6SAlex Hornung *p = '\0';
1291eee3ce6SAlex Hornung }
1301eee3ce6SAlex Hornung
1311eee3ce6SAlex Hornung if (!oflag) {
1321eee3ce6SAlex Hornung /*
1331eee3ce6SAlex Hornung * No explicit output file:
1341eee3ce6SAlex Hornung * By default we'll take the basename of the runlist file
1351eee3ce6SAlex Hornung * and append .plist to it in the cwd; i.e.:
1361eee3ce6SAlex Hornung * /foo/bar/baz.run -> ./baz.plist
1371eee3ce6SAlex Hornung */
1381eee3ce6SAlex Hornung p = strrchr(runlist_file, '/');
1391eee3ce6SAlex Hornung if (p == NULL) {
140*5392f728SSascha Wildner fprintf(stderr, "Unknown error while determining "
1411eee3ce6SAlex Hornung "default output file. runlist_file = %s\n",
1421eee3ce6SAlex Hornung runlist_file);
1431eee3ce6SAlex Hornung exit(1);
1441eee3ce6SAlex Hornung /* NOTREACHED */
1451eee3ce6SAlex Hornung }
1461eee3ce6SAlex Hornung
1471eee3ce6SAlex Hornung ++p;
1481eee3ce6SAlex Hornung
1491eee3ce6SAlex Hornung s = getcwd(output_file, PATH_MAX);
1501eee3ce6SAlex Hornung if (s == NULL)
1511eee3ce6SAlex Hornung err(1, "getcwd()");
1521eee3ce6SAlex Hornung /* NOTREACHED */
1531eee3ce6SAlex Hornung
1541eee3ce6SAlex Hornung strcat(output_file, "/");
1551eee3ce6SAlex Hornung strcat(output_file, p);
1561eee3ce6SAlex Hornung
1571eee3ce6SAlex Hornung if ((p = strrchr(output_file, '.')) != NULL)
1581eee3ce6SAlex Hornung *p = '\0';
1591eee3ce6SAlex Hornung
1601eee3ce6SAlex Hornung
1611eee3ce6SAlex Hornung strcat(output_file, ".plist");
1621eee3ce6SAlex Hornung }
1631eee3ce6SAlex Hornung
1641eee3ce6SAlex Hornung printf("Output plist results:\t%s\n", output_file);
1651eee3ce6SAlex Hornung printf("Runlist:\t\t%s\n", runlist_file);
1661eee3ce6SAlex Hornung printf("Testcase directory:\t%s\n", testcase_dir);
167ac87931eSAlex Hornung printf("\n");
1681eee3ce6SAlex Hornung
169a563ca70SAlex Hornung prop_array_t runlist = runlist_load_from_text(runlist_file);
170a563ca70SAlex Hornung runlist_iterate(runlist, runlist_run_test, runlist);
171a563ca70SAlex Hornung
172a563ca70SAlex Hornung return 0;
173a563ca70SAlex Hornung }
174