Read directory of hwdbg script test cases and run each of them.
46{
47 CHAR TempFilePath[MAX_PATH] = {0};
48
49
50
51
52 try
53 {
54 for (const auto & entry : fs::directory_iterator(HwdbgScriptTestCasesPath))
55 {
56
57
58
59 if (entry.is_regular_file())
60 {
61
62
63
64 std::string FilePath = entry.path().string();
65
66
67
68
69
70
71
72
73
74 std::ifstream File(FilePath);
75 if (File.is_open())
76 {
77 std::string Content((std::istreambuf_iterator<char>(File)),
78 std::istreambuf_iterator<char>());
79
80
81
82
83 std::cout << "Reading script test case file " << entry.path().filename().string() << std::endl;
84
85
86
88
89
90
91
92 printf(
"File content: %s\n", Content.c_str());
93
96 CompiledVersionFilePath.c_str(),
98 {
99 std::cout << "[-] Could not run the script: " << FilePath << std::endl;
101 }
102
103
104
105
106
107
108
109
111 {
112
113
114
115 std::cout << "[-] Could not find the compiled version of the hwdbg test case file" << endl;
117 }
118
119 std::ifstream CompiledFile(TempFilePath);
120 if (CompiledFile.is_open())
121 {
122
123
124
125 std::string CompiledContent((std::istreambuf_iterator<char>(CompiledFile)),
126 std::istreambuf_iterator<char>());
127 CompiledFile.close();
128
129
130
131
133
134
135
136
138 entry.path().filename().string() +
139 "\n;\n; !hw script " +
140 CommentedContent +
141 "\n" +
142 CompiledContent;
143
144
145
146
147 std::ofstream CompiledFileOut(TempFilePath);
148 if (CompiledFileOut.is_open())
149 {
150 CompiledFileOut << NewContent;
151 CompiledFileOut.close();
152 }
153 else
154 {
155 std::cerr << "Could not open file for writing: " << CompiledVersionFilePath << std::endl;
156 }
157 }
158 else
159 {
160 std::cerr << "Could not open compiled file: " << CompiledVersionFilePath << std::endl;
161 }
162
163 std::cout << "--------------------------------------------" << std::endl;
164
165
166
167
168 File.close();
169 }
170 else
171 {
172 std::cerr << "Could not open file: " << FilePath << std::endl;
173 }
174 }
175 }
176 }
177 catch (const fs::filesystem_error & e)
178 {
179 std::cerr << "Filesystem error: " << e.what() << std::endl;
181 }
182
183
184
185
187}
#define HWDBG_SCRIPT_TEST_CASE_COMPILED_SCRIPTS_DIRECTORY
Test cases directory name for hwdbg script (compiled-scripts) tests.
Definition Definition.h:115
IMPORT_EXPORT_LIBHYPERDBG BOOLEAN hwdbg_script_run_script(const CHAR *script, const CHAR *instance_filepath_to_read, const CHAR *hardware_script_file_path_to_save, UINT32 initial_bram_buffer_size)
Run hwdbg script.
Definition export.cpp:853
std::string CommentContent(const std::string &Content)
function to comment each line by adding ';' at the start
Definition hwdbg-tests.cpp:23