summaryrefslogtreecommitdiff
path: root/lib/igt_core.h
diff options
context:
space:
mode:
authorPetri Latvala <petri.latvala@intel.com>2019-05-23 15:26:52 +0300
committerPetri Latvala <petri.latvala@intel.com>2019-05-27 12:47:38 +0300
commitc17f0cc405b67c88bda594daf98934cbc7adbf1f (patch)
tree5993d26884bc09d847484321f7be6aa013be9523 /lib/igt_core.h
parentcdd6b0a7630762cec14596b9863f418b48c32f46 (diff)
lib: Introduce main function macros with custom args
Instead of using a custom main function and calling igt_subtest_init_parse_opts / igt_simple_init_parse_opts, the _args variants of igt_main and igt_simple_main take the relevant parameters and pass them along to the correct init function. Open-coding a custom main function is no longer necessary and not recommended. Signed-off-by: Petri Latvala <petri.latvala@intel.com> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com> Reviewed-by: Don Hiatt <don.hiatt@intel.com>
Diffstat (limited to 'lib/igt_core.h')
-rw-r--r--lib/igt_core.h64
1 files changed, 48 insertions, 16 deletions
diff --git a/lib/igt_core.h b/lib/igt_core.h
index 44634e0f..cd89921e 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -250,23 +250,38 @@ void __igt_subtest_group_restore(int);
__igt_subtest_group_restore(igt_tokencat(__save,__LINE__) ))
/**
- * igt_main:
- *
- * This is a magic control flow block used instead of a main() function for
- * tests with subtests. Open-coding the main() function is only recommended if
- * the test needs to parse additional command line arguments of its own.
- */
-#define igt_main \
+ * igt_main_args:
+ * @extra_short_opts: getopt_long() compliant list with additional short options
+ * @extra_long_opts: getopt_long() compliant list with additional long options
+ * @help_str: help string for the additional options
+ * @extra_opt_handler: handler for the additional options
+ * @handler_data: user data given to @extra_opt_handler when invoked
+ *
+ * This is a magic control flow block used instead of a main()
+ * function for tests with subtests, along with custom command line
+ * arguments. The macro parameters are passed directly to
+ * #igt_subtest_init_parse_opts.
+ */
+#define igt_main_args(short_opts, long_opts, help_str, opt_handler, handler_data) \
static void igt_tokencat(__real_main, __LINE__)(void); \
int main(int argc, char **argv) { \
- igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, \
- NULL, NULL); \
+ igt_subtest_init_parse_opts(&argc, argv, \
+ short_opts, long_opts, help_str, \
+ opt_handler, handler_data); \
igt_tokencat(__real_main, __LINE__)(); \
igt_exit(); \
} \
static void igt_tokencat(__real_main, __LINE__)(void) \
+/**
+ * igt_main:
+ *
+ * This is a magic control flow block used instead of a main() function for
+ * tests with subtests. Open-coding the main() function is not recommended.
+ */
+#define igt_main igt_main_args(NULL, NULL, NULL, NULL, NULL)
+
const char *igt_test_name(void);
void igt_simple_init_parse_opts(int *argc, char **argv,
const char *extra_short_opts,
@@ -289,23 +304,40 @@ void igt_simple_init_parse_opts(int *argc, char **argv,
#define igt_simple_init(argc, argv) \
igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL, NULL);
+
/**
- * igt_simple_main:
+ * igt_simple_main_args:
+ * @extra_short_opts: getopt_long() compliant list with additional short options
+ * @extra_long_opts: getopt_long() compliant list with additional long options
+ * @help_str: help string for the additional options
+ * @extra_opt_handler: handler for the additional options
+ * @handler_data: user data given to @extra_opt_handler when invoked
*
- * This is a magic control flow block used instead of a main() function for
- * simple tests. Open-coding the main() function is only recommended if
- * the test needs to parse additional command line arguments of its own.
+ * This is a magic control flow block used instead of a main()
+ * function for simple tests with custom command line arguments. The
+ * macro parameters are passed directly to
+ * #igt_simple_init_parse_opts.
*/
-#define igt_simple_main \
+#define igt_simple_main_args(short_opts, long_opts, help_str, opt_handler, handler_data) \
static void igt_tokencat(__real_main, __LINE__)(void); \
int main(int argc, char **argv) { \
- igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, \
- NULL, NULL); \
+ igt_simple_init_parse_opts(&argc, argv, \
+ short_opts, long_opts, help_str, \
+ opt_handler, handler_data); \
igt_tokencat(__real_main, __LINE__)(); \
igt_exit(); \
} \
static void igt_tokencat(__real_main, __LINE__)(void) \
+
+/**
+ * igt_simple_main:
+ *
+ * This is a magic control flow block used instead of a main() function for
+ * simple tests. Open-coding the main() function is not recommended.
+ */
+#define igt_simple_main igt_simple_main_args(NULL, NULL, NULL, NULL, NULL)
+
/**
* igt_constructor:
*