diff options
Diffstat (limited to 'src/third_party/wiredtiger/test/cppsuite')
4 files changed, 155 insertions, 7 deletions
diff --git a/src/third_party/wiredtiger/test/cppsuite/test_config.c b/src/third_party/wiredtiger/test/cppsuite/test_config.c new file mode 100644 index 00000000000..6d1585172c8 --- /dev/null +++ b/src/third_party/wiredtiger/test/cppsuite/test_config.c @@ -0,0 +1,28 @@ +/* DO NOT EDIT: automatically built by dist/api_config.py. */ + +#include "wt_internal.h" + +static const WT_CONFIG_CHECK confchk_poc_test[] = { + {"collection_count", "int", NULL, "min=1,max=10", NULL, 0}, + {"key_size", "int", NULL, "min=1,max=10000", NULL, 0}, + {"values", "string", NULL, "choices=[\"first\",\"second\",\"third\"]", NULL, 0}, + {NULL, NULL, NULL, NULL, NULL, 0}}; + +static const WT_CONFIG_ENTRY config_entries[] = { + {"poc_test", "collection_count=1,key_size=10,values=first", confchk_poc_test, 3}, + {NULL, NULL, NULL, 0}}; + +/* + * __wt_test_config_match -- + * Return the static configuration entry for a test. + */ +const WT_CONFIG_ENTRY * +__wt_test_config_match(const char *test_name) +{ + const WT_CONFIG_ENTRY *ep; + + for (ep = config_entries; ep->method != NULL; ++ep) + if (strcmp(test_name, ep->method) == 0) + return (ep); + return (NULL); +} diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration_settings.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration_settings.h new file mode 100644 index 00000000000..9f1d43773c9 --- /dev/null +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/configuration_settings.h @@ -0,0 +1,107 @@ +/* Include guard. */ +#ifndef CONFIGURATION_SETTINGS_H +#define CONFIGURATION_SETTINGS_H + +#include "wt_internal.h" +#include <string> +#include <stdexcept> + +namespace test_harness { +class configuration { + private: + std::string _config; + WT_CONFIG_PARSER *_config_parser; + + public: + configuration(const char *test_config_name, const char *config) : _config(config) + { + int ret = wiredtiger_config_parser_open(nullptr, config, strlen(config), &_config_parser); + if (ret != 0) + throw std::invalid_argument( + "failed to create configuration parser for provided config"); + if (wiredtiger_test_config_validate(nullptr, nullptr, test_config_name, config) != 0) + throw std::invalid_argument( + "failed to validate given config, ensure test config exists"); + } + + configuration(const char *test_config_name, const WT_CONFIG_ITEM &nested) + { + if (nested.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_STRUCT) + throw std::invalid_argument("provided config item isn't a structure"); + int ret = wiredtiger_config_parser_open(nullptr, nested.str, nested.len, &_config_parser); + if (ret != 0) + throw std::invalid_argument( + "failed to create configuration parser for provided sub config"); + } + + ~configuration() + { + if (_config_parser != nullptr) { + _config_parser->close(_config_parser); + _config_parser = nullptr; + } + } + + std::string + get_config() + { + return _config; + } + + /* + * Wrapper functions for retrieving basic configuration values. Ideally the tests can avoid + * using the config item struct provided by wiredtiger. However if they still wish to use it the + * get and next functions can be used. + */ + int + get_string(const char *key, std::string &value) + { + WT_CONFIG_ITEM temp_value; + WT_RET(_config_parser->get(_config_parser, key, &temp_value)); + if (temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_STRING || + temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_ID) + return (-1); + value = std::string(temp_value.str, temp_value.len); + return (0); + } + + int + get_bool(const char *key, bool &value) + { + WT_CONFIG_ITEM temp_value; + WT_RET(_config_parser->get(_config_parser, key, &temp_value)); + if (temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_BOOL) + return (-1); + value = temp_value.val != 0; + return (0); + } + + int + get_int(const char *key, int64_t &value) + { + WT_CONFIG_ITEM temp_value; + WT_RET(_config_parser->get(_config_parser, key, &temp_value)); + if (temp_value.type != WT_CONFIG_ITEM::WT_CONFIG_ITEM_NUM) + return (-1); + value = temp_value.val; + return (0); + } + + /* + * Basic configuration parsing helper functions. + */ + int + next(WT_CONFIG_ITEM *key, WT_CONFIG_ITEM *value) + { + return _config_parser->next(_config_parser, key, value); + } + + int + get(const char *key, WT_CONFIG_ITEM *value) + { + return _config_parser->get(_config_parser, key, value); + } +}; +} // namespace test_harness + +#endif diff --git a/src/third_party/wiredtiger/test/cppsuite/test_harness/test_harness.h b/src/third_party/wiredtiger/test/cppsuite/test_harness/test_harness.h index 5660944ae67..b489c84b8ec 100644 --- a/src/third_party/wiredtiger/test/cppsuite/test_harness/test_harness.h +++ b/src/third_party/wiredtiger/test/cppsuite/test_harness/test_harness.h @@ -5,19 +5,27 @@ /* Required to build using older versions of g++. */ #include <cinttypes> -extern "C" { +/* Include various wiredtiger libs. */ #include "wiredtiger.h" #include "wt_internal.h" -} + +#include "configuration_settings.h" namespace test_harness { class test { public: + configuration *_configuration; + static const std::string _name; /* * All tests will implement this initially, the return value from it will indicate whether the * test was successful or not. */ virtual int run() = 0; + + test(std::string config) + { + _configuration = new configuration(_name.c_str(), config.c_str()); + } }; } // namespace test_harness diff --git a/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx b/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx index 0bf50387344..d41ff8dfa6b 100644 --- a/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx +++ b/src/third_party/wiredtiger/test/cppsuite/tests/poc.cxx @@ -8,23 +8,28 @@ class poc_test : public test_harness::test { WT_CONNECTION *conn; int ret = 0; /* Setup basic test directory. */ - const std::string default_dir = "WT_TEST"; + const char *default_dir = "WT_TEST"; /* * Csuite tests utilise a test_util.h command to make their directory, currently that doesn't * compile under c++ and some extra work will be needed to make it work. Its unclear if the * test framework will use test_util.h yet. */ - const std::string mkdir_cmd = "mkdir " + default_dir; - ret = system(mkdir_cmd.c_str()); + const char *mkdir_cmd = "mkdir WT_TEST"; + ret = system(mkdir_cmd); if (ret != 0) return (ret); - ret = wiredtiger_open(default_dir.c_str(), NULL, "create,cache_size=1G", &conn); + ret = wiredtiger_open(default_dir, NULL, "create,cache_size=1G", &conn); return (ret); } + + poc_test(std::string config) : test(config) {} }; +const std::string poc_test::test::_name = "poc_test"; + int main(int argc, char *argv[]) { - return poc_test().run(); + const char *cfg = "collection_count=1,key_size=5"; + return poc_test(cfg).run(); } |