Skip to content

Commit

Permalink
Several tweaks to script flags
Browse files Browse the repository at this point in the history
- Changed multi-field flags to action=append instead of comma-separated.
- Dropped short-names for geometries/powerlosses
- Renamed -Pexponential -> -Plog
- Allowed omitting the 0 for -W0/-H0/-n0 and made -j0 consistent
- Better handling of --xlim/--ylim
  • Loading branch information
geky committed Nov 15, 2022
1 parent 42d889e commit 9507e62
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 137 deletions.
8 changes: 4 additions & 4 deletions Makefile
Expand Up @@ -170,10 +170,10 @@ coverage: $(GCDA)
.PHONY: summary sizes
summary sizes: $(BUILDDIR)lfs.csv
$(strip ./scripts/summary.py -Y $^ \
-fcode=code_size,$\
data=data_size,$\
stack=stack_limit,$\
struct=struct_size \
-fcode=code_size \
-fdata=data_size \
-fstack=stack_limit \
-fstruct=struct_size \
--max=stack \
$(SUMMARYFLAGS))

Expand Down
44 changes: 19 additions & 25 deletions runners/bench_runner.c
Expand Up @@ -90,9 +90,7 @@ static uintmax_t leb16_parse(const char *s, char **tail) {
// bench_runner types

typedef struct bench_geometry {
char short_name;
const char *long_name;

const char *name;
bench_define_t defines[BENCH_GEOMETRY_DEFINE_COUNT];
} bench_geometry_t;

Expand Down Expand Up @@ -1057,7 +1055,7 @@ static void list_implicit_defines(void) {

// make sure to include builtin geometries here
extern const bench_geometry_t builtin_geometries[];
for (size_t g = 0; builtin_geometries[g].long_name; g++) {
for (size_t g = 0; builtin_geometries[g].name; g++) {
bench_define_geometry(&builtin_geometries[g]);
bench_define_flush();

Expand Down Expand Up @@ -1089,12 +1087,12 @@ static void list_implicit_defines(void) {
// geometries to bench

const bench_geometry_t builtin_geometries[] = {
{'d', "default", {{NULL}, BENCH_CONST(16), BENCH_CONST(512), {NULL}}},
{'e', "eeprom", {{NULL}, BENCH_CONST(1), BENCH_CONST(512), {NULL}}},
{'E', "emmc", {{NULL}, {NULL}, BENCH_CONST(512), {NULL}}},
{'n', "nor", {{NULL}, BENCH_CONST(1), BENCH_CONST(4096), {NULL}}},
{'N', "nand", {{NULL}, BENCH_CONST(4096), BENCH_CONST(32768), {NULL}}},
{0, NULL, {{NULL}, {NULL}, {NULL}, {NULL}}},
{"default", {{NULL}, BENCH_CONST(16), BENCH_CONST(512), {NULL}}},
{"eeprom", {{NULL}, BENCH_CONST(1), BENCH_CONST(512), {NULL}}},
{"emmc", {{NULL}, {NULL}, BENCH_CONST(512), {NULL}}},
{"nor", {{NULL}, BENCH_CONST(1), BENCH_CONST(4096), {NULL}}},
{"nand", {{NULL}, BENCH_CONST(4096), BENCH_CONST(32768), {NULL}}},
{NULL, {{NULL}, {NULL}, {NULL}, {NULL}}},
};

const bench_geometry_t *bench_geometries = builtin_geometries;
Expand All @@ -1107,12 +1105,11 @@ static void list_geometries(void) {

printf("%-24s %7s %7s %7s %7s %11s\n",
"geometry", "read", "prog", "erase", "count", "size");
for (size_t g = 0; builtin_geometries[g].long_name; g++) {
for (size_t g = 0; builtin_geometries[g].name; g++) {
bench_define_geometry(&builtin_geometries[g]);
bench_define_flush();
printf("%c,%-22s %7ju %7ju %7ju %7ju %11ju\n",
builtin_geometries[g].short_name,
builtin_geometries[g].long_name,
printf("%-24s %7ju %7ju %7ju %7ju %11ju\n",
builtin_geometries[g].name,
READ_SIZE,
PROG_SIZE,
BLOCK_SIZE,
Expand Down Expand Up @@ -1253,7 +1250,7 @@ enum opt_flags {
OPT_LIST_IMPLICIT_DEFINES = 5,
OPT_LIST_GEOMETRIES = 6,
OPT_DEFINE = 'D',
OPT_GEOMETRY = 'g',
OPT_GEOMETRY = 'G',
OPT_STEP = 's',
OPT_DISK = 'd',
OPT_TRACE = 't',
Expand All @@ -1262,7 +1259,7 @@ enum opt_flags {
OPT_ERASE_SLEEP = 9,
};

const char *short_opts = "hYlLD:g:s:d:t:";
const char *short_opts = "hYlLD:G:s:d:t:";

const struct option long_opts[] = {
{"help", no_argument, NULL, OPT_HELP},
Expand Down Expand Up @@ -1300,7 +1297,7 @@ const char *const help_text[] = {
"List implicit defines in this bench-runner.",
"List the available disk geometries.",
"Override a bench define.",
"Comma-separated list of disk geometries to bench. Defaults to d,e,E,n,N.",
"Comma-separated list of disk geometries to bench.",
"Comma-separated range of bench permutations to run (start,stop,step).",
"Redirect block device operations to this file.",
"Redirect trace output to this file.",
Expand Down Expand Up @@ -1555,14 +1552,11 @@ int main(int argc, char **argv) {

// named disk geometry
size_t len = strcspn(optarg, " ,");
for (size_t i = 0; builtin_geometries[i].long_name; i++) {
if ((len == 1
&& *optarg == builtin_geometries[i].short_name)
|| (len == strlen(
builtin_geometries[i].long_name)
&& memcmp(optarg,
builtin_geometries[i].long_name,
len) == 0)) {
for (size_t i = 0; builtin_geometries[i].name; i++) {
if (len == strlen(builtin_geometries[i].name)
&& memcmp(optarg,
builtin_geometries[i].name,
len) == 0) {
*geometry = builtin_geometries[i];
optarg += len;
goto geometry_next;
Expand Down
95 changes: 44 additions & 51 deletions runners/test_runner.c
Expand Up @@ -90,16 +90,12 @@ static uintmax_t leb16_parse(const char *s, char **tail) {
// test_runner types

typedef struct test_geometry {
char short_name;
const char *long_name;

const char *name;
test_define_t defines[TEST_GEOMETRY_DEFINE_COUNT];
} test_geometry_t;

typedef struct test_powerloss {
char short_name;
const char *long_name;

const char *name;
void (*run)(
const lfs_emubd_powercycles_t *cycles,
size_t cycle_count,
Expand Down Expand Up @@ -574,6 +570,11 @@ void test_seen_cleanup(test_seen_t *seen) {
free(seen->branches);
}

static void run_powerloss_none(
const lfs_emubd_powercycles_t *cycles,
size_t cycle_count,
const struct test_suite *suite,
const struct test_case *case_);
static void run_powerloss_cycles(
const lfs_emubd_powercycles_t *cycles,
size_t cycle_count,
Expand Down Expand Up @@ -606,7 +607,7 @@ static void case_forperm(
} else {
for (size_t p = 0; p < test_powerloss_count; p++) {
// skip non-reentrant tests when powerloss testing
if (test_powerlosses[p].short_name != '0'
if (test_powerlosses[p].run != run_powerloss_none
&& !(case_->flags & TEST_REENTRANT)) {
continue;
}
Expand Down Expand Up @@ -646,7 +647,7 @@ static void case_forperm(
} else {
for (size_t p = 0; p < test_powerloss_count; p++) {
// skip non-reentrant tests when powerloss testing
if (test_powerlosses[p].short_name != '0'
if (test_powerlosses[p].run != run_powerloss_none
&& !(case_->flags & TEST_REENTRANT)) {
continue;
}
Expand Down Expand Up @@ -1094,7 +1095,7 @@ static void list_implicit_defines(void) {

// make sure to include builtin geometries here
extern const test_geometry_t builtin_geometries[];
for (size_t g = 0; builtin_geometries[g].long_name; g++) {
for (size_t g = 0; builtin_geometries[g].name; g++) {
test_define_geometry(&builtin_geometries[g]);
test_define_flush();

Expand Down Expand Up @@ -1126,12 +1127,12 @@ static void list_implicit_defines(void) {
// geometries to test

const test_geometry_t builtin_geometries[] = {
{'d', "default", {{NULL}, TEST_CONST(16), TEST_CONST(512), {NULL}}},
{'e', "eeprom", {{NULL}, TEST_CONST(1), TEST_CONST(512), {NULL}}},
{'E', "emmc", {{NULL}, {NULL}, TEST_CONST(512), {NULL}}},
{'n', "nor", {{NULL}, TEST_CONST(1), TEST_CONST(4096), {NULL}}},
{'N', "nand", {{NULL}, TEST_CONST(4096), TEST_CONST(32768), {NULL}}},
{0, NULL, {{NULL}, {NULL}, {NULL}, {NULL}}},
{"default", {{NULL}, TEST_CONST(16), TEST_CONST(512), {NULL}}},
{"eeprom", {{NULL}, TEST_CONST(1), TEST_CONST(512), {NULL}}},
{"emmc", {{NULL}, {NULL}, TEST_CONST(512), {NULL}}},
{"nor", {{NULL}, TEST_CONST(1), TEST_CONST(4096), {NULL}}},
{"nand", {{NULL}, TEST_CONST(4096), TEST_CONST(32768), {NULL}}},
{NULL, {{NULL}, {NULL}, {NULL}, {NULL}}},
};

const test_geometry_t *test_geometries = builtin_geometries;
Expand All @@ -1144,12 +1145,11 @@ static void list_geometries(void) {

printf("%-24s %7s %7s %7s %7s %11s\n",
"geometry", "read", "prog", "erase", "count", "size");
for (size_t g = 0; builtin_geometries[g].long_name; g++) {
for (size_t g = 0; builtin_geometries[g].name; g++) {
test_define_geometry(&builtin_geometries[g]);
test_define_flush();
printf("%c,%-22s %7ju %7ju %7ju %7ju %11ju\n",
builtin_geometries[g].short_name,
builtin_geometries[g].long_name,
printf("%-24s %7ju %7ju %7ju %7ju %11ju\n",
builtin_geometries[g].name,
READ_SIZE,
PROG_SIZE,
BLOCK_SIZE,
Expand Down Expand Up @@ -1314,7 +1314,7 @@ static void run_powerloss_linear(
}
}

static void run_powerloss_exponential(
static void run_powerloss_log(
const lfs_emubd_powercycles_t *cycles,
size_t cycle_count,
const struct test_suite *suite,
Expand Down Expand Up @@ -1646,11 +1646,11 @@ static void run_powerloss_exhaustive(


const test_powerloss_t builtin_powerlosses[] = {
{'0', "none", run_powerloss_none, NULL, 0},
{'e', "exponential", run_powerloss_exponential, NULL, 0},
{'l', "linear", run_powerloss_linear, NULL, 0},
{'x', "exhaustive", run_powerloss_exhaustive, NULL, SIZE_MAX},
{0, NULL, NULL, NULL, 0},
{"none", run_powerloss_none, NULL, 0},
{"log", run_powerloss_log, NULL, 0},
{"linear", run_powerloss_linear, NULL, 0},
{"exhaustive", run_powerloss_exhaustive, NULL, SIZE_MAX},
{NULL, NULL, NULL, 0},
};

const char *const builtin_powerlosses_help[] = {
Expand All @@ -1664,17 +1664,16 @@ const char *const builtin_powerlosses_help[] = {
};

const test_powerloss_t *test_powerlosses = (const test_powerloss_t[]){
{'0', "none", run_powerloss_none, NULL, 0},
{"none", run_powerloss_none, NULL, 0},
};
size_t test_powerloss_count = 1;

static void list_powerlosses(void) {
printf("%-24s %s\n", "scenario", "description");
size_t i = 0;
for (; builtin_powerlosses[i].long_name; i++) {
printf("%c,%-22s %s\n",
builtin_powerlosses[i].short_name,
builtin_powerlosses[i].long_name,
for (; builtin_powerlosses[i].name; i++) {
printf("%-24s %s\n",
builtin_powerlosses[i].name,
builtin_powerlosses_help[i]);
}

Expand Down Expand Up @@ -1765,8 +1764,8 @@ enum opt_flags {
OPT_LIST_GEOMETRIES = 6,
OPT_LIST_POWERLOSSES = 7,
OPT_DEFINE = 'D',
OPT_GEOMETRY = 'g',
OPT_POWERLOSS = 'p',
OPT_GEOMETRY = 'G',
OPT_POWERLOSS = 'P',
OPT_STEP = 's',
OPT_DISK = 'd',
OPT_TRACE = 't',
Expand All @@ -1775,7 +1774,7 @@ enum opt_flags {
OPT_ERASE_SLEEP = 10,
};

const char *short_opts = "hYlLD:g:p:s:d:t:";
const char *short_opts = "hYlLD:G:P:s:d:t:";

const struct option long_opts[] = {
{"help", no_argument, NULL, OPT_HELP},
Expand Down Expand Up @@ -1816,8 +1815,8 @@ const char *const help_text[] = {
"List the available disk geometries.",
"List the available power-loss scenarios.",
"Override a test define.",
"Comma-separated list of disk geometries to test. Defaults to d,e,E,n,N.",
"Comma-separated list of power-loss scenarios to test. Defaults to 0,l.",
"Comma-separated list of disk geometries to test.",
"Comma-separated list of power-loss scenarios to test.",
"Comma-separated range of test permutations to run (start,stop,step).",
"Redirect block device operations to this file.",
"Redirect trace output to this file.",
Expand Down Expand Up @@ -2076,14 +2075,11 @@ int main(int argc, char **argv) {

// named disk geometry
size_t len = strcspn(optarg, " ,");
for (size_t i = 0; builtin_geometries[i].long_name; i++) {
if ((len == 1
&& *optarg == builtin_geometries[i].short_name)
|| (len == strlen(
builtin_geometries[i].long_name)
&& memcmp(optarg,
builtin_geometries[i].long_name,
len) == 0)) {
for (size_t i = 0; builtin_geometries[i].name; i++) {
if (len == strlen(builtin_geometries[i].name)
&& memcmp(optarg,
builtin_geometries[i].name,
len) == 0) {
*geometry = builtin_geometries[i];
optarg += len;
goto geometry_next;
Expand Down Expand Up @@ -2224,14 +2220,11 @@ int main(int argc, char **argv) {

// named power-loss scenario
size_t len = strcspn(optarg, " ,");
for (size_t i = 0; builtin_powerlosses[i].long_name; i++) {
if ((len == 1
&& *optarg == builtin_powerlosses[i].short_name)
|| (len == strlen(
builtin_powerlosses[i].long_name)
&& memcmp(optarg,
builtin_powerlosses[i].long_name,
len) == 0)) {
for (size_t i = 0; builtin_powerlosses[i].name; i++) {
if (len == strlen(builtin_powerlosses[i].name)
&& memcmp(optarg,
builtin_powerlosses[i].name,
len) == 0) {
*powerloss = builtin_powerlosses[i];
optarg += len;
goto powerloss_next;
Expand Down
15 changes: 9 additions & 6 deletions scripts/bench.py
Expand Up @@ -511,7 +511,7 @@ def find_runner(runner, **args):

# other context
if args.get('geometry'):
cmd.append('-g%s' % args['geometry'])
cmd.append('-G%s' % args['geometry'])
if args.get('disk'):
cmd.append('-d%s' % args['disk'])
if args.get('trace'):
Expand Down Expand Up @@ -1003,6 +1003,10 @@ def run(runner, bench_ids=[], **args):
total_perms))
print()

# automatic job detection?
if args.get('jobs') == 0:
args['jobs'] = len(os.sched_getaffinity(0))

# truncate and open logs here so they aren't disconnected between benches
stdout = None
if args.get('stdout'):
Expand Down Expand Up @@ -1246,9 +1250,8 @@ def main(**args):
action='append',
help="Override a bench define.")
bench_parser.add_argument(
'-g', '--geometry',
help="Comma-separated list of disk geometries to bench. "
"Defaults to d,e,E,n,N.")
'-G', '--geometry',
help="Comma-separated list of disk geometries to bench.")
bench_parser.add_argument(
'-d', '--disk',
help="Direct block device operations to this file.")
Expand All @@ -1274,8 +1277,8 @@ def main(**args):
'-j', '--jobs',
nargs='?',
type=lambda x: int(x, 0),
const=len(os.sched_getaffinity(0)),
help="Number of parallel runners to run.")
const=0,
help="Number of parallel runners to run. 0 runs one runner per core.")
bench_parser.add_argument(
'-k', '--keep-going',
action='store_true',
Expand Down

0 comments on commit 9507e62

Please sign in to comment.