From 01ae5bad7d4f0b95acc0563d2a464b7c27a80017 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Mon, 17 Sep 2018 13:06:43 +0300 Subject: [PATCH] mdbx-test: add data-check before delete/update. Change-Id: I5afc1cbd95b5db0b442714229510d6786bf68d43 --- test/hill.cc | 5 +++++ test/test.cc | 10 ++++++++++ test/test.h | 2 ++ test/utils.cc | 5 +++++ test/utils.h | 2 +- 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test/hill.cc b/test/hill.cc index 0193c4f2..abccf9c7 100644 --- a/test/hill.cc +++ b/test/hill.cc @@ -114,6 +114,7 @@ bool testcase_hill::run() { log_trace("uphill: update-a (age %" PRIu64 "->0) %" PRIu64, age_shift, a_serial); generate_pair(a_serial, a_key, a_data_0, 0); + checkdata("uphill: update-a", dbi, a_key->value, a_data_1->value); rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_0->value, &a_data_1->value, update_flags); if (unlikely(rc != MDBX_SUCCESS)) @@ -126,6 +127,7 @@ bool testcase_hill::run() { // удаляем вторую запись log_trace("uphill: delete-b %" PRIu64, b_serial); + checkdata("uphill: delete-b", dbi, b_key->value, b_data->value); rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value); if (unlikely(rc != MDBX_SUCCESS)) failure_perror("mdbx_del(b)", rc); @@ -158,6 +160,7 @@ bool testcase_hill::run() { a_serial); generate_pair(a_serial, a_key, a_data_0, 0); generate_pair(a_serial, a_key, a_data_1, age_shift); + checkdata("downhill: update-a", dbi, a_key->value, a_data_0->value); int rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_1->value, &a_data_0->value, update_flags); if (unlikely(rc != MDBX_SUCCESS)) @@ -184,6 +187,7 @@ bool testcase_hill::run() { // удаляем первую запись log_trace("downhill: delete-a (age %" PRIu64 ") %" PRIu64, age_shift, a_serial); + checkdata("downhill: delete-a", dbi, a_key->value, a_data_1->value); rc = mdbx_del(txn_guard.get(), dbi, &a_key->value, &a_data_1->value); if (unlikely(rc != MDBX_SUCCESS)) failure_perror("mdbx_del(a)", rc); @@ -195,6 +199,7 @@ bool testcase_hill::run() { // удаляем вторую запись log_trace("downhill: delete-b %" PRIu64, b_serial); + checkdata("downhill: delete-b", dbi, b_key->value, b_data->value); rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value); if (unlikely(rc != MDBX_SUCCESS)) failure_perror("mdbx_del(b)", rc); diff --git a/test/test.cc b/test/test.cc index c28bbd22..9990ca1d 100644 --- a/test/test.cc +++ b/test/test.cc @@ -410,6 +410,16 @@ void testcase::db_table_close(MDBX_dbi handle) { log_trace("<< testcase::db_table_close"); } +void testcase::checkdata(const char *step, MDBX_dbi handle, MDBX_val key, + MDBX_val expect) { + MDBX_val data = expect; + int rc = mdbx_get2(txn_guard.get(), handle, &key, &data); + if (unlikely(rc != MDBX_SUCCESS)) + failure_perror(step, rc); + if (!is_samedata(&data, &expect)) + failure("%s data mismatch", step); +} + //----------------------------------------------------------------------------- bool test_execute(const actor_config &config) { diff --git a/test/test.h b/test/test.h index ef1c4caa..588660b1 100644 --- a/test/test.h +++ b/test/test.h @@ -112,6 +112,8 @@ protected: void fetch_canary(); void update_canary(uint64_t increment); void kick_progress(bool active) const; + void checkdata(const char *step, MDBX_dbi handle, MDBX_val key, + MDBX_val expect); MDBX_dbi db_table_open(bool create); void db_table_drop(MDBX_dbi handle); diff --git a/test/utils.cc b/test/utils.cc index 53a750e3..5a5290f0 100644 --- a/test/utils.cc +++ b/test/utils.cc @@ -91,6 +91,11 @@ bool hex2data(const char *hex_begin, const char *hex_end, void *ptr, return true; } +bool is_samedata(const MDBX_val *a, const MDBX_val *b) { + return a->iov_len == b->iov_len && + memcmp(a->iov_base, b->iov_base, a->iov_len) == 0; +} + //----------------------------------------------------------------------------- /* TODO: replace my 'libmera' from t1ha. */ diff --git a/test/utils.h b/test/utils.h index 5d62909f..42d497e8 100644 --- a/test/utils.h +++ b/test/utils.h @@ -317,7 +317,7 @@ struct simple_checksum { std::string data2hex(const void *ptr, size_t bytes, simple_checksum &checksum); bool hex2data(const char *hex_begin, const char *hex_end, void *ptr, size_t bytes, simple_checksum &checksum); - +bool is_samedata(const MDBX_val *a, const MDBX_val *b); std::string format(const char *fmt, ...); uint64_t entropy_ticks(void);