将最小解释器验证改为fixture驱动
结论:最小解释器 harness 改为读取 G-code fixture,并通过 expected canonical event fixture 验证 G0/G1/feed 输出,后续扩展覆盖可直接新增 fixture。检查:git diff --check 通过;wasm-port/tests/native/verify_native_probes.sh 通过。
This commit is contained in:
@@ -3,14 +3,17 @@
|
||||
#undef private
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "canon_event_sink.hh"
|
||||
|
||||
int main()
|
||||
namespace {
|
||||
|
||||
void initialize_minimal_interp(Interp &interp)
|
||||
{
|
||||
Interp interp;
|
||||
standalone::reset_canon_events();
|
||||
interp._setup.length_units = CANON_UNITS_MM;
|
||||
interp._setup.distance_mode = DISTANCE_MODE::ABSOLUTE;
|
||||
interp._setup.ijk_distance_mode = DISTANCE_MODE::ABSOLUTE;
|
||||
@@ -21,17 +24,63 @@ int main()
|
||||
interp._setup.sequence_number = 0;
|
||||
interp._setup.parameter_occurrence = 0;
|
||||
std::memcpy(interp._readers, Interp::default_readers, sizeof(Interp::default_readers));
|
||||
}
|
||||
|
||||
char line[] = "G0 X1.0 Y2.0 (Comment)\n";
|
||||
std::vector<std::string> load_program(int argc, char **argv)
|
||||
{
|
||||
if (argc <= 1) {
|
||||
return {
|
||||
"G0 X1.0 Y2.0 (Comment)\n",
|
||||
"G1 X3.0 Y4.0 F120.0\n",
|
||||
};
|
||||
}
|
||||
|
||||
std::ifstream input(argv[1]);
|
||||
if (!input) {
|
||||
std::cerr << "failed to open fixture: " << argv[1] << "\n";
|
||||
std::exit(2);
|
||||
}
|
||||
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
while (std::getline(input, line)) {
|
||||
if (!line.empty()) {
|
||||
lines.push_back(line + "\n");
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Interp interp;
|
||||
standalone::reset_canon_events();
|
||||
initialize_minimal_interp(interp);
|
||||
|
||||
const std::vector<std::string> program = load_program(argc, argv);
|
||||
if (program.empty()) {
|
||||
std::cerr << "empty fixture\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
char line[LINELEN] = {0};
|
||||
std::strncpy(line, program.front().c_str(), sizeof(line) - 1);
|
||||
char raw_line[LINELEN] = {0};
|
||||
char cooked_line[LINELEN] = {0};
|
||||
int length = -1;
|
||||
|
||||
const int read_text_rc = interp.read_text(line, nullptr, raw_line, cooked_line, &length);
|
||||
const int downcase_rc = interp.close_and_downcase(line);
|
||||
const int read_rc = interp.read("G0 X1.0 Y2.0 (Comment)\n");
|
||||
const int execute_rc = interp.execute("G0 X1.0 Y2.0 (Comment)\n");
|
||||
const int execute_feed_rc = interp.execute("G1 X3.0 Y4.0 F120.0\n");
|
||||
const int read_rc = interp.read(program.front().c_str());
|
||||
|
||||
initialize_minimal_interp(interp);
|
||||
for (std::size_t idx = 0; idx < program.size(); ++idx) {
|
||||
interp._setup.sequence_number = static_cast<int>(idx + 1);
|
||||
const int execute_rc = interp.execute(program[idx].c_str());
|
||||
std::cout << "execute_line_" << (idx + 1) << "=" << execute_rc << "\n";
|
||||
}
|
||||
|
||||
block block{};
|
||||
const int init_block_rc = interp.init_block(&block);
|
||||
@@ -45,8 +94,6 @@ int main()
|
||||
std::cout << "cooked_line=" << cooked_line << "\n";
|
||||
std::cout << "line_length=" << length << "\n";
|
||||
std::cout << "read=" << read_rc << "\n";
|
||||
std::cout << "execute=" << execute_rc << "\n";
|
||||
std::cout << "execute_feed=" << execute_feed_rc << "\n";
|
||||
std::cout << "setup.linetext=" << interp._setup.linetext << "\n";
|
||||
std::cout << "setup.blocktext=" << interp._setup.blocktext << "\n";
|
||||
std::cout << "setup.line_length=" << interp._setup.line_length << "\n";
|
||||
|
||||
Reference in New Issue
Block a user