Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void print_usage_and_exit (std::string error_msg = "") {
std::cout << "\t-d, --out-dir=<out-dir> Output directory\n";
std::cout << "\t-s, --seed=<seed> Predefined seed (it is accepted in form of SSS or VV_SSS)\n";
std::cout << "\t-m, --bit-mode=<32/64> Generated test's bit mode\n";
std::cout << "\t-r, --reduce Generate test with verbose output to help reduce a failed testcase\n";
std::cout << "\t--std=<standard> Generated test's language standard\n";
auto search_for_default_std = [] (const std::pair<std::string, Options::StandardID> &pair) {
return pair.second == options->standard_id;
Expand Down Expand Up @@ -197,6 +198,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")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update help message - see print_usage_and_exit() above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated according to your comment.

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