From a10506fb6a08e01b1c57fb4764d902f141d3a2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Thu, 13 Jun 2024 11:59:19 +0300 Subject: [PATCH] =?UTF-8?q?mdbx-testing:=20=D1=82=D0=B5=D1=85=D0=BD=D0=B8?= =?UTF-8?q?=D1=87=D0=B5=D1=81=D0=BA=D0=B8=D0=B9=20=D0=B2=D0=BE=D0=B7=D0=B2?= =?UTF-8?q?=D1=80=D0=B0=D1=82=20`bool`=20=D0=B8=D0=B7=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BE=D1=87=D0=BD=D1=8B=D1=85=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=B9=20=D0=B2=20=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D1=83=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D1=81=D1=82=D0=B2=D0=B0=20ad-hoc=20=D0=B4=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test.c++ | 55 ++++++++++++++++++++++++++++----------------------- test/test.h++ | 8 ++++---- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/test/test.c++ b/test/test.c++ index 21900731..1926bb83 100644 --- a/test/test.c++ +++ b/test/test.c++ @@ -726,7 +726,7 @@ void testcase::verbose(const char *where, const char *stage, const MDBX_val &k, mdbx_dump_val(&v, dump_value, sizeof(dump_value))); } -void testcase::speculum_check_iterator(const char *where, const char *stage, +bool testcase::speculum_check_iterator(const char *where, const char *stage, const testcase::SET::const_iterator &it, const MDBX_val &k, const MDBX_val &v) const { @@ -737,16 +737,17 @@ void testcase::speculum_check_iterator(const char *where, const char *stage, // mdbx_dump_val(&it_key, dump_key, sizeof(dump_key)), // mdbx_dump_val(&it_data, dump_value, sizeof(dump_value))); if (!is_samedata(it_key, k)) - failure("speculum-%s: %s key mismatch %s (must) != %s", where, stage, - mdbx_dump_val(&it_key, dump_key, sizeof(dump_key)), - mdbx_dump_val(&k, dump_value, sizeof(dump_value))); + return failure("speculum-%s: %s key mismatch %s (must) != %s", where, stage, + mdbx_dump_val(&it_key, dump_key, sizeof(dump_key)), + mdbx_dump_val(&k, dump_value, sizeof(dump_value))); if (!is_samedata(it_data, v)) - failure("speculum-%s: %s data mismatch %s (must) != %s", where, stage, - mdbx_dump_val(&it_data, dump_key, sizeof(dump_key)), - mdbx_dump_val(&v, dump_value, sizeof(dump_value))); + return failure("speculum-%s: %s data mismatch %s (must) != %s", where, + stage, mdbx_dump_val(&it_data, dump_key, sizeof(dump_key)), + mdbx_dump_val(&v, dump_value, sizeof(dump_value))); + return true; } -void testcase::failure(const char *fmt, ...) const { +bool testcase::failure(const char *fmt, ...) const { va_list ap; va_start(ap, fmt); fflush(nullptr); @@ -756,10 +757,11 @@ void testcase::failure(const char *fmt, ...) const { if (txn_guard) mdbx_txn_commit(const_cast(this)->txn_guard.release()); exit(EXIT_FAILURE); + return false; } #if SPECULUM_CURSORS -void testcase::speculum_check_cursor(const char *where, const char *stage, +bool testcase::speculum_check_cursor(const char *where, const char *stage, const testcase::SET::const_iterator &it, int cursor_err, const MDBX_val &cursor_key, const MDBX_val &cursor_data) const { @@ -767,25 +769,29 @@ void testcase::speculum_check_cursor(const char *where, const char *stage, // verbose(where, stage, it); if (cursor_err != MDBX_SUCCESS && cursor_err != MDBX_NOTFOUND && cursor_err != MDBX_RESULT_TRUE && cursor_err != MDBX_ENODATA) - failure("speculum-%s: %s %s %d %s", where, stage, "cursor-get", cursor_err, - mdbx_strerror(cursor_err)); + return failure("speculum-%s: %s %s %d %s", where, stage, "cursor-get", + cursor_err, mdbx_strerror(cursor_err)); char dump_key[32], dump_value[32]; if (it == speculum.end() && cursor_err != MDBX_NOTFOUND) - failure("speculum-%s: %s extra pair {%s, %s}", where, stage, - mdbx_dump_val(&cursor_key, dump_key, sizeof(dump_key)), - mdbx_dump_val(&cursor_data, dump_value, sizeof(dump_value))); + return failure("speculum-%s: %s extra pair {%s, %s}", where, stage, + mdbx_dump_val(&cursor_key, dump_key, sizeof(dump_key)), + mdbx_dump_val(&cursor_data, dump_value, sizeof(dump_value))); else if (it != speculum.end() && cursor_err == MDBX_NOTFOUND) { MDBX_val it_key = dataview2iov(it->first); MDBX_val it_data = dataview2iov(it->second); - failure("speculum-%s: %s lack pair {%s, %s}", where, stage, - mdbx_dump_val(&it_key, dump_key, sizeof(dump_key)), - mdbx_dump_val(&it_data, dump_value, sizeof(dump_value))); + return failure("speculum-%s: %s lack pair {%s, %s}", where, stage, + mdbx_dump_val(&it_key, dump_key, sizeof(dump_key)), + mdbx_dump_val(&it_data, dump_value, sizeof(dump_value))); } else if (cursor_err == MDBX_SUCCESS || cursor_err == MDBX_RESULT_TRUE) - speculum_check_iterator(where, stage, it, cursor_key, cursor_data); + return speculum_check_iterator(where, stage, it, cursor_key, cursor_data); + else { + assert(it == speculum.end() && cursor_err == MDBX_NOTFOUND); + return true; + } } -void testcase::speculum_check_cursor(const char *where, const char *stage, +bool testcase::speculum_check_cursor(const char *where, const char *stage, const testcase::SET::const_iterator &it, MDBX_cursor *cursor, const MDBX_cursor_op op) const { @@ -908,11 +914,10 @@ int testcase::insert(const keygen::buffer &akey, const keygen::buffer &adata, check_seek_cursor = speculum_cursors[seek_check].get(); seek_check_key = akey->value; seek_check_data = adata->value; - seek_check_err = mdbx_cursor_get( - check_seek_cursor, &seek_check_key, &seek_check_data, - (config.params.table_flags & MDBX_DUPSORT) ? MDBX_GET_BOTH - : MDBX_SET_KEY); - if (seek_check_err != MDBX_SUCCESS && seek_check_err != MDBX_NOTFOUND) + seek_check_err = mdbx_cursor_get(check_seek_cursor, &seek_check_key, + &seek_check_data, MDBX_SET_LOWERBOUND); + if (seek_check_err != MDBX_SUCCESS && seek_check_err != MDBX_NOTFOUND && + seek_check_err != MDBX_RESULT_TRUE) failure("speculum-%s: %s pre-insert %d %s", "insert", "seek", seek_check_err, mdbx_strerror(seek_check_err)); #endif /* SPECULUM_CURSORS */ @@ -940,7 +945,7 @@ int testcase::insert(const keygen::buffer &akey, const keygen::buffer &adata, #if SPECULUM_CURSORS if (insertion_result.second) { - if (seek_check_err != MDBX_NOTFOUND) { + if (seek_check_err == MDBX_SUCCESS) { log_error( "speculum.pre-insert-seek: unexpected %d {%s, %s}", seek_check_err, mdbx_dump_val(&seek_check_key, dump_key, sizeof(dump_key)), diff --git a/test/test.h++ b/test/test.h++ index 583e539a..3e0ac49c 100644 --- a/test/test.h++ +++ b/test/test.h++ @@ -194,16 +194,16 @@ protected: #if SPECULUM_CURSORS scoped_cursor_guard speculum_cursors[5 + 1]; void speculum_prepare_cursors(const Item &item); - void speculum_check_cursor(const char *where, const char *stage, + bool speculum_check_cursor(const char *where, const char *stage, const testcase::SET::const_iterator &it, int cursor_err, const MDBX_val &cursor_key, const MDBX_val &cursor_data) const; - void speculum_check_cursor(const char *where, const char *stage, + bool speculum_check_cursor(const char *where, const char *stage, const testcase::SET::const_iterator &it, MDBX_cursor *cursor, const MDBX_cursor_op op) const; #endif /* SPECULUM_CURSORS */ - void speculum_check_iterator(const char *where, const char *stage, + bool speculum_check_iterator(const char *where, const char *stage, const testcase::SET::const_iterator &it, const MDBX_val &k, const MDBX_val &v) const; @@ -271,7 +271,7 @@ protected: void signal(); bool should_continue(bool check_timeout_only = false) const; - void failure(const char *fmt, ...) const; + bool failure(const char *fmt, ...) const; void generate_pair(const keygen::serial_t serial, keygen::buffer &out_key, keygen::buffer &out_value, keygen::serial_t data_age) { keyvalue_maker.pair(serial, out_key, out_value, data_age, false);