Skip to content

Commit

Permalink
Add wd3 test.
Browse files Browse the repository at this point in the history
This test may have been able to find #40.
  • Loading branch information
kohler committed Dec 28, 2019
1 parent ab8bdd2 commit 4f4bc58
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 14 deletions.
58 changes: 58 additions & 0 deletions kvtest.hh
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,64 @@ void kvtest_wd2_check(C &client)
client.report(result);
}

template <typename C>
void kvtest_wd3(C& client, uint64_t nk_total)
{
if (client.has_param("rangesize")) {
nk_total = client.param("rangesize").to_u64() * client.nthreads();
} else if (client.has_param("nkeys")) {
nk_total = client.param("nkeys").to_u64();
}
uint64_t nk = (nk_total + client.nthreads() - 1) / client.nthreads();
quick_istr k0(nk * client.id(), 8);

String prefix = client.param("prefix").to_s();
size_t plen = prefix.length();
char buf[128];
always_assert(plen + k0.length() < sizeof(buf));
memcpy(buf, prefix.data(), plen);
char* ebuf = buf + plen + k0.length();

double t0 = client.now();
unsigned long nrounds = 0;
while (!client.timeout(0)) {
++nrounds;
memcpy(ebuf - k0.length(), k0.data(), k0.length());
for (uint64_t i = nk; i != 0; --i) {
client.insert_check(Str(buf, ebuf), Str(ebuf - 8, ebuf));
quick_istr::increment_from_end(ebuf);
}

memcpy(ebuf - k0.length(), k0.data(), k0.length());
for (uint64_t i = nk; i != 0; --i) {
client.get_check(Str(buf, ebuf), Str(ebuf - 8, ebuf));
quick_istr::increment_from_end(ebuf);
}

memcpy(ebuf - k0.length(), k0.data(), k0.length());
for (uint64_t i = nk; i != 0; --i) {
client.remove_check(Str(buf, ebuf));
quick_istr::increment_from_end(ebuf);
}

memcpy(ebuf - k0.length(), k0.data(), k0.length());
for (uint64_t i = nk; i != 0; --i) {
client.get_check_absent(Str(buf, ebuf));
quick_istr::increment_from_end(ebuf);
}
}
client.wait_all();
double t1 = client.now();

Json result;
result.set("rangesize", nk);
memcpy(ebuf - k0.length(), k0.data(), k0.length());
result.set("first", Str(buf, ebuf));
kvtest_set_time(result, "rounds", nrounds, t1 - t0);
kvtest_set_time(result, "ops", nrounds * nk * 4, t1 - t0);
client.report(result);
}

// Create a range of keys [initial_pos, initial_pos + n)
// where key k == initial_pos + i has value (n - 1 - i).
// Many overwrites.
Expand Down
29 changes: 25 additions & 4 deletions mtclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "clp.h"

const char *serverip = "127.0.0.1";
static Json test_param;

typedef void (*get_async_cb)(struct child *c, struct async *a,
bool has_val, const Str &val);
Expand Down Expand Up @@ -192,6 +193,9 @@ struct kvtest_client {
int prefixLen() const {
return ::prefixLen;
}
Json param(const String& name, Json default_value = Json()) {
return test_param.count(name) ? test_param.at(name) : default_value;
}
double now() const {
return ::now();
}
Expand Down Expand Up @@ -563,19 +567,36 @@ main(int argc, char *argv[])
getratio = clp->val.i;
break;
case opt_minkeyletter:
assert(strlen(clp->vstr) == 1);
minkeyletter = clp->vstr[0];
break;
case opt_maxkeyletter:
assert(strlen(clp->vstr) == 1);
maxkeyletter = clp->vstr[0];
break;
case opt_nofork:
dofork = !clp->negated;
break;
case Clp_NotOption:
test = testrunner::find(clp->vstr);
if (!test)
usage();
case Clp_NotOption: {
// check for parameter setting
if (const char* eqchr = strchr(clp->vstr, '=')) {
Json& param = test_param[String(clp->vstr, eqchr)];
const char* end_vstr = clp->vstr + strlen(clp->vstr);
if (param.assign_parse(eqchr + 1, end_vstr)) {
// OK, param was valid JSON
} else if (eqchr[1] != 0) {
param = String(eqchr + 1, end_vstr);
} else {
param = Json();
}
} else {
test = testrunner::find(clp->vstr);
if (!test) {
usage();
}
}
break;
}
case Clp_BadOption:
usage();
break;
Expand Down
20 changes: 13 additions & 7 deletions mttest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ struct kvtest_client {
uint64_t limit() const {
return limit_;
}
Json param(const String& name) const {
return test_param[name];
bool has_param(const String& name) const {
return test_param.count(name);
}
Json param(const String& name, Json default_value = Json()) const {
return test_param.count(name) ? test_param.at(name) : default_value;
}

int ncores() const {
Expand Down Expand Up @@ -555,6 +558,7 @@ MAKE_TESTRUNNER(rw4fixed, kvtest_rw4fixed(client));
MAKE_TESTRUNNER(wd1, kvtest_wd1(10000000, 1, client));
MAKE_TESTRUNNER(wd1m1, kvtest_wd1(100000000, 1, client));
MAKE_TESTRUNNER(wd1m2, kvtest_wd1(1000000000, 4, client));
MAKE_TESTRUNNER(wd3, kvtest_wd3(client, 70 * client.nthreads()));
MAKE_TESTRUNNER(same, kvtest_same(client));
MAKE_TESTRUNNER(rwsmall24, kvtest_rwsmall24(client));
MAKE_TESTRUNNER(rwsep24, kvtest_rwsep24(client));
Expand Down Expand Up @@ -948,17 +952,19 @@ main(int argc, char *argv[])
if (const char* eqchr = strchr(clp->vstr, '=')) {
Json& param = test_param[String(clp->vstr, eqchr)];
const char* end_vstr = clp->vstr + strlen(clp->vstr);
if (param.assign_parse(eqchr + 1, end_vstr))
/* OK, param was valid JSON */;
else if (eqchr[1] != 0)
if (param.assign_parse(eqchr + 1, end_vstr)) {
// OK, param was valid JSON
} else if (eqchr[1] != 0) {
param = String(eqchr + 1, end_vstr);
else
} else {
param = Json();
}
} else {
// otherwise, tree or test
bool is_treetype = false;
for (int i = 0; i < (int) arraysize(test_thread_map) && !is_treetype; ++i)
for (int i = 0; i < (int) arraysize(test_thread_map) && !is_treetype; ++i) {
is_treetype = (strcmp(test_thread_map[i].treetype, clp->vstr) == 0);
}
(is_treetype ? treetypes.push_back(clp->vstr) : tests.push_back(clp->vstr));
}
break;
Expand Down
6 changes: 3 additions & 3 deletions testrunner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdio.h>

class testrunner_base {
public:
public:
testrunner_base(const lcdf::String& name)
: name_(name), next_(0) {
thehead ? thetail->next_ = this : thehead = this;
Expand All @@ -25,7 +25,7 @@ class testrunner_base {
return t;
}
static void print_names(FILE* stream, int maxcol);
private:
private:
static testrunner_base* thehead;
static testrunner_base* thetail;
lcdf::String name_;
Expand All @@ -35,7 +35,7 @@ class testrunner_base {
#ifdef TESTRUNNER_CLIENT_TYPE

class testrunner : public testrunner_base {
public:
public:
inline testrunner(const lcdf::String& name)
: testrunner_base(name) {
}
Expand Down

0 comments on commit 4f4bc58

Please sign in to comment.