lib: add igt_main macro

In the past new testcases with subtest often forgot to add the call to
igt_exit at the end of their main() function. That is now caught with
a bit more obnoxious asserts, but it's still a nuissance.

This little igt_main macro takes care of that (and also of calling the
subtest machinery initialization code correctly).

If no one objects I'll roll this out for all the simple cases (i.e.
those tests that don't have additional argv parsing on top of the
subtest machinery).

v2: Roll it out across the board.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter 2013-10-31 16:23:26 +01:00
parent 223a61e12e
commit 071e9ca1ca
40 changed files with 49 additions and 182 deletions

View File

@ -138,6 +138,16 @@ bool __igt_run_subtest(const char *subtest_name);
(setjmp(igt_subtest_jmpbuf) == 0); \ (setjmp(igt_subtest_jmpbuf) == 0); \
igt_success()) igt_success())
const char *igt_subtest_name(void); const char *igt_subtest_name(void);
#define igt_main \
static void igt_tokencat(__real_main, __LINE__)(void); \
int main(int argc, char **argv) { \
igt_subtest_init(argc, argv); \
igt_tokencat(__real_main, __LINE__)(); \
igt_exit(); \
} \
static void igt_tokencat(__real_main, __LINE__)(void) \
/** /**
* igt_skip - subtest aware test skipping * igt_skip - subtest aware test skipping
* *

View File

@ -206,12 +206,10 @@ static void test_read_crc(data_t *data, int pipe, unsigned flags)
} }
int main(int argc, char **argv) igt_main
{ {
data_t data = {0, }; data_t data = {0, };
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -261,6 +259,4 @@ int main(int argc, char **argv)
display_fini(&data); display_fini(&data);
fclose(data.ctl); fclose(data.ctl);
} }
igt_exit();
} }

View File

@ -77,10 +77,8 @@ test_create_fd_close(int fd)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture igt_fixture
fd = drm_open_any(); fd = drm_open_any();
@ -90,6 +88,4 @@ int main(int argc, char **argv)
test_create_close(fd); test_create_close(fd);
igt_subtest("create-fd-close") igt_subtest("create-fd-close")
test_create_fd_close(fd); test_create_fd_close(fd);
igt_exit();
} }

View File

@ -103,14 +103,13 @@ blt_bo_fill(drm_intel_bo *tmp_bo, drm_intel_bo *bo, uint8_t val)
#define TEST_READ 0x1 #define TEST_READ 0x1
#define TEST_WRITE 0x2 #define TEST_WRITE 0x2
#define TEST_BOTH (TEST_READ | TEST_WRITE) #define TEST_BOTH (TEST_READ | TEST_WRITE)
int main(int argc, char **argv) igt_main
{ {
unsigned flags = TEST_BOTH; unsigned flags = TEST_BOTH;
int i, j; int i, j;
uint8_t *cpu_ptr; uint8_t *cpu_ptr;
uint8_t *gtt_ptr; uint8_t *gtt_ptr;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -284,6 +283,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -209,10 +209,9 @@ static void *thread_busy(void *_data)
return 0; return 0;
} }
int main(int argc, char *argv[]) igt_main
{ {
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_subtest_init(argc, argv);
sprintf(device, "/dev/dri/card%d", drm_get_card()); sprintf(device, "/dev/dri/card%d", drm_get_card());
{ {
@ -263,6 +262,4 @@ int main(int argc, char *argv[])
close(data->fds[n]); close(data->fds[n]);
free(data); free(data);
} }
igt_exit();
} }

View File

@ -354,12 +354,10 @@ run_modes(struct access_mode *mode)
run_basic_modes(mode, src, dst, dummy, "-forked", run_forked); run_basic_modes(mode, src, dst, dummy, "-forked", run_forked);
} }
int igt_main
main(int argc, char **argv)
{ {
int max, i; int max, i;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -372,6 +370,4 @@ main(int argc, char **argv)
for (i = 0; i < ARRAY_SIZE(access_modes); i++) for (i = 0; i < ARRAY_SIZE(access_modes); i++)
run_modes(&access_modes[i]); run_modes(&access_modes[i]);
igt_exit();
} }

View File

@ -145,10 +145,9 @@ static void run_on_ring(int fd, unsigned ring_id, const char *ring_name)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -174,6 +173,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -85,10 +85,9 @@ uint32_t batch[2] = {MI_BATCH_BUFFER_END};
uint32_t ctx_id; uint32_t ctx_id;
int fd; int fd;
int main(int argc, char *argv[]) igt_main
{ {
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
fd = drm_open_any_render(); fd = drm_open_any_render();
@ -110,6 +109,4 @@ int main(int argc, char *argv[])
igt_subtest("vebox") igt_subtest("vebox")
igt_assert(exec(fd, handle, I915_EXEC_VEBOX, ctx_id) != 0); igt_assert(exec(fd, handle, I915_EXEC_VEBOX, ctx_id) != 0);
#endif #endif
igt_exit();
} }

View File

@ -127,10 +127,8 @@ int fd;
int devid; int devid;
int num_rings; int num_rings;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -199,6 +197,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -177,12 +177,10 @@ static void major_evictions(int fd, int size, int count)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
int size, count; int size, count;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture igt_fixture
@ -216,6 +214,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -296,14 +296,12 @@ static void major_evictions(int fd, int size, int count)
free(bo); free(bo);
} }
int main(int argc, char **argv) igt_main
{ {
int size, count, fd; int size, count, fd;
size = count = 0; size = count = 0;
fd = -1; fd = -1;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -359,6 +357,4 @@ int main(int argc, char **argv)
igt_fixture { igt_fixture {
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -150,10 +150,8 @@ static void multi_write_domain(int fd)
int fd; int fd;
drm_intel_bo *tmp; drm_intel_bo *tmp;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
fd = drm_open_any(); fd = drm_open_any();
@ -231,6 +229,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -208,10 +208,8 @@ static void run(int object_size)
close(fd); close(fd);
} }
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_subtest("normal") igt_subtest("normal")
run(OBJECT_SIZE); run(OBJECT_SIZE);
igt_subtest("no-prefault") { igt_subtest("no-prefault") {
@ -219,6 +217,4 @@ int main(int argc, char **argv)
run(OBJECT_SIZE); run(OBJECT_SIZE);
igt_enable_prefault(); igt_enable_prefault();
} }
igt_exit();
} }

View File

@ -109,10 +109,8 @@ uint32_t batch[2] = {MI_BATCH_BUFFER_END};
uint32_t handle; uint32_t handle;
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
fd = drm_open_any(); fd = drm_open_any();
@ -137,6 +135,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -198,10 +198,8 @@ static int run_test(int threads_per_fence, void *f, int tiling,
return 0; return 0;
} }
int igt_main
main(int argc, char **argv)
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_subtest("bo-write-verify-none") igt_subtest("bo-write-verify-none")
@ -232,6 +230,4 @@ main(int argc, char **argv)
igt_subtest("bo-copy") igt_subtest("bo-copy")
igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0); igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);
igt_exit();
} }

View File

@ -218,11 +218,8 @@ static void run_test(int fd, int num_fences, int expected_errno,
int fd; int fd;
int num_fences; int num_fences;
int igt_main
main(int argc, char **argv)
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -247,6 +244,4 @@ main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -151,10 +151,8 @@ test_flink_lifetime(int fd)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture igt_fixture
fd = drm_open_any(); fd = drm_open_any();
@ -168,6 +166,4 @@ int main(int argc, char **argv)
test_bad_open(fd); test_bad_open(fd);
igt_subtest("flink-lifetime") igt_subtest("flink-lifetime")
test_flink_lifetime(fd); test_flink_lifetime(fd);
igt_exit();
} }

View File

@ -190,17 +190,13 @@ static void test_flink_close(void)
igt_assert(obj_count == 0); igt_assert(obj_count == 0);
} }
int main(int argc, char **argv) igt_main
{ {
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_subtest_init(argc, argv);
igt_subtest("flink_name") igt_subtest("flink_name")
test_flink_name(); test_flink_name();
igt_subtest("flink_close") igt_subtest("flink_close")
test_flink_close(); test_flink_close();
igt_exit();
} }

View File

@ -42,7 +42,7 @@
int fd; int fd;
int handle; int handle;
int main(int argc, char **argv) igt_main
{ {
struct drm_i915_gem_mmap arg; struct drm_i915_gem_mmap arg;
uint8_t expected[OBJECT_SIZE]; uint8_t expected[OBJECT_SIZE];
@ -50,8 +50,6 @@ int main(int argc, char **argv)
uint8_t *addr; uint8_t *addr;
int ret; int ret;
igt_subtest_init(argc, argv);
igt_fixture igt_fixture
fd = drm_open_any(); fd = drm_open_any();
@ -96,6 +94,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -191,13 +191,11 @@ run_without_prefault(int fd,
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
if (igt_run_in_simulation()) if (igt_run_in_simulation())
OBJECT_SIZE = 1 * 1024 * 1024; OBJECT_SIZE = 1 * 1024 * 1024;
igt_subtest_init(argc, argv);
igt_fixture igt_fixture
fd = drm_open_any(); fd = drm_open_any();
@ -220,6 +218,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -253,11 +253,10 @@ static void do_tests(int cache_level, const char *suffix)
test_partial_read_writes(); test_partial_read_writes();
} }
int main(int argc, char **argv) igt_main
{ {
srandom(0xdeadbeef); srandom(0xdeadbeef);
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -289,6 +288,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -328,9 +328,8 @@ static void do_forked_test(int fd, unsigned flags)
int fd; int fd;
#define MAX_BLT_SIZE 128 #define MAX_BLT_SIZE 128
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
memset(blob, 'A', sizeof(blob)); memset(blob, 'A', sizeof(blob));
@ -371,6 +370,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -151,10 +151,8 @@ store_pipe_control_loop(bool preuse_buffer)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
fd = drm_open_any(); fd = drm_open_any();
devid = intel_get_drm_devid(fd); devid = intel_get_drm_devid(fd);
@ -186,6 +184,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -171,12 +171,10 @@ static void do_test(int fd, int cache_level,
drm_intel_bo *src[2], *dst[2]; drm_intel_bo *src[2], *dst[2];
int fd; int fd;
int igt_main
main(int argc, char **argv)
{ {
const uint32_t start[2] = {0, 1024 * 1024 / 4}; const uint32_t start[2] = {0, 1024 * 1024 / 4};
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -240,6 +238,4 @@ main(int argc, char **argv)
} }
close(fd); close(fd);
igt_exit();
} }

View File

@ -76,14 +76,13 @@ do_write(int fd, int handle, void *buf, int offset, int size)
int fd; int fd;
uint32_t handle; uint32_t handle;
int main(int argc, char **argv) igt_main
{ {
uint8_t expected[OBJECT_SIZE]; uint8_t expected[OBJECT_SIZE];
uint8_t buf[OBJECT_SIZE]; uint8_t buf[OBJECT_SIZE];
int ret; int ret;
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
fd = drm_open_any(); fd = drm_open_any();
@ -145,6 +144,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -250,10 +250,8 @@ static void buffer_count_tests(void)
} }
} }
int main(int argc, char *argv[]) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
int ring; int ring;
uint32_t batch_data [2] = { MI_NOOP, MI_BATCH_BUFFER_END }; uint32_t batch_data [2] = { MI_NOOP, MI_BATCH_BUFFER_END };
@ -306,6 +304,4 @@ int main(int argc, char *argv[])
gem_close(fd, batch_handle); gem_close(fd, batch_handle);
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -323,9 +323,8 @@ static void do_forked_test(int fd, unsigned flags)
int fd; int fd;
#define MAX_BLT_SIZE 128 #define MAX_BLT_SIZE 128
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
memset(blob, 'A', sizeof(blob)); memset(blob, 'A', sizeof(blob));
@ -372,6 +371,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -200,10 +200,8 @@ struct intel_batchbuffer *batch;
render_copyfunc_t copy; render_copyfunc_t copy;
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -234,6 +232,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -229,12 +229,11 @@ static void do_test(uint32_t tiling, unsigned stride,
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
int i; int i;
uint32_t tiling, tiling_after; uint32_t tiling, tiling_after;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -275,6 +274,4 @@ int main(int argc, char **argv)
igt_assert(tiling == I915_TILING_X); igt_assert(tiling == I915_TILING_X);
igt_assert(tiling_after == I915_TILING_X); igt_assert(tiling_after == I915_TILING_X);
} }
igt_exit();
} }

View File

@ -122,9 +122,8 @@ cont:
int fd; int fd;
int devid; int devid;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -166,6 +165,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -147,10 +147,8 @@ test_sysfs_reader(void)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture igt_fixture
@ -170,6 +168,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -255,11 +255,10 @@ static void test_partial_read_writes(void)
} }
} }
int main(int argc, char **argv) igt_main
{ {
uint32_t tiling_mode = I915_TILING_X; uint32_t tiling_mode = I915_TILING_X;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
srandom(0xdeadbeef); srandom(0xdeadbeef);
@ -303,6 +302,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -143,7 +143,7 @@ static void run_test(int ring)
drm_intel_bo_unreference(target_bo); drm_intel_bo_unreference(target_bo);
} }
int main(int argc, char **argv) igt_main
{ {
static const struct { static const struct {
const char *name; const char *name;
@ -155,7 +155,6 @@ int main(int argc, char **argv)
}; };
int i; int i;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -196,6 +195,4 @@ int main(int argc, char **argv)
close(fd); close(fd);
} }
igt_exit();
} }

View File

@ -215,10 +215,8 @@ static void size_tests(int fd)
int fd; int fd;
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture igt_fixture
fd = drm_open_any(); fd = drm_open_any();
@ -228,6 +226,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(fd); close(fd);
igt_exit();
} }

View File

@ -321,11 +321,10 @@ static void create_cursor_fb(data_t *data,
igt_assert(cairo_status(cr) == 0); igt_assert(cairo_status(cr) == 0);
} }
int main(int argc, char **argv) igt_main
{ {
data_t data = {}; data_t data = {};
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -377,6 +376,4 @@ int main(int argc, char **argv)
display_fini(&data); display_fini(&data);
fclose(data.ctl); fclose(data.ctl);
} }
igt_exit();
} }

View File

@ -221,7 +221,7 @@ static int run_test(const char *test_name, enum test_flags flags)
return 1; return 1;
} }
int main(int argc, char **argv) igt_main
{ {
struct { struct {
enum test_flags flags; enum test_flags flags;
@ -232,7 +232,6 @@ int main(int argc, char **argv)
}; };
int i; int i;
igt_subtest_init(argc, argv);
igt_skip_on_simulation(); igt_skip_on_simulation();
igt_fixture { igt_fixture {
@ -252,6 +251,4 @@ int main(int argc, char **argv)
igt_fixture igt_fixture
close(drm_fd); close(drm_fd);
igt_exit();
} }

View File

@ -510,10 +510,8 @@ static int test_nv_self_import_to_different_fd(void)
return 0; return 0;
} }
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
igt_assert(find_and_open_devices() == 0); igt_assert(find_and_open_devices() == 0);
@ -574,6 +572,4 @@ int main(int argc, char **argv)
close(intel_fd); close(intel_fd);
close(nouveau_fd); close(nouveau_fd);
} }
igt_exit();
} }

View File

@ -1263,10 +1263,8 @@ out:
return ret; return ret;
} }
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
igt_assert(find_and_open_devices() == 0); igt_assert(find_and_open_devices() == 0);
@ -1318,6 +1316,4 @@ int main(int argc, char **argv)
close(intel_fd); close(intel_fd);
close(nouveau_fd); close(nouveau_fd);
} }
igt_exit();
} }

View File

@ -352,10 +352,8 @@ static void test_i915_blt_fill_nv_read(void)
/* test 9 nouveau copy engine?? */ /* test 9 nouveau copy engine?? */
int main(int argc, char **argv) igt_main
{ {
igt_subtest_init(argc, argv);
igt_fixture { igt_fixture {
igt_assert(find_and_open_devices() == 0); igt_assert(find_and_open_devices() == 0);
@ -399,6 +397,4 @@ int main(int argc, char **argv)
close(intel_fd); close(intel_fd);
close(nouveau_fd); close(nouveau_fd);
} }
igt_exit();
} }

View File

@ -420,7 +420,7 @@ static void test_llseek_bad(void)
close(fd); close(fd);
} }
int main(int argc, char **argv) igt_main
{ {
struct { struct {
const char *name; const char *name;
@ -437,12 +437,8 @@ int main(int argc, char **argv)
}; };
int i; int i;
igt_subtest_init(argc, argv);
for (i = 0; i < ARRAY_SIZE(tests); i++) { for (i = 0; i < ARRAY_SIZE(tests); i++) {
igt_subtest(tests[i].name) igt_subtest(tests[i].name)
tests[i].fn(); tests[i].fn();
} }
igt_exit();
} }