From 32937ac63b9de9e35c1f779155fbe6f0947e3d00 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 23 Apr 2017 19:00:28 +0300 Subject: [PATCH] test: canary fetch/update for jitter testcase. Change-Id: I8402328f880addb1170e8e778b64aa4f12d18718 --- test/jitter.cc | 10 ++++++---- test/test.cc | 37 +++++++++++++++++++++++++++++++++++++ test/test.h | 7 +++++++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/test/jitter.cc b/test/jitter.cc index 4129de75..92d272e1 100644 --- a/test/jitter.cc +++ b/test/jitter.cc @@ -31,27 +31,29 @@ bool testcase_jitter::run() { if (flipcoin()) { jitter_delay(); txn_begin(true); + fetch_canary(); jitter_delay(); - txn_end(false); + txn_end(flipcoin()); } jitter_delay(); txn_begin(mode_readonly()); jitter_delay(); if (!mode_readonly()) { + fetch_canary(); + update_canary(1); /* TODO: - * - db_sequence() * - db_setsize() * ... */ } - txn_end(false); + txn_end(flipcoin()); if (flipcoin()) { jitter_delay(); txn_begin(true); jitter_delay(); - txn_end(false); + txn_end(flipcoin()); } jitter_delay(); diff --git a/test/test.cc b/test/test.cc index 28290c46..346d2e8d 100644 --- a/test/test.cc +++ b/test/test.cc @@ -252,6 +252,43 @@ bool testcase::should_continue() const { return result; } +void testcase::fetch_canary() { + mdbx_canary canary_now; + log_trace(">> fetch_canary"); + + int rc = mdbx_canary_get(txn_guard.get(), &canary_now); + if (rc != MDB_SUCCESS) + failure_perror("mdbx_canary_get()", rc); + + if (canary_now.v < last.canary.v) + failure("fetch_canary: %" PRIu64 " canary-now.v) < %" PRIu64 + "(canary-last.v)", + canary_now.v, last.canary.v); + if (canary_now.y < last.canary.y) + failure("fetch_canary: %" PRIu64 "(canary-now.y) < %" PRIu64 + "(canary-last.y)", + canary_now.y, last.canary.y); + + last.canary = canary_now; + log_trace("<< fetch_canary: db-sequence %" PRIu64 + ", db-sequence.txnid %" PRIu64, + last.canary.y, last.canary.v); +} + +void testcase::update_canary(uint64_t increment) { + mdbx_canary canary_now = last.canary; + + log_trace(">> update_canary: sequence %" PRIu64 " += %" PRIu64, canary_now.y, + increment); + canary_now.y += increment; + + int rc = mdbx_canary_put(txn_guard.get(), &canary_now); + if (rc != MDB_SUCCESS) + failure_perror("mdbx_canary_put()", rc); + + log_trace(">> update_canary: sequence = %" PRIu64, canary_now.y); +} + //----------------------------------------------------------------------------- bool test_execute(const actor_config &config) { diff --git a/test/test.h b/test/test.h index c12e08a6..79c26479 100644 --- a/test/test.h +++ b/test/test.h @@ -88,11 +88,17 @@ protected: size_t nops_completed; chrono::time start_timestamp; + struct { + mdbx_canary canary; + } last; + void db_prepare(); void db_open(); void db_close(); void txn_begin(bool readonly); void txn_end(bool abort); + void fetch_canary(); + void update_canary(uint64_t increment); bool wait4start(); void report(size_t nops_done); @@ -107,6 +113,7 @@ public: testcase(const actor_config &config, const mdbx_pid_t pid) : config(config), pid(pid), nops_completed(0) { start_timestamp.reset(); + memset(&last, 0, sizeof(last)); } virtual bool setup();