runners: bench: Added flags to control reading from bench probes
- -S/--probe - Specify a probe to sample.
- -x/--probe-step - Sample probes every n steps.
- --probe-runfreq - Sample probes at this frequency in hz.
- -X/--probe-simfreq - Sample probes at this frequency in simulated hz.
Also:
- --trace-simfreq - Sample trace output at this frequency in
simulated hz.
These give finer grain control over which probes we measure during
benching, and how we measure them.
These also introduce several exciting bench features:
- -S/--probe provides the ability to easily filter which probes you're
interested in at runtime.
This should replace the growing use of MASK defines in the benches.
- -x/--probe-step makes it easy to relax sampling rate when the amount
of data overwhelms later scripts.
This should replace the growing use of STEP defines in the benches.
- The additional concept of simfreq, which allows perf-esque sampling in
simtime. This provides another option for intuitively relaxing probe
sampling rate without sacrificing reproducibility.
(runfreq depends on wall time, so good bye reproducibility, though may
still be useful in interactive contexts.)
Note -S/--probe and -x/--probe-step replace MASK/STEP defines, which
have already proved their usefulness, but required reimplementation in
every bench case. An obvious contender to move into the bench_runner!
---
Note note that -S/--probe also supports some simple sample expressions,
allowing flexible step/simfreq/runfreq at the per-probe level:
- -Swrite=100 - Sample probe "write" every 100 steps
- -Swrite=100rhz - Sample probe "write" 100 times a runtime second
- -Swrite=100shz - Sample probe "write" 100 times a simulated second
Though I wonder how long it will take before I forget this feature
exists.
This commit is contained in:
@@ -56,7 +56,7 @@ code = '''
|
|||||||
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
|
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
|
||||||
|
|
||||||
// taking too long?
|
// taking too long?
|
||||||
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
|
if (SIM_TIME && BENCH_SIMTIME() >= SIM_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ code = '''
|
|||||||
lfs3_off_t size = 0;
|
lfs3_off_t size = 0;
|
||||||
uint64_t readed = 0;
|
uint64_t readed = 0;
|
||||||
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// read from the file
|
// read from the file
|
||||||
uint8_t rbuf[CHUNK];
|
uint8_t rbuf[CHUNK];
|
||||||
lfs3_file_read(&lfs3, &file, rbuf, CHUNK) => CHUNK;
|
lfs3_file_read(&lfs3, &file, rbuf, CHUNK) => CHUNK;
|
||||||
@@ -123,7 +123,7 @@ code = '''
|
|||||||
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
|
lfs3_file_write(&lfs3, &file, wbuf, CHUNK) => CHUNK;
|
||||||
|
|
||||||
// taking too long?
|
// taking too long?
|
||||||
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
|
if (SIM_TIME && BENCH_SIMTIME() >= SIM_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ code = '''
|
|||||||
lfs3_file_open(&lfs3, &file, "bench_random", LFS3_O_RDONLY) => 0;
|
lfs3_file_open(&lfs3, &file, "bench_random", LFS3_O_RDONLY) => 0;
|
||||||
uint64_t readed = 0;
|
uint64_t readed = 0;
|
||||||
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// seek to a random location
|
// seek to a random location
|
||||||
lfs3_off_t pos = BENCH_PRNG(&prng) % SIZE;
|
lfs3_off_t pos = BENCH_PRNG(&prng) % SIZE;
|
||||||
lfs3_file_seek(&lfs3, &file, pos, LFS3_SEEK_SET) => pos;
|
lfs3_file_seek(&lfs3, &file, pos, LFS3_SEEK_SET) => pos;
|
||||||
@@ -191,7 +191,7 @@ code = '''
|
|||||||
lfs3_file_write(&lfs3, &file, wbuf, d) => d;
|
lfs3_file_write(&lfs3, &file, wbuf, d) => d;
|
||||||
|
|
||||||
// taking too long?
|
// taking too long?
|
||||||
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
|
if (SIM_TIME && BENCH_SIMTIME() >= SIM_TIME) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ code = '''
|
|||||||
BENCH_START("read");
|
BENCH_START("read");
|
||||||
uint64_t readed = 0;
|
uint64_t readed = 0;
|
||||||
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && readed >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// choose a random filename
|
// choose a random filename
|
||||||
lfs3_off_t pos = BENCH_PRNG(&prng) % ((SIZE+(CHUNK-1))/CHUNK);
|
lfs3_off_t pos = BENCH_PRNG(&prng) % ((SIZE+(CHUNK-1))/CHUNK);
|
||||||
char name[256];
|
char name[256];
|
||||||
@@ -224,7 +224,7 @@ code = '''
|
|||||||
readed += d;
|
readed += d;
|
||||||
|
|
||||||
// taking too long?
|
// taking too long?
|
||||||
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
|
if (SIM_TIME && BENCH_SIMTIME() >= SIM_TIME) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ code = '''
|
|||||||
// ok, one of these needs to be non-zero
|
// ok, one of these needs to be non-zero
|
||||||
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
|
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
|
||||||
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// arguably we should just rewind and continue writing to the
|
// arguably we should just rewind and continue writing to the
|
||||||
// front of the file when we hit the end, but this overly
|
// front of the file when we hit the end, but this overly
|
||||||
// penalizes littlefs2, so instead we truncate
|
// penalizes littlefs2, so instead we truncate
|
||||||
@@ -122,7 +122,7 @@ code = '''
|
|||||||
lfs3_off_t size = 0;
|
lfs3_off_t size = 0;
|
||||||
uint64_t written = 0;
|
uint64_t written = 0;
|
||||||
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// seek to a random location
|
// seek to a random location
|
||||||
lfs3_off_t pos = BENCH_PRNG(&prng) % SIZE;
|
lfs3_off_t pos = BENCH_PRNG(&prng) % SIZE;
|
||||||
lfs3_file_seek(&lfs3, &file, pos, LFS3_SEEK_SET) => pos;
|
lfs3_file_seek(&lfs3, &file, pos, LFS3_SEEK_SET) => pos;
|
||||||
@@ -189,7 +189,7 @@ code = '''
|
|||||||
// ok, one of these needs to be non-zero
|
// ok, one of these needs to be non-zero
|
||||||
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
|
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
|
||||||
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// append to log
|
// append to log
|
||||||
uint8_t wbuf[CHUNK];
|
uint8_t wbuf[CHUNK];
|
||||||
for (lfs3_size_t j = 0; j < CHUNK; j++) {
|
for (lfs3_size_t j = 0; j < CHUNK; j++) {
|
||||||
@@ -265,7 +265,7 @@ code = '''
|
|||||||
// ok, one of these needs to be non-zero
|
// ok, one of these needs to be non-zero
|
||||||
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
|
LFS3_ASSERT(SIM_TIME > 0 || SIM_SIZE > 0);
|
||||||
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
while (!(SIM_SIZE && written >= (uint64_t)SIM_SIZE)
|
||||||
&& !(SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME)) {
|
&& !(SIM_TIME && BENCH_SIMTIME() >= SIM_TIME)) {
|
||||||
// choose a random filename
|
// choose a random filename
|
||||||
lfs3_off_t pos = BENCH_PRNG(&prng) % FILE_COUNT;
|
lfs3_off_t pos = BENCH_PRNG(&prng) % FILE_COUNT;
|
||||||
char name[256];
|
char name[256];
|
||||||
@@ -287,7 +287,7 @@ code = '''
|
|||||||
written += d;
|
written += d;
|
||||||
|
|
||||||
// taking too long?
|
// taking too long?
|
||||||
if (SIM_TIME && BENCH_SIMTIME() >= (bench_ns_t)SIM_TIME) {
|
if (SIM_TIME && BENCH_SIMTIME() >= SIM_TIME) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+582
-245
File diff suppressed because it is too large
Load Diff
@@ -156,7 +156,7 @@ void bench_fresult(const char *probe, uintmax_t n, double result);
|
|||||||
|
|
||||||
// extra hooks to get the current simtime, pause readed/progged/erased
|
// extra hooks to get the current simtime, pause readed/progged/erased
|
||||||
// counters, etc
|
// counters, etc
|
||||||
bench_ns_t bench_simtime(void);
|
bench_sns_t bench_simtime(void);
|
||||||
void bench_simreset(void);
|
void bench_simreset(void);
|
||||||
void bench_simpause(void);
|
void bench_simpause(void);
|
||||||
void bench_simresume(void);
|
void bench_simresume(void);
|
||||||
@@ -185,6 +185,13 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size);
|
|||||||
#define BENCH_FACTORIAL(x) bench_factorial(x)
|
#define BENCH_FACTORIAL(x) bench_factorial(x)
|
||||||
#define BENCH_PERMUTATION(i, buffer, size) bench_permutation(i, buffer, size)
|
#define BENCH_PERMUTATION(i, buffer, size) bench_permutation(i, buffer, size)
|
||||||
|
|
||||||
|
// option to pause trace output
|
||||||
|
void bench_trace_pause(void);
|
||||||
|
void bench_trace_resume(void);
|
||||||
|
|
||||||
|
#define BENCH_TRACE_PAUSE() bench_trace_pause()
|
||||||
|
#define BENCH_TRACE_RESUME() bench_trace_resume()
|
||||||
|
|
||||||
#ifdef BENCH_STACK
|
#ifdef BENCH_STACK
|
||||||
// get the maximum/current stack usage for this run
|
// get the maximum/current stack usage for this run
|
||||||
extern size_t bench_stack_watermark;
|
extern size_t bench_stack_watermark;
|
||||||
|
|||||||
+133
-114
@@ -176,6 +176,7 @@ ssize_t *test_suite_define_map = NULL;
|
|||||||
|
|
||||||
test_define_t *test_override_defines = NULL;
|
test_define_t *test_override_defines = NULL;
|
||||||
size_t test_override_define_count = 0;
|
size_t test_override_define_count = 0;
|
||||||
|
size_t test_override_define_capacity = 0;
|
||||||
|
|
||||||
size_t test_define_depth = 1000;
|
size_t test_define_depth = 1000;
|
||||||
|
|
||||||
@@ -432,23 +433,25 @@ const test_id_t *test_ids = (const test_id_t[]) {
|
|||||||
{NULL, NULL, 0, {NULL, NULL, NULL, 0}},
|
{NULL, NULL, 0, {NULL, NULL, NULL, 0}},
|
||||||
};
|
};
|
||||||
size_t test_id_count = 1;
|
size_t test_id_count = 1;
|
||||||
|
size_t test_id_capacity = 0;
|
||||||
|
|
||||||
size_t test_step_start = 0;
|
size_t test_step_start = 0;
|
||||||
size_t test_step_stop = -1;
|
size_t test_step_stop = -1;
|
||||||
size_t test_step_step = 1;
|
size_t test_step_step = 1;
|
||||||
size_t test_step = 0; // incremented every permutation
|
size_t test_steps = 0; // incremented every permutation
|
||||||
bool test_force = false;
|
bool test_force = false;
|
||||||
test_flags_t test_mask = 0;
|
test_flags_t test_mask = 0;
|
||||||
|
|
||||||
const char *test_disk_path = NULL;
|
const char *test_disk_path = NULL;
|
||||||
const char *test_trace_path = NULL;
|
const char *test_trace_path = NULL;
|
||||||
bool test_trace_backtrace = false;
|
bool test_trace_backtrace = false;
|
||||||
uint32_t test_trace_step = 0;
|
size_t test_trace_step = 0;
|
||||||
uint32_t test_trace_runfreq = 0;
|
double test_trace_runfreq = 0;
|
||||||
|
uint32_t test_trace_paused = false;
|
||||||
FILE *test_trace_file = NULL;
|
FILE *test_trace_file = NULL;
|
||||||
uint32_t test_trace_cycles = 0;
|
size_t test_trace_steps = 0;
|
||||||
uint64_t test_trace_time = 0;
|
test_ns_t test_trace_runtime = 0;
|
||||||
uint64_t test_trace_open_time = 0;
|
test_ns_t test_trace_open_runtime = 0;
|
||||||
test_ns_t test_read_sleep = 0.0;
|
test_ns_t test_read_sleep = 0.0;
|
||||||
test_ns_t test_prog_sleep = 0.0;
|
test_ns_t test_prog_sleep = 0.0;
|
||||||
test_ns_t test_erase_sleep = 0.0;
|
test_ns_t test_erase_sleep = 0.0;
|
||||||
@@ -469,104 +472,123 @@ void *test_trace_backtrace_buffer[
|
|||||||
|
|
||||||
// trace printing
|
// trace printing
|
||||||
void test_trace(const char *fmt, ...) {
|
void test_trace(const char *fmt, ...) {
|
||||||
if (test_trace_path) {
|
if (!test_trace_path || test_trace_paused) {
|
||||||
// sample at a specific step?
|
goto done;
|
||||||
if (test_trace_step) {
|
|
||||||
if (test_trace_cycles % test_trace_step != 0) {
|
|
||||||
test_trace_cycles += 1;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
test_trace_cycles += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sample at a specific frequency?
|
|
||||||
if (test_trace_runfreq) {
|
|
||||||
struct timespec t;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
|
||||||
uint64_t now = (uint64_t)t.tv_sec*1000*1000*1000
|
|
||||||
+ (uint64_t)t.tv_nsec;
|
|
||||||
if (now - test_trace_time
|
|
||||||
< (1000*1000*1000) / test_trace_runfreq) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
test_trace_time = now;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!test_trace_file) {
|
|
||||||
// Tracing output is heavy and trying to open every trace
|
|
||||||
// call is slow, so we only try to open the trace file every
|
|
||||||
// so often. Note this doesn't affect successfully opened files
|
|
||||||
struct timespec t;
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
|
||||||
uint64_t now = (uint64_t)t.tv_sec*1000*1000*1000
|
|
||||||
+ (uint64_t)t.tv_nsec;
|
|
||||||
if (now - test_trace_open_time < 100*1000*1000) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
test_trace_open_time = now;
|
|
||||||
|
|
||||||
// try to open the trace file
|
|
||||||
int fd;
|
|
||||||
if (strcmp(test_trace_path, "-") == 0) {
|
|
||||||
fd = dup(1);
|
|
||||||
if (fd < 0) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fd = open(
|
|
||||||
test_trace_path,
|
|
||||||
O_WRONLY | O_CREAT | O_APPEND | O_NONBLOCK,
|
|
||||||
0666);
|
|
||||||
if (fd < 0) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
int err = fcntl(fd, F_SETFL, O_WRONLY | O_CREAT | O_APPEND);
|
|
||||||
assert(!err);
|
|
||||||
}
|
|
||||||
|
|
||||||
FILE *f = fdopen(fd, "a");
|
|
||||||
assert(f);
|
|
||||||
int err = setvbuf(f, NULL, _IOFBF,
|
|
||||||
TEST_TRACE_BACKTRACE_BUFFER_SIZE);
|
|
||||||
assert(!err);
|
|
||||||
test_trace_file = f;
|
|
||||||
}
|
|
||||||
|
|
||||||
// print trace
|
|
||||||
va_list va;
|
|
||||||
va_start(va, fmt);
|
|
||||||
int res = vfprintf(test_trace_file, fmt, va);
|
|
||||||
va_end(va);
|
|
||||||
if (res < 0) {
|
|
||||||
fclose(test_trace_file);
|
|
||||||
test_trace_file = NULL;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (test_trace_backtrace) {
|
|
||||||
// print backtrace
|
|
||||||
size_t count = backtrace(
|
|
||||||
test_trace_backtrace_buffer,
|
|
||||||
TEST_TRACE_BACKTRACE_BUFFER_SIZE);
|
|
||||||
// note we skip our own stack frame
|
|
||||||
for (size_t i = 1; i < count; i++) {
|
|
||||||
res = fprintf(test_trace_file, "\tat %p\n",
|
|
||||||
test_trace_backtrace_buffer[i]);
|
|
||||||
if (res < 0) {
|
|
||||||
fclose(test_trace_file);
|
|
||||||
test_trace_file = NULL;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// flush immediately
|
|
||||||
fflush(test_trace_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent accidental recursion
|
||||||
|
TEST_TRACE_PAUSE();
|
||||||
|
|
||||||
|
// sample at a specific step?
|
||||||
|
if (test_trace_step) {
|
||||||
|
if (test_trace_steps % test_trace_step != 0) {
|
||||||
|
test_trace_steps += 1;
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
test_trace_steps += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sample at a specific frequency?
|
||||||
|
if (test_trace_runfreq) {
|
||||||
|
struct timespec t;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||||
|
test_ns_t now = (test_ns_t)t.tv_sec*1000*1000*1000
|
||||||
|
+ (test_ns_t)t.tv_nsec;
|
||||||
|
if (now - test_trace_runtime
|
||||||
|
< (test_ns_t)((1000.0*1000.0*1000.0)
|
||||||
|
/ test_trace_runfreq)) {
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
test_trace_runtime = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!test_trace_file) {
|
||||||
|
// Tracing output is heavy and trying to open every trace
|
||||||
|
// call is slow, so we only try to open the trace file every
|
||||||
|
// so often. Note this doesn't affect successfully opened files
|
||||||
|
struct timespec t;
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||||
|
test_ns_t now = (test_ns_t)t.tv_sec*1000*1000*1000
|
||||||
|
+ (test_ns_t)t.tv_nsec;
|
||||||
|
if (now - test_trace_open_runtime < 100*1000*1000) {
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
test_trace_open_runtime = now;
|
||||||
|
|
||||||
|
// try to open the trace file
|
||||||
|
int fd;
|
||||||
|
if (strcmp(test_trace_path, "-") == 0) {
|
||||||
|
fd = dup(1);
|
||||||
|
if (fd < 0) {
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fd = open(
|
||||||
|
test_trace_path,
|
||||||
|
O_WRONLY | O_CREAT | O_APPEND | O_NONBLOCK,
|
||||||
|
0666);
|
||||||
|
if (fd < 0) {
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
int err = fcntl(fd, F_SETFL, O_WRONLY | O_CREAT | O_APPEND);
|
||||||
|
assert(!err);
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *f = fdopen(fd, "a");
|
||||||
|
assert(f);
|
||||||
|
int err = setvbuf(f, NULL, _IOFBF,
|
||||||
|
TEST_TRACE_BACKTRACE_BUFFER_SIZE);
|
||||||
|
assert(!err);
|
||||||
|
test_trace_file = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// print trace
|
||||||
|
va_list va;
|
||||||
|
va_start(va, fmt);
|
||||||
|
int res = vfprintf(test_trace_file, fmt, va);
|
||||||
|
va_end(va);
|
||||||
|
if (res < 0) {
|
||||||
|
fclose(test_trace_file);
|
||||||
|
test_trace_file = NULL;
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (test_trace_backtrace) {
|
||||||
|
// print backtrace
|
||||||
|
size_t count = backtrace(
|
||||||
|
test_trace_backtrace_buffer,
|
||||||
|
TEST_TRACE_BACKTRACE_BUFFER_SIZE);
|
||||||
|
// note we skip our own stack frame
|
||||||
|
for (size_t i = 1; i < count; i++) {
|
||||||
|
res = fprintf(test_trace_file, "\tat %p\n",
|
||||||
|
test_trace_backtrace_buffer[i]);
|
||||||
|
if (res < 0) {
|
||||||
|
fclose(test_trace_file);
|
||||||
|
test_trace_file = NULL;
|
||||||
|
goto done_;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// flush immediately
|
||||||
|
fflush(test_trace_file);
|
||||||
|
|
||||||
|
done_:;
|
||||||
|
TEST_TRACE_RESUME();
|
||||||
|
|
||||||
done:;
|
done:;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_trace_pause(void) {
|
||||||
|
test_trace_paused += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_trace_resume(void) {
|
||||||
|
assert(test_trace_paused);
|
||||||
|
test_trace_paused -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// test prng
|
// test prng
|
||||||
uint32_t test_prng(uint32_t *state) {
|
uint32_t test_prng(uint32_t *state) {
|
||||||
// A simple xorshift32 generator, easily reproducible. Keep in mind
|
// A simple xorshift32 generator, easily reproducible. Keep in mind
|
||||||
@@ -822,13 +844,13 @@ void perm_count(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// skip this step?
|
// skip this step?
|
||||||
if (!(test_step >= test_step_start
|
if (!(test_steps >= test_step_start
|
||||||
&& test_step < test_step_stop
|
&& test_steps < test_step_stop
|
||||||
&& (test_step-test_step_start) % test_step_step == 0)) {
|
&& (test_steps-test_step_start) % test_step_step == 0)) {
|
||||||
test_step += 1;
|
test_steps += 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
test_step += 1;
|
test_steps += 1;
|
||||||
|
|
||||||
state->total += 1;
|
state->total += 1;
|
||||||
|
|
||||||
@@ -1868,6 +1890,7 @@ size_t test_powerloss_count = 2;
|
|||||||
#else
|
#else
|
||||||
size_t test_powerloss_count = 1;
|
size_t test_powerloss_count = 1;
|
||||||
#endif
|
#endif
|
||||||
|
size_t test_powerloss_capacity = 0;
|
||||||
|
|
||||||
static void list_powerlosses(void) {
|
static void list_powerlosses(void) {
|
||||||
// at least size so that names fit
|
// at least size so that names fit
|
||||||
@@ -1913,13 +1936,13 @@ void perm_run(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// skip this step?
|
// skip this step?
|
||||||
if (!(test_step >= test_step_start
|
if (!(test_steps >= test_step_start
|
||||||
&& test_step < test_step_stop
|
&& test_steps < test_step_stop
|
||||||
&& (test_step-test_step_start) % test_step_step == 0)) {
|
&& (test_steps-test_step_start) % test_step_step == 0)) {
|
||||||
test_step += 1;
|
test_steps += 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
test_step += 1;
|
test_steps += 1;
|
||||||
|
|
||||||
// set pls to 1 if running under powerloss so it useful for if predicates
|
// set pls to 1 if running under powerloss so it useful for if predicates
|
||||||
TEST_PLS = (powerloss->run != run_powerloss_none);
|
TEST_PLS = (powerloss->run != run_powerloss_none);
|
||||||
@@ -2062,10 +2085,6 @@ const char *const help_text[] = {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
void (*op)(void) = run;
|
void (*op)(void) = run;
|
||||||
|
|
||||||
size_t test_override_define_capacity = 0;
|
|
||||||
size_t test_powerloss_capacity = 0;
|
|
||||||
size_t test_id_capacity = 0;
|
|
||||||
|
|
||||||
// parse options
|
// parse options
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getopt_long(argc, argv, short_opts, long_opts, NULL);
|
int c = getopt_long(argc, argv, short_opts, long_opts, NULL);
|
||||||
@@ -2582,7 +2601,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
case OPT_TRACE_RUNFREQ:;
|
case OPT_TRACE_RUNFREQ:;
|
||||||
parsed = NULL;
|
parsed = NULL;
|
||||||
test_trace_runfreq = strtoumax(optarg, &parsed, 0);
|
test_trace_runfreq = strtod(optarg, &parsed);
|
||||||
if (parsed == optarg) {
|
if (parsed == optarg) {
|
||||||
fprintf(stderr, "error: invalid trace-runfreq: %s\n", optarg);
|
fprintf(stderr, "error: invalid trace-runfreq: %s\n", optarg);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|||||||
@@ -153,6 +153,13 @@ void test_permutation(size_t i, uint32_t *buffer, size_t size);
|
|||||||
#define TEST_FACTORIAL(x) test_factorial(x)
|
#define TEST_FACTORIAL(x) test_factorial(x)
|
||||||
#define TEST_PERMUTATION(i, buffer, size) test_permutation(i, buffer, size)
|
#define TEST_PERMUTATION(i, buffer, size) test_permutation(i, buffer, size)
|
||||||
|
|
||||||
|
// option to pause trace output
|
||||||
|
void test_trace_pause(void);
|
||||||
|
void test_trace_resume(void);
|
||||||
|
|
||||||
|
#define TEST_TRACE_PAUSE() test_trace_pause()
|
||||||
|
#define TEST_TRACE_RESUME() test_trace_resume()
|
||||||
|
|
||||||
|
|
||||||
// declare implicit defines as global intmax_ts
|
// declare implicit defines as global intmax_ts
|
||||||
#define TEST_DEFINE(k, v) \
|
#define TEST_DEFINE(k, v) \
|
||||||
|
|||||||
+28
-3
@@ -822,6 +822,15 @@ def find_runner(runner, id=None, main=True, **args):
|
|||||||
# other context
|
# other context
|
||||||
if args.get('define_depth'):
|
if args.get('define_depth'):
|
||||||
cmd.append('--define-depth=%s' % args['define_depth'])
|
cmd.append('--define-depth=%s' % args['define_depth'])
|
||||||
|
if args.get('probe'):
|
||||||
|
for probe in args['probe']:
|
||||||
|
cmd.append('-S%s' % probe)
|
||||||
|
if args.get('probe_step'):
|
||||||
|
cmd.append('-x%s' % args['probe_step'])
|
||||||
|
if args.get('probe_runfreq'):
|
||||||
|
cmd.append('--probe-runfreq=%s' % args['probe_runfreq'])
|
||||||
|
if args.get('probe_simfreq'):
|
||||||
|
cmd.append('-X%s' % args['probe_simfreq'])
|
||||||
if args.get('force'):
|
if args.get('force'):
|
||||||
cmd.append('--force')
|
cmd.append('--force')
|
||||||
if args.get('no_internal'):
|
if args.get('no_internal'):
|
||||||
@@ -1203,7 +1212,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
|
|||||||
last_defines = None # fetched on demand
|
last_defines = None # fetched on demand
|
||||||
last_stdout = co.deque(maxlen=args.get('context', 5) + 1)
|
last_stdout = co.deque(maxlen=args.get('context', 5) + 1)
|
||||||
last_assert = None
|
last_assert = None
|
||||||
last_time = time.time()
|
last_runtime = time.time()
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
# parse a line for state changes
|
# parse a line for state changes
|
||||||
@@ -1234,7 +1243,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
|
|||||||
last_defines = None
|
last_defines = None
|
||||||
last_stdout.clear()
|
last_stdout.clear()
|
||||||
last_assert = None
|
last_assert = None
|
||||||
last_time = time.time()
|
last_runtime = time.time()
|
||||||
elif op == 'finished':
|
elif op == 'finished':
|
||||||
# force a failure
|
# force a failure
|
||||||
if args.get('fail'):
|
if args.get('fail'):
|
||||||
@@ -1296,7 +1305,7 @@ def run_stage(name, runner, bench_ids, stdout_, trace_, output_, **args):
|
|||||||
'bench_erased': erased_,
|
'bench_erased': erased_,
|
||||||
'bench_simtime': simtime_,
|
'bench_simtime': simtime_,
|
||||||
'bench_runtime': '%.6f' % (
|
'bench_runtime': '%.6f' % (
|
||||||
time.time() - last_time)})
|
time.time() - last_runtime)})
|
||||||
# keep track of total for summary
|
# keep track of total for summary
|
||||||
readed += readed_
|
readed += readed_
|
||||||
progged += progged_
|
progged += progged_
|
||||||
@@ -1758,6 +1767,19 @@ if __name__ == "__main__":
|
|||||||
bench_parser.add_argument(
|
bench_parser.add_argument(
|
||||||
'--define-depth',
|
'--define-depth',
|
||||||
help="How deep to evaluate recursive defines before erroring.")
|
help="How deep to evaluate recursive defines before erroring.")
|
||||||
|
bench_parser.add_argument(
|
||||||
|
'-S', '--probe',
|
||||||
|
action='append',
|
||||||
|
help="Specify a probe to sample.")
|
||||||
|
bench_parser.add_argument(
|
||||||
|
'-x', '--probe-step',
|
||||||
|
help="Sample probes every n steps.")
|
||||||
|
bench_parser.add_argument(
|
||||||
|
'--probe-runfreq',
|
||||||
|
help="Sample probes at this frequency in hz.")
|
||||||
|
bench_parser.add_argument(
|
||||||
|
'-X', '--probe-simfreq',
|
||||||
|
help="Sample probes at this frequency in simulated hz.")
|
||||||
bench_parser.add_argument(
|
bench_parser.add_argument(
|
||||||
'--force',
|
'--force',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@@ -1786,6 +1808,9 @@ if __name__ == "__main__":
|
|||||||
bench_parser.add_argument(
|
bench_parser.add_argument(
|
||||||
'--trace-runfreq',
|
'--trace-runfreq',
|
||||||
help="Sample trace output at this frequency in hz.")
|
help="Sample trace output at this frequency in hz.")
|
||||||
|
bench_parser.add_argument(
|
||||||
|
'--trace-simfreq',
|
||||||
|
help="Sample trace output at this frequency in simulated hz.")
|
||||||
bench_parser.add_argument(
|
bench_parser.add_argument(
|
||||||
'-O', '--stdout',
|
'-O', '--stdout',
|
||||||
help="Direct stdout to this file. Note stderr is already merged "
|
help="Direct stdout to this file. Note stderr is already merged "
|
||||||
|
|||||||
+3
-3
@@ -1179,7 +1179,7 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args):
|
|||||||
last_id = None
|
last_id = None
|
||||||
last_stdout = co.deque(maxlen=args.get('context', 5) + 1)
|
last_stdout = co.deque(maxlen=args.get('context', 5) + 1)
|
||||||
last_assert = None
|
last_assert = None
|
||||||
last_time = time.time()
|
last_runtime = time.time()
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
# parse a line for state changes
|
# parse a line for state changes
|
||||||
@@ -1207,7 +1207,7 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args):
|
|||||||
last_id = m.group('id')
|
last_id = m.group('id')
|
||||||
last_stdout.clear()
|
last_stdout.clear()
|
||||||
last_assert = None
|
last_assert = None
|
||||||
last_time = time.time()
|
last_runtime = time.time()
|
||||||
elif op == 'powerloss':
|
elif op == 'powerloss':
|
||||||
last_id = m.group('id')
|
last_id = m.group('id')
|
||||||
powerlosses += 1
|
powerlosses += 1
|
||||||
@@ -1232,7 +1232,7 @@ def run_stage(name, runner, test_ids, stdout_, trace_, output_, **args):
|
|||||||
**defines,
|
**defines,
|
||||||
'test_passed': '1/1',
|
'test_passed': '1/1',
|
||||||
'test_runtime': '%.6f' % (
|
'test_runtime': '%.6f' % (
|
||||||
time.time() - last_time)})
|
time.time() - last_runtime)})
|
||||||
elif op == 'skipped':
|
elif op == 'skipped':
|
||||||
locals.seen_perms += 1
|
locals.seen_perms += 1
|
||||||
elif op == 'assert':
|
elif op == 'assert':
|
||||||
|
|||||||
Reference in New Issue
Block a user