Skip to content

Commit

Permalink
Added group configuration file parser
Browse files Browse the repository at this point in the history
  • Loading branch information
rfdavid committed May 5, 2023
1 parent dd1bb6c commit 907b8e3
Show file tree
Hide file tree
Showing 71 changed files with 152 additions and 69 deletions.
12 changes: 12 additions & 0 deletions src/include/common/file_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ class FileUtils {
}

static std::vector<std::string> globFilePath(const std::string& path);

static inline std::string getParentPath(const std::filesystem::path& path) {
return path.parent_path().string();
}

static inline std::string getParentPathStem(const std::filesystem::path& path) {
return path.parent_path().stem().string();
}

static inline std::string getFileExtension(const std::filesystem::path& path) {
return path.extension().string();
}
};

} // namespace common
Expand Down
7 changes: 0 additions & 7 deletions test/include/graph_test/graph_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ enum class TransactionTestType : uint8_t {
RECOVERY = 1,
};

struct TestConfig {
std::string testSuiteName;
std::string testName;
std::string dataset;
std::vector<std::string> files;
};

class BaseGraphTest : public Test {
public:
void SetUp() override {
Expand Down
16 changes: 14 additions & 2 deletions test/include/test_helper/test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ using namespace kuzu::main;
namespace kuzu {
namespace testing {

struct TestConfig {
std::string testGroup;
std::string testName;
std::string dataset;
bool checkOrder = false;
std::vector<std::string> files;

bool isValid() const {
return !testGroup.empty() && !testName.empty() && !dataset.empty() && !files.empty();
}
};

struct TestQueryConfig {
std::string name;
std::string query;
Expand All @@ -26,6 +38,8 @@ struct TestQueryConfig {

class TestHelper {
public:
static TestConfig parseGroupFile(const std::string& path);

static std::vector<std::unique_ptr<TestQueryConfig>> parseTestFile(
const std::string& path, bool checkOutputOrder = false);

Expand All @@ -49,8 +63,6 @@ class TestHelper {
static std::unique_ptr<planner::LogicalPlan> getLogicalPlan(
const std::string& query, Connection& conn);

static std::string convertSnakeCaseToCamelCase(const std::string& snakeCase);

private:
static void initializeConnection(TestQueryConfig* config, Connection& conn);
static bool testQuery(TestQueryConfig* config, Connection& conn);
Expand Down
79 changes: 37 additions & 42 deletions test/runner/e2e_read_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,65 @@

using ::testing::Test;
using namespace kuzu::testing;
using namespace kuzu::common;

class RunDynamicTest : public DBTest {
class EndToEndReadTest : public DBTest {
public:
std::string getInputDir() override { return TestHelper::appendKuzuRootPath(dataset_); }

explicit RunDynamicTest(std::vector<std::string> testFiles, std::string dataset)
: testFiles_(testFiles), dataset_(dataset) {}

std::string getInputDir() override {
return TestHelper::appendKuzuRootPath("dataset/" + testConfig.dataset + "/");
}
EndToEndReadTest(TestConfig testConfig) : testConfig(std::move(testConfig)) {}
void TestBody() override {
for (auto& file : testFiles_) {
runTest(file);
for (auto& file : testConfig.files) {
if (testConfig.checkOrder) {
runTestAndCheckOrder(file);
} else {
runTest(file);
}
}
}

private:
std::vector<std::string> testFiles_;
std::string dataset_;
TestConfig testConfig;
};

void RegisterE2ETests(const std::vector<TestConfig> testConfig) {
void registerTests(const std::vector<TestConfig> testConfig) {
for (auto testItem : testConfig) {
testing::RegisterTest(testItem.testSuiteName.c_str(), testItem.testName.c_str(), nullptr,
testItem.testName.c_str(), __FILE__, __LINE__,
[=]() -> DBTest* { return new RunDynamicTest(testItem.files, testItem.dataset); });
testing::RegisterTest(testItem.testGroup.c_str(), testItem.testName.c_str(), nullptr,
nullptr, __FILE__, __LINE__,
[=]() -> DBTest* { return new EndToEndReadTest(testItem); });
}
}

std::vector<TestConfig> scanEndToEndTestFiles(const std::string& path) {
std::vector<TestConfig> scanTestFiles(const std::string& path) {
TestConfig testConfig;
std::vector<TestConfig> tests;

for (const auto& entry : std::filesystem::directory_iterator(path)) {
std::string dirName = entry.path().filename().string();
testConfig.testSuiteName = TestHelper::convertSnakeCaseToCamelCase(dirName + "Test");
std::replace(dirName.begin(), dirName.end(), '_', '-');
testConfig.dataset = "dataset/" + dirName + "/";

for (const auto& subEntry :
std::filesystem::directory_iterator(path + "/" + entry.path().filename().string())) {
testConfig.files.clear();
if (subEntry.is_directory()) {
testConfig.testName =
TestHelper::convertSnakeCaseToCamelCase(subEntry.path().filename().string());
for (const auto& file : std::filesystem::directory_iterator(subEntry.path())) {
if (file.is_regular_file()) {
testConfig.files.push_back(file.path().string());
}
}
} else {
testConfig.testName = testConfig.testSuiteName;
testConfig.files.push_back(subEntry.path().string());
}
tests.push_back(testConfig);
std::string previousDirectory;
for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
if (!entry.is_regular_file())
continue;
std::string testGroupFile = FileUtils::getParentPath(entry) + "/test.group";
if (!FileUtils::fileOrPathExists(testGroupFile))
continue;
if (FileUtils::getParentPathStem(entry) != previousDirectory) {
if (testConfig.isValid())
tests.push_back(testConfig);
testConfig = TestHelper::parseGroupFile(testGroupFile);
}
if (FileUtils::getFileExtension(entry) == ".test") {
testConfig.files.push_back(entry.path().string());
}
previousDirectory = FileUtils::getParentPathStem(entry);
}

if (testConfig.isValid())
tests.push_back(testConfig);
return tests;
}

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
std::vector<TestConfig> tests =
scanEndToEndTestFiles(TestHelper::appendKuzuRootPath("test/test_files/e2e"));

RegisterE2ETests(tests);
scanTestFiles(TestHelper::appendKuzuRootPath("test/test_files"));
registerTests(tests);
return RUN_ALL_TESTS();
}
4 changes: 4 additions & 0 deletions test/test_files/long_string_pk/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP LongStringPKTest
-TEST LongStringPKTest
-DATASET long-string-pk-tests
-READ_ONLY TRUE
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/npy-1d/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP OneDimNpyReadTest
-TEST Match
-DATASET npy-1d
-READ_ONLY TRUE
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/shortest_path/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP SingleSourceShortestPathTest
-TEST BFS_SSSP
-DATASET shortest-path-tests
-READ_ONLY TRUE
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/acc/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Acc
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/agg/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Agg
-DATASET tinysnb
-READ_ONLY TRUE
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/cyclic/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Cyclic
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/filter/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Filter
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/function/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Function
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/match/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Match
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/optional_match/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST OptionalMatch
-DATASET tinysnb
-READ_ONLY TRUE
5 changes: 5 additions & 0 deletions test/test_files/tinysnb/order_by/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-GROUP TinySnbReadTest
-TEST OrderBy
-DATASET tinysnb
-READ_ONLY TRUE
-CHECK_ORDER TRUE
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/projection/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Projection
-DATASET tinysnb
-READ_ONLY TRUE
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/subquery/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Subquery
-DATASET tinysnb
-READ_ONLY TRUE
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/union/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Union
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/unwind/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST Unwind
-DATASET tinysnb
-READ_ONLY TRUE
File renamed without changes.
4 changes: 4 additions & 0 deletions test/test_files/tinysnb/var_length_extend/test.group
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-GROUP TinySnbReadTest
-TEST VarLengthExtendTests
-DATASET tinysnb
-READ_ONLY TRUE
42 changes: 24 additions & 18 deletions test/test_helper/test_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@ using namespace kuzu::main;
namespace kuzu {
namespace testing {

TestConfig TestHelper::parseGroupFile(const std::string& path) {
TestConfig result;
if (!FileUtils::fileOrPathExists(path)) {
return result;
}
std::ifstream ifs(path);
std::string line;
while (getline(ifs, line)) {
if (line.starts_with("-GROUP")) {
result.testGroup = line.substr(7, line.length());
}
if (line.starts_with("-TEST")) {
result.testName = line.substr(6, line.length());
}
if (line.starts_with("-DATASET")) {
result.dataset = line.substr(9, line.length());
}
if (line.starts_with("-CHECK_ORDER")) {
result.checkOrder = (line.substr(13, line.length()) == "TRUE");
}
}
return result;
}

std::vector<std::unique_ptr<TestQueryConfig>> TestHelper::parseTestFile(
const std::string& path, bool checkOutputOrder) {
std::vector<std::unique_ptr<TestQueryConfig>> result;
Expand Down Expand Up @@ -145,23 +169,5 @@ std::unique_ptr<planner::LogicalPlan> TestHelper::getLogicalPlan(
return std::move(conn.prepare(query)->logicalPlans[0]);
}

std::string TestHelper::convertSnakeCaseToCamelCase(const std::string& snakeCase) {
std::string camelCase;
bool toUpper = true;
for (auto c : snakeCase) {
if (c == '_') {
toUpper = true;
} else {
if (toUpper) {
camelCase += std::toupper(c);
toUpper = false;
} else {
camelCase += c;
}
}
}
return camelCase;
}

} // namespace testing
} // namespace kuzu

0 comments on commit 907b8e3

Please sign in to comment.