Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion test/query-test-suite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ function(add_query_suite_target exe_name)
turing_testutils_s)
endfunction()

set(V3_QUERY_SUITE_LIBS
turing_db_interpreter_v3_s
turing_db_ir_codegen_s
turing_db_ir_dbdialect_s
turing_db_ir_nldialect_s
turing_db_ir_storagedialect_s
turing_db_ir_interpreter_s
turing_db_ir_common_s
turing_db_frontend_cypher_s)

add_query_suite_target(test_query_test_suite
QueryTestSuite.cpp
QueryTestRunner.cpp
Expand All @@ -40,15 +50,30 @@ gtest_discover_tests(test_remote_query_test_suite
DISCOVERY_TIMEOUT 10
DISCOVER_MODE PRE_TEST)

add_query_suite_target(test_query_v3_test_suite
V3QueryTestSuite.cpp
V3QueryTestRunner.cpp
QueryTestRunner.cpp
QueryResultFormatter.cpp)

target_link_libraries(test_query_v3_test_suite
PRIVATE ${V3_QUERY_SUITE_LIBS})

gtest_discover_tests(test_query_v3_test_suite
DISCOVERY_TIMEOUT 10
DISCOVER_MODE PRE_TEST)

add_query_suite_target(query_test_suite_cli
QueryTestSuiteCLI.cpp
QueryTestRunner.cpp
RemoteQueryTestRunner.cpp
V3QueryTestRunner.cpp
QueryResultFormatter.cpp)

target_link_libraries(query_test_suite_cli
PRIVATE turing_db_server_s
turing_db_proto_client_s)
turing_db_proto_client_s
${V3_QUERY_SUITE_LIBS})

set(QUERY_TEST_SUITE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)

Expand All @@ -58,5 +83,8 @@ target_compile_definitions(test_query_test_suite
target_compile_definitions(test_remote_query_test_suite
PRIVATE QUERY_TEST_SUITE_DIR="${QUERY_TEST_SUITE_DIR}")

target_compile_definitions(test_query_v3_test_suite
PRIVATE QUERY_TEST_SUITE_DIR="${QUERY_TEST_SUITE_DIR}")

target_compile_definitions(query_test_suite_cli
PRIVATE QUERY_TEST_SUITE_DIR="${QUERY_TEST_SUITE_DIR}")
17 changes: 17 additions & 0 deletions test/query-test-suite/QueryResultFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,23 @@ void QueryResultFormatter::appendRows(std::vector<std::vector<std::string>>& row
}
}

void QueryResultFormatter::appendChunkRows(std::vector<std::vector<std::string>>& rows,
std::vector<std::string>& values,
std::span<const db::Column* const> chunks,
size_t offset,
size_t rowCount) {
for (size_t row = offset; row < offset + rowCount; ++row) {
values.clear();
values.reserve(chunks.size());

for (const db::Column* col : chunks) {
values.push_back(columnValueToString(col, row));
}

rows.push_back(values);
}
}

std::string QueryResultFormatter::formatResultOutput(const db::QueryStatus& status,
const std::vector<std::string>& columnNames,
const std::vector<std::vector<std::string>>& rows) {
Expand Down
8 changes: 8 additions & 0 deletions test/query-test-suite/QueryResultFormatter.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#pragma once

#include <span>
#include <string>
#include <vector>

namespace db {

class Column;
class Dataframe;
class QueryStatus;

Expand All @@ -21,6 +23,12 @@ class QueryResultFormatter {
std::vector<std::string>& values,
const db::Dataframe* df);

static void appendChunkRows(std::vector<std::vector<std::string>>& rows,
std::vector<std::string>& values,
std::span<const db::Column* const> chunks,
size_t offset,
size_t rowCount);

static std::string formatResultOutput(const db::QueryStatus& status,
const std::vector<std::string>& columnNames,
const std::vector<std::vector<std::string>>& rows);
Expand Down
1 change: 1 addition & 0 deletions test/query-test-suite/QueryTestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ void QueryTestRunner::loadTestsFromDir(std::vector<QueryTestSpec>& specs,
spec._expectPlan = expect.value("plan", "");
spec._expectResult = expect.value("result", "");
spec._expectResultJson = expect.value("resultJson", "");
spec._expectMlir = expect.value("mlir", "");
}

specs.push_back(std::move(spec));
Expand Down
69 changes: 68 additions & 1 deletion test/query-test-suite/QueryTestSuiteCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "QueryTestRunner.h"
#include "RemoteQueryTestRunner.h"
#include "V3QueryTestRunner.h"

using namespace turing::test;

Expand Down Expand Up @@ -110,6 +111,18 @@ std::string serializeResult(const QueryTestResult& result, bool includeJsonField
result._resultJsonValid ? "true" : "false", result._timeUs);
}

std::string serializeResultV3(const V3QueryTestResult& result) {
return fmt::format(
"{{\"name\":\"{}\",\"resultV3Output\":\"{}\","
"\"mlirProgram\":\"{}\","
"\"resultV3Matched\":{},\"mlirMatched\":{},"
"\"timeUs\":{}}}",
escapeJson(result._name), escapeJson(result._resultOutput),
escapeJson(result._mlirOutput),
result._resultMatched ? "true" : "false",
result._mlirMatched ? "true" : "false", result._timeUs);
}

} // namespace

