Single tests to respond to --list-subtests
v2 cover Single tests to respond to --list-subtests
From: Tim Gore <[email protected]>
A step towards towards removing the distinction between single and multiple tests. The first step is to change the igt_simple_main macro to pass argc/v through to the real_main function, so that several simple tests that want argc/v can still use this macro.
Once this is done, all the simple tests can use this macro and we then modify this macro and the igt_simple_init function so that argc/v are available to igt_simple_init. Finally modify igt_simple_init to call the igt_subtest_init function to parse the cmdline args for --list-subtest and --help. There are some subtleties introduced by the fact that igt_subtest_init registers the check_igt_exit exit handler, so now single as well as multiple tests must always exit via igt_exit.
v2: a) Moved some comments into the Doxygen function comments.
b) Renamed the igt_simple_init function to __igt_simple_init to indicate that it should only be called from the framework macros.
c) A few simple tests had return statements for error exits, so replaced these with igt_fail calls. This ensures that the igt_exit function is called as required by the framework.
Tim Gore (2):
intel-gpu-tools: pass argc/argv to simple main
intel-gpu-tools: Re-use igt_subtest_init for simple tests
lib/igt_core.c | 39 ++++++++++++++++++++++----------------- lib/igt_core.h | 19 +++++++++++-------- tests/gem_ctx_basic.c | 6 +----- tests/gem_exec_blt.c | 5 +---- tests/gem_gtt_hog.c | 2 +- tests/gem_gtt_speed.c | 7 ++----- tests/gem_hang.c | 5 +---- tests/gem_render_copy.c | 4 +--- tests/gem_render_linear_blits.c | 9 +++------ tests/gem_render_tiled_blits.c | 7 ++----- tests/gem_seqno_wrap.c | 11 ++++------- tests/gem_stress.c | 5 +---- tests/gen3_mixed_blits.c | 5 +---- tests/gen3_render_linear_blits.c | 5 +---- tests/gen3_render_mixed_blits.c | 5 +---- tests/gen3_render_tiledx_blits.c | 5 +---- tests/gen3_render_tiledy_blits.c | 5 +---- tests/igt_simulation.c | 4 ++-- 18 files changed, 57 insertions(+), 91 deletions(-)
Signature · 1 line
1.9.2
PATCH v2 1/2 intel-gpu-tools: pass argc/argv to simple main
From: Tim Gore <[email protected]>
Quite a few single tests do not use the igt_simple_main macro because they want access to argc/argv. So change the igt_simple_main macro to pass these arguments through to the "__real_mainxxx" function, and change these tests to use the macro.
Also rename the igt_simple_init to __igt_simple_init to indicate that it should be accessed via the macros
--- lib/igt_core.c | 4 ++-- lib/igt_core.h | 19 +++++++++++-------- tests/gem_ctx_basic.c | 6 +----- tests/gem_exec_blt.c | 5 +---- tests/gem_gtt_speed.c | 7 ++----- tests/gem_hang.c | 5 +---- tests/gem_render_copy.c | 4 +--- tests/gem_render_linear_blits.c | 9 +++------ tests/gem_render_tiled_blits.c | 7 ++----- tests/gem_seqno_wrap.c | 11 ++++------- tests/gem_stress.c | 5 +---- tests/gen3_mixed_blits.c | 5 +---- tests/gen3_render_linear_blits.c | 5 +---- tests/gen3_render_mixed_blits.c | 5 +---- tests/gen3_render_tiledx_blits.c | 5 +---- tests/gen3_render_tiledy_blits.c | 5 +---- tests/igt_simulation.c | 2 +- 17 files changed, 35 insertions(+), 74 deletions(-)
lib/igt_core.c +2 -2
@@ -450,7 +450,7 @@ void igt_subtest_init(int argc, char **argv) }/** -* igt_simple_init: +* __igt_simple_init: * * This initializes a simple test without any support for subtests. *
@@ -458,7 +458,7 @@ void igt_subtest_init(int argc, char **argv)* #igt_simple_main block instead of stitching the tests's main() function together * manually. */ -void igt_simple_init (void ) +void __igt_simple_init (void ) {print_version ();
lib/igt_core.h +11 -8
@@ -166,23 +166,26 @@ bool igt_only_list_subtests(void);* * Init for simple tests without subtests */ -void igt_simple_init (void ); +void __igt_simple_init (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 only recommended if -* the test needs to parse additional cmdline arguments of its own. +* simple tests. It calls __igt_simple_init() to do basic setup +* and passes argc/v through to the "__real_main" function that +* follows the macro. +* Open-coding the main() function is only recommended if there is a +* requirement that cannot be met otherwise */ #define igt_simple_main \ - static void igt_tokencat(__real_main, __LINE__)(void); \ + static void igt_tokencat(__real_main, __LINE__)(int argc, char **argv); \ int main(int argc, char **argv) { \ - igt_simple_init(); \ - igt_tokencat(__real_main, __LINE__)(); \ - exit(0); \ + __igt_simple_init(); \ + igt_tokencat(__real_main, __LINE__)(argc, argv); \ + igt_exit(); \ } \ - static void igt_tokencat(__real_main, __LINE__)(void) \ + static void igt_tokencat(__real_main, __LINE__)(int argc, char **argv) \ __attribute__((format (printf,1 ,2 )))void igt_skip (const char *f, ...) __attribute__((noreturn));
tests/gem_ctx_basic.c +1 -5
@@ -145,12 +145,10 @@ static void parse(int argc, char *argv[]) } } -int main (int argc,char *argv[]) +igt_simple_main {int i; -igt_simple_init (); - fd =drm_open_any_render (); devid =intel_get_drm_devid (fd);
@@ -173,6 +171,4 @@ int main(int argc, char *argv[])free (threads);close (fd); - -return 0 ; }
tests/gem_exec_blt.c +1 -4
@@ -253,12 +253,10 @@ static void run(int object_size)close (fd); } -int main (int argc,char **argv) +igt_simple_main {int i; -igt_simple_init (); -igt_skip_on_simulation ();if (argc >1 ) {
@@ -270,5 +268,4 @@ int main(int argc, char **argv) }else run (OBJECT_SIZE ); -return 0 ; }
tests/gem_gtt_speed.c +2 -5
@@ -50,7 +50,7 @@ static double elapsed(const struct timeval *start,return (1e6 *(end->tv_sec - start->tv_sec) + (end->tv_usec - start->tv_usec))/loop; } -int main (int argc,char **argv) +igt_simple_main {struct timeval start, end;uint8_t *buf;
@@ -59,15 +59,13 @@ int main(int argc, char **argv)int loop, i, tiling;int fd; -igt_simple_init (); -igt_skip_on_simulation ();if (argc >1 ) size =atoi (argv[1 ]);if (size ==0 ) {igt_warn ("Invalid object size specified\n" ); -return 1 ; +igt_fail (1 ); } buf =malloc (size);
@@ -329,5 +327,4 @@ int main(int argc, char **argv)gem_close (fd, handle);close (fd); -return 0 ; }
tests/gem_hang.c +1 -4
@@ -68,12 +68,10 @@ gpu_hang(void)intel_batchbuffer_flush (batch); } -int main (int argc,char **argv) +igt_simple_main {int fd; -igt_simple_init (); -igt_assert_f (argc ==2 ,"usage: %s <disabled pipe number>\n" , argv[0 ]);
@@ -93,5 +91,4 @@ int main(int argc, char **argv)close (fd); -return 0 ; }
tests/gem_render_copy.c +1 -3
@@ -117,7 +117,7 @@ scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y, color, val, x, y); } -int main (int argc,char **argv) +igt_simple_main {data_t data = {0 , };struct intel_batchbuffer *batch =NULL ;
@@ -127,7 +127,6 @@ int main(int argc, char **argv)int opt_dump_png = false;int opt_dump_aub =igt_aub_dump_enabled (); -igt_simple_init ();while ((opt =getopt (argc, argv,"d" )) !=-1 ) {switch (opt) {
@@ -189,5 +188,4 @@ int main(int argc, char **argv)scratch_buf_check (&data, &dst,WIDTH -10 ,HEIGHT -10 ,SRC_COLOR ); } -return 0 ; }
tests/gem_render_linear_blits.c +3 -6
@@ -81,7 +81,7 @@ check_bo(int fd, uint32_t handle, uint32_t val) } } -int main (int argc,char **argv) +igt_simple_main {drm_intel_bufmgr *bufmgr;struct intel_batchbuffer *batch;
@@ -90,8 +90,6 @@ int main(int argc, char **argv)uint32_t start =0 ;int i, j, fd, count; -igt_simple_init (); - fd =drm_open_any (); render_copy =igt_get_render_copyfunc (intel_get_drm_devid (fd));
@@ -110,7 +108,7 @@ int main(int argc, char **argv) count =3 *gem_aperture_size (fd) /SIZE /2 ; else if (count < 2) {igt_warn ("count must be >= 2\n" ); -return 1 ; +igt_fail (1 ); }if (count >intel_get_total_ram_mb () *9 /10 ) {
@@ -154,7 +152,7 @@ int main(int argc, char **argv)check_bo (fd, bo[i]->handle, start_val[i]);if (igt_run_in_simulation ()) -return 0 ; +return ;igt_info ("Cyclic blits, backward...\n" );for (i =0 ; i < count *4 ; i++) {
@@ -201,5 +199,4 @@ int main(int argc, char **argv)for (i =0 ; i < count; i++)check_bo (fd, bo[i]->handle, start_val[i]); -return 0 ; }
tests/gem_render_tiled_blits.c +2 -5
@@ -95,7 +95,7 @@ check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)dri_bo_unmap (linear); } -int main (int argc,char **argv) +igt_simple_main {drm_intel_bufmgr *bufmgr;struct intel_batchbuffer *batch;
@@ -105,8 +105,6 @@ int main(int argc, char **argv)int i, j, fd, count;uint32_t devid; -igt_simple_init (); -igt_skip_on_simulation (); fd =drm_open_any ();
@@ -132,7 +130,7 @@ int main(int argc, char **argv) count =3 *gem_aperture_size (fd) /SIZE /2 ; else if (count < 2) {igt_warn ("count must be >= 2\n" ); -return 1 ; +igt_fail (1 ); }if (count >intel_get_total_ram_mb () *9 /10 ) {
@@ -212,5 +210,4 @@ int main(int argc, char **argv)for (i =0 ; i < count; i++)check_bo (batch, &buf[i], start_val[i]); -return 0 ; }
tests/gem_seqno_wrap.c +4 -7
@@ -533,12 +533,9 @@ static void parse_options(int argc, char **argv) } } -int main (int argc,char **argv) +igt_simple_main {int wcount =0 ; -int r =-1 ; - -igt_simple_init ();parse_options (argc, argv);
@@ -563,8 +560,8 @@ int main(int argc, char **argv)if (options.rounds == wcount) {igt_debug ("done %d wraps successfully\n" , wcount); -return 0 ; } - -return r; +else { +igt_fail (-1 ); + } }
tests/gem_stress.c +1 -4
@@ -860,13 +860,11 @@ static void check_render_copyfunc(void) } -int main (int argc,char **argv) +igt_simple_main {int i, j;unsigned *current_permutation, *tmp_permutation; -igt_simple_init (); - drm_fd =drm_open_any (); devid =intel_get_drm_devid (drm_fd);
@@ -925,5 +923,4 @@ int main(int argc, char **argv)igt_stop_signal_helper (); -return 0 ; }
tests/gen3_mixed_blits.c +1 -4
@@ -457,14 +457,12 @@ check_bo(int fd, uint32_t handle, uint32_t val)munmap (v,WIDTH *HEIGHT *4 ); } -int main (int argc,char **argv) +igt_simple_main {uint32_t *handle, *tiling, *start_val;uint32_t start =0 ;int i, fd, count; -igt_simple_init (); - fd =drm_open_any ();igt_require (IS_GEN3 (intel_get_drm_devid (fd)));
@@ -533,5 +531,4 @@ int main(int argc, char **argv)check_bo (fd, handle[i], start_val[i]);igt_info ("done\n" ); -return 0 ; }
tests/gen3_render_linear_blits.c +1 -4
@@ -325,14 +325,12 @@ check_bo(int fd, uint32_t handle, uint32_t val) } } -int main (int argc,char **argv) +igt_simple_main {uint32_t *handle, *start_val;uint32_t start =0 ;int i, fd, count; -igt_simple_init (); - fd =drm_open_any ();igt_require (IS_GEN3 (intel_get_drm_devid (fd)));
@@ -393,5 +391,4 @@ int main(int argc, char **argv)for (i =0 ; i < count; i++)check_bo (fd, handle[i], start_val[i]); -return 0 ; }
tests/gen3_render_mixed_blits.c +1 -4
@@ -345,14 +345,12 @@ check_bo(int fd, uint32_t handle, uint32_t val)munmap (v,WIDTH *HEIGHT *4 ); } -int main (int argc,char **argv) +igt_simple_main {uint32_t *handle, *tiling, *start_val;uint32_t start =0 ;int i, fd, count; -igt_simple_init (); - fd =drm_open_any ();igt_require (IS_GEN3 (intel_get_drm_devid (fd)));
@@ -421,5 +419,4 @@ int main(int argc, char **argv)check_bo (fd, handle[i], start_val[i]);igt_info ("done\n" ); -return 0 ; }
tests/gen3_render_tiledx_blits.c +1 -4
@@ -332,14 +332,12 @@ check_bo(int fd, uint32_t handle, uint32_t val)munmap (v,WIDTH *HEIGHT *4 ); } -int main (int argc,char **argv) +igt_simple_main {uint32_t *handle, *start_val;uint32_t start =0 ;int i, fd, count; -igt_simple_init (); - fd =drm_open_any ();igt_require (IS_GEN3 (intel_get_drm_devid (fd)));
@@ -400,5 +398,4 @@ int main(int argc, char **argv)for (i =0 ; i < count; i++)check_bo (fd, handle[i], start_val[i]); -return 0 ; }
tests/gen3_render_tiledy_blits.c +1 -4
@@ -332,14 +332,12 @@ check_bo(int fd, uint32_t handle, uint32_t val)munmap (v,WIDTH *HEIGHT *4 ); } -int main (int argc,char **argv) +igt_simple_main {uint32_t *handle, *start_val;uint32_t start =0 ;int i, fd, count; -igt_simple_init (); - fd =drm_open_any ();igt_require (IS_GEN3 (intel_get_drm_devid (fd)));
@@ -407,5 +405,4 @@ int main(int argc, char **argv)check_bo (fd, handle[i], start_val[i]);igt_info ("done\n" ); -return 0 ; }
tests/igt_simulation.c +1 -1
@@ -53,7 +53,7 @@ static int do_fork(void)assert (0 );case 0 :if (simple) { -igt_simple_init (); +__igt_simple_init ();igt_skip_on_simulation ();
Signature · 1 line
1.9.2
PATCH v2 2/2 intel-gpu-tools: Re-use igt_subtest_init for simple tests
In reply to [email protected]From: Tim Gore <[email protected]>
igt_subtest_init mainly does stuff that we also want for simple/single tests, such as looking for --list-subtests and --help options and calling common_init. So just call this from igt_simple_init and then set tests_with_subtests to false. NOTE that this means that check_igt_exit is now registered as an exit handler for single tests, so need to make sure that ALL tests exit via igt_exit.
--- lib/igt_core.c | 37 +++++++++++++++++++++---------------- lib/igt_core.h | 4 ++-- tests/gem_gtt_hog.c | 2 +- tests/igt_simulation.c | 4 ++-- 4 files changed, 26 insertions(+), 21 deletions(-)
lib/igt_core.c +21 -16
@@ -457,14 +457,21 @@ void igt_subtest_init(int argc, char **argv)* If there's not a reason to the contrary it's less error prone to just use an * #igt_simple_main block instead of stitching the tests's main() function together * manually. +* We now call through to the igt_subtest_init function since we want most of its +* functionality. Note that this will install the igt_exit_handler so you need to +* exit via igt_exit(), Dont call exit() +* */ -void __igt_simple_init (void ) +void __igt_simple_init (int argc,char **argv) { -print_version (); - -oom_adjust_for_doom (); - -common_init (); +/* use igt_subtest_init, it does mostly what we want */ +igt_subtest_init (argc, argv); +/* but of course we dont have subtests - so mark this */ + test_with_subtests = false; +if (list_subtests) +igt_exit (); +if (run_single_subtest) +igt_fail (1 );/* we dont have subtests ! */ }/*
@@ -565,7 +572,7 @@ void igt_skip(const char *f, ...)assert (in_fixture);__igt_fixture_end (); }else { -exit (IGT_EXIT_SKIP ); +igt_exit (); } }
@@ -655,7 +662,7 @@ void igt_fail(int exitcode)__igt_fixture_end (); } -exit (exitcode); +igt_exit (); } }
@@ -713,18 +720,16 @@ void igt_exit(void)if (igt_only_list_subtests ())exit (IGT_EXIT_SUCCESS ); -if (!test_with_subtests) -exit (IGT_EXIT_SUCCESS ); - -/* Calling this without calling one of the above is a failure */ -assert (skipped_one || succeeded_one || failed_one); +if (test_with_subtests) +/* Calling this without calling one of the above is a failure */ +assert (skipped_one || succeeded_one || failed_one);if (failed_one)exit (igt_exitcode); -else if (succeeded_one) -exit (IGT_EXIT_SUCCESS ); -else +else if (skipped_one)exit (IGT_EXIT_SKIP ); +else +exit (IGT_EXIT_SUCCESS ); }/* fork support code */
lib/igt_core.h +2 -2
@@ -166,7 +166,7 @@ bool igt_only_list_subtests(void);* * Init for simple tests without subtests */ -void __igt_simple_init (void ); +void __igt_simple_init (int argc,char **argv);/** * igt_simple_main:
@@ -181,7 +181,7 @@ void __igt_simple_init(void);#define igt_simple_main \ static void igt_tokencat(__real_main, __LINE__)(int argc, char **argv); \ int main(int argc, char **argv) { \ - __igt_simple_init(); \ + __igt_simple_init(argc, argv); \ igt_tokencat(__real_main, __LINE__)(argc, argv); \ igt_exit(); \ } \
tests/gem_gtt_hog.c +1 -1
@@ -150,7 +150,7 @@ static void run(data_t *data, int child)munmap (ptr, size);igt_assert (x == canary); -exit (0 ); +_exit (0 ); } igt_simple_main
tests/igt_simulation.c +2 -2
@@ -53,11 +53,11 @@ static int do_fork(void)assert (0 );case 0 :if (simple) { -__igt_simple_init (); +__igt_simple_init (1 , argv_run);igt_skip_on_simulation (); -exit (0 ); +igt_exit (); }else {if (list_subtests)igt_subtest_init (2 , argv_list);
Signature · 1 line
1.9.2