Expand WASM sim-config staging coverage

This commit is contained in:
2026-06-09 07:32:15 +08:00
parent 2658ee3b72
commit 5116b9894d
26 changed files with 5989 additions and 141 deletions

View File

@@ -158,6 +158,61 @@ std::vector<std::string> load_program(int argc, char **argv)
return lines;
}
bool is_uri_unreserved(char value)
{
return (value >= 'A' && value <= 'Z') ||
(value >= 'a' && value <= 'z') ||
(value >= '0' && value <= '9') ||
value == '-' || value == '_' || value == '.' || value == '~';
}
void append_percent_encoded_text(std::ostream &output, const char *text)
{
constexpr char hex[] = "0123456789ABCDEF";
for (const char *cursor = text ? text : ""; *cursor; ++cursor) {
char value = *cursor;
switch (*cursor) {
case '\r':
case '\n':
case '\t':
value = ' ';
break;
default:
break;
}
if (is_uri_unreserved(value)) {
output << value;
} else {
const auto byte = static_cast<unsigned char>(value);
output << '%' << hex[(byte >> 4) & 0x0f] << hex[byte & 0x0f];
}
}
}
void append_run_step(std::ostream &output,
const Interp &interp,
const char *phase,
int step,
int rc)
{
output << "run_step phase=" << phase
<< " step=" << step
<< " rc=" << rc
<< " line=" << interp._setup.sequence_number
<< " x=" << interp._setup.current_x
<< " y=" << interp._setup.current_y
<< " z=" << interp._setup.current_z
<< " a=" << interp._setup.AA_current
<< " b=" << interp._setup.BB_current
<< " c=" << interp._setup.CC_current
<< " u=" << interp._setup.u_current
<< " v=" << interp._setup.v_current
<< " w=" << interp._setup.w_current
<< " statement_uri=";
append_percent_encoded_text(output, interp._setup.linetext);
output << "\n";
}
} // namespace
int main(int argc, char **argv)
@@ -228,6 +283,7 @@ int main(int argc, char **argv)
}
++file_read_count;
std::cout << "file_read_" << file_read_count << "=" << file_read_rc << "\n";
append_run_step(std::cout, file_interp, "read", file_read_count, file_read_rc);
if ((file_read_rc != INTERP_OK) && (file_read_rc != INTERP_EXECUTE_FINISH)) {
if (file_read_rc > INTERP_MIN_ERROR) {
char error_buf[LINELEN] = {0};
@@ -244,6 +300,7 @@ int main(int argc, char **argv)
const int file_execute_rc = file_interp.execute();
++file_execute_count;
std::cout << "file_execute_" << file_execute_count << "=" << file_execute_rc << "\n";
append_run_step(std::cout, file_interp, "execute", file_execute_count, file_execute_rc);
if (file_execute_rc > INTERP_MIN_ERROR) {
char error_buf[LINELEN] = {0};
file_interp.error_text(file_execute_rc, error_buf, sizeof(error_buf));

View File

@@ -264,6 +264,61 @@ void append_tool_table_state(std::ostringstream &output)
output << "tool_index_for_tool_2=" << standalone::find_tool_index_for_tool(2) << "\n";
}
bool is_uri_unreserved(char value)
{
return (value >= 'A' && value <= 'Z') ||
(value >= 'a' && value <= 'z') ||
(value >= '0' && value <= '9') ||
value == '-' || value == '_' || value == '.' || value == '~';
}
void append_percent_encoded_text(std::ostringstream &output, const char *text)
{
constexpr char hex[] = "0123456789ABCDEF";
for (const char *cursor = text ? text : ""; *cursor; ++cursor) {
char value = *cursor;
switch (*cursor) {
case '\r':
case '\n':
case '\t':
value = ' ';
break;
default:
break;
}
if (is_uri_unreserved(value)) {
output << value;
} else {
const auto byte = static_cast<unsigned char>(value);
output << '%' << hex[(byte >> 4) & 0x0f] << hex[byte & 0x0f];
}
}
}
void append_run_step(std::ostringstream &output,
const Interp &interp,
const char *phase,
int step,
int rc)
{
output << "run_step phase=" << phase
<< " step=" << step
<< " rc=" << rc
<< " line=" << interp._setup.sequence_number
<< " x=" << interp._setup.current_x
<< " y=" << interp._setup.current_y
<< " z=" << interp._setup.current_z
<< " a=" << interp._setup.AA_current
<< " b=" << interp._setup.BB_current
<< " c=" << interp._setup.CC_current
<< " u=" << interp._setup.u_current
<< " v=" << interp._setup.v_current
<< " w=" << interp._setup.w_current
<< " statement_uri=";
append_percent_encoded_text(output, interp._setup.linetext);
output << "\n";
}
void append_error_text(std::ostringstream &output, Interp &interp, const char *prefix, int rc)
{
if (rc > INTERP_MIN_ERROR) {
@@ -539,6 +594,7 @@ char *run_file_with_ini_internal(const char *path, const char *ini_path, bool co
++file_read_count;
output << "file_read_" << file_read_count << "=" << read_rc << "\n";
append_run_step(output, interp, "read", file_read_count, read_rc);
if ((read_rc != INTERP_OK) && (read_rc != INTERP_EXECUTE_FINISH)) {
if (read_rc > INTERP_MIN_ERROR) {
char error_buf[LINELEN] = {0};
@@ -555,6 +611,7 @@ char *run_file_with_ini_internal(const char *path, const char *ini_path, bool co
const int execute_rc = interp.execute();
++file_execute_count;
output << "file_execute_" << file_execute_count << "=" << execute_rc << "\n";
append_run_step(output, interp, "execute", file_execute_count, execute_rc);
if (execute_rc > INTERP_MIN_ERROR) {
char error_buf[LINELEN] = {0};
interp.error_text(execute_rc, error_buf, sizeof(error_buf));