int main(int argc, char** argv) {
Expand All @@ -128,6 +141,10 @@ int main(int argc, char** argv) {
.help("Run a single test by name through the remote protocol")
.metavar("name")
.nargs(1);
program.add_argument("--run-v3")
.help("Run a single test by name through the v3 MLIR interpreter")
.metavar("name")
.nargs(1);
program.add_argument("--run-all")
.help("Run all enabled tests")
.default_value(false)
Expand All @@ -136,6 +153,10 @@ int main(int argc, char** argv) {
.help("Run all enabled tests through the remote protocol")
.default_value(false)
.implicit_value(true);
program.add_argument("--run-all-v3")
.help("Run all enabled tests through the v3 MLIR interpreter")
.default_value(false)
.implicit_value(true);

try {
program.parse_args(argc, argv);
Expand All @@ -148,10 +169,15 @@ int main(int argc, char** argv) {
const bool doList = program.get<bool>("--list");
const bool doRunAll = program.get<bool>("--run-all");
const bool doRunAllRemote = program.get<bool>("--run-all-remote");
const bool doRunAllV3 = program.get<bool>("--run-all-v3");
const bool doRun = program.is_used("--run");
const bool doRunRemote = program.is_used("--run-remote");
const bool doRunV3 = program.is_used("--run-v3");

if ((doList ? 1 : 0) + (doRun ? 1 : 0) + (doRunRemote ? 1 : 0) + (doRunAll ? 1 : 0) + (doRunAllRemote ? 1 : 0) != 1) {
const int selectedModes = (doList ? 1 : 0) + (doRun ? 1 : 0) + (doRunRemote ? 1 : 0)
+ (doRunV3 ? 1 : 0) + (doRunAll ? 1 : 0) + (doRunAllRemote ? 1 : 0)
+ (doRunAllV3 ? 1 : 0);
if (selectedModes != 1) {
fmt::println("{}", argParserUsage(program));
return 1;
}
Expand Down Expand Up @@ -181,6 +207,7 @@ int main(int argc, char** argv) {

QueryTestRunner runner;
RemoteQueryTestRunner remoteRunner;
V3QueryTestRunner v3Runner;

if (doRun) {
const std::string name = program.get<std::string>("--run");
Expand Down Expand Up @@ -218,6 +245,46 @@ int main(int argc, char** argv) {
return 1;
}

if (doRunV3) {
const std::string name = program.get<std::string>("--run-v3");
for (const auto& test : tests) {
if (test._name != name) {
continue;
}
const fs::Path outDir = fs::Path {"query_test_suite_cli_v3"} / test._name;
const V3QueryTestResult result = v3Runner.runTest(test, outDir);
fmt::println("{}", serializeResultV3(result));
return 0;
}
fmt::println("{}", "{\"error\":\"Unknown test name\"}");
return 1;
}

if (doRunAllV3) {
fmt::print("[");
bool first = true;
for (const auto& test : tests) {
if (!test._enabled) {
continue;
}
V3QueryTestResult result;
try {
result = v3Runner.runTest(test, fs::Path {"query_test_suite_cli_v3"} / test._name);
} catch (const std::exception& e) {
result._name = test._name;
result._resultOutput = fmt::format("ERROR: {}", e.what());
}

if (!first) {
fmt::print(",");
}
first = false;
fmt::print("{}", serializeResultV3(result));
}
fmt::println("]");
return 0;
}

fmt::print("[");
bool first = true;
for (const auto& test : tests) {
Expand Down
10 changes: 10 additions & 0 deletions test/query-test-suite/QueryTestTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct QueryTestSpec {
std::string _expectPlan;
std::string _expectResult;
std::string _expectResultJson;
std::string _expectMlir;
std::vector<std::string> _tags;
bool _enabled {true};
bool _remoteEnabled {true};
Expand All @@ -34,4 +35,13 @@ struct QueryTestResult {
uint64_t _timeUs {0};
};

struct V3QueryTestResult {
std::string _name;
std::string _resultOutput;
std::string _mlirOutput;
bool _resultMatched {false};
bool _mlirMatched {false};
uint64_t _timeUs {0};
};

}
Loading
Loading