From 189b30b6309d6223eb9b94a721d02e98059963fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 10 Aug 2021 17:35:31 +0200 Subject: [PATCH] Work in progress for generate_set_session_csv generate_set_session_csv will be able to automatically generate a long list of SET statements for testing purpose --- .gitignore | 1 + test/tap/tests/generate_set_session_csv.cpp | 96 +++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 test/tap/tests/generate_set_session_csv.cpp diff --git a/.gitignore b/.gitignore index c80320a84..610766c9e 100644 --- a/.gitignore +++ b/.gitignore @@ -188,3 +188,4 @@ heaptrack.* test/tap/tests/galera_1_timeout_count test/tap/tests/galera_2_timeout_no_count test/tap/tests/setparser_test +test/tap/tests/generate_set_session_csv diff --git a/test/tap/tests/generate_set_session_csv.cpp b/test/tap/tests/generate_set_session_csv.cpp new file mode 100644 index 000000000..2ac80243d --- /dev/null +++ b/test/tap/tests/generate_set_session_csv.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + + +std::vector bool_values = { + "0", "1", + "ON", "OFF", + "oN", "Off", + "`ON`", "`OFF`", + "\"ON\"", "\"OFF\"", +}; +std::vector int_values = { + 10, 20, 100, 1010, 1234, 3456, 7890, 34564, 68100, 123456, 456123 +}; + +std::unordered_map fixed_sets = { + { "SET session transaction read only", "{'transaction_read_only':'ON'}" }, + { "SET session transaction read write", "{'transaction_read_only':'OFF'}" }, + { "SET session transaction isolation level READ COMMITTED", "{'transaction_isolation':'READ-COMMITTED'}" }, + { "SET session transaction isolation level READ UNCOMMITTED", "{'transaction_isolation':'READ-UNCOMMITTED'}" }, + { "SET session transaction isolation level REPEATABLE READ", "{'transaction_isolation':'REPEATABLE-READ'}" }, + { "SET session transaction isolation level SERIALIZABLE", "{'transaction_isolation':'SERIALIZABLE'}" } +}; + +class variable { + public: + std::string name; + int uses_quotes = 0; + bool mix = false; + bool number = false; + std::vector values; + variable(const std::string& n, bool m, bool is_n) { + name = n; + mix = m; + number = is_n; + } + void add(const std::string& v) { + values.push_back(v); + } + void add(const std::vector& v) { + for (std::vector::const_iterator it = v.begin() ; it != v.end() ; it++) { + values.push_back(*it); + } + } + void add(const std::vector& v, int inc) { + for (std::vector::const_iterator it = v.begin() ; it != v.end() ; it++) { + int a = *it; + a += inc; + values.push_back(std::to_string(a)); + } + } +}; + + +std::unordered_map vars; + +int main() { + + srand(1); + vars["sql_log_bin"] = new variable("sql_log_bin", false, false); + vars["sql_log_bin"]->add(bool_values); + vars["sql_safe_updates"] = new variable("sql_safe_updates", true, false); + vars["sql_safe_updates"]->add(bool_values); + vars["sql_auto_is_null"] = new variable("sql_auto_is_null", true, false); + vars["sql_auto_is_null"]->add(bool_values); + vars["foreign_key_checks"] = new variable("foreign_key_checks", true, false); + vars["foreign_key_checks"]->add(bool_values); + vars["unique_checks"] = new variable("unique_checks", true, false); + vars["unique_checks"]->add(bool_values); + //vars[""] = new variable(""); + //vars[""]->add(bool_values); + vars["sql_select_limit"] = new variable("sql_select_limit", true, true); + vars["sql_select_limit"]->add(int_values, 5); + vars["group_concat_max_len"] = new variable("group_concat_max_len", true, true); + vars["group_concat_max_len"]->add(int_values, 123); + vars["max_join_size"] = new variable("max_join_size", true, true); + vars["max_join_size"]->add(int_values, 1000); + vars["max_join_size"]->add("18446744073709551615"); + + + + vars["time_zone"] = new variable("time_zone", true, false); + vars["time_zone"]->add(std::vector {"+01:00", "`+02:15`", "\"+03:30\""}); + vars["time_zone"]->add(std::vector {"+04:45", "`+05:00`", "\"+06:10\""}); + vars["time_zone"]->add(std::vector {"-1:10", "-03:33", "\"-04:56\""}); + vars["sql_mode"] = new variable("sql_mode", true, false); + + for (int i=0; i<1000; i++) { + int ne = rand()%4+1; + int r1 = rand()%vars.size(); + } + + return 0; +}