xref: /dragonfly/usr.bin/dfregress/testcase.h (revision 039caa27)
1 /*
2  * Copyright (c) 2011 Alex Hornung <alex@alexhornung.com>.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
20  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #define TESTCASE_TYPE_USERLAND	0x01
31 #define TESTCASE_TYPE_KERNEL	0x02
32 #define TESTCASE_TYPE_BUILDONLY	0x03
33 
34 #define TESTCASE_INT_PRE	0x001
35 #define TESTCASE_INT_POST	0x002
36 #define TESTCASE_CUSTOM_PRE	0x004
37 #define TESTCASE_CUSTOM_POST	0x008
38 #define TESTCASE_NOBUILD	0x010
39 #define TESTCASE_RUN_AS		0x020
40 
41 
42 struct testcase_options {
43 	long int	timeout_in_secs;
44 	uint32_t	flags;
45 	uid_t		runas_uid;
46 
47 	char		*interpreter;
48 	int32_t		rc;
49 	char		*pre_cmd;
50 	char		*post_cmd;
51 	char		*make_cmd;
52 };
53 
54 struct testcase_result {
55 	int		result;
56 	int		exit_value;
57 	int		signal;
58 	int		core_dumped;
59 
60 	char		*stdout_buf;
61 	char		*stderr_buf;
62 
63 	struct rusage	rusage;
64 };
65 
66 struct testcase {
67 	char		*name;
68 	char		**argv;
69 	int		argc;
70 	char		*type_str;
71 	int		type;
72 
73 	struct testcase_options	opts;
74 	struct testcase_result	results;
75 };
76 
77 prop_dictionary_t testcase_from_struct(struct testcase *testcase);
78 
79 struct timeval *testcase_get_timeout(prop_dictionary_t testcase);
80 int testcase_get_type(prop_dictionary_t testcase);
81 int testcase_get_rc(prop_dictionary_t testcase);
82 const char *testcase_get_type_desc(prop_dictionary_t testcase);
83 const char *testcase_get_name(prop_dictionary_t testcase);
84 int testcase_get_argc(prop_dictionary_t testcase);
85 const char **testcase_get_args(prop_dictionary_t testcase);
86 uint32_t testcase_get_flags(prop_dictionary_t testcase);
87 int testcase_get_precmd_type(prop_dictionary_t testcase);
88 int testcase_get_postcmd_type(prop_dictionary_t testcase);
89 int testcase_needs_setuid(prop_dictionary_t testcase);
90 uid_t testcase_get_runas_uid(prop_dictionary_t testcase);
91 const char *testcase_get_custom_precmd(prop_dictionary_t testcase);
92 const char *testcase_get_custom_postcmd(prop_dictionary_t testcase);
93 const char *testcase_get_interpreter(prop_dictionary_t testcase);
94 const char *testcase_get_interpreter_noexit(prop_dictionary_t testcase);
95 const char *testcase_get_make_cmd(prop_dictionary_t testcase);
96 prop_dictionary_t testcase_get_result_dict(prop_dictionary_t testcase);
97 int testcase_set_build_buf(prop_dictionary_t testcase, const char *buf);
98 int testcase_set_cleanup_buf(prop_dictionary_t testcase, const char *buf);
99 int testcase_set_sys_buf(prop_dictionary_t testcase, const char *buf);
100 int testcase_set_precmd_buf(prop_dictionary_t testcase, const char *buf);
101 int testcase_set_postcmd_buf(prop_dictionary_t testcase, const char *buf);
102 int testcase_set_stdout_buf(prop_dictionary_t testcase, const char *buf);
103 int testcase_set_stderr_buf(prop_dictionary_t testcase, const char *buf);
104 int testcase_set_stdout_buf_from_file(prop_dictionary_t testcase, const char *file);
105 int testcase_set_stderr_buf_from_file(prop_dictionary_t testcase, const char *file);
106 int testcase_set_result(prop_dictionary_t testcase, int result);
107 int testcase_set_exit_value(prop_dictionary_t testcase, int exitval);
108 int testcase_set_signal(prop_dictionary_t testcase, int sig);
109 const char *testcase_get_build_buf(prop_dictionary_t testcase);
110 const char *testcase_get_cleanup_buf(prop_dictionary_t testcase);
111 const char *testcase_get_sys_buf(prop_dictionary_t testcase);
112 const char *testcase_get_precmd_buf(prop_dictionary_t testcase);
113 const char *testcase_get_postcmd_buf(prop_dictionary_t testcase);
114 const char *testcase_get_stdout_buf(prop_dictionary_t testcase);
115 const char *testcase_get_stderr_buf(prop_dictionary_t testcase);
116 int testcase_get_result(prop_dictionary_t testcase);
117 const char *testcase_get_result_desc(prop_dictionary_t testcase);
118 int testcase_get_exit_value(prop_dictionary_t testcase);
119 int testcase_get_signal(prop_dictionary_t testcase);
120 
121 int parse_testcase_option(struct testcase_options *opts, char *option);
122 void testcase_entry_parser(void *arg, char **tokens);
123