mirror of
https://github.com/isar/libmdbx.git
synced 2025-08-25 21:54:28 +08:00
mdbx: новые настройки clang-format (косметика).
This commit is contained in:
@@ -17,8 +17,7 @@ protected:
|
||||
unsigned dbi_state{0};
|
||||
|
||||
public:
|
||||
testcase_smoke4fork(const actor_config &config, const mdbx_pid_t pid)
|
||||
: testcase(config, pid) {}
|
||||
testcase_smoke4fork(const actor_config &config, const mdbx_pid_t pid) : testcase(config, pid) {}
|
||||
virtual void txn_end(bool abort) override;
|
||||
bool run() override;
|
||||
virtual bool smoke() = 0;
|
||||
@@ -27,8 +26,7 @@ public:
|
||||
|
||||
bool testcase_smoke4fork::open_dbi() {
|
||||
if (!dbi || dbi_invalid) {
|
||||
if (dbi_stable ||
|
||||
(mdbx_txn_flags(txn_guard.get()) & MDBX_TXN_RDONLY) == 0) {
|
||||
if (dbi_stable || (mdbx_txn_flags(txn_guard.get()) & MDBX_TXN_RDONLY) == 0) {
|
||||
dbi = db_table_open(!dbi_stable);
|
||||
dbi_invalid = false;
|
||||
}
|
||||
@@ -37,8 +35,7 @@ bool testcase_smoke4fork::open_dbi() {
|
||||
dbi_state = 0;
|
||||
if (dbi && !dbi_invalid) {
|
||||
unsigned unused_dbi_flags;
|
||||
int err =
|
||||
mdbx_dbi_flags_ex(txn_guard.get(), dbi, &unused_dbi_flags, &dbi_state);
|
||||
int err = mdbx_dbi_flags_ex(txn_guard.get(), dbi, &unused_dbi_flags, &dbi_state);
|
||||
if (unlikely(err != MDBX_SUCCESS))
|
||||
failure_perror("mdbx_dbi_flags_ex()", err);
|
||||
if ((dbi_state & (MDBX_DBI_CREAT | MDBX_DBI_FRESH)) == 0)
|
||||
@@ -69,8 +66,7 @@ bool testcase_smoke4fork::run() {
|
||||
if (history.empty() || current_pid != history.front()) {
|
||||
history.push_back(current_pid);
|
||||
if (history.size() > /* TODO: add test option */ 2) {
|
||||
log_notice("force exit to avoid fork-bomb: deep %zu, pid stack",
|
||||
history.size());
|
||||
log_notice("force exit to avoid fork-bomb: deep %zu, pid stack", history.size());
|
||||
for (const auto pid : history)
|
||||
logging::feed(" %d", pid);
|
||||
logging::ln();
|
||||
@@ -82,23 +78,19 @@ bool testcase_smoke4fork::run() {
|
||||
|
||||
int err = db_open__begin__table_create_open_clean(dbi);
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
log_notice("fork[deep %d, pid %d]: bailout-prepare due '%s'", deep,
|
||||
current_pid, mdbx_strerror(err));
|
||||
log_notice("fork[deep %d, pid %d]: bailout-prepare due '%s'", deep, current_pid, mdbx_strerror(err));
|
||||
return false;
|
||||
}
|
||||
open_dbi();
|
||||
|
||||
if (flipcoin()) {
|
||||
if (!smoke()) {
|
||||
log_notice("%s[deep %d, pid %d] probe %s", "pre-fork", deep, current_pid,
|
||||
"failed");
|
||||
log_notice("%s[deep %d, pid %d] probe %s", "pre-fork", deep, current_pid, "failed");
|
||||
return false;
|
||||
}
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "pre-fork", deep, current_pid,
|
||||
"done");
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "pre-fork", deep, current_pid, "done");
|
||||
} else {
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "pre-fork", deep, current_pid,
|
||||
"skipped");
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "pre-fork", deep, current_pid, "skipped");
|
||||
#ifdef __SANITIZE_ADDRESS__
|
||||
const bool commit_txn_to_avoid_memleak = true;
|
||||
#else
|
||||
@@ -115,13 +107,12 @@ bool testcase_smoke4fork::run() {
|
||||
|
||||
if (child == 0) {
|
||||
const pid_t new_pid = getpid();
|
||||
log_verbose(">>> %s, deep %d, parent-pid %d, child-pid %d",
|
||||
"mdbx_env_resurrect_after_fork()", deep, current_pid, new_pid);
|
||||
log_verbose(">>> %s, deep %d, parent-pid %d, child-pid %d", "mdbx_env_resurrect_after_fork()", deep, current_pid,
|
||||
new_pid);
|
||||
log_flush();
|
||||
int err = mdbx_env_resurrect_after_fork(db_guard.get());
|
||||
log_verbose("<<< %s, deep %d, parent-pid %d, child-pid %d, err %d",
|
||||
"mdbx_env_resurrect_after_fork()", deep, current_pid, new_pid,
|
||||
err);
|
||||
log_verbose("<<< %s, deep %d, parent-pid %d, child-pid %d, err %d", "mdbx_env_resurrect_after_fork()", deep,
|
||||
current_pid, new_pid, err);
|
||||
log_flush();
|
||||
if (err != MDBX_SUCCESS)
|
||||
failure_perror("mdbx_env_resurrect_after_fork()", err);
|
||||
@@ -134,12 +125,10 @@ bool testcase_smoke4fork::run() {
|
||||
mdbx_txn_abort(txn_guard.release());
|
||||
}
|
||||
if (!smoke()) {
|
||||
log_notice("%s[deep %d, pid %d] probe %s", "fork-child", deep, new_pid,
|
||||
"failed");
|
||||
log_notice("%s[deep %d, pid %d] probe %s", "fork-child", deep, new_pid, "failed");
|
||||
return false;
|
||||
}
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "fork-child", deep, new_pid,
|
||||
"done");
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "fork-child", deep, new_pid, "done");
|
||||
log_flush();
|
||||
return true;
|
||||
}
|
||||
@@ -154,12 +143,10 @@ bool testcase_smoke4fork::run() {
|
||||
if (WIFEXITED(status)) {
|
||||
const int code = WEXITSTATUS(status);
|
||||
if (code != EXIT_SUCCESS) {
|
||||
log_notice("%s[deep %d, pid %d] child-pid %d failed, err %d",
|
||||
"fork-child", deep, current_pid, child, code);
|
||||
log_notice("%s[deep %d, pid %d] child-pid %d failed, err %d", "fork-child", deep, current_pid, child, code);
|
||||
return false;
|
||||
}
|
||||
log_notice("%s[deep %d, pid %d] child-pid %d done", "fork-child", deep,
|
||||
current_pid, child);
|
||||
log_notice("%s[deep %d, pid %d] child-pid %d done", "fork-child", deep, current_pid, child);
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
const int sig = WTERMSIG(status);
|
||||
switch (sig) {
|
||||
@@ -168,12 +155,12 @@ bool testcase_smoke4fork::run() {
|
||||
case SIGFPE:
|
||||
case SIGILL:
|
||||
case SIGSEGV:
|
||||
log_notice("%s[deep %d, pid %d] child-pid %d %s by SIG%s", "fork-child",
|
||||
deep, current_pid, child, "terminated", signal_name(sig));
|
||||
log_notice("%s[deep %d, pid %d] child-pid %d %s by SIG%s", "fork-child", deep, current_pid, child, "terminated",
|
||||
signal_name(sig));
|
||||
break;
|
||||
default:
|
||||
log_notice("%s[deep %d, pid %d] child-id %d %s by SIG%s", "fork-child",
|
||||
deep, current_pid, child, "killed", signal_name(sig));
|
||||
log_notice("%s[deep %d, pid %d] child-id %d %s by SIG%s", "fork-child", deep, current_pid, child, "killed",
|
||||
signal_name(sig));
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
@@ -181,12 +168,10 @@ bool testcase_smoke4fork::run() {
|
||||
}
|
||||
|
||||
if (!smoke()) {
|
||||
log_notice("%s[deep %d, pid %d] probe %s", "post-fork", deep, current_pid,
|
||||
"failed");
|
||||
log_notice("%s[deep %d, pid %d] probe %s", "post-fork", deep, current_pid, "failed");
|
||||
return false;
|
||||
}
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "post-fork", deep, current_pid,
|
||||
"done");
|
||||
log_verbose("%s[deep %d, pid %d] probe %s", "post-fork", deep, current_pid, "done");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -196,16 +181,14 @@ class testcase_forkread : public testcase_smoke4fork {
|
||||
using inherited = testcase_smoke4fork;
|
||||
|
||||
public:
|
||||
testcase_forkread(const actor_config &config, const mdbx_pid_t pid)
|
||||
: testcase_smoke4fork(config, pid) {}
|
||||
testcase_forkread(const actor_config &config, const mdbx_pid_t pid) : testcase_smoke4fork(config, pid) {}
|
||||
bool smoke() override;
|
||||
};
|
||||
REGISTER_TESTCASE(forkread);
|
||||
|
||||
bool testcase_forkread::smoke() {
|
||||
MDBX_envinfo env_info;
|
||||
int err = mdbx_env_info_ex(db_guard.get(), txn_guard.get(), &env_info,
|
||||
sizeof(env_info));
|
||||
int err = mdbx_env_info_ex(db_guard.get(), txn_guard.get(), &env_info, sizeof(env_info));
|
||||
if (err)
|
||||
failure_perror("mdbx_env_info_ex()", err);
|
||||
|
||||
@@ -217,8 +200,7 @@ bool testcase_forkread::smoke() {
|
||||
if (err)
|
||||
failure_perror("mdbx_txn_info()", err);
|
||||
fetch_canary();
|
||||
err = mdbx_env_info_ex(db_guard.get(), txn_guard.get(), &env_info,
|
||||
sizeof(env_info));
|
||||
err = mdbx_env_info_ex(db_guard.get(), txn_guard.get(), &env_info, sizeof(env_info));
|
||||
if (err)
|
||||
failure_perror("mdbx_env_info_ex()", err);
|
||||
|
||||
@@ -226,15 +208,13 @@ bool testcase_forkread::smoke() {
|
||||
if (dbi_invalid) {
|
||||
err = mdbx_dbi_sequence(txn_guard.get(), dbi, &seq, 0);
|
||||
if (unlikely(err != (dbi ? MDBX_BAD_DBI : MDBX_SUCCESS)))
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(get, bad_dbi %d)",
|
||||
mdbx_strerror(err), dbi);
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(get, bad_dbi %d)", mdbx_strerror(err), dbi);
|
||||
open_dbi();
|
||||
}
|
||||
if (!dbi_invalid) {
|
||||
err = mdbx_dbi_sequence(txn_guard.get(), dbi, &seq, 0);
|
||||
if (unlikely(err != MDBX_SUCCESS))
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(get, dbi %d)",
|
||||
mdbx_strerror(err), dbi);
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(get, dbi %d)", mdbx_strerror(err), dbi);
|
||||
}
|
||||
txn_end(false);
|
||||
return true;
|
||||
@@ -246,8 +226,7 @@ class testcase_forkwrite : public testcase_forkread {
|
||||
using inherited = testcase_forkread;
|
||||
|
||||
public:
|
||||
testcase_forkwrite(const actor_config &config, const mdbx_pid_t pid)
|
||||
: testcase_forkread(config, pid) {}
|
||||
testcase_forkwrite(const actor_config &config, const mdbx_pid_t pid) : testcase_forkread(config, pid) {}
|
||||
bool smoke() override;
|
||||
};
|
||||
REGISTER_TESTCASE(forkwrite);
|
||||
@@ -266,15 +245,13 @@ bool testcase_forkwrite::smoke() {
|
||||
if (dbi_invalid) {
|
||||
int err = mdbx_dbi_sequence(txn_guard.get(), dbi, &seq, 0);
|
||||
if (unlikely(err != (dbi ? MDBX_BAD_DBI : MDBX_EACCESS)))
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(get, bad_dbi %d)",
|
||||
mdbx_strerror(err), dbi);
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(get, bad_dbi %d)", mdbx_strerror(err), dbi);
|
||||
open_dbi();
|
||||
}
|
||||
if (!dbi_invalid) {
|
||||
int err = mdbx_dbi_sequence(txn_guard.get(), dbi, &seq, 1);
|
||||
if (unlikely(err != MDBX_SUCCESS))
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(inc, dbi %d)",
|
||||
mdbx_strerror(err), dbi);
|
||||
failure("unexpected '%s' from mdbx_dbi_sequence(inc, dbi %d)", mdbx_strerror(err), dbi);
|
||||
}
|
||||
txn_end(false);
|
||||
|
||||
|
Reference in New Issue
Block a user