1416
This commit is contained in:
parent
1f852acc8f
commit
5feb36ff8f
37
003trace.cc
37
003trace.cc
|
@ -86,9 +86,16 @@ bool Hide_warnings = false;
|
|||
//? cerr << "AAA setup\n"; //? 2
|
||||
Hide_warnings = false;
|
||||
|
||||
:(before "End Types")
|
||||
struct trace_line {
|
||||
string label;
|
||||
string contents;
|
||||
trace_line(string l, string c) :label(l), contents(c) {}
|
||||
};
|
||||
|
||||
:(before "End Tracing")
|
||||
struct trace_stream {
|
||||
vector<pair<string, string> > past_lines; // [(layer label, line)]
|
||||
vector<trace_line> past_lines;
|
||||
// accumulator for current line
|
||||
ostringstream* curr_stream;
|
||||
string curr_layer;
|
||||
|
@ -107,7 +114,7 @@ struct trace_stream {
|
|||
void newline() {
|
||||
if (!curr_stream) return;
|
||||
string curr_contents = curr_stream->str();
|
||||
past_lines.push_back(pair<string, string>(trim(curr_layer), curr_contents)); // preserve indent in contents
|
||||
past_lines.push_back(trace_line(trim(curr_layer), curr_contents)); // preserve indent in contents
|
||||
if (curr_layer == dump_layer || curr_layer == "dump" || dump_layer == "all" ||
|
||||
(!Hide_warnings && curr_layer == "warn"))
|
||||
//? if (dump_layer == "all" && (Current_routine->id == 3 || curr_layer == "schedule")) //? 1
|
||||
|
@ -121,9 +128,10 @@ struct trace_stream {
|
|||
newline();
|
||||
ostringstream output;
|
||||
layer = trim(layer);
|
||||
for (vector<pair<string, string> >::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
|
||||
if (layer.empty() || layer == p->first)
|
||||
output << p->first << ": " << p->second << '\n';
|
||||
for (vector<trace_line>::iterator p = past_lines.begin(); p != past_lines.end(); ++p)
|
||||
if (layer.empty() || layer == p->label) {
|
||||
output << p->label << ": " << p->contents << '\n';
|
||||
}
|
||||
return output.str();
|
||||
}
|
||||
};
|
||||
|
@ -196,13 +204,13 @@ bool check_trace_contents(string FUNCTION, string FILE, int LINE, string expecte
|
|||
Trace_stream->newline();
|
||||
string layer, contents;
|
||||
split_layer_contents(expected_lines.at(curr_expected_line), &layer, &contents);
|
||||
for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
|
||||
//? cerr << "AAA " << layer << ' ' << p->first << '\n'; //? 1
|
||||
if (layer != p->first)
|
||||
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
|
||||
//? cerr << "AAA " << layer << ' ' << p->label << '\n'; //? 1
|
||||
if (layer != p->label)
|
||||
continue;
|
||||
|
||||
//? cerr << "BBB ^" << contents << "$ ^" << p->second << "$\n"; //? 1
|
||||
if (contents != trim(p->second))
|
||||
//? cerr << "BBB ^" << contents << "$ ^" << p->contents << "$\n"; //? 1
|
||||
if (contents != trim(p->contents))
|
||||
continue;
|
||||
|
||||
//? cerr << "CCC\n"; //? 1
|
||||
|
@ -243,9 +251,9 @@ int trace_count(string layer) {
|
|||
int trace_count(string layer, string line) {
|
||||
Trace_stream->newline();
|
||||
long result = 0;
|
||||
for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
|
||||
if (p->first == layer)
|
||||
if (line == "" || p->second == line)
|
||||
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
|
||||
if (layer == p->label)
|
||||
if (line == "" || line == p->contents)
|
||||
++result;
|
||||
}
|
||||
return result;
|
||||
|
@ -307,8 +315,6 @@ string trim(const string& s) {
|
|||
using std::vector;
|
||||
#include<list>
|
||||
using std::list;
|
||||
#include<utility>
|
||||
using std::pair;
|
||||
#include<map>
|
||||
using std::map;
|
||||
#include<set>
|
||||
|
@ -321,6 +327,7 @@ using std::ostream;
|
|||
using std::cin;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
#include<iomanip>
|
||||
|
||||
#include<sstream>
|
||||
using std::istringstream;
|
||||
|
|
2
010vm.cc
2
010vm.cc
|
@ -258,3 +258,5 @@ void dump_memory() {
|
|||
:(before "End Includes")
|
||||
#include <map>
|
||||
using std::map;
|
||||
#include<utility>
|
||||
using std::pair;
|
||||
|
|
|
@ -336,13 +336,13 @@ case TRACE_SHOULD_CONTAIN: {
|
|||
bool check_trace(const string& expected) {
|
||||
//? cerr << "AAA " << expected << '\n'; //? 1
|
||||
Trace_stream->newline();
|
||||
vector<pair<string, string> > expected_lines = parse_trace(expected);
|
||||
vector<trace_line> expected_lines = parse_trace(expected);
|
||||
//? cerr << "BBB " << SIZE(expected_lines) << '\n'; //? 1
|
||||
if (expected_lines.empty()) return true;
|
||||
long long int curr_expected_line = 0;
|
||||
for (vector<pair<string, string> >::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
|
||||
if (expected_lines.at(curr_expected_line).first != p->first) continue;
|
||||
if (expected_lines.at(curr_expected_line).second != p->second) continue;
|
||||
for (vector<trace_line>::iterator p = Trace_stream->past_lines.begin(); p != Trace_stream->past_lines.end(); ++p) {
|
||||
if (expected_lines.at(curr_expected_line).label != p->label) continue;
|
||||
if (expected_lines.at(curr_expected_line).contents != trim(p->contents)) continue;
|
||||
// match
|
||||
++curr_expected_line;
|
||||
if (curr_expected_line == SIZE(expected_lines)) {
|
||||
|
@ -351,20 +351,20 @@ bool check_trace(const string& expected) {
|
|||
}
|
||||
}
|
||||
|
||||
raise << "missing [" << expected_lines.at(curr_expected_line).second << "] "
|
||||
<< "in trace layer " << expected_lines.at(curr_expected_line).first << '\n';
|
||||
raise << "missing [" << expected_lines.at(curr_expected_line).contents << "] "
|
||||
<< "in trace layer " << expected_lines.at(curr_expected_line).label << '\n';
|
||||
Passed = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<pair<string, string> > parse_trace(const string& expected) {
|
||||
vector<trace_line> parse_trace(const string& expected) {
|
||||
vector<string> buf = split(expected, "\n");
|
||||
vector<pair<string, string> > result;
|
||||
vector<trace_line> result;
|
||||
for (long long int i = 0; i < SIZE(buf); ++i) {
|
||||
buf.at(i) = trim(buf.at(i));
|
||||
if (buf.at(i).empty()) continue;
|
||||
long long int delim = buf.at(i).find(": ");
|
||||
result.push_back(pair<string, string>(buf.at(i).substr(0, delim), buf.at(i).substr(delim+2)));
|
||||
result.push_back(trace_line(trim(buf.at(i).substr(0, delim)), trim(buf.at(i).substr(delim+2))));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -425,10 +425,10 @@ case TRACE_SHOULD_NOT_CONTAIN: {
|
|||
// than just printing to stderr
|
||||
bool check_trace_missing(const string& in) {
|
||||
Trace_stream->newline();
|
||||
vector<pair<string, string> > lines = parse_trace(in);
|
||||
vector<trace_line> lines = parse_trace(in);
|
||||
for (long long int i = 0; i < SIZE(lines); ++i) {
|
||||
if (trace_count(lines.at(i).first, lines.at(i).second) != 0) {
|
||||
raise << "unexpected [" << lines.at(i).second << "] in trace layer " << lines.at(i).first << '\n';
|
||||
if (trace_count(lines.at(i).label, lines.at(i).contents) != 0) {
|
||||
raise << "unexpected [" << lines.at(i).contents << "] in trace layer " << lines.at(i).label << '\n';
|
||||
Passed = false;
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue