Skip to content

Commit 13134e1

Browse files
committed
yarpgen_v1: Add an option to change code output to help preparing a reduced testcase.
This patch adda a new option "--reduce" ("-r") and changes the code output to print (and reset) the hash for every entry in all checksum functions. * Redirecting the output of the compiled program to a result file is needed. * Using a "diff -u" on the result files, finding and removing the working testcode is an easy way to get a reduced testcase. Example: https://savannah.nongnu.org/bugs/?63895 -- Regards ... Detlef
1 parent 30072f7 commit 13134e1

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

src/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ int main (int argc, char* argv[128]) {
197197
else if (!strcmp(argv[i], "-q")) {
198198
quiet = true;
199199
}
200+
else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--reduce")) {
201+
options->reduce = true;
202+
}
200203
else if (parse_long_args(i, argv, "--std", standard_action,
201204
"Can't recognize language standard:")) {}
202205
else if (parse_long_and_short_args(argc, i, argv, "-d", "--out-dir", out_dir_action,

src/options.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ using namespace yarpgen;
2525
Options* yarpgen::options;
2626

2727
Options::Options() : standard_id(CXX11), mode_64bit(true), windows_mode(false),
28-
include_valarray(false), include_vector(false), include_array(false) {
28+
include_valarray(false), include_vector(false), include_array(false),
29+
reduce(false) {
2930
plane_yarpgen_version = yarpgen_version;
3031
plane_yarpgen_version.erase(std::remove(plane_yarpgen_version.begin(), plane_yarpgen_version.end(), '.'),
3132
plane_yarpgen_version.end());

src/options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct Options {
5353
bool include_valarray;
5454
bool include_vector;
5555
bool include_array;
56+
bool reduce;
5657
};
5758

5859
extern Options *options;

src/program.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,17 @@ void Program::emit_main () {
395395
tf_prefix = NameHandler::common_test_func_prefix + std::to_string(i) + "_";
396396
out_file << " " << tf_prefix << "init ();\n";
397397
out_file << " " << tf_prefix << "foo ();\n";
398-
out_file << " " << tf_prefix << "checksum ();\n\n";
398+
out_file << " " << tf_prefix << "checksum ();\n";
399+
if (options->reduce) {
400+
out_file << " printf(\"%d:%llu\\n\", __LINE__, seed);\n";
401+
if (i < gen_policy.get_test_func_count()) {
402+
out_file << " seed=0;\n\n";
403+
}
404+
}
405+
}
406+
if (!options->reduce) {
407+
out_file << "\n printf(\"%llu\\n\", seed);\n";
399408
}
400-
out_file << " printf(\"%llu\\n\", seed);\n";
401409
out_file << " return 0;\n";
402410
out_file << "}\n";
403411

src/sym_table.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ void SymbolTable::emit_variable_def (std::ostream& stream, std::string offset) {
201201
void SymbolTable::emit_variable_check (std::ostream& stream, std::string offset) {
202202
for (const auto &i : variable) {
203203
stream << offset + "hash(&seed, " + i->get_name() + ");\n";
204+
if (options->reduce) {
205+
stream << offset + "printf(\"" + i->get_name() + ":%llu\\n\", seed);\n";
206+
stream << offset + "seed=0;\n";
207+
}
204208
}
205209
}
206210

@@ -300,6 +304,12 @@ void SymbolTable::emit_single_struct_check (std::shared_ptr<MemberExpr> parent_m
300304
stream << offset + "hash(&seed, ";
301305
member_expr->emit(stream);
302306
stream << ");\n";
307+
if (options->reduce) {
308+
stream << offset + "printf(\"";
309+
member_expr->emit(stream);
310+
stream << ":%llu\\n\", seed);\n";
311+
stream << offset + "seed=0;\n";
312+
}
303313
}
304314
}
305315
}
@@ -357,6 +367,10 @@ void SymbolTable::emit_array_check (std::ostream& stream, std::string offset) {
357367
switch (array_elem->get_class_id()) {
358368
case Data::VAR:
359369
stream << offset + "hash(&seed, " + array_elem->get_name() + ");\n";
370+
if (options->reduce) {
371+
stream << offset + "printf(\"" + array_elem->get_name() + ":%llu\\n\", seed);\n";
372+
stream << offset + "seed=0;\n";
373+
}
360374
break;
361375
case Data::STRUCT:
362376
emit_single_struct_check(nullptr, std::static_pointer_cast<Struct>(array_elem), stream, offset);
@@ -392,6 +406,12 @@ void SymbolTable::emit_ptr_check (std::ostream& stream, std::string offset) {
392406
stream << offset + "hash(&seed, ";
393407
pointers.deref_expr.at(i)->emit(stream);
394408
stream << ");\n";
409+
if (options->reduce) {
410+
stream << offset + "printf(\"";
411+
pointers.deref_expr.at(i)->emit(stream);
412+
stream << ":%llu\\n\", seed);\n";
413+
stream << offset + "seed=0;\n";
414+
}
395415
}
396416
}
397417

0 commit comments

Comments
 (0)