Commit 071e9ca1 authored by Daniel Vetter's avatar Daniel Vetter

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's avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 223a61e1
......@@ -138,6 +138,16 @@ bool __igt_run_subtest(const char *subtest_name);
(setjmp(igt_subtest_jmpbuf) == 0); \
igt_success())
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
*
......
......@@ -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, };
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -261,6 +259,4 @@ int main(int argc, char **argv)
display_fini(&data);
fclose(data.ctl);
}
igt_exit();
}
......@@ -77,10 +77,8 @@ test_create_fd_close(int fd)
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture
fd = drm_open_any();
......@@ -90,6 +88,4 @@ int main(int argc, char **argv)
test_create_close(fd);
igt_subtest("create-fd-close")
test_create_fd_close(fd);
igt_exit();
}
......@@ -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_WRITE 0x2
#define TEST_BOTH (TEST_READ | TEST_WRITE)
int main(int argc, char **argv)
igt_main
{
unsigned flags = TEST_BOTH;
int i, j;
uint8_t *cpu_ptr;
uint8_t *gtt_ptr;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -284,6 +283,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -209,10 +209,9 @@ static void *thread_busy(void *_data)
return 0;
}
int main(int argc, char *argv[])
igt_main
{
igt_skip_on_simulation();
igt_subtest_init(argc, argv);
sprintf(device, "/dev/dri/card%d", drm_get_card());
{
......@@ -263,6 +262,4 @@ int main(int argc, char *argv[])
close(data->fds[n]);
free(data);
}
igt_exit();
}
......@@ -354,12 +354,10 @@ run_modes(struct access_mode *mode)
run_basic_modes(mode, src, dst, dummy, "-forked", run_forked);
}
int
main(int argc, char **argv)
igt_main
{
int max, i;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -372,6 +370,4 @@ main(int argc, char **argv)
for (i = 0; i < ARRAY_SIZE(access_modes); i++)
run_modes(&access_modes[i]);
igt_exit();
}
......@@ -145,10 +145,9 @@ static void run_on_ring(int fd, unsigned ring_id, const char *ring_name)
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -174,6 +173,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -85,10 +85,9 @@ uint32_t batch[2] = {MI_BATCH_BUFFER_END};
uint32_t ctx_id;
int fd;
int main(int argc, char *argv[])
igt_main
{
igt_skip_on_simulation();
igt_subtest_init(argc, argv);
igt_fixture {
fd = drm_open_any_render();
......@@ -110,6 +109,4 @@ int main(int argc, char *argv[])
igt_subtest("vebox")
igt_assert(exec(fd, handle, I915_EXEC_VEBOX, ctx_id) != 0);
#endif
igt_exit();
}
......@@ -127,10 +127,8 @@ int fd;
int devid;
int num_rings;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -199,6 +197,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -177,12 +177,10 @@ static void major_evictions(int fd, int size, int count)
int fd;
int main(int argc, char **argv)
igt_main
{
int size, count;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture
......@@ -216,6 +214,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -296,14 +296,12 @@ static void major_evictions(int fd, int size, int count)
free(bo);
}
int main(int argc, char **argv)
igt_main
{
int size, count, fd;
size = count = 0;
fd = -1;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -359,6 +357,4 @@ int main(int argc, char **argv)
igt_fixture {
close(fd);
}
igt_exit();
}
......@@ -150,10 +150,8 @@ static void multi_write_domain(int fd)
int fd;
drm_intel_bo *tmp;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture {
fd = drm_open_any();
......@@ -231,6 +229,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -208,10 +208,8 @@ static void run(int object_size)
close(fd);
}
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_subtest("normal")
run(OBJECT_SIZE);
igt_subtest("no-prefault") {
......@@ -219,6 +217,4 @@ int main(int argc, char **argv)
run(OBJECT_SIZE);
igt_enable_prefault();
}
igt_exit();
}
......@@ -109,10 +109,8 @@ uint32_t batch[2] = {MI_BATCH_BUFFER_END};
uint32_t handle;
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture {
fd = drm_open_any();
......@@ -137,6 +135,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -198,10 +198,8 @@ static int run_test(int threads_per_fence, void *f, int tiling,
return 0;
}
int
main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_subtest("bo-write-verify-none")
......@@ -232,6 +230,4 @@ main(int argc, char **argv)
igt_subtest("bo-copy")
igt_assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);
igt_exit();
}
......@@ -218,11 +218,8 @@ static void run_test(int fd, int num_fences, int expected_errno,
int fd;
int num_fences;
int
main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -247,6 +244,4 @@ main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -151,10 +151,8 @@ test_flink_lifetime(int fd)
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture
fd = drm_open_any();
......@@ -168,6 +166,4 @@ int main(int argc, char **argv)
test_bad_open(fd);
igt_subtest("flink-lifetime")
test_flink_lifetime(fd);
igt_exit();
}
......@@ -190,17 +190,13 @@ static void test_flink_close(void)
igt_assert(obj_count == 0);
}
int main(int argc, char **argv)
igt_main
{
igt_skip_on_simulation();
igt_subtest_init(argc, argv);
igt_subtest("flink_name")
test_flink_name();
igt_subtest("flink_close")
test_flink_close();
igt_exit();
}
......@@ -42,7 +42,7 @@
int fd;
int handle;
int main(int argc, char **argv)
igt_main
{
struct drm_i915_gem_mmap arg;
uint8_t expected[OBJECT_SIZE];
......@@ -50,8 +50,6 @@ int main(int argc, char **argv)
uint8_t *addr;
int ret;
igt_subtest_init(argc, argv);
igt_fixture
fd = drm_open_any();
......@@ -96,6 +94,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -191,13 +191,11 @@ run_without_prefault(int fd,
int fd;
int main(int argc, char **argv)
igt_main
{
if (igt_run_in_simulation())
OBJECT_SIZE = 1 * 1024 * 1024;
igt_subtest_init(argc, argv);
igt_fixture
fd = drm_open_any();
......@@ -220,6 +218,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -253,11 +253,10 @@ static void do_tests(int cache_level, const char *suffix)
test_partial_read_writes();
}
int main(int argc, char **argv)
igt_main
{
srandom(0xdeadbeef);
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -289,6 +288,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -328,9 +328,8 @@ static void do_forked_test(int fd, unsigned flags)
int fd;
#define MAX_BLT_SIZE 128
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
memset(blob, 'A', sizeof(blob));
......@@ -371,6 +370,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -151,10 +151,8 @@ store_pipe_control_loop(bool preuse_buffer)
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture {
fd = drm_open_any();
devid = intel_get_drm_devid(fd);
......@@ -186,6 +184,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -171,12 +171,10 @@ static void do_test(int fd, int cache_level,
drm_intel_bo *src[2], *dst[2];
int fd;
int
main(int argc, char **argv)
igt_main
{
const uint32_t start[2] = {0, 1024 * 1024 / 4};
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -240,6 +238,4 @@ main(int argc, char **argv)
}
close(fd);
igt_exit();
}
......@@ -76,14 +76,13 @@ do_write(int fd, int handle, void *buf, int offset, int size)
int fd;
uint32_t handle;
int main(int argc, char **argv)
igt_main
{
uint8_t expected[OBJECT_SIZE];
uint8_t buf[OBJECT_SIZE];
int ret;
igt_skip_on_simulation();
igt_subtest_init(argc, argv);
igt_fixture {
fd = drm_open_any();
......@@ -145,6 +144,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -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 {
int ring;
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);
close(fd);
}
igt_exit();
}
......@@ -323,9 +323,8 @@ static void do_forked_test(int fd, unsigned flags)
int fd;
#define MAX_BLT_SIZE 128
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
memset(blob, 'A', sizeof(blob));
......@@ -372,6 +371,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -200,10 +200,8 @@ struct intel_batchbuffer *batch;
render_copyfunc_t copy;
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -234,6 +232,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -229,12 +229,11 @@ static void do_test(uint32_t tiling, unsigned stride,
int fd;
int main(int argc, char **argv)
igt_main
{
int i;
uint32_t tiling, tiling_after;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -275,6 +274,4 @@ int main(int argc, char **argv)
igt_assert(tiling == I915_TILING_X);
igt_assert(tiling_after == I915_TILING_X);
}
igt_exit();
}
......@@ -122,9 +122,8 @@ cont:
int fd;
int devid;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -166,6 +165,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -147,10 +147,8 @@ test_sysfs_reader(void)
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture
......@@ -170,6 +168,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -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;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
srandom(0xdeadbeef);
......@@ -303,6 +302,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -143,7 +143,7 @@ static void run_test(int ring)
drm_intel_bo_unreference(target_bo);
}
int main(int argc, char **argv)
igt_main
{
static const struct {
const char *name;
......@@ -155,7 +155,6 @@ int main(int argc, char **argv)
};
int i;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -196,6 +195,4 @@ int main(int argc, char **argv)
close(fd);
}
igt_exit();
}
......@@ -215,10 +215,8 @@ static void size_tests(int fd)
int fd;
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture
fd = drm_open_any();
......@@ -228,6 +226,4 @@ int main(int argc, char **argv)
igt_fixture
close(fd);
igt_exit();
}
......@@ -321,11 +321,10 @@ static void create_cursor_fb(data_t *data,
igt_assert(cairo_status(cr) == 0);
}
int main(int argc, char **argv)
igt_main
{
data_t data = {};
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -377,6 +376,4 @@ int main(int argc, char **argv)
display_fini(&data);
fclose(data.ctl);
}
igt_exit();
}
......@@ -221,7 +221,7 @@ static int run_test(const char *test_name, enum test_flags flags)
return 1;
}
int main(int argc, char **argv)
igt_main
{
struct {
enum test_flags flags;
......@@ -232,7 +232,6 @@ int main(int argc, char **argv)
};
int i;
igt_subtest_init(argc, argv);
igt_skip_on_simulation();
igt_fixture {
......@@ -252,6 +251,4 @@ int main(int argc, char **argv)
igt_fixture
close(drm_fd);
igt_exit();
}
......@@ -510,10 +510,8 @@ static int test_nv_self_import_to_different_fd(void)
return 0;
}
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture {
igt_assert(find_and_open_devices() == 0);
......@@ -574,6 +572,4 @@ int main(int argc, char **argv)
close(intel_fd);
close(nouveau_fd);
}
igt_exit();
}
......@@ -1263,10 +1263,8 @@ out:
return ret;
}
int main(int argc, char **argv)
igt_main
{
igt_subtest_init(argc, argv);
igt_fixture {
igt_assert(find_and_open_devices() == 0);
......@@ -1318,6 +1316,4 @@ int main(int argc, char **argv)