| 17 | namespace benchmark { |
| 18 | |
| 19 | std::vector<std::unique_ptr<ParsedBenchmark>> BenchmarkParser::parseBenchmarkFile( |
| 20 | const std::string& path, bool checkOutputOrder) { |
| 21 | std::vector<std::unique_ptr<ParsedBenchmark>> result; |
| 22 | if (access(path.c_str(), 0) != 0) { |
| 23 | throw common::Exception("Test file not exists! [" + path + "]."); |
| 24 | } |
| 25 | struct stat status {}; |
| 26 | stat(path.c_str(), &status); |
| 27 | if (status.st_mode & S_IFDIR) { |
| 28 | throw common::Exception("Test file is a directory. [" + path + "]."); |
| 29 | } |
| 30 | std::ifstream ifs(path); |
| 31 | std::string line; |
| 32 | ParsedBenchmark* currentConfig = nullptr; |
| 33 | while (getline(ifs, line)) { |
| 34 | if (line.starts_with("-NAME")) { |
| 35 | auto config = std::make_unique<ParsedBenchmark>(); |
| 36 | currentConfig = config.get(); |
| 37 | result.push_back(std::move(config)); |
| 38 | currentConfig->name = line.substr(6, line.length()); |
| 39 | } else if (line.starts_with("-QUERY")) { |
| 40 | DASSERT(currentConfig); |
| 41 | currentConfig->query = line.substr(7, line.length()); |
| 42 | replaceVariables(currentConfig->query); |
| 43 | } else if (line.starts_with("-PRERUN")) { |
| 44 | DASSERT(currentConfig); |
| 45 | currentConfig->preRun = line.substr(8, line.length()); |
| 46 | replaceVariables(currentConfig->preRun); |
| 47 | } else if (line.starts_with("-POSTRUN")) { |
| 48 | DASSERT(currentConfig); |
| 49 | replaceVariables(currentConfig->postRun); |
| 50 | currentConfig->postRun = line.substr(9, line.length()); |
| 51 | } else if (line.starts_with("-PARALLELISM")) { |
| 52 | DASSERT(currentConfig); |
| 53 | currentConfig->numThreads = stoi(line.substr(13, line.length())); |
| 54 | } else if (line.starts_with("-SKIP_COMPARE_RESULT")) { |
| 55 | DASSERT(currentConfig); |
| 56 | currentConfig->compareResult = false; |
| 57 | } else if (line.starts_with("----")) { |
| 58 | uint64_t numTuples = stoi(line.substr(5, line.length())); |
| 59 | DASSERT(currentConfig); |
| 60 | currentConfig->expectedNumTuples = numTuples; |
| 61 | if (currentConfig->compareResult) { |
| 62 | for (auto i = 0u; i < numTuples; i++) { |
| 63 | getline(ifs, line); |
| 64 | currentConfig->expectedTuples.push_back(line); |
| 65 | } |
| 66 | if (!checkOutputOrder) { // order is not important for result |
| 67 | sort(currentConfig->expectedTuples.begin(), |
| 68 | currentConfig->expectedTuples.end()); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | void BenchmarkParser::replaceVariables(std::string& str) const { |