summaryrefslogtreecommitdiff
path: root/libs/libmdbx/src/test/config.cc
diff options
context:
space:
mode:
Diffstat (limited to 'libs/libmdbx/src/test/config.cc')
-rw-r--r--libs/libmdbx/src/test/config.cc133
1 files changed, 118 insertions, 15 deletions
diff --git a/libs/libmdbx/src/test/config.cc b/libs/libmdbx/src/test/config.cc
index cbff68ce4e..619bd35727 100644
--- a/libs/libmdbx/src/test/config.cc
+++ b/libs/libmdbx/src/test/config.cc
@@ -43,6 +43,11 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
if (narg + 1 < argc && strncmp("--", argv[narg + 1], 2) != 0) {
*value = argv[narg + 1];
+ if (strcmp(*value, "default") == 0) {
+ if (!default_value)
+ failure("Option '--%s' doen't accept default value\n", option);
+ *value = default_value;
+ }
++narg;
return true;
}
@@ -57,9 +62,15 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
bool parse_option(int argc, char *const argv[], int &narg, const char *option,
std::string &value, bool allow_empty) {
+ return parse_option(argc, argv, narg, option, value, allow_empty,
+ allow_empty ? "" : nullptr);
+}
+
+bool parse_option(int argc, char *const argv[], int &narg, const char *option,
+ std::string &value, bool allow_empty,
+ const char *default_value) {
const char *value_cstr;
- if (!parse_option(argc, argv, narg, option, &value_cstr,
- allow_empty ? "" : nullptr))
+ if (!parse_option(argc, argv, narg, option, &value_cstr, default_value))
return false;
if (!allow_empty && strlen(value_cstr) == 0)
@@ -75,7 +86,7 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
if (!parse_option(argc, argv, narg, option, &list))
return false;
- mask = 0;
+ unsigned clear = 0;
while (*list) {
if (*list == ',' || *list == ' ' || *list == '\t') {
++list;
@@ -83,14 +94,21 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
}
const char *const comma = strchr(list, ',');
+ const bool strikethrough = *list == '-' || *list == '~';
+ if (strikethrough || *list == '+')
+ ++list;
+ else
+ mask = clear;
const size_t len = (comma) ? comma - list : strlen(list);
const option_verb *scan = verbs;
+
while (true) {
if (!scan->verb)
failure("Unknown verb '%.*s', for option '==%s'\n", (int)len, list,
option);
if (strlen(scan->verb) == len && strncmp(list, scan->verb, len) == 0) {
- mask |= scan->mask;
+ mask = strikethrough ? mask & ~scan->mask : mask | scan->mask;
+ clear = strikethrough ? clear & ~scan->mask : clear | scan->mask;
list += len;
break;
}
@@ -103,15 +121,36 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
bool parse_option(int argc, char *const argv[], int &narg, const char *option,
uint64_t &value, const scale_mode scale,
- const uint64_t minval, const uint64_t maxval) {
+ const uint64_t minval, const uint64_t maxval,
+ const uint64_t default_value) {
const char *value_cstr;
if (!parse_option(argc, argv, narg, option, &value_cstr))
return false;
+ if (default_value && strcmp(value_cstr, "default") == 0) {
+ value = default_value;
+ return true;
+ }
+
+ if (strcmp(value_cstr, "min") == 0 || strcmp(value_cstr, "minimal") == 0) {
+ value = minval;
+ return true;
+ }
+
+ if (strcmp(value_cstr, "max") == 0 || strcmp(value_cstr, "maximal") == 0) {
+ value = maxval;
+ return true;
+ }
+
char *suffix = nullptr;
errno = 0;
- unsigned long raw = strtoul(value_cstr, &suffix, 0);
+ unsigned long long raw = strtoull(value_cstr, &suffix, 0);
+ if ((suffix && *suffix) || errno) {
+ suffix = nullptr;
+ errno = 0;
+ raw = strtoull(value_cstr, &suffix, 10);
+ }
if (errno)
failure("Option '--%s' expects a numeric value (%s)\n", option,
test_strerror(errno));
@@ -167,28 +206,58 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option,
bool parse_option(int argc, char *const argv[], int &narg, const char *option,
unsigned &value, const scale_mode scale,
- const unsigned minval, const unsigned maxval) {
+ const unsigned minval, const unsigned maxval,
+ const unsigned default_value) {
uint64_t huge;
- if (!parse_option(argc, argv, narg, option, huge, scale, minval, maxval))
+ if (!parse_option(argc, argv, narg, option, huge, scale, minval, maxval,
+ default_value))
return false;
value = (unsigned)huge;
return true;
}
bool parse_option(int argc, char *const argv[], int &narg, const char *option,
- uint8_t &value, const uint8_t minval, const uint8_t maxval) {
+ uint8_t &value, const uint8_t minval, const uint8_t maxval,
+ const uint8_t default_value) {
uint64_t huge;
- if (!parse_option(argc, argv, narg, option, huge, no_scale, minval, maxval))
+ if (!parse_option(argc, argv, narg, option, huge, no_scale, minval, maxval,
+ default_value))
return false;
value = (uint8_t)huge;
return true;
}
bool parse_option(int argc, char *const argv[], int &narg, const char *option,
+ int64_t &value, const int64_t minval, const int64_t maxval,
+ const int64_t default_value) {
+ uint64_t proxy = (uint64_t)value;
+ if (parse_option(argc, argv, narg, option, proxy, config::binary,
+ (uint64_t)minval, (uint64_t)maxval,
+ (uint64_t)default_value)) {
+ value = (int64_t)proxy;
+ return true;
+ }
+ return false;
+}
+
+bool parse_option(int argc, char *const argv[], int &narg, const char *option,
+ int32_t &value, const int32_t minval, const int32_t maxval,
+ const int32_t default_value) {
+ uint64_t proxy = (uint64_t)value;
+ if (parse_option(argc, argv, narg, option, proxy, config::binary,
+ (uint64_t)minval, (uint64_t)maxval,
+ (uint64_t)default_value)) {
+ value = (int32_t)proxy;
+ return true;
+ }
+ return false;
+}
+
+bool parse_option(int argc, char *const argv[], int &narg, const char *option,
bool &value) {
- const char *value_cstr = NULL;
+ const char *value_cstr = nullptr;
if (!parse_option(argc, argv, narg, option, &value_cstr, "yes")) {
const char *current = argv[narg];
if (strncmp(current, "--no-", 5) == 0 && strcmp(current + 5, option) == 0) {
@@ -257,7 +326,7 @@ static void dump_verbs(const char *caption, size_t bits,
++verbs;
}
- logging::feed("\n");
+ logging::feed("%s\n", (*comma == '\0') ? "none" : "");
}
static void dump_duration(const char *caption, unsigned duration) {
@@ -288,8 +357,12 @@ void dump(const char *title) {
: i->params.pathname_log.c_str());
}
- log_info("database: %s, size %" PRIu64 "\n", i->params.pathname_db.c_str(),
- i->params.size);
+ log_info("database: %s, size %" PRIuPTR "[%" PRIiPTR "..%" PRIiPTR
+ ", %i %i, %i]\n",
+ i->params.pathname_db.c_str(), i->params.size_now,
+ i->params.size_lower, i->params.size_upper,
+ i->params.shrink_threshold, i->params.growth_step,
+ i->params.pagesize);
dump_verbs("mode", i->params.mode_flags, mode_bits);
dump_verbs("table", i->params.table_flags, table_bits);
@@ -306,7 +379,13 @@ void dump(const char *title) {
log_info("threads %u\n", i->params.nthreads);
- log_info("keygen.case: %s\n", keygencase2str(i->params.keygen.keycase));
+ log_info(
+ "keygen.params: case %s, width %u, mesh %u, rotate %u, offset %" PRIu64
+ ", split %u/%u\n",
+ keygencase2str(i->params.keygen.keycase), i->params.keygen.width,
+ i->params.keygen.mesh, i->params.keygen.rotate, i->params.keygen.offset,
+ i->params.keygen.split,
+ i->params.keygen.width - i->params.keygen.split);
log_info("keygen.seed: %u\n", i->params.keygen.seed);
log_info("key: minlen %u, maxlen %u\n", i->params.keylen_min,
i->params.keylen_max);
@@ -469,3 +548,27 @@ bool actor_config::deserialize(const char *str, actor_config &config) {
TRACE("<< actor_config::deserialize: OK\n");
return true;
}
+
+unsigned actor_params::mdbx_keylen_min() const {
+ return (table_flags & MDBX_INTEGERKEY) ? 4 : 0;
+}
+
+unsigned actor_params::mdbx_keylen_max() const {
+ return (table_flags & MDBX_INTEGERKEY)
+ ? 8
+ : std::min((unsigned)mdbx_limits_keysize_max(pagesize),
+ (unsigned)UINT16_MAX);
+}
+
+unsigned actor_params::mdbx_datalen_min() const {
+ return (table_flags & MDBX_INTEGERDUP) ? 4 : 0;
+}
+
+unsigned actor_params::mdbx_datalen_max() const {
+ return (table_flags & MDBX_INTEGERDUP)
+ ? 8
+ : std::min((table_flags & MDBX_DUPSORT)
+ ? (unsigned)mdbx_limits_keysize_max(pagesize)
+ : (unsigned)MDBX_MAXDATASIZE,
+ (unsigned)UINT16_MAX);
+}