1 #ifndef RUNNER_SETTINGS_H
2 #define RUNNER_SETTINGS_H
3 
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <sys/types.h>
7 #include <stdio.h>
8 #include <glib.h>
9 
10 enum {
11 	LOG_LEVEL_NORMAL = 0,
12 	LOG_LEVEL_QUIET = -1,
13 	LOG_LEVEL_VERBOSE = 1,
14 };
15 
16 #define ABORT_TAINT   (1 << 0)
17 #define ABORT_LOCKDEP (1 << 1)
18 #define ABORT_ALL     (ABORT_TAINT | ABORT_LOCKDEP)
19 
20 _Static_assert(ABORT_ALL == (ABORT_TAINT | ABORT_LOCKDEP), "ABORT_ALL must be all conditions bitwise or'd");
21 
22 struct regex_list {
23 	char **regex_strings;
24 	GRegex **regexes;
25 	size_t size;
26 };
27 
28 struct settings {
29 	int abort_mask;
30 	char *test_list;
31 	char *name;
32 	bool dry_run;
33 	struct regex_list include_regexes;
34 	struct regex_list exclude_regexes;
35 	bool sync;
36 	int log_level;
37 	bool overwrite;
38 	bool multiple_mode;
39 	int inactivity_timeout;
40 	int overall_timeout;
41 	bool use_watchdog;
42 	char *test_root;
43 	char *results_path;
44 	bool piglit_style_dmesg;
45 	int dmesg_warn_level;
46 	bool list_all;
47 };
48 
49 /**
50  * init_settings:
51  *
52  * Initializes a settings object to an empty state (all values NULL, 0
53  * or false).
54  *
55  * @settings: Object to initialize. Storage for it must exist.
56  */
57 void init_settings(struct settings *settings);
58 
59 /**
60  * free_settings:
61  *
62  * Releases all allocated resources for a settings object and
63  * initializes it to an empty state (see #init_settings).
64  *
65  * @settings: Object to release and initialize.
66  */
67 void free_settings(struct settings *settings);
68 
69 /**
70  * parse_options:
71  *
72  * Parses command line options and sets the settings object to
73  * designated values.
74  *
75  * The function can be called again on the same settings object. The
76  * old values will be properly released and cleared. On a parse
77  * failure, the settings object will be in an empty state (see
78  * #init_settings) and usage instructions will be printed with an
79  * error message.
80  *
81  * @argc: Argument count
82  * @argv: Argument array. First element is the program name.
83  * @settings: Settings object to fill with values. Must have proper
84  * storage.
85  *
86  * Returns: True on successful parse, false on error.
87  */
88 bool parse_options(int argc, char **argv,
89 		   struct settings *settings);
90 
91 /**
92  * validate_settings:
93  *
94  * Checks the settings object against the system to see if executing
95  * on it can be done. Checks pathnames for existence and access
96  * rights. Note that this function will not check that the designated
97  * job listing (through a test-list file or the -t/-x flags) yields a
98  * non-zero amount of testing to be done. On errors, usage
99  * instructions will be printed with an error message.
100  *
101  * @settings: Settings object to check.
102  *
103  * Returns: True on valid settings, false on any error.
104  */
105 bool validate_settings(struct settings *settings);
106 
107 /* TODO: Better place for this */
108 char *absolute_path(char *path);
109 
110 /**
111  * serialize_settings:
112  *
113  * Serializes the settings object to a file in the results_path
114  * directory.
115  *
116  * @settings: Settings object to serialize.
117  */
118 bool serialize_settings(struct settings *settings);
119 
120 bool read_settings_from_file(struct settings *settings, FILE* f);
121 bool read_settings_from_dir(struct settings *settings, int dirfd);
122 
123 #endif
124