| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "TestUtil.h" | ||
| 4 | |||
| 5 | #include <dirent.h> | ||
| 6 | #if OS_UNIX | ||
| 7 | #include <cstring> // Required by builds on Unix | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #include <gtest/gtest.h> | ||
| 11 | |||
| 12 | #include <util/CommonUtil.h> | ||
| 13 | #include <util/FileUtil.h> | ||
| 14 | |||
| 15 | #include "../driver/TestDriver.h" | ||
| 16 | |||
| 17 | namespace spice::testing { | ||
| 18 | |||
| 19 | using namespace spice::compiler; | ||
| 20 | |||
| 21 | extern TestDriverCliOptions testDriverCliOptions; | ||
| 22 | |||
| 23 | 438 | void TestUtil::parseTestArgs(const std::filesystem::path &sourceCodePath, std::vector<std::string> &args) { | |
| 24 |
3/4✓ Branch 2 → 3 taken 438 times.
✗ Branch 2 → 70 not taken.
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 437 times.
|
438 | if (!exists(sourceCodePath)) |
| 25 | 420 | return; | |
| 26 | |||
| 27 |
1/2✓ Branch 5 → 6 taken 437 times.
✗ Branch 5 → 70 not taken.
|
437 | std::ifstream file(sourceCodePath); |
| 28 |
1/2✗ Branch 7 → 8 not taken.
✓ Branch 7 → 9 taken 437 times.
|
437 | assert(file.is_open()); |
| 29 | |||
| 30 | 437 | std::string firstLine; | |
| 31 |
4/6✓ Branch 10 → 11 taken 437 times.
✗ Branch 10 → 66 not taken.
✓ Branch 11 → 12 taken 437 times.
✗ Branch 11 → 66 not taken.
✓ Branch 12 → 13 taken 1 time.
✓ Branch 12 → 14 taken 436 times.
|
437 | if (!std::getline(file, firstLine)) |
| 32 | 1 | return; | |
| 33 |
1/2✓ Branch 14 → 15 taken 436 times.
✗ Branch 14 → 54 not taken.
|
436 | firstLine = CommonUtil::trim(firstLine); |
| 34 | |||
| 35 | // Only allow "// TEST: " as prefix | ||
| 36 |
2/4✓ Branch 17 → 18 taken 436 times.
✗ Branch 17 → 66 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 20 taken 436 times.
|
436 | assert(firstLine.rfind("//TEST:", 0) != 0); |
| 37 | − | if (firstLine.rfind("// TEST: ", 0) != 0) // GCOV_EXCL_LINE | |
| 38 | − | return; // GCOV_EXCL_LINE | |
| 39 | |||
| 40 | 18 | const size_t colonPos = firstLine.find(':'); | |
| 41 |
1/2✗ Branch 24 → 25 not taken.
✓ Branch 24 → 26 taken 18 times.
|
18 | if (colonPos == std::string::npos) |
| 42 | ✗ | return; | |
| 43 | |||
| 44 |
2/4✓ Branch 26 → 27 taken 18 times.
✗ Branch 26 → 57 not taken.
✓ Branch 27 → 28 taken 18 times.
✗ Branch 27 → 55 not taken.
|
18 | const std::string argString = CommonUtil::trim(firstLine.substr(colonPos + 1)); |
| 45 |
3/4✓ Branch 29 → 30 taken 18 times.
✗ Branch 29 → 63 not taken.
✓ Branch 40 → 32 taken 24 times.
✓ Branch 40 → 41 taken 18 times.
|
42 | for (const std::string &arg : CommonUtil::split(argString)) { |
| 46 |
1/2✓ Branch 33 → 34 taken 24 times.
✗ Branch 33 → 60 not taken.
|
24 | const std::string trimmedArg = CommonUtil::trim(arg); |
| 47 |
1/2✓ Branch 35 → 36 taken 24 times.
✗ Branch 35 → 37 not taken.
|
24 | if (trimmedArg.length() > 0) |
| 48 |
1/2✓ Branch 36 → 37 taken 24 times.
✗ Branch 36 → 58 not taken.
|
24 | args.push_back(trimmedArg); |
| 49 | 42 | } | |
| 50 |
4/4✓ Branch 45 → 46 taken 18 times.
✓ Branch 45 → 47 taken 419 times.
✓ Branch 49 → 50 taken 18 times.
✓ Branch 49 → 52 taken 419 times.
|
856 | } |
| 51 | |||
| 52 | /** | ||
| 53 | * Collect the test cases in a particular test suite | ||
| 54 | * | ||
| 55 | * @param suiteName Name of the test suite | ||
| 56 | * @param useSubDirs Use subdirectories as test cases | ||
| 57 | * @return Vector of tests cases | ||
| 58 | */ | ||
| 59 | 10 | std::vector<TestCase> TestUtil::collectTestCases(const char *suiteName, bool useSubDirs) { | |
| 60 |
3/6✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 79 not taken.
✓ Branch 3 → 4 taken 10 times.
✗ Branch 3 → 76 not taken.
✓ Branch 4 → 5 taken 10 times.
✗ Branch 4 → 74 not taken.
|
10 | const std::filesystem::path suitePath = std::filesystem::path(PATH_TEST_FILES) / suiteName; |
| 61 | |||
| 62 | 10 | std::vector<TestCase> testCases; | |
| 63 |
1/2✓ Branch 7 → 8 taken 10 times.
✗ Branch 7 → 139 not taken.
|
10 | testCases.reserve(EXPECTED_NUMBER_OF_TESTS); |
| 64 | |||
| 65 |
2/2✓ Branch 8 → 9 taken 4 times.
✓ Branch 8 → 43 taken 6 times.
|
10 | if (useSubDirs) { |
| 66 | // Collect subdirectories of the given suite | ||
| 67 |
1/2✓ Branch 9 → 10 taken 4 times.
✗ Branch 9 → 112 not taken.
|
4 | const std::vector<std::string> testGroupDirs = getSubdirs(suitePath); |
| 68 | |||
| 69 | // Convert them to test cases | ||
| 70 |
2/2✓ Branch 40 → 12 taken 84 times.
✓ Branch 40 → 41 taken 4 times.
|
88 | for (const std::string &groupDirName : testGroupDirs) { |
| 71 |
2/4✓ Branch 13 → 14 taken 84 times.
✗ Branch 13 → 82 not taken.
✓ Branch 14 → 15 taken 84 times.
✗ Branch 14 → 80 not taken.
|
84 | const std::filesystem::path groupPath = suitePath / groupDirName; |
| 72 |
3/4✓ Branch 16 → 17 taken 84 times.
✗ Branch 16 → 105 not taken.
✓ Branch 35 → 19 taken 405 times.
✓ Branch 35 → 36 taken 84 times.
|
489 | for (const std::string &caseDirName : getSubdirs(groupPath)) { |
| 73 |
2/4✓ Branch 20 → 21 taken 405 times.
✗ Branch 20 → 85 not taken.
✓ Branch 21 → 22 taken 405 times.
✗ Branch 21 → 83 not taken.
|
405 | const std::filesystem::path testPath = groupPath / caseDirName; |
| 74 |
5/14✓ Branch 23 → 24 taken 405 times.
✗ Branch 23 → 97 not taken.
✓ Branch 24 → 25 taken 405 times.
✗ Branch 24 → 95 not taken.
✓ Branch 25 → 26 taken 405 times.
✗ Branch 25 → 91 not taken.
✓ Branch 26 → 27 taken 405 times.
✗ Branch 26 → 89 not taken.
✓ Branch 27 → 28 taken 405 times.
✗ Branch 27 → 86 not taken.
✗ Branch 86 → 87 not taken.
✗ Branch 86 → 88 not taken.
✗ Branch 92 → 93 not taken.
✗ Branch 92 → 94 not taken.
|
405 | const TestCase tc = {toCamelCase(groupDirName), toCamelCase(caseDirName), testPath}; |
| 75 |
1/2✓ Branch 30 → 31 taken 405 times.
✗ Branch 30 → 98 not taken.
|
405 | testCases.push_back(tc); |
| 76 | 489 | } | |
| 77 | 84 | } | |
| 78 | 4 | } else { | |
| 79 | // Collect test cases | ||
| 80 |
3/4✓ Branch 43 → 44 taken 6 times.
✗ Branch 43 → 138 not taken.
✓ Branch 65 → 46 taken 35 times.
✓ Branch 65 → 66 taken 6 times.
|
41 | for (const std::string &caseDirName : getSubdirs(suitePath)) { |
| 81 |
2/4✓ Branch 47 → 48 taken 35 times.
✗ Branch 47 → 115 not taken.
✓ Branch 48 → 49 taken 35 times.
✗ Branch 48 → 113 not taken.
|
35 | const std::filesystem::path testPath = suitePath / caseDirName; |
| 82 |
5/14✓ Branch 52 → 53 taken 35 times.
✗ Branch 52 → 127 not taken.
✓ Branch 53 → 54 taken 35 times.
✗ Branch 53 → 125 not taken.
✓ Branch 54 → 55 taken 35 times.
✗ Branch 54 → 121 not taken.
✓ Branch 55 → 56 taken 35 times.
✗ Branch 55 → 119 not taken.
✓ Branch 56 → 57 taken 35 times.
✗ Branch 56 → 116 not taken.
✗ Branch 116 → 117 not taken.
✗ Branch 116 → 118 not taken.
✗ Branch 122 → 123 not taken.
✗ Branch 122 → 124 not taken.
|
35 | const TestCase tc = {toCamelCase(suiteName), toCamelCase(caseDirName), testPath}; |
| 83 |
1/2✓ Branch 60 → 61 taken 35 times.
✗ Branch 60 → 131 not taken.
|
35 | testCases.push_back(tc); |
| 84 | 41 | } | |
| 85 | } | ||
| 86 | |||
| 87 |
1/2✗ Branch 69 → 70 not taken.
✓ Branch 69 → 71 taken 10 times.
|
10 | assert(testCases.size() <= EXPECTED_NUMBER_OF_TESTS); |
| 88 | 10 | return testCases; | |
| 89 | 10 | } | |
| 90 | |||
| 91 | /** | ||
| 92 | * Check if the expected output matches the actual output | ||
| 93 | * | ||
| 94 | * @param originalRefPath Path to the reference file | ||
| 95 | * @param getActualOutput Callback to execute the required steps to get the actual test output | ||
| 96 | * @param modifyOutputFct Callback to modify the output before comparing it with the reference | ||
| 97 | * @param x86Only Only compare/update ref file on x86_64 | ||
| 98 | * | ||
| 99 | * @return True, if the ref file was found | ||
| 100 | */ | ||
| 101 | 4320 | bool TestUtil::checkRefMatch(const std::filesystem::path &originalRefPath, GetOutputFct getActualOutput, | |
| 102 | ModifyOutputFct modifyOutputFct, [[maybe_unused]] bool x86Only) { | ||
| 103 |
3/4✓ Branch 2 → 3 taken 4320 times.
✗ Branch 2 → 64 not taken.
✓ Branch 39 → 4 taken 12950 times.
✓ Branch 39 → 40 taken 3697 times.
|
16647 | for (const std::filesystem::path &refPath : expandRefPaths(originalRefPath)) { |
| 104 | − | if (testDriverCliOptions.isVerbose) // GCOV_EXCL_LINE | |
| 105 | − | std::cout << "Checking for ref file: " << refPath << " - "; // GCOV_EXCL_LINE | |
| 106 |
3/4✓ Branch 8 → 9 taken 12950 times.
✗ Branch 8 → 61 not taken.
✓ Branch 9 → 10 taken 12327 times.
✓ Branch 9 → 14 taken 623 times.
|
12950 | if (!exists(refPath)) { |
| 107 | − | if (testDriverCliOptions.isVerbose) // GCOV_EXCL_LINE | |
| 108 | − | std::cout << "not found" << std::endl; // GCOV_EXCL_LINE | |
| 109 | 12327 | continue; | |
| 110 | } | ||
| 111 | − | if (testDriverCliOptions.isVerbose) // GCOV_EXCL_LINE | |
| 112 | − | std::cout << "ok" << std::endl; // GCOV_EXCL_LINE | |
| 113 | |||
| 114 | // Get actual output | ||
| 115 |
1/2✓ Branch 17 → 18 taken 623 times.
✗ Branch 17 → 61 not taken.
|
623 | std::string actualOutput = getActualOutput(); |
| 116 | |||
| 117 | #ifndef ARCH_X86_64 | ||
| 118 | // Cancel early, before comparing or updating the refs | ||
| 119 | if (x86Only && refPath == originalRefPath) | ||
| 120 | return true; | ||
| 121 | #endif | ||
| 122 | |||
| 123 | − | if (testDriverCliOptions.updateRefs) { // GCOV_EXCL_LINE | |
| 124 | − | FileUtil::writeToFile(refPath, actualOutput); // GCOV_EXCL_LINE | |
| 125 | } else { | ||
| 126 |
1/2✓ Branch 20 → 21 taken 623 times.
✗ Branch 20 → 58 not taken.
|
623 | std::string expectedOutput = FileUtil::getFileContent(refPath); |
| 127 |
1/2✓ Branch 21 → 22 taken 623 times.
✗ Branch 21 → 56 not taken.
|
623 | modifyOutputFct(expectedOutput, actualOutput); |
| 128 |
2/14✓ Branch 22 → 23 taken 623 times.
✗ Branch 22 → 55 not taken.
✗ Branch 24 → 25 not taken.
✓ Branch 24 → 34 taken 623 times.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 52 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 50 not taken.
✗ Branch 27 → 28 not taken.
✗ Branch 27 → 50 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 49 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 47 not taken.
|
623 | EXPECT_EQ(expectedOutput, actualOutput) << "Output does not match the reference file: " << refPath; |
| 129 | 623 | } | |
| 130 | 623 | return true; | |
| 131 |
2/2✓ Branch 42 → 43 taken 3697 times.
✓ Branch 42 → 45 taken 623 times.
|
4943 | } |
| 132 | 3697 | return false; | |
| 133 | } | ||
| 134 | |||
| 135 | /** | ||
| 136 | * Check if a variant of the requested ref file was found | ||
| 137 | * | ||
| 138 | * @param originalRefPath Path to the reference file | ||
| 139 | * @return True, if the ref file was found | ||
| 140 | */ | ||
| 141 | 950 | bool TestUtil::doesRefExist(const std::filesystem::path &originalRefPath) { | |
| 142 |
1/2✓ Branch 2 → 3 taken 950 times.
✗ Branch 2 → 10 not taken.
|
950 | const std::array<std::filesystem::path, 3> refPaths = expandRefPaths(originalRefPath); |
| 143 |
1/2✓ Branch 3 → 4 taken 950 times.
✗ Branch 3 → 8 not taken.
|
4744 | return std::ranges::any_of(refPaths, [](const std::filesystem::path &refPath) { return exists(refPath); }); |
| 144 | 950 | } | |
| 145 | |||
| 146 | /** | ||
| 147 | * Handle a test error | ||
| 148 | * | ||
| 149 | * @param testCase Testcase which has produced the error | ||
| 150 | * @param error Exception with error message | ||
| 151 | */ | ||
| 152 | 182 | void TestUtil::handleError(const TestCase &testCase, const std::exception &error) { | |
| 153 |
1/2✓ Branch 5 → 6 taken 182 times.
✗ Branch 5 → 48 not taken.
|
364 | std::string errorWhat = error.what(); |
| 154 |
3/6✓ Branch 9 → 10 taken 182 times.
✗ Branch 9 → 59 not taken.
✓ Branch 12 → 13 taken 182 times.
✗ Branch 12 → 53 not taken.
✓ Branch 13 → 14 taken 182 times.
✗ Branch 13 → 51 not taken.
|
546 | CommonUtil::replaceAll(errorWhat, "\\", "/"); |
| 155 | |||
| 156 | // Fail if no ref file exists | ||
| 157 |
2/4✓ Branch 18 → 19 taken 182 times.
✗ Branch 18 → 65 not taken.
✓ Branch 19 → 20 taken 182 times.
✗ Branch 19 → 63 not taken.
|
182 | const std::filesystem::path refPath = testCase.testPath / REF_NAME_ERROR_OUTPUT; |
| 158 | − | if (!doesRefExist(refPath)) // LCOV_EXCL_LINE | |
| 159 | − | FAIL() << "Expected no error, but got: " + errorWhat; // LCOV_EXCL_LINE | |
| 160 | |||
| 161 | // Check if the exception message matches the expected output | ||
| 162 |
1/2✓ Branch 34 → 35 taken 182 times.
✗ Branch 34 → 75 not taken.
|
364 | checkRefMatch(refPath, [&] { return errorWhat; }); |
| 163 |
2/4✓ Branch 39 → 40 taken 182 times.
✗ Branch 39 → 41 not taken.
✓ Branch 43 → 44 taken 182 times.
✗ Branch 43 → 46 not taken.
|
182 | } |
| 164 | |||
| 165 | /** | ||
| 166 | * Get subdirectories of the given path | ||
| 167 | * | ||
| 168 | * @param basePath Path to a directory | ||
| 169 | * @return Vector of subdirs | ||
| 170 | */ | ||
| 171 | 94 | std::vector<std::string> TestUtil::getSubdirs(const std::filesystem::path &basePath) { | |
| 172 | 94 | std::vector<std::string> subdirs; | |
| 173 |
3/6✓ Branch 2 → 3 taken 94 times.
✗ Branch 2 → 19 not taken.
✓ Branch 4 → 5 taken 94 times.
✗ Branch 4 → 17 not taken.
✓ Branch 6 → 7 taken 94 times.
✗ Branch 6 → 15 not taken.
|
94 | if (DIR *dir = opendir(basePath.string().c_str()); dir != nullptr) { |
| 174 | dirent *ent; | ||
| 175 |
3/4✓ Branch 12 → 13 taken 806 times.
✗ Branch 12 → 20 not taken.
✓ Branch 13 → 8 taken 712 times.
✓ Branch 13 → 14 taken 94 times.
|
806 | while ((ent = readdir(dir)) != nullptr) { |
| 176 |
4/4✓ Branch 8 → 9 taken 618 times.
✓ Branch 8 → 11 taken 94 times.
✓ Branch 9 → 10 taken 524 times.
✓ Branch 9 → 11 taken 94 times.
|
712 | if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) |
| 177 |
1/2✓ Branch 10 → 11 taken 524 times.
✗ Branch 10 → 20 not taken.
|
524 | subdirs.emplace_back(ent->d_name); |
| 178 | } | ||
| 179 |
1/2✓ Branch 14 → 15 taken 94 times.
✗ Branch 14 → 20 not taken.
|
94 | closedir(dir); |
| 180 | } | ||
| 181 | 94 | return subdirs; | |
| 182 | ✗ | } | |
| 183 | |||
| 184 | /** | ||
| 185 | * Retrieve the contents of a file as a vector of line strings. Empty lines are omitted | ||
| 186 | * | ||
| 187 | * @param filePath File path | ||
| 188 | * @return Vector of strings which are the lines of the file | ||
| 189 | */ | ||
| 190 | 2 | std::vector<std::string> TestUtil::getFileContentLinesVector(const std::filesystem::path &filePath) { | |
| 191 | 2 | std::vector<std::string> lines; | |
| 192 |
1/2✓ Branch 2 → 3 taken 2 times.
✗ Branch 2 → 23 not taken.
|
2 | std::ifstream inputFileStream; |
| 193 |
1/2✓ Branch 3 → 4 taken 2 times.
✗ Branch 3 → 21 not taken.
|
2 | inputFileStream.open(filePath); |
| 194 |
4/6✓ Branch 11 → 12 taken 4 times.
✗ Branch 11 → 18 not taken.
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 18 not taken.
✓ Branch 13 → 5 taken 2 times.
✓ Branch 13 → 14 taken 2 times.
|
6 | for (std::string line; std::getline(inputFileStream, line);) { |
| 195 |
1/2✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 2 times.
|
2 | if (!line.empty()) |
| 196 |
1/2✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 18 not taken.
|
2 | lines.push_back(line); |
| 197 | 2 | } | |
| 198 | 2 | return lines; | |
| 199 | 2 | } | |
| 200 | |||
| 201 | /** | ||
| 202 | * Convert a string to camel case | ||
| 203 | * | ||
| 204 | * @param input Input string | ||
| 205 | * @return Camel-cased string | ||
| 206 | */ | ||
| 207 | 1760 | std::string TestUtil::toCamelCase(std::string input) { | |
| 208 |
2/2✓ Branch 18 → 3 taken 26956 times.
✓ Branch 18 → 19 taken 1760 times.
|
28716 | for (auto it = input.begin(); it != input.end(); ++it) { |
| 209 |
5/6✓ Branch 4 → 5 taken 25659 times.
✓ Branch 4 → 7 taken 1297 times.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 8 taken 25659 times.
✓ Branch 9 → 10 taken 1297 times.
✓ Branch 9 → 15 taken 25659 times.
|
26956 | if (*it == '-' || *it == '_') { |
| 210 |
1/2✓ Branch 11 → 12 taken 1297 times.
✗ Branch 11 → 21 not taken.
|
1297 | it = input.erase(it); |
| 211 | 1297 | *it = static_cast<char>(toupper(*it)); | |
| 212 | } | ||
| 213 | } | ||
| 214 | 1760 | return input; | |
| 215 | } | ||
| 216 | |||
| 217 | /** | ||
| 218 | * Check if the provided test case is disabled | ||
| 219 | * | ||
| 220 | * @param testCase Test case to check | ||
| 221 | * @return Disabled or not | ||
| 222 | */ | ||
| 223 | 440 | bool TestUtil::isDisabled(const TestCase &testCase) { | |
| 224 |
5/8✓ Branch 2 → 3 taken 440 times.
✗ Branch 2 → 28 not taken.
✓ Branch 3 → 4 taken 440 times.
✗ Branch 3 → 26 not taken.
✓ Branch 4 → 5 taken 440 times.
✗ Branch 4 → 24 not taken.
✓ Branch 7 → 8 taken 2 times.
✓ Branch 7 → 9 taken 438 times.
|
440 | if (exists(testCase.testPath / CTL_SKIP_DISABLED)) |
| 225 | 2 | return true; | |
| 226 |
8/20✓ Branch 9 → 10 taken 438 times.
✗ Branch 9 → 15 not taken.
✓ Branch 10 → 11 taken 438 times.
✗ Branch 10 → 30 not taken.
✓ Branch 11 → 12 taken 438 times.
✗ Branch 11 → 30 not taken.
✓ Branch 12 → 13 taken 438 times.
✗ Branch 12 → 30 not taken.
✗ Branch 13 → 14 not taken.
✓ Branch 13 → 15 taken 438 times.
✓ Branch 16 → 17 taken 438 times.
✗ Branch 16 → 18 not taken.
✓ Branch 18 → 19 taken 438 times.
✗ Branch 18 → 20 not taken.
✗ Branch 20 → 21 not taken.
✓ Branch 20 → 22 taken 438 times.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 32 not taken.
✗ Branch 34 → 35 not taken.
✗ Branch 34 → 36 not taken.
|
438 | if (testDriverCliOptions.isGitHubActions && exists(testCase.testPath / CTL_SKIP_GH)) |
| 227 | ✗ | return true; | |
| 228 | #ifdef OS_WINDOWS | ||
| 229 | if (exists(testCase.testPath / CTL_SKIP_WINDOWS)) | ||
| 230 | return true; | ||
| 231 | #elifdef OS_MACOS | ||
| 232 | if (exists(testCase.testPath / CTL_SKIP_MACOS)) | ||
| 233 | return true; | ||
| 234 | #endif | ||
| 235 | 438 | return false; | |
| 236 | } | ||
| 237 | |||
| 238 | // LCOV_EXCL_START | ||
| 239 | /** | ||
| 240 | * Removes the first n lines of the GDB output to not compare target dependent code | ||
| 241 | * | ||
| 242 | * @param gdbOutput GDB output to modify | ||
| 243 | */ | ||
| 244 | − | void TestUtil::eraseGDBHeader(std::string &gdbOutput) { | |
| 245 | // Remove header | ||
| 246 | − | size_t pos = gdbOutput.find(GDB_READING_SYMBOLS_MESSAGE); | |
| 247 | − | if (pos != std::string::npos) { | |
| 248 | − | if (const size_t lineStart = gdbOutput.rfind('\n', pos); lineStart != std::string::npos) | |
| 249 | − | gdbOutput.erase(0, lineStart + 1); | |
| 250 | } | ||
| 251 | |||
| 252 | // Remove inferior message | ||
| 253 | − | pos = gdbOutput.find(GDB_INFERIOR_MESSAGE); | |
| 254 | − | if (pos != std::string::npos) | |
| 255 | − | gdbOutput.erase(pos); | |
| 256 | − | } | |
| 257 | // LCOV_EXCL_STOP | ||
| 258 | |||
| 259 | /** | ||
| 260 | * Remove lines, containing a certain substring to make the IR string comparable | ||
| 261 | * | ||
| 262 | * @param irCode IR code to modify | ||
| 263 | * @param needle Substring to search for | ||
| 264 | */ | ||
| 265 | 12 | void TestUtil::eraseLinesBySubstring(std::string &irCode, const char *const needle) { | |
| 266 | 12 | std::string::size_type pos = 0; | |
| 267 |
2/2✓ Branch 12 → 3 taken 24 times.
✓ Branch 12 → 13 taken 12 times.
|
36 | while ((pos = irCode.find(needle, pos)) != std::string::npos) { |
| 268 | // Find the start of the line that contains the substring | ||
| 269 | 24 | std::string::size_type lineStart = irCode.rfind('\n', pos); | |
| 270 |
1/2✗ Branch 4 → 5 not taken.
✓ Branch 4 → 6 taken 24 times.
|
24 | if (lineStart == std::string::npos) |
| 271 | ✗ | lineStart = 0; | |
| 272 | else | ||
| 273 | 24 | lineStart++; // move past the '\n' | |
| 274 | |||
| 275 | // Find the end of the line that contains the substring | ||
| 276 | 24 | std::string::size_type lineEnd = irCode.find('\n', pos); | |
| 277 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 10 taken 24 times.
|
24 | if (lineEnd == std::string::npos) |
| 278 | ✗ | lineEnd = irCode.length(); | |
| 279 | |||
| 280 | // Erase the line | ||
| 281 | 24 | irCode.erase(lineStart, lineEnd - lineStart); | |
| 282 | } | ||
| 283 | 12 | } | |
| 284 | |||
| 285 | 5270 | std::array<std::filesystem::path, 3> TestUtil::expandRefPaths(const std::filesystem::path &refPath) { | |
| 286 |
1/2✓ Branch 2 → 3 taken 5270 times.
✗ Branch 2 → 83 not taken.
|
5270 | const std::filesystem::path parent = refPath.parent_path(); |
| 287 |
2/4✓ Branch 3 → 4 taken 5270 times.
✗ Branch 3 → 40 not taken.
✓ Branch 4 → 5 taken 5270 times.
✗ Branch 4 → 38 not taken.
|
5270 | const std::string stem = refPath.stem().string(); |
| 288 |
2/4✓ Branch 6 → 7 taken 5270 times.
✗ Branch 6 → 43 not taken.
✓ Branch 7 → 8 taken 5270 times.
✗ Branch 7 → 41 not taken.
|
5270 | const std::string ext = refPath.extension().string(); |
| 289 | // Construct array of files to search for | ||
| 290 |
3/6✓ Branch 9 → 10 taken 5270 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 5270 times.
✗ Branch 10 → 46 not taken.
✓ Branch 11 → 12 taken 5270 times.
✗ Branch 11 → 44 not taken.
|
5270 | const std::string osFileName = stem + "-" + SPICE_TARGET_OS + ext; |
| 291 |
5/10✓ Branch 14 → 15 taken 5270 times.
✗ Branch 14 → 58 not taken.
✓ Branch 15 → 16 taken 5270 times.
✗ Branch 15 → 56 not taken.
✓ Branch 16 → 17 taken 5270 times.
✗ Branch 16 → 54 not taken.
✓ Branch 17 → 18 taken 5270 times.
✗ Branch 17 → 52 not taken.
✓ Branch 18 → 19 taken 5270 times.
✗ Branch 18 → 50 not taken.
|
5270 | const std::string osArchFileName = stem + "-" + SPICE_TARGET_OS + "-" + SPICE_TARGET_ARCH + ext; |
| 292 | 10540 | return {parent / osArchFileName, parent / osFileName, refPath}; | |
| 293 |
5/14✓ Branch 23 → 24 taken 5270 times.
✗ Branch 23 → 67 not taken.
✓ Branch 24 → 25 taken 5270 times.
✗ Branch 24 → 65 not taken.
✓ Branch 25 → 26 taken 5270 times.
✗ Branch 25 → 64 not taken.
✓ Branch 26 → 27 taken 5270 times.
✗ Branch 26 → 62 not taken.
✓ Branch 27 → 28 taken 5270 times.
✗ Branch 27 → 62 not taken.
✗ Branch 68 → 69 not taken.
✗ Branch 68 → 72 not taken.
✗ Branch 70 → 71 not taken.
✗ Branch 70 → 72 not taken.
|
10540 | } |
| 294 | |||
| 295 | } // namespace spice::testing | ||
| 296 |