diff --git a/test/base.h b/test/base.h index ad804813..39e2c357 100644 --- a/test/base.h +++ b/test/base.h @@ -35,9 +35,11 @@ #include #if defined(_WIN32) || defined(_WIN64) || defined(_WINDOWS) +#include #else #include #include +#include #endif #ifdef _BSD_SOURCE diff --git a/test/config.cc b/test/config.cc index c1d2a76d..02a4f955 100644 --- a/test/config.cc +++ b/test/config.cc @@ -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 */ diff --git a/test/main.cc b/test/main.cc index 009b3e01..8cc21e51 100644 --- a/test/main.cc +++ b/test/main.cc @@ -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); diff --git a/test/osal-unix.cc b/test/osal-unix.cc index c44ade47..88a10f11 100644 --- a/test/osal-unix.cc +++ b/test/osal-unix.cc @@ -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; } diff --git a/test/osal-windows.cc b/test/osal-windows.cc index 2c540f44..57f7f547 100644 --- a/test/osal-windows.cc +++ b/test/osal-windows.cc @@ -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; } diff --git a/test/osal.h b/test/osal.h index 7eac2ad8..29d52219 100644 --- a/test/osal.h +++ b/test/osal.h @@ -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); diff --git a/test/test.cc b/test/test.cc index d19d684c..cded3e2a 100644 --- a/test/test.cc +++ b/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; } diff --git a/test/test.h b/test/test.h index 7b43357b..34083805 100644 --- a/test/test.h +++ b/test/test.h @@ -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);