static void setup(void) { if (tst_parse_int(str_reads, &reads, 1, INT_MAX)) tst_brk(TBROK, "Invalid reads (-r) argument: '%s'", str_reads); if (tst_parse_long(str_max_workers, &max_workers, 1, LONG_MAX)) { tst_brk(TBROK, "Invalid max workers (-w) argument: '%s'", str_max_workers); } if (tst_parse_long(str_worker_count, &worker_count, 1, LONG_MAX)) { tst_brk(TBROK, "Invalid worker count (-W) argument: '%s'", str_worker_count); } if (!root_dir) tst_brk(TBROK, "The directory argument (-d) is required"); if (!worker_count) worker_count = MIN(MAX(tst_ncpus() - 1, 1), max_workers); workers = SAFE_MALLOC(worker_count * sizeof(*workers)); }
static void parse_mtest_options(char *str_chunksize, int *chunksize, char *str_maxbytes, long *maxbytes, char *str_maxpercent, int *maxpercent) { if (str_chunksize) if (tst_parse_int(str_chunksize, chunksize, 1, INT_MAX)) tst_brk(TBROK, "Invalid chunksize '%s'", str_chunksize); if (str_maxbytes) { if (tst_parse_long(str_maxbytes, maxbytes, 1, LONG_MAX)) { tst_brk(TBROK, "Invalid maxbytes '%s'", str_maxbytes); } else if (str_maxpercent) { tst_brk(TBROK, "ERROR: -b option cannot be used with -p " "option at the same time"); } alloc_maxbytes = (unsigned long long)maxbytes; } if (str_maxpercent) { if (tst_parse_int(str_maxpercent, maxpercent, 1, 99)) { tst_brk(TBROK, "Invalid maxpercent '%s'", str_maxpercent); } else if (str_maxbytes) { tst_brk(TBROK, "ERROR: -p option cannot be used with -b " "option at the same time"); } } }
int tst_parse_int(const char *str, int *val, int min, int max) { long rval; if (!str) return 0; int ret = tst_parse_long(str, &rval, min, max); if (ret) return ret; *val = (int)rval; return 0; }