MCPcopy Index your code
hub / github.com/GJDuck/e9patch / runTest

Function runTest

test/regtest/regtest.cpp:52–183  ·  view source on GitHub ↗

* Run a single test case. */

Source from the content-addressed store, hash-verified

50 * Run a single test case.
51 */
52static bool runTest(const struct dirent *test, const std::string &options)
53{
54 std::string in(test->d_name);
55 std::string basename(in, 0, in.size()-3);
56 std::string out(basename);
57 out += ".out";
58 std::string exp(basename);
59 exp += ".exp";
60 std::string exe(basename);
61 exe += ".exe";
62 std::string log(basename);
63 log += ".log";
64 std::string cmd(basename);
65 cmd += ".cmd";
66 std::string diff(basename);
67 diff += ".diff";
68
69 // Step (0): reset
70 unlink(out.c_str());
71 unlink(exe.c_str());
72 unlink(log.c_str());
73 unlink(diff.c_str());
74
75 // Step (1): generate the EXE
76 std::string command("../../e9tool ");
77 if (options != "")
78 {
79 command += options;
80 command += ' ';
81 }
82 command += "-M 'addr >= &\"entry\"' ";
83 FILE *IN = fopen(in.c_str(), "r");
84 if (IN == nullptr)
85 error("failed to open file \"%s\": %s", in.c_str(), strerror(errno));
86 char c;
87 for (int i = 0; (c = getc(IN)) != '\n' && isprint(c) && i < 1024; i++)
88 command += c;
89 fclose(IN);
90 command += " -E data..data_END -E data2...text -E .text..begin -o ";
91 command += exe;
92 command += " >>";
93 command += log;
94 command += " 2>&1";
95
96 FILE *LOG = fopen(log.c_str(), "w");
97 if (LOG != NULL)
98 {
99 fprintf(LOG, "%s\n", command.c_str());
100 fclose(LOG);
101 }
102 printf("\n\t%s\n", command.c_str());
103 int r = system(command.c_str());
104 if (r != 0)
105 {
106 printf("%s%s%s: %sFAILED%s (patching failed with status %d, see %s)\n",
107 (option_tty? YELLOW: ""), basename.c_str(), (option_tty? WHITE: ""),
108 (option_tty? RED: ""), (option_tty? WHITE: ""),
109 r, log.c_str());

Callers 1

mainFunction · 0.85

Calls 11

unlinkFunction · 0.85
fopenFunction · 0.85
errorFunction · 0.85
strerrorFunction · 0.85
getcFunction · 0.85
isprintFunction · 0.85
fcloseFunction · 0.85
statClass · 0.70
fprintfFunction · 0.50
printfFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected