summaryrefslogtreecommitdiff
path: root/libs/libmdbx/src/test
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-11-06 13:07:56 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-11-06 13:07:56 +0300
commitee25ba7f21361902fa8fde104a29d92b39c8db9c (patch)
tree511557132a91a2ad9fe0c8e18ea4114ebf956bec /libs/libmdbx/src/test
parentd8d3c2cfc50e05fe4b8f6ddd69f2b27b0890ebb8 (diff)
merge with libmdbx trunk - fixes one rare problem with database shrinking
Diffstat (limited to 'libs/libmdbx/src/test')
-rw-r--r--libs/libmdbx/src/test/CMakeLists.txt51
-rw-r--r--libs/libmdbx/src/test/cases.cc3
-rw-r--r--libs/libmdbx/src/test/config.h5
-rw-r--r--libs/libmdbx/src/test/copy.cc26
-rw-r--r--libs/libmdbx/src/test/dead.cc42
-rw-r--r--libs/libmdbx/src/test/gc.sh1
-rw-r--r--libs/libmdbx/src/test/hill.cc18
-rw-r--r--libs/libmdbx/src/test/jitter.cc16
-rw-r--r--libs/libmdbx/src/test/main.cc4
-rw-r--r--libs/libmdbx/src/test/osal-unix.cc8
-rw-r--r--libs/libmdbx/src/test/osal-windows.cc6
-rw-r--r--libs/libmdbx/src/test/osal.h3
-rw-r--r--libs/libmdbx/src/test/test.cc7
-rw-r--r--libs/libmdbx/src/test/test.h33
-rw-r--r--libs/libmdbx/src/test/test.vcxproj3
-rw-r--r--libs/libmdbx/src/test/try.cc19
16 files changed, 105 insertions, 140 deletions
diff --git a/libs/libmdbx/src/test/CMakeLists.txt b/libs/libmdbx/src/test/CMakeLists.txt
index 3ed01bddf9..ca7dd794cd 100644
--- a/libs/libmdbx/src/test/CMakeLists.txt
+++ b/libs/libmdbx/src/test/CMakeLists.txt
@@ -1,34 +1,35 @@
-set(TARGET mdbx_test)
+set(TARGET mdbx_test)
project(${TARGET})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-declarations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-cast-qual")
add_executable(${TARGET}
- base.h
- cases.cc
- chrono.cc
- chrono.h
- config.cc
- config.h
- dead.cc
- hill.cc
- jitter.cc
- keygen.cc
- keygen.h
- log.cc
- log.h
- main.cc
- osal.h
- osal-unix.cc
- test.cc
- test.h
- try.cc
- utils.cc
- utils.h
-)
+ base.h
+ cases.cc
+ chrono.cc
+ chrono.h
+ config.cc
+ config.h
+ copy.cc
+ dead.cc
+ hill.cc
+ jitter.cc
+ keygen.cc
+ keygen.h
+ log.cc
+ log.h
+ main.cc
+ osal.h
+ osal-unix.cc
+ test.cc
+ test.h
+ try.cc
+ utils.cc
+ utils.h
+ )
target_link_libraries(${TARGET}
- mdbx
- )
+ mdbx
+ )
diff --git a/libs/libmdbx/src/test/cases.cc b/libs/libmdbx/src/test/cases.cc
index 4f4306d58e..13d475763a 100644
--- a/libs/libmdbx/src/test/cases.cc
+++ b/libs/libmdbx/src/test/cases.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -68,6 +68,7 @@ void testcase_setup(const char *casename, actor_params &params,
configure_actor(last_space_id, ac_jitter, nullptr, params);
configure_actor(last_space_id, ac_hill, nullptr, params);
configure_actor(last_space_id, ac_try, nullptr, params);
+ configure_actor(last_space_id, ac_copy, nullptr, params);
log_notice("<<< testcase_setup(%s): done", casename);
} else {
failure("unknown testcase `%s`", casename);
diff --git a/libs/libmdbx/src/test/config.h b/libs/libmdbx/src/test/config.h
index 2d0fede046..1886a8ea57 100644
--- a/libs/libmdbx/src/test/config.h
+++ b/libs/libmdbx/src/test/config.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -26,7 +26,8 @@ enum actor_testcase {
ac_deadread,
ac_deadwrite,
ac_jitter,
- ac_try
+ ac_try,
+ ac_copy
};
enum actor_status {
diff --git a/libs/libmdbx/src/test/copy.cc b/libs/libmdbx/src/test/copy.cc
new file mode 100644
index 0000000000..e239d41e34
--- /dev/null
+++ b/libs/libmdbx/src/test/copy.cc
@@ -0,0 +1,26 @@
+#include "test.h"
+
+void testcase_copy::copy_db(const bool with_compaction) {
+ int err = osal_removefile(copy_pathname);
+ if (err != MDBX_SUCCESS && err != MDBX_ENOFILE)
+ failure_perror("mdbx_removefile()", err);
+
+ err = mdbx_env_copy(db_guard.get(), copy_pathname.c_str(),
+ with_compaction ? MDBX_CP_COMPACT : 0);
+ if (unlikely(err != MDBX_SUCCESS))
+ failure_perror(with_compaction ? "mdbx_env_copy(MDBX_CP_COMPACT)"
+ : "mdbx_env_copy(MDBX_CP_ASIS)",
+ err);
+}
+
+bool testcase_copy::run() {
+ jitter_delay();
+ db_open();
+ assert(!txn_guard);
+ const bool order = flipcoin();
+ jitter_delay();
+ copy_db(order);
+ jitter_delay();
+ copy_db(!order);
+ return true;
+}
diff --git a/libs/libmdbx/src/test/dead.cc b/libs/libmdbx/src/test/dead.cc
index ee13fbd0ae..3dd1ee7b24 100644
--- a/libs/libmdbx/src/test/dead.cc
+++ b/libs/libmdbx/src/test/dead.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -14,50 +14,22 @@
#include "test.h"
-bool testcase_deadread::setup() {
- log_trace(">> setup");
- if (!inherited::setup())
- return false;
-
- log_trace("<< setup");
- return true;
-}
-
bool testcase_deadread::run() {
db_open();
txn_begin(true);
+ cursor_guard.reset();
+ txn_guard.reset();
+ db_guard.reset();
return true;
}
-bool testcase_deadread::teardown() {
- log_trace(">> teardown");
- cursor_guard.release();
- txn_guard.release();
- db_guard.release();
- return inherited::teardown();
-}
-
//-----------------------------------------------------------------------------
-bool testcase_deadwrite::setup() {
- log_trace(">> setup");
- if (!inherited::setup())
- return false;
-
- log_trace("<< setup");
- return true;
-}
-
bool testcase_deadwrite::run() {
db_open();
txn_begin(false);
+ cursor_guard.reset();
+ txn_guard.reset();
+ db_guard.reset();
return true;
}
-
-bool testcase_deadwrite::teardown() {
- log_trace(">> teardown");
- cursor_guard.release();
- txn_guard.release();
- db_guard.release();
- return inherited::teardown();
-}
diff --git a/libs/libmdbx/src/test/gc.sh b/libs/libmdbx/src/test/gc.sh
index be6991a48f..76c7a9a51c 100644
--- a/libs/libmdbx/src/test/gc.sh
+++ b/libs/libmdbx/src/test/gc.sh
@@ -25,6 +25,7 @@ function probe {
rm -f ${TESTDB_PREFIX}* \
&& ./mdbx_test --pathname=${TESTDB_PREFIX}db "$@" | lz4 > ${TESTDB_PREFIX}log.lz4 \
&& ./mdbx_chk -nvvv ${TESTDB_PREFIX}db | tee ${TESTDB_PREFIX}chk \
+ && ./mdbx_chk -nvvv ${TESTDB_PREFIX}db-copy | tee ${TESTDB_PREFIX}chk-copy \
|| (echo "FAILED"; exit 1)
}
diff --git a/libs/libmdbx/src/test/hill.cc b/libs/libmdbx/src/test/hill.cc
index 10cb308942..856aeb9356 100644
--- a/libs/libmdbx/src/test/hill.cc
+++ b/libs/libmdbx/src/test/hill.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -14,17 +14,6 @@
#include "test.h"
-bool testcase_hill::setup() {
- log_trace(">> setup");
- if (!inherited::setup())
- return false;
-
- /* TODO */
-
- log_trace("<< setup");
- return true;
-}
-
bool testcase_hill::run() {
db_open();
@@ -225,8 +214,3 @@ bool testcase_hill::run() {
}
return true;
}
-
-bool testcase_hill::teardown() {
- log_trace(">> teardown");
- return inherited::teardown();
-}
diff --git a/libs/libmdbx/src/test/jitter.cc b/libs/libmdbx/src/test/jitter.cc
index 2551400443..48f9bd998e 100644
--- a/libs/libmdbx/src/test/jitter.cc
+++ b/libs/libmdbx/src/test/jitter.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -14,15 +14,6 @@
#include "test.h"
-bool testcase_jitter::setup() {
- log_trace(">> setup");
- if (!inherited::setup())
- return false;
-
- log_trace("<< setup");
- return true;
-}
-
bool testcase_jitter::run() {
while (should_continue()) {
jitter_delay();
@@ -66,8 +57,3 @@ bool testcase_jitter::run() {
}
return true;
}
-
-bool testcase_jitter::teardown() {
- log_trace(">> teardown");
- return inherited::teardown();
-}
diff --git a/libs/libmdbx/src/test/main.cc b/libs/libmdbx/src/test/main.cc
index 3384311b3b..275b7b136b 100644
--- a/libs/libmdbx/src/test/main.cc
+++ b/libs/libmdbx/src/test/main.cc
@@ -337,6 +337,10 @@ int main(int argc, char *const argv[]) {
configure_actor(last_space_id, ac_deadwrite, value, params);
continue;
}
+ if (config::parse_option(argc, argv, narg, "copy", nullptr)) {
+ configure_actor(last_space_id, ac_copy, value, params);
+ continue;
+ }
if (config::parse_option(argc, argv, narg, "failfast",
global::config::failfast))
continue;
diff --git a/libs/libmdbx/src/test/osal-unix.cc b/libs/libmdbx/src/test/osal-unix.cc
index 6661ae42c8..6e6d7a1c5c 100644
--- a/libs/libmdbx/src/test/osal-unix.cc
+++ b/libs/libmdbx/src/test/osal-unix.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -184,7 +184,7 @@ void osal_killall_actors(void) {
int osal_actor_poll(mdbx_pid_t &pid, unsigned timeout) {
struct timespec ts;
ts.tv_nsec = 0;
- ts.tv_sec = timeout;
+ ts.tv_sec = (timeout > INT_MAX) ? INT_MAX : timeout;
retry:
int status, options = WNOHANG;
#ifdef WUNTRACED
@@ -301,3 +301,7 @@ std::string osal_tempdir(void) {
return "/dev/shm/";
return "";
}
+
+int osal_removefile(const std::string &pathname) {
+ return unlink(pathname.c_str()) ? errno : MDBX_SUCCESS;
+}
diff --git a/libs/libmdbx/src/test/osal-windows.cc b/libs/libmdbx/src/test/osal-windows.cc
index 7d59f657c2..f7f1de56e0 100644
--- a/libs/libmdbx/src/test/osal-windows.cc
+++ b/libs/libmdbx/src/test/osal-windows.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -405,3 +405,7 @@ std::string osal_tempdir(void) {
DWORD len = GetTempPathA(sizeof(buf), buf);
return std::string(buf, len);
}
+
+int osal_removefile(const std::string &pathname) {
+ return DeleteFileA(pathname.c_str()) ? MDBX_SUCCESS : GetLastError();
+}
diff --git a/libs/libmdbx/src/test/osal.h b/libs/libmdbx/src/test/osal.h
index c27282a656..3ccc7bbec1 100644
--- a/libs/libmdbx/src/test/osal.h
+++ b/libs/libmdbx/src/test/osal.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -32,6 +32,7 @@ void osal_udelay(unsigned us);
void osal_yield(void);
bool osal_istty(int fd);
std::string osal_tempdir(void);
+int osal_removefile(const std::string &pathname);
#ifdef _MSC_VER
#ifndef STDIN_FILENO
diff --git a/libs/libmdbx/src/test/test.cc b/libs/libmdbx/src/test/test.cc
index b9663c2a09..6bba425a67 100644
--- a/libs/libmdbx/src/test/test.cc
+++ b/libs/libmdbx/src/test/test.cc
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -31,6 +31,8 @@ const char *testcase2str(const actor_testcase testcase) {
return "jitter";
case ac_try:
return "try";
+ case ac_copy:
+ return "copy";
}
}
@@ -453,6 +455,9 @@ bool test_execute(const actor_config &config) {
case ac_try:
test.reset(new testcase_try(config, pid));
break;
+ case ac_copy:
+ test.reset(new testcase_copy(config, pid));
+ break;
default:
test.reset(new testcase(config, pid));
break;
diff --git a/libs/libmdbx/src/test/test.h b/libs/libmdbx/src/test/test.h
index 4b10a40fef..d145ec2e38 100644
--- a/libs/libmdbx/src/test/test.h
+++ b/libs/libmdbx/src/test/test.h
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 2017-2018 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
@@ -152,56 +152,47 @@ public:
};
class testcase_hill : public testcase {
- typedef testcase inherited;
-
public:
testcase_hill(const actor_config &config, const mdbx_pid_t pid)
: testcase(config, pid) {}
- bool setup();
bool run();
- bool teardown();
};
class testcase_deadread : public testcase {
- typedef testcase inherited;
-
public:
testcase_deadread(const actor_config &config, const mdbx_pid_t pid)
: testcase(config, pid) {}
- bool setup();
bool run();
- bool teardown();
};
class testcase_deadwrite : public testcase {
- typedef testcase inherited;
-
public:
testcase_deadwrite(const actor_config &config, const mdbx_pid_t pid)
: testcase(config, pid) {}
- bool setup();
bool run();
- bool teardown();
};
class testcase_jitter : public testcase {
- typedef testcase inherited;
-
public:
testcase_jitter(const actor_config &config, const mdbx_pid_t pid)
: testcase(config, pid) {}
- bool setup();
bool run();
- bool teardown();
};
class testcase_try : public testcase {
- typedef testcase inherited;
-
public:
testcase_try(const actor_config &config, const mdbx_pid_t pid)
: testcase(config, pid) {}
- bool setup();
bool run();
- bool teardown();
+};
+
+class testcase_copy : public testcase {
+ const std::string copy_pathname;
+ void copy_db(const bool with_compaction);
+
+public:
+ testcase_copy(const actor_config &config, const mdbx_pid_t pid)
+ : testcase(config, pid),
+ copy_pathname(config.params.pathname_db + "-copy") {}
+ bool run();
};
diff --git a/libs/libmdbx/src/test/test.vcxproj b/libs/libmdbx/src/test/test.vcxproj
index a8c21d38c5..b47bc7a813 100644
--- a/libs/libmdbx/src/test/test.vcxproj
+++ b/libs/libmdbx/src/test/test.vcxproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@@ -184,6 +184,7 @@
<ClCompile Include="cases.cc" />
<ClCompile Include="chrono.cc" />
<ClCompile Include="config.cc" />
+ <ClCompile Include="copy.cc" />
<ClCompile Include="dead.cc" />
<ClCompile Include="hill.cc" />
<ClCompile Include="try.cc" />
diff --git a/libs/libmdbx/src/test/try.cc b/libs/libmdbx/src/test/try.cc
index 1deae71d31..150abd36de 100644
--- a/libs/libmdbx/src/test/try.cc
+++ b/libs/libmdbx/src/test/try.cc
@@ -1,13 +1,4 @@
-#include "test.h"
-
-bool testcase_try::setup() {
- log_trace(">> setup");
- if (!inherited::setup())
- return false;
-
- log_trace("<< setup");
- return true;
-}
+#include "test.h"
bool testcase_try::run() {
db_open();
@@ -27,11 +18,3 @@ bool testcase_try::run() {
txn_guard.reset(txn);
return true;
}
-
-bool testcase_try::teardown() {
- log_trace(">> teardown");
- cursor_guard.release();
- txn_guard.release();
- db_guard.release();
- return inherited::teardown();
-}