Skip to content

Commit

Permalink
yarpgen_v1: Add an option to change code output to help preparing a r…
Browse files Browse the repository at this point in the history
…educed 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
  • Loading branch information
winspool committed Mar 8, 2023
1 parent 30072f7 commit 13134e1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ int main (int argc, char* argv[128]) {
else if (!strcmp(argv[i], "-q")) {
quiet = true;
}
else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--reduce")) {
options->reduce = true;
}
else if (parse_long_args(i, argv, "--std", standard_action,
"Can't recognize language standard:")) {}
else if (parse_long_and_short_args(argc, i, argv, "-d", "--out-dir", out_dir_action,
Expand Down
3 changes: 2 additions & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ using namespace yarpgen;
Options* yarpgen::options;

Options::Options() : standard_id(CXX11), mode_64bit(true), windows_mode(false),
include_valarray(false), include_vector(false), include_array(false) {
include_valarray(false), include_vector(false), include_array(false),
reduce(false) {
plane_yarpgen_version = yarpgen_version;
plane_yarpgen_version.erase(std::remove(plane_yarpgen_version.begin(), plane_yarpgen_version.end(), '.'),
plane_yarpgen_version.end());
Expand Down
1 change: 1 addition & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct Options {
bool include_valarray;
bool include_vector;
bool include_array;
bool reduce;
};

extern Options *options;
Expand Down
12 changes: 10 additions & 2 deletions src/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,17 @@ void Program::emit_main () {
tf_prefix = NameHandler::common_test_func_prefix + std::to_string(i) + "_";
out_file << " " << tf_prefix << "init ();\n";
out_file << " " << tf_prefix << "foo ();\n";
out_file << " " << tf_prefix << "checksum ();\n\n";
out_file << " " << tf_prefix << "checksum ();\n";
if (options->reduce) {
out_file << " printf(\"%d:%llu\\n\", __LINE__, seed);\n";
if (i < gen_policy.get_test_func_count()) {
out_file << " seed=0;\n\n";
}
}
}
if (!options->reduce) {
out_file << "\n printf(\"%llu\\n\", seed);\n";
}
out_file << " printf(\"%llu\\n\", seed);\n";
out_file << " return 0;\n";
out_file << "}\n";

Expand Down
20 changes: 20 additions & 0 deletions src/sym_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ void SymbolTable::emit_variable_def (std::ostream& stream, std::string offset) {
void SymbolTable::emit_variable_check (std::ostream& stream, std::string offset) {
for (const auto &i : variable) {
stream << offset + "hash(&seed, " + i->get_name() + ");\n";
if (options->reduce) {
stream << offset + "printf(\"" + i->get_name() + ":%llu\\n\", seed);\n";
stream << offset + "seed=0;\n";
}
}
}

Expand Down Expand Up @@ -300,6 +304,12 @@ void SymbolTable::emit_single_struct_check (std::shared_ptr<MemberExpr> parent_m
stream << offset + "hash(&seed, ";
member_expr->emit(stream);
stream << ");\n";
if (options->reduce) {
stream << offset + "printf(\"";
member_expr->emit(stream);
stream << ":%llu\\n\", seed);\n";
stream << offset + "seed=0;\n";
}
}
}
}
Expand Down Expand Up @@ -357,6 +367,10 @@ void SymbolTable::emit_array_check (std::ostream& stream, std::string offset) {
switch (array_elem->get_class_id()) {
case Data::VAR:
stream << offset + "hash(&seed, " + array_elem->get_name() + ");\n";
if (options->reduce) {
stream << offset + "printf(\"" + array_elem->get_name() + ":%llu\\n\", seed);\n";
stream << offset + "seed=0;\n";
}
break;
case Data::STRUCT:
emit_single_struct_check(nullptr, std::static_pointer_cast<Struct>(array_elem), stream, offset);
Expand Down Expand Up @@ -392,6 +406,12 @@ void SymbolTable::emit_ptr_check (std::ostream& stream, std::string offset) {
stream << offset + "hash(&seed, ";
pointers.deref_expr.at(i)->emit(stream);
stream << ");\n";
if (options->reduce) {
stream << offset + "printf(\"";
pointers.deref_expr.at(i)->emit(stream);
stream << ":%llu\\n\", seed);\n";
stream << offset + "seed=0;\n";
}
}
}

Expand Down

0 comments on commit 13134e1

Please sign in to comment.