mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 00:44:12 +08:00
test: add simple progress indicator.
This commit is contained in:
parent
06de7a5155
commit
a6c8c1ad08
@ -35,9 +35,11 @@
|
||||
#include <time.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS)
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <sys/param.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _BSD_SOURCE
|
||||
|
@ -339,6 +339,8 @@ void dump(const char *title) {
|
||||
global::config::cleanup_after ? "Yes" : "No");
|
||||
|
||||
log_info("failfast: %s\n", global::config::failfast ? "Yes" : "No");
|
||||
log_info("progress indicator: %s\n",
|
||||
global::config::progress_indicator ? "Yes" : "No");
|
||||
}
|
||||
|
||||
} /* namespace config */
|
||||
|
@ -76,6 +76,7 @@ void actor_params::set_defaults(void) {
|
||||
global::config::cleanup_before = true;
|
||||
global::config::cleanup_after = true;
|
||||
global::config::failfast = true;
|
||||
global::config::progress_indicator = osal_istty(STDERR_FILENO);
|
||||
}
|
||||
|
||||
namespace global {
|
||||
@ -95,6 +96,7 @@ bool dump_config;
|
||||
bool cleanup_before;
|
||||
bool cleanup_after;
|
||||
bool failfast;
|
||||
bool progress_indicator;
|
||||
} /* namespace config */
|
||||
|
||||
} /* namespace global */
|
||||
@ -272,6 +274,9 @@ int main(int argc, char *const argv[]) {
|
||||
if (config::parse_option(argc, argv, narg, "failfast",
|
||||
global::config::failfast))
|
||||
continue;
|
||||
if (config::parse_option(argc, argv, narg, "progress",
|
||||
global::config::progress_indicator))
|
||||
continue;
|
||||
|
||||
if (*argv[narg] != '-')
|
||||
testcase_setup(argv[narg], params, last_space_id);
|
||||
|
@ -270,3 +270,5 @@ void osal_udelay(unsigned us) {
|
||||
now = chrono::now_motonic();
|
||||
} while (until.fixedpoint > now.fixedpoint);
|
||||
}
|
||||
|
||||
bool osal_istty(int fd) { return isatty(fd) == 1; }
|
||||
|
@ -303,3 +303,5 @@ void osal_udelay(unsigned us) {
|
||||
now = chrono::now_motonic();
|
||||
} while (now.fixedpoint < until.fixedpoint);
|
||||
}
|
||||
|
||||
bool osal_istty(int fd) { return _isatty(fd) != 0; }
|
||||
|
@ -30,3 +30,4 @@ mdbx_pid_t osal_getpid(void);
|
||||
int osal_delay(unsigned seconds);
|
||||
void osal_udelay(unsigned us);
|
||||
void osal_yield(void);
|
||||
bool osal_istty(int fd);
|
||||
|
32
test/test.cc
32
test/test.cc
@ -101,7 +101,7 @@ int testcase::oom_callback(MDBX_env *env, int pid, mdbx_tid_t tid, uint64_t txn,
|
||||
pid, (size_t)tid, txn, gap);
|
||||
|
||||
if (self->should_continue()) {
|
||||
osal_yield();
|
||||
/* osal_yield(); */
|
||||
osal_udelay(retry * 100);
|
||||
return 1 /* always retry */;
|
||||
}
|
||||
@ -239,11 +239,38 @@ bool testcase::wait4start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void testcase::kick_progress(bool active) const {
|
||||
static chrono::time last;
|
||||
chrono::time now = chrono::now_motonic();
|
||||
|
||||
if (active) {
|
||||
static int last_point = -1;
|
||||
int point = (now.fixedpoint >> 29) & 3;
|
||||
if (point != last_point) {
|
||||
last = now;
|
||||
fprintf(stderr, "%c\b", "-\\|/"[last_point = point]);
|
||||
fflush(stderr);
|
||||
}
|
||||
} else if (now.fixedpoint - last.fixedpoint >
|
||||
chrono::from_seconds(2).fixedpoint) {
|
||||
last = now;
|
||||
fprintf(stderr, "%c\b", "@*"[now.utc & 1]);
|
||||
fflush(stderr);
|
||||
}
|
||||
}
|
||||
|
||||
void testcase::report(size_t nops_done) {
|
||||
assert(nops_done > 0);
|
||||
if (!nops_done)
|
||||
return;
|
||||
|
||||
nops_completed += nops_done;
|
||||
log_verbose("== complete +%" PRIuPTR " iteration, total %" PRIuPTR " done",
|
||||
nops_done, nops_completed);
|
||||
|
||||
if (global::config::progress_indicator)
|
||||
kick_progress(true);
|
||||
|
||||
if (config.signal_nops && !signalled &&
|
||||
config.signal_nops <= nops_completed) {
|
||||
log_trace(">> signal(n-ops %" PRIuPTR ")", nops_completed);
|
||||
@ -295,6 +322,9 @@ bool testcase::should_continue() const {
|
||||
if (config.params.test_nops && nops_completed >= config.params.test_nops)
|
||||
result = false;
|
||||
|
||||
if (result && global::config::progress_indicator)
|
||||
kick_progress(false);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ extern bool dump_config;
|
||||
extern bool cleanup_before;
|
||||
extern bool cleanup_after;
|
||||
extern bool failfast;
|
||||
extern bool progress_indicator;
|
||||
} /* namespace config */
|
||||
|
||||
} /* namespace global */
|
||||
@ -107,6 +108,7 @@ protected:
|
||||
void txn_restart(bool abort, bool readonly);
|
||||
void fetch_canary();
|
||||
void update_canary(uint64_t increment);
|
||||
void kick_progress(bool active) const;
|
||||
|
||||
MDBX_dbi db_table_open(bool create);
|
||||
void db_table_drop(MDBX_dbi handle);
|
||||
|
Loading…
x
Reference in New Issue
Block a user