tests: convert simple tests to use igt_simple_init_parse_opts

Convert simple tests to use igt_simple_init_parse_opts if they require
extra options.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
This commit is contained in:
Thomas Wood 2014-07-21 15:57:16 +01:00
parent 82b424a419
commit 80d2c9bf82
5 changed files with 98 additions and 135 deletions

View File

@ -36,6 +36,7 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdarg.h> #include <stdarg.h>
#include <getopt.h>
/** /**
* IGT_EXIT_TIMEOUT: * IGT_EXIT_TIMEOUT:

View File

@ -39,7 +39,6 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <getopt.h>
#include "drm.h" #include "drm.h"
#include "ioctl_wrappers.h" #include "ioctl_wrappers.h"
#include "drmtest.h" #include "drmtest.h"
@ -119,10 +118,8 @@ static void *work(void *arg)
pthread_exit(NULL); pthread_exit(NULL);
} }
static void parse(int argc, char *argv[]) static int opt_handler(int opt, int opt_index)
{ {
int opt;
while ((opt = getopt(argc, argv, "i:c:n:muh?")) != -1) {
switch (opt) { switch (opt) {
case 'i': case 'i':
iter = atoi(optarg); iter = atoi(optarg);
@ -136,20 +133,17 @@ static void parse(int argc, char *argv[])
case 'u': case 'u':
uncontexted = 1; uncontexted = 1;
break; break;
case 'h':
case '?':
default:
igt_success();
break;
}
} }
return 0;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i; int i;
igt_simple_init(argc, argv); igt_simple_init_parse_opts(argc, argv, "i:c:n:mu", NULL, NULL,
opt_handler);
fd = drm_open_any_render(); fd = drm_open_any_render();
devid = intel_get_drm_devid(fd); devid = intel_get_drm_devid(fd);
@ -159,8 +153,6 @@ int main(int argc, char *argv[])
iter = 4; iter = 4;
} }
parse(argc, argv);
threads = calloc(num_contexts, sizeof(*threads)); threads = calloc(num_contexts, sizeof(*threads));
for (i = 0; i < num_contexts; i++) for (i = 0; i < num_contexts; i++)

View File

@ -41,7 +41,6 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <getopt.h>
#include <drm.h> #include <drm.h>
@ -67,6 +66,7 @@ typedef struct {
drm_intel_bufmgr *bufmgr; drm_intel_bufmgr *bufmgr;
uint32_t linear[WIDTH * HEIGHT]; uint32_t linear[WIDTH * HEIGHT];
} data_t; } data_t;
static int opt_dump_png = false;
static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename) static void scratch_buf_write_to_png(struct igt_buf *buf, const char *filename)
{ {
@ -117,27 +117,24 @@ scratch_buf_check(data_t *data, struct igt_buf *buf, int x, int y,
color, val, x, y); color, val, x, y);
} }
static int opt_handler(int opt, int opt_index)
{
if (opt == 'd') {
opt_dump_png = true;
}
return 0;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
data_t data = {0, }; data_t data = {0, };
struct intel_batchbuffer *batch = NULL; struct intel_batchbuffer *batch = NULL;
struct igt_buf src, dst; struct igt_buf src, dst;
igt_render_copyfunc_t render_copy = NULL; igt_render_copyfunc_t render_copy = NULL;
int opt;
int opt_dump_png = false;
int opt_dump_aub = igt_aub_dump_enabled(); int opt_dump_aub = igt_aub_dump_enabled();
igt_simple_init(argc, argv); igt_simple_init_parse_opts(argc, argv, "d", NULL, NULL, opt_handler);
while ((opt = getopt(argc, argv, "d")) != -1) {
switch (opt) {
case 'd':
opt_dump_png = true;
break;
default:
break;
}
}
igt_fixture { igt_fixture {
data.drm_fd = drm_open_any_render(); data.drm_fd = drm_open_any_render();

View File

@ -38,7 +38,6 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <limits.h> #include <limits.h>
#include <getopt.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
@ -452,45 +451,9 @@ static void background_run_once(void)
sleep(3); sleep(3);
} }
static void print_usage(const char *s) static int parse_options(int opt, int opt_index)
{ {
igt_info("%s: [OPTION]...\n", s); switch(opt) {
igt_info(" where options are:\n");
igt_info(" -b --background run in background inducing wraps\n");
igt_info(" -n --rounds=num run num times across wrap boundary, 0 == forever\n");
igt_info(" -t --timeout=sec set timeout to wait for testrun to sec seconds\n");
igt_info(" -d --dontwrap don't wrap just run the test\n");
igt_info(" -p --prewrap=n set seqno to WRAP - n for each testrun\n");
igt_info(" -r --norandom dont randomize prewrap space\n");
igt_info(" -i --buffers number of buffers to copy\n");
igt_fail(-1);
}
static void parse_options(int argc, char **argv)
{
int c;
int option_index = 0;
static struct option long_options[] = {
{"rounds", required_argument, 0, 'n'},
{"background", no_argument, 0, 'b'},
{"timeout", required_argument, 0, 't'},
{"dontwrap", no_argument, 0, 'd'},
{"prewrap", required_argument, 0, 'p'},
{"norandom", no_argument, 0, 'r'},
{"buffers", required_argument, 0, 'i'},
};
options.rounds = SLOW_QUICK(50, 2);
options.background = 0;
options.dontwrap = 0;
options.timeout = 20;
options.random = 1;
options.prewrap_space = 21;
options.buffers = 10;
while((c = getopt_long(argc, argv, "n:bvt:dp:ri:",
long_options, &option_index)) != -1) {
switch(c) {
case 'b': case 'b':
options.background = 1; options.background = 1;
igt_info("running in background inducing wraps\n"); igt_info("running in background inducing wraps\n");
@ -520,17 +483,9 @@ static void parse_options(int argc, char **argv)
options.prewrap_space = atoi(optarg); options.prewrap_space = atoi(optarg);
igt_info("prewrap set to %d (0x%x)\n", options.prewrap_space, UINT32_MAX - options.prewrap_space); igt_info("prewrap set to %d (0x%x)\n", options.prewrap_space, UINT32_MAX - options.prewrap_space);
break; break;
default:
igt_info("unkown command options\n");
print_usage(argv[0]);
break;
}
} }
if (optind < argc) { return 0;
igt_info("unkown command options\n");
print_usage(argv[0]);
}
} }
int main(int argc, char **argv) int main(int argc, char **argv)
@ -538,9 +493,36 @@ int main(int argc, char **argv)
int wcount = 0; int wcount = 0;
int r = -1; int r = -1;
igt_simple_init(argc, argv); static struct option long_options[] = {
{"rounds", required_argument, 0, 'n'},
{"background", no_argument, 0, 'b'},
{"timeout", required_argument, 0, 't'},
{"dontwrap", no_argument, 0, 'd'},
{"prewrap", required_argument, 0, 'p'},
{"norandom", no_argument, 0, 'r'},
{"buffers", required_argument, 0, 'i'},
{ 0, 0, 0, 0 }
};
parse_options(argc, argv); const char *help =
" -b --background run in background inducing wraps\n"
" -n --rounds=num run num times across wrap boundary, 0 == forever\n"
" -t --timeout=sec set timeout to wait for testrun to sec seconds\n"
" -d --dontwrap don't wrap just run the test\n"
" -p --prewrap=n set seqno to WRAP - n for each testrun\n"
" -r --norandom dont randomize prewrap space\n"
" -i --buffers number of buffers to copy\n";
options.rounds = SLOW_QUICK(50, 2);
options.background = 0;
options.dontwrap = 0;
options.timeout = 20;
options.random = 1;
options.prewrap_space = 21;
options.buffers = 10;
igt_simple_init_parse_opts(argc, argv, "n:bvt:dp:ri:", long_options,
help, parse_options);
card_index = drm_get_card(); card_index = drm_get_card();

View File

@ -58,7 +58,6 @@
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <getopt.h>
#include <drm.h> #include <drm.h>
@ -72,6 +71,10 @@
#define CMD_POLY_STIPPLE_OFFSET 0x7906 #define CMD_POLY_STIPPLE_OFFSET 0x7906
#define DUCTAPE 0xdead0001
#define TILESZ 0xdead0002
#define CHCK_RENDER 0xdead0003
/** TODO: /** TODO:
* - beat on relaxed fencing (i.e. mappable/fenceable tracking in the kernel) * - beat on relaxed fencing (i.e. mappable/fenceable tracking in the kernel)
* - render copy (to check fence tracking and cache coherency management by the * - render copy (to check fence tracking and cache coherency management by the
@ -624,54 +627,11 @@ static void sanitize_tiles_per_buf(void)
options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size); options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
} }
static void parse_options(int argc, char **argv) static int parse_options(int opt, int opt_index)
{ {
int c, tmp; int tmp;
int option_index = 0;
static struct option long_options[] = {
{"no-hw", 0, 0, 'd'},
{"buf-size", 1, 0, 's'},
{"gpu-busy-load", 1, 0, 'g'},
{"no-signals", 0, 0, 'S'},
{"buffer-count", 1, 0, 'c'},
{"trace-tile", 1, 0, 't'},
{"disable-blt", 0, 0, 'b'},
{"disable-render", 0, 0, 'r'},
{"untiled", 0, 0, 'u'},
{"x-tiled", 0, 0, 'x'},
{"use-cpu-maps", 0, 0, 'm'},
{"rounds", 1, 0, 'o'},
{"no-fail", 0, 0, 'f'},
{"tiles-per-buf", 0, 0, 'p'},
#define DUCTAPE 0xdead0001
{"remove-duct-tape", 0, 0, DUCTAPE},
#define TILESZ 0xdead0002
{"tile-size", 1, 0, TILESZ},
#define CHCK_RENDER 0xdead0003
{"check-render-cpyfn", 0, 0, CHCK_RENDER},
{NULL, 0, 0, 0},
};
options.scratch_buf_size = 256*4096; switch(opt) {
options.no_hw = 0;
options.use_signal_helper = 1;
options.gpu_busy_load = 0;
options.num_buffers = 0;
options.trace_tile = -1;
options.use_render = 1;
options.use_blt = 1;
options.forced_tiling = -1;
options.use_cpu_maps = 0;
options.total_rounds = 512;
options.fail = 1;
options.ducttape = 1;
options.tile_size = 16;
options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
options.check_render_cpyfn = 0;
while((c = getopt_long(argc, argv, "ds:g:c:t:rbuxmo:fp:",
long_options, &option_index)) != -1) {
switch(c) {
case 'd': case 'd':
options.no_hw = 1; options.no_hw = 1;
igt_info("no-hw debug mode\n"); igt_info("no-hw debug mode\n");
@ -759,14 +719,7 @@ static void parse_options(int argc, char **argv)
options.check_render_cpyfn = 1; options.check_render_cpyfn = 1;
igt_info("checking render copy function\n"); igt_info("checking render copy function\n");
break; break;
default:
igt_info("unkown command options\n");
break;
} }
}
if (optind < argc)
igt_info("unkown command options\n");
/* actually 32767, according to docs, but that kills our nice pot calculations. */ /* actually 32767, according to docs, but that kills our nice pot calculations. */
options.max_dimension = 16*1024; options.max_dimension = 16*1024;
@ -777,6 +730,8 @@ static void parse_options(int argc, char **argv)
options.max_dimension = 8192; options.max_dimension = 8192;
} }
igt_info("Limiting buffer to %dx%d\n", options.max_dimension, options.max_dimension); igt_info("Limiting buffer to %dx%d\n", options.max_dimension, options.max_dimension);
return 0;
} }
static void init(void) static void init(void)
@ -864,14 +819,50 @@ int main(int argc, char **argv)
{ {
int i, j; int i, j;
unsigned *current_permutation, *tmp_permutation; unsigned *current_permutation, *tmp_permutation;
static struct option long_options[] = {
{"no-hw", 0, 0, 'd'},
{"buf-size", 1, 0, 's'},
{"gpu-busy-load", 1, 0, 'g'},
{"no-signals", 0, 0, 'S'},
{"buffer-count", 1, 0, 'c'},
{"trace-tile", 1, 0, 't'},
{"disable-blt", 0, 0, 'b'},
{"disable-render", 0, 0, 'r'},
{"untiled", 0, 0, 'u'},
{"x-tiled", 0, 0, 'x'},
{"use-cpu-maps", 0, 0, 'm'},
{"rounds", 1, 0, 'o'},
{"no-fail", 0, 0, 'f'},
{"tiles-per-buf", 0, 0, 'p'},
{"remove-duct-tape", 0, 0, DUCTAPE},
{"tile-size", 1, 0, TILESZ},
{"check-render-cpyfn", 0, 0, CHCK_RENDER},
{NULL, 0, 0, 0},
};
igt_simple_init(argc, argv); options.scratch_buf_size = 256*4096;
options.no_hw = 0;
options.use_signal_helper = 1;
options.gpu_busy_load = 0;
options.num_buffers = 0;
options.trace_tile = -1;
options.use_render = 1;
options.use_blt = 1;
options.forced_tiling = -1;
options.use_cpu_maps = 0;
options.total_rounds = 512;
options.fail = 1;
options.ducttape = 1;
options.tile_size = 16;
options.tiles_per_buf = options.scratch_buf_size / TILE_BYTES(options.tile_size);
options.check_render_cpyfn = 0;
igt_simple_init_parse_opts(argc, argv,"ds:g:c:t:rbuxmo:fp:",
long_options, NULL, parse_options);
drm_fd = drm_open_any(); drm_fd = drm_open_any();
devid = intel_get_drm_devid(drm_fd); devid = intel_get_drm_devid(drm_fd);
parse_options(argc, argv);
/* start our little helper early before too may allocations occur */ /* start our little helper early before too may allocations occur */
if (options.use_signal_helper) if (options.use_signal_helper)
igt_fork_signal_helper(); igt_fork_signal_helper();