mirror of
https://github.com/apple/foundationdb.git
synced 2025-06-02 19:25:52 +08:00
SysTester: remove direct dependencies on flow
This commit is contained in:
parent
f5d722b65b
commit
e4311ae661
@ -109,6 +109,7 @@ if(NOT WIN32 AND NOT IS_ARM_MAC)
|
||||
test/system/SysTestTransactionExecutor.h
|
||||
test/system/SysTestWorkload.cpp
|
||||
test/system/SysTestWorkload.h
|
||||
../../flow/SimpleOpt.h
|
||||
)
|
||||
|
||||
if(OPEN_FOR_IDE)
|
||||
@ -154,7 +155,7 @@ if(NOT WIN32 AND NOT IS_ARM_MAC)
|
||||
target_link_libraries(fdb_c_unit_tests_version_510 PRIVATE fdb_c Threads::Threads)
|
||||
target_link_libraries(trace_partial_file_suffix_test PRIVATE fdb_c Threads::Threads)
|
||||
target_link_libraries(disconnected_timeout_unit_tests PRIVATE fdb_c Threads::Threads)
|
||||
target_link_libraries(fdb_c_system_tester PRIVATE fdb_c flow)
|
||||
target_link_libraries(fdb_c_system_tester PRIVATE fdb_c Threads::Threads)
|
||||
|
||||
# do not set RPATH for mako
|
||||
set_property(TARGET mako PROPERTY SKIP_BUILD_RPATH TRUE)
|
||||
|
@ -23,12 +23,10 @@
|
||||
#ifndef SYS_TEST_OPTIONS_TESTER_OPTIONS_H
|
||||
#define SYSTEM_TESTER_TESTER_OPTIONS_H
|
||||
|
||||
#include "flow/SimpleOpt.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#define FDB_API_VERSION 710
|
||||
#include "bindings/c/foundationdb/fdb_c.h"
|
||||
|
||||
namespace FDBSystemTester {
|
||||
|
||||
@ -49,12 +47,6 @@ public:
|
||||
int numDatabases = 1;
|
||||
std::string externalClientLibrary;
|
||||
int numFdbThreads = 1;
|
||||
|
||||
bool parseArgs(int argc, char** argv);
|
||||
|
||||
private:
|
||||
bool processArg(const CSimpleOpt& args);
|
||||
static void printProgramUsage(const char* execName);
|
||||
};
|
||||
|
||||
} // namespace FDBSystemTester
|
||||
|
@ -19,9 +19,9 @@
|
||||
*/
|
||||
|
||||
#include "SysTestTransactionExecutor.h"
|
||||
#include "flow/IRandom.h"
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <random>
|
||||
|
||||
namespace FDBSystemTester {
|
||||
|
||||
@ -150,10 +150,12 @@ public:
|
||||
fdb_check(fdb_create_database(clusterFile, &db));
|
||||
databases.push_back(db);
|
||||
}
|
||||
std::random_device dev;
|
||||
random.seed(dev());
|
||||
}
|
||||
|
||||
void execute(ITransactionActor* txActor, TTaskFct cont) override {
|
||||
int idx = deterministicRandom()->randomInt(0, options.numDatabases);
|
||||
int idx = std::uniform_int_distribution<>(0, options.numDatabases - 1)(random);
|
||||
FDBTransaction* tx;
|
||||
fdb_check(fdb_database_create_transaction(databases[idx], &tx));
|
||||
TransactionContext* ctx = new TransactionContext(tx, txActor, cont, options, scheduler);
|
||||
@ -171,6 +173,7 @@ private:
|
||||
std::vector<FDBDatabase*> databases;
|
||||
TransactionExecutorOptions options;
|
||||
IScheduler* scheduler;
|
||||
std::mt19937 random;
|
||||
};
|
||||
|
||||
ITransactionExecutor* createTransactionExecutor() {
|
||||
|
@ -20,15 +20,11 @@
|
||||
|
||||
#include "SysTestOptions.h"
|
||||
#include "SysTestWorkload.h"
|
||||
#include "flow/Platform.h"
|
||||
#include "flow/Trace.h"
|
||||
#include "flow/ArgParseUtil.h"
|
||||
#include "test/system/SysTestScheduler.h"
|
||||
#include "test/system/SysTestTransactionExecutor.h"
|
||||
#include "SysTestScheduler.h"
|
||||
#include "SysTestTransactionExecutor.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
#define FDB_API_VERSION 710
|
||||
#include "flow/SimpleOpt.h"
|
||||
#include "bindings/c/foundationdb/fdb_c.h"
|
||||
|
||||
namespace FDBSystemTester {
|
||||
@ -68,17 +64,14 @@ CSimpleOpt::SOption TesterOptionDefs[] = //
|
||||
{ OPT_EXTERNAL_CLIENT_LIBRARY, "--external-client-library", SO_REQ_SEP },
|
||||
{ OPT_NUM_FDB_THREADS, "--num-fdb-threads", SO_REQ_SEP } };
|
||||
|
||||
} // namespace
|
||||
|
||||
void TesterOptions::printProgramUsage(const char* execName) {
|
||||
void printProgramUsage(const char* execName) {
|
||||
printf("usage: %s [OPTIONS]\n"
|
||||
"\n",
|
||||
execName);
|
||||
printf(" -C CONNFILE The path of a file containing the connection string for the\n"
|
||||
" FoundationDB cluster. The default is first the value of the\n"
|
||||
" FDB_CLUSTER_FILE environment variable, then `./fdb.cluster',\n"
|
||||
" FoundationDB cluster. The default is `fdb.cluster',\n"
|
||||
" then `%s'.\n",
|
||||
platform::getDefaultClusterFilePath().c_str());
|
||||
"fdb.cluster");
|
||||
printf(" --log Enables trace file logging for the CLI session.\n"
|
||||
" --log-dir PATH Specifes the output directory for trace files. If\n"
|
||||
" unspecified, defaults to the current directory. Has\n"
|
||||
@ -106,32 +99,6 @@ void TesterOptions::printProgramUsage(const char* execName) {
|
||||
" -h, --help Display this help and exit.\n");
|
||||
}
|
||||
|
||||
bool TesterOptions::parseArgs(int argc, char** argv) {
|
||||
// declare our options parser, pass in the arguments from main
|
||||
// as well as our array of valid options.
|
||||
CSimpleOpt args(argc, argv, TesterOptionDefs);
|
||||
|
||||
// while there are arguments left to process
|
||||
while (args.Next()) {
|
||||
if (args.LastError() == SO_SUCCESS) {
|
||||
if (args.OptionId() == OPT_HELP) {
|
||||
printProgramUsage(argv[0]);
|
||||
return false;
|
||||
}
|
||||
if (!processArg(args)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
printf("Invalid argument: %s\n", args.OptionText());
|
||||
printProgramUsage(argv[0]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
bool processIntArg(const CSimpleOpt& args, int& res, int minVal, int maxVal) {
|
||||
char* endptr;
|
||||
res = strtol(args.OptionArg(), &endptr, 10);
|
||||
@ -146,66 +113,104 @@ bool processIntArg(const CSimpleOpt& args, int& res, int minVal, int maxVal) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
// Extracts the key for command line arguments that are specified with a prefix (e.g. --knob-).
|
||||
// This function converts any hyphens in the extracted key to underscores.
|
||||
bool extractPrefixedArgument(std::string prefix, const std::string& arg, std::string& res) {
|
||||
if (arg.size() <= prefix.size() || arg.find(prefix) != 0 ||
|
||||
(arg[prefix.size()] != '-' && arg[prefix.size()] != '_')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TesterOptions::processArg(const CSimpleOpt& args) {
|
||||
res = arg.substr(prefix.size() + 1);
|
||||
std::transform(res.begin(), res.end(), res.begin(), [](int c) { return c == '-' ? '_' : c; });
|
||||
return true;
|
||||
}
|
||||
|
||||
bool validateTraceFormat(std::string_view format) {
|
||||
return format == "xml" || format == "json";
|
||||
}
|
||||
|
||||
bool processArg(TesterOptions& options, const CSimpleOpt& args) {
|
||||
switch (args.OptionId()) {
|
||||
case OPT_CONNFILE:
|
||||
clusterFile = args.OptionArg();
|
||||
options.clusterFile = args.OptionArg();
|
||||
break;
|
||||
case OPT_API_VERSION: {
|
||||
// multi-version fdbcli only available after 7.0
|
||||
processIntArg(args, api_version, 700, FDB_API_VERSION);
|
||||
processIntArg(args, options.api_version, 700, FDB_API_VERSION);
|
||||
break;
|
||||
}
|
||||
case OPT_TRACE:
|
||||
trace = true;
|
||||
options.trace = true;
|
||||
break;
|
||||
case OPT_TRACE_DIR:
|
||||
traceDir = args.OptionArg();
|
||||
options.traceDir = args.OptionArg();
|
||||
break;
|
||||
case OPT_LOGGROUP:
|
||||
logGroup = args.OptionArg();
|
||||
options.logGroup = args.OptionArg();
|
||||
break;
|
||||
case OPT_TRACE_FORMAT:
|
||||
if (!validateTraceFormat(args.OptionArg())) {
|
||||
fprintf(stderr, "WARNING: Unrecognized trace format `%s'\n", args.OptionArg());
|
||||
}
|
||||
traceFormat = args.OptionArg();
|
||||
options.traceFormat = args.OptionArg();
|
||||
break;
|
||||
case OPT_KNOB: {
|
||||
Optional<std::string> knobName = extractPrefixedArgument("--knob", args.OptionSyntax());
|
||||
if (!knobName.present()) {
|
||||
std::string knobName;
|
||||
if (!extractPrefixedArgument("--knob", args.OptionSyntax(), knobName)) {
|
||||
fprintf(stderr, "ERROR: unable to parse knob option '%s'\n", args.OptionSyntax());
|
||||
return false;
|
||||
}
|
||||
knobs.emplace_back(knobName.get(), args.OptionArg());
|
||||
options.knobs.emplace_back(knobName, args.OptionArg());
|
||||
break;
|
||||
}
|
||||
case OPT_BLOCK_ON_FUTURES:
|
||||
blockOnFutures = true;
|
||||
options.blockOnFutures = true;
|
||||
break;
|
||||
|
||||
case OPT_NUM_CLIENT_THREADS:
|
||||
processIntArg(args, numClientThreads, 1, 1000);
|
||||
processIntArg(args, options.numClientThreads, 1, 1000);
|
||||
break;
|
||||
|
||||
case OPT_NUM_DATABASES:
|
||||
processIntArg(args, numDatabases, 1, 1000);
|
||||
processIntArg(args, options.numDatabases, 1, 1000);
|
||||
break;
|
||||
|
||||
case OPT_EXTERNAL_CLIENT_LIBRARY:
|
||||
externalClientLibrary = args.OptionArg();
|
||||
options.externalClientLibrary = args.OptionArg();
|
||||
break;
|
||||
|
||||
case OPT_NUM_FDB_THREADS:
|
||||
processIntArg(args, numFdbThreads, 1, 1000);
|
||||
processIntArg(args, options.numFdbThreads, 1, 1000);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool parseArgs(TesterOptions& options, int argc, char** argv) {
|
||||
// declare our options parser, pass in the arguments from main
|
||||
// as well as our array of valid options.
|
||||
CSimpleOpt args(argc, argv, TesterOptionDefs);
|
||||
|
||||
// while there are arguments left to process
|
||||
while (args.Next()) {
|
||||
if (args.LastError() == SO_SUCCESS) {
|
||||
if (args.OptionId() == OPT_HELP) {
|
||||
printProgramUsage(argv[0]);
|
||||
return false;
|
||||
}
|
||||
if (!processArg(options, args)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
printf("Invalid argument: %s\n", args.OptionText());
|
||||
printProgramUsage(argv[0]);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void fdb_check(fdb_error_t e) {
|
||||
if (e) {
|
||||
std::cerr << fdb_get_error(e) << std::endl;
|
||||
@ -254,7 +259,7 @@ void runApiCorrectness(TesterOptions& options) {
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
TesterOptions options;
|
||||
if (!options.parseArgs(argc, argv)) {
|
||||
if (!parseArgs(options, argc, argv)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user