clang-format
This commit is contained in:
@@ -37,160 +37,148 @@
|
||||
#include "main.h"
|
||||
|
||||
struct workload {
|
||||
const char *name;
|
||||
const char *argname;
|
||||
union {
|
||||
void (*witharg)(const char *);
|
||||
void (*noarg)(void);
|
||||
} run;
|
||||
const char *name;
|
||||
const char *argname;
|
||||
union {
|
||||
void (*witharg)(const char *);
|
||||
void (*noarg)(void);
|
||||
} run;
|
||||
};
|
||||
|
||||
#define WL(n) { .name = #n, .argname = NULL, .run.noarg = wl_##n }
|
||||
#define WLA(n,a) { .name = #n, .argname = #a, .run.witharg = wl_##n }
|
||||
#define WL(n) {.name = #n, .argname = NULL, .run.noarg = wl_##n}
|
||||
#define WLA(n, a) {.name = #n, .argname = #a, .run.witharg = wl_##n}
|
||||
|
||||
static const struct workload workloads[] = {
|
||||
WLA(createwrite, size),
|
||||
WLA(rewrite, size),
|
||||
WLA(randupdate, size),
|
||||
WLA(truncwrite, size),
|
||||
WLA(makehole, size),
|
||||
WLA(fillhole, size),
|
||||
WLA(truncfill, size),
|
||||
WLA(append, size),
|
||||
WLA(trunczero, size),
|
||||
WLA(trunconeblock, size),
|
||||
WLA(truncsmallersize, size),
|
||||
WLA(trunclargersize, size),
|
||||
WLA(appendandtrunczero, size),
|
||||
WLA(appendandtruncpartly, size),
|
||||
WL(mkfile),
|
||||
WL(mkdir),
|
||||
WL(mkmanyfile),
|
||||
WL(mkmanydir),
|
||||
WL(mktree),
|
||||
WLA(mkrandtree, seed),
|
||||
WL(rmfile),
|
||||
WL(rmdir),
|
||||
WL(rmfiledelayed),
|
||||
WL(rmfiledelayedappend),
|
||||
WL(rmdirdelayed),
|
||||
WL(rmmanyfile),
|
||||
WL(rmmanyfiledelayed),
|
||||
WL(rmmanyfiledelayedandappend),
|
||||
WL(rmmanydir),
|
||||
WL(rmmanydirdelayed),
|
||||
WL(rmtree),
|
||||
WLA(rmrandtree, seed),
|
||||
WL(linkfile),
|
||||
WL(linkmanyfile),
|
||||
WL(unlinkfile),
|
||||
WL(unlinkmanyfile),
|
||||
WL(linkunlinkfile),
|
||||
WL(renamefile),
|
||||
WL(renamedir),
|
||||
WL(renamesubtree),
|
||||
WL(renamexdfile),
|
||||
WL(renamexddir),
|
||||
WL(renamexdsubtree),
|
||||
WL(renamemanyfile),
|
||||
WL(renamemanydir),
|
||||
WL(renamemanysubtree),
|
||||
WL(copyandrename),
|
||||
WL(untar),
|
||||
WL(compile),
|
||||
WL(cvsupdate),
|
||||
WLA(writefileseq, seed),
|
||||
WLA(writetruncseq, seed),
|
||||
WLA(mkrmseq, seed),
|
||||
WLA(linkunlinkseq, seed),
|
||||
WLA(renameseq, seed),
|
||||
WLA(diropseq, seed),
|
||||
WLA(genseq, seed),
|
||||
WLA(createwrite, size),
|
||||
WLA(rewrite, size),
|
||||
WLA(randupdate, size),
|
||||
WLA(truncwrite, size),
|
||||
WLA(makehole, size),
|
||||
WLA(fillhole, size),
|
||||
WLA(truncfill, size),
|
||||
WLA(append, size),
|
||||
WLA(trunczero, size),
|
||||
WLA(trunconeblock, size),
|
||||
WLA(truncsmallersize, size),
|
||||
WLA(trunclargersize, size),
|
||||
WLA(appendandtrunczero, size),
|
||||
WLA(appendandtruncpartly, size),
|
||||
WL(mkfile),
|
||||
WL(mkdir),
|
||||
WL(mkmanyfile),
|
||||
WL(mkmanydir),
|
||||
WL(mktree),
|
||||
WLA(mkrandtree, seed),
|
||||
WL(rmfile),
|
||||
WL(rmdir),
|
||||
WL(rmfiledelayed),
|
||||
WL(rmfiledelayedappend),
|
||||
WL(rmdirdelayed),
|
||||
WL(rmmanyfile),
|
||||
WL(rmmanyfiledelayed),
|
||||
WL(rmmanyfiledelayedandappend),
|
||||
WL(rmmanydir),
|
||||
WL(rmmanydirdelayed),
|
||||
WL(rmtree),
|
||||
WLA(rmrandtree, seed),
|
||||
WL(linkfile),
|
||||
WL(linkmanyfile),
|
||||
WL(unlinkfile),
|
||||
WL(unlinkmanyfile),
|
||||
WL(linkunlinkfile),
|
||||
WL(renamefile),
|
||||
WL(renamedir),
|
||||
WL(renamesubtree),
|
||||
WL(renamexdfile),
|
||||
WL(renamexddir),
|
||||
WL(renamexdsubtree),
|
||||
WL(renamemanyfile),
|
||||
WL(renamemanydir),
|
||||
WL(renamemanysubtree),
|
||||
WL(copyandrename),
|
||||
WL(untar),
|
||||
WL(compile),
|
||||
WL(cvsupdate),
|
||||
WLA(writefileseq, seed),
|
||||
WLA(writetruncseq, seed),
|
||||
WLA(mkrmseq, seed),
|
||||
WLA(linkunlinkseq, seed),
|
||||
WLA(renameseq, seed),
|
||||
WLA(diropseq, seed),
|
||||
WLA(genseq, seed),
|
||||
};
|
||||
static const unsigned numworkloads = sizeof(workloads) / sizeof(workloads[0]);
|
||||
|
||||
#undef WL
|
||||
#undef WLA
|
||||
|
||||
static
|
||||
const struct workload *
|
||||
findworkload(const char *name)
|
||||
{
|
||||
unsigned i;
|
||||
static const struct workload *findworkload(const char *name) {
|
||||
unsigned i;
|
||||
|
||||
for (i=0; i<numworkloads; i++) {
|
||||
if (!strcmp(workloads[i].name, name)) {
|
||||
return &workloads[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
for (i = 0; i < numworkloads; i++) {
|
||||
if (!strcmp(workloads[i].name, name)) {
|
||||
return &workloads[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
printworkloads(void)
|
||||
{
|
||||
unsigned i;
|
||||
static void printworkloads(void) {
|
||||
unsigned i;
|
||||
|
||||
printf("Supported workloads:\n");
|
||||
for (i=0; i<numworkloads; i++) {
|
||||
printf(" %s", workloads[i].name);
|
||||
if (workloads[i].argname) {
|
||||
printf(" %s", workloads[i].argname);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("Supported workloads:\n");
|
||||
for (i = 0; i < numworkloads; i++) {
|
||||
printf(" %s", workloads[i].name);
|
||||
if (workloads[i].argname) {
|
||||
printf(" %s", workloads[i].argname);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *workloadname;
|
||||
const struct workload *workload;
|
||||
int checkmode = 0;
|
||||
int main(int argc, char *argv[]) {
|
||||
const char *workloadname;
|
||||
const struct workload *workload;
|
||||
int checkmode = 0;
|
||||
|
||||
if (argc == 2 && !strcmp(argv[1], "list")) {
|
||||
printworkloads();
|
||||
exit(0);
|
||||
}
|
||||
if (argc == 2 && !strcmp(argv[1], "list")) {
|
||||
printworkloads();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
warnx("Usage: %s do|check workload [arg]", argv[0]);
|
||||
warnx("Use \"list\" for a list of workloads");
|
||||
exit(1);
|
||||
}
|
||||
if (argc < 3) {
|
||||
warnx("Usage: %s do|check workload [arg]", argv[0]);
|
||||
warnx("Use \"list\" for a list of workloads");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "do")) {
|
||||
checkmode = 0;
|
||||
}
|
||||
else if (!strcmp(argv[1], "check")) {
|
||||
checkmode = 1;
|
||||
}
|
||||
else {
|
||||
errx(1, "Action must be \"do\" or \"check\"");
|
||||
}
|
||||
if (!strcmp(argv[1], "do")) {
|
||||
checkmode = 0;
|
||||
} else if (!strcmp(argv[1], "check")) {
|
||||
checkmode = 1;
|
||||
} else {
|
||||
errx(1, "Action must be \"do\" or \"check\"");
|
||||
}
|
||||
|
||||
workloadname = argv[2];
|
||||
workload = findworkload(workloadname);
|
||||
if (workload == NULL) {
|
||||
errx(1, "Unknown workload %s\n", workloadname);
|
||||
printworkloads();
|
||||
exit(1);
|
||||
}
|
||||
setcheckmode(checkmode);
|
||||
if (workload->argname) {
|
||||
if (argc != 4) {
|
||||
errx(1, "%s requires argument %s\n",
|
||||
workloadname, workload->argname);
|
||||
}
|
||||
workload->run.witharg(argv[3]);
|
||||
}
|
||||
else {
|
||||
if (argc != 3) {
|
||||
errx(1, "Stray argument for workload %s",workloadname);
|
||||
}
|
||||
workload->run.noarg();
|
||||
}
|
||||
complete();
|
||||
return 0;
|
||||
workloadname = argv[2];
|
||||
workload = findworkload(workloadname);
|
||||
if (workload == NULL) {
|
||||
errx(1, "Unknown workload %s\n", workloadname);
|
||||
printworkloads();
|
||||
exit(1);
|
||||
}
|
||||
setcheckmode(checkmode);
|
||||
if (workload->argname) {
|
||||
if (argc != 4) {
|
||||
errx(1, "%s requires argument %s\n", workloadname, workload->argname);
|
||||
}
|
||||
workload->run.witharg(argv[3]);
|
||||
} else {
|
||||
if (argc != 3) {
|
||||
errx(1, "Stray argument for workload %s", workloadname);
|
||||
}
|
||||
workload->run.noarg();
|
||||
}
|
||||
complete();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user