File: Runner.c

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 158,500 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (127 lines) | stat: -rw-r--r-- 2,634 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2010, 2013 Oracle and/or its affiliates.  All rights reserved.
 *
 * $Id$
 */

/*
 * A simple main function that gives a command line to the CuTest suite.
 * It lets users run the entire suites (default), or choose individual
 * suite(s), or individual tests.
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "CuTest.h"
#include "db.h"

#ifdef _WIN32
extern int getopt(int, char * const *, const char *);
#endif

int append_case(char **cases, int *num_cases, const char *this_case);
int usage();
void CuTestAssertForDb(const char *msg, const char *file, int line);

const char *progname;

int main(int argc, char **argv)
{
#define MAX_CASES 1000
	extern char *optarg;
	extern int optind;
	char *suites[MAX_CASES], *tests[MAX_CASES];
	int ch, failed, i, num_suites, num_tests, verbose;
	char *test;

	progname = argv[0];

	num_suites = num_tests = verbose = 0;
	while ((ch = getopt(argc, argv, "s:t:v")) != EOF)
		switch (ch) {
		case 's':
			append_case(suites, &num_suites, optarg);
			break;
		case 't':
			append_case(tests, &num_tests, optarg);
			break;
		case 'v':
			verbose = 1;
			break;
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	if (argc != 0)
		return (usage());

	/* Setup the assert to override the default DB one. */
	db_env_set_func_assert(CuTestAssertForDb);
	failed = 0;
	if (num_tests == 0 && num_suites == 0)
		failed = RunAllSuites();
	else {
		for(i = 0; i < num_suites; i++)
			failed += RunSuite(suites[i]);
		for(i = 0; i < num_tests; i++) {
			test = strchr(tests[i], ':');
			if (test == NULL) {
				fprintf(stderr, "Invalid test case: %s\n", tests[i]);
				continue;
			}
			/*
			 * Replace the ':' with NULL, to split the current
			 * value into two strings.
			 */
			*test = '\0';
			++test;
			failed += RunTest(tests[i], test);
		}
	}
	while(num_suites != 0)
		free(suites[num_suites--]);
	while(num_tests != 0)
		free(tests[num_tests--]);
	if (failed > 0)
		return (1);
	else
		return (0);
}

int append_case(char **cases, int *pnum_cases, const char *this_case)
{
	int num_cases;

	num_cases = *pnum_cases;

	if (num_cases >= MAX_CASES)
		return (1);

	cases[num_cases] = strdup(this_case);

	if (cases[num_cases] == NULL)
		return (1);

	++(*pnum_cases);
	return (0);
}

void CuTestAssertForDb(const char *msg, const char *file, int line)
{
	CuFail_Line(NULL, file, line, NULL, msg);
}

int
usage()
{
	(void)fprintf(stderr, "usage: %s %s\n", progname,
	    "[-s suite] [-t test] -v. Multiple test and suite args allowed.");
	return (EXIT_FAILURE);
}