From b54fe4c035010fb9cd06a90d981c89df7918d8a0 Mon Sep 17 00:00:00 2001 From: Thibaud Michaud Date: Tue, 9 Dec 2014 14:11:05 +0100 Subject: [PATCH] autfilt: return with exit code 1 if there is no match * src/bin/autfilt.cc: Return with exit code 1 if no match found. * src/tgbaalgos/are_isomorphic.cc,src/tgbatest/degenlskip.test src/tgbatest/explpro2.test,src/tgbatest/explpro3.test src/tgbatest/explpro4.test,src/tgbatest/explprod.test src/tgbatest/neverclaimread.test, src/tgbatest/readsave.test src/tgbatest/tripprod.test: Use exit status to check for output emptiness instead of 'test -n'. * src/tgbatest/isomorph.test: Simplify test. --- src/bin/autfilt.cc | 29 ++++++-- src/tgbaalgos/are_isomorphic.cc | 17 ++--- src/tgbatest/degenlskip.test | 4 +- src/tgbatest/explpro2.test | 2 +- src/tgbatest/explpro3.test | 2 +- src/tgbatest/explpro4.test | 2 +- src/tgbatest/explprod.test | 2 +- src/tgbatest/isomorph.test | 120 +++---------------------------- src/tgbatest/neverclaimread.test | 4 +- src/tgbatest/readsave.test | 4 +- src/tgbatest/tripprod.test | 2 +- 11 files changed, 48 insertions(+), 140 deletions(-) diff --git a/src/bin/autfilt.cc b/src/bin/autfilt.cc index c814e384a..87422b1ca 100644 --- a/src/bin/autfilt.cc +++ b/src/bin/autfilt.cc @@ -49,7 +49,10 @@ static const char argp_program_doc[] ="\ Convert, transform, and filter Büchi automata.\n\ -"; +Exit status:\n\ + 0 if some automata were output\n\ + 1 if no automata were output (no match)\n\ + 2 if any error has been reported"; #define OPT_TGBA 1 @@ -151,6 +154,7 @@ static const struct argp_child children[] = static enum output_format { Dot, Lbtt, Lbtt_t, Spin, Spot, Stats, Hoa } format = Dot; +static bool one_match = false; static const char* stats = ""; static const char* hoa_opt = 0; static spot::option_map extra_options; @@ -412,8 +416,8 @@ namespace auto aut = haut->aut; - // Do this first, because it is cheap and will help most - // algorithms. + // Preprocessing. + if (opt_merge) { aut->merge_transitions(); @@ -421,12 +425,23 @@ namespace opt_are_isomorphic->merge_transitions(); } + // Filters. + + bool matched = true; + + if (opt_isomorph) + matched &= !are_isomorphic(aut, opt_isomorph).empty(); + + one_match |= matched; + + if (!matched) + return 0; + + // Postprocessing. + if (opt_product) aut = spot::product(std::move(aut), opt_product); - if (opt_isomorph && are_isomorphic(aut, opt_isomorph).empty()) - return 0; - aut = post.run(aut, nullptr); if (randomize_st || randomize_tr) @@ -534,5 +549,5 @@ main(int argc, char** argv) { error(2, 0, "%s", e.what()); } - return 0; + return one_match ? 0 : 1; } diff --git a/src/tgbaalgos/are_isomorphic.cc b/src/tgbaalgos/are_isomorphic.cc index 86e3a2692..74bb1e864 100644 --- a/src/tgbaalgos/are_isomorphic.cc +++ b/src/tgbaalgos/are_isomorphic.cc @@ -74,13 +74,10 @@ namespace for (auto& t: a->transitions()) { - if (!a->is_dead_transition(t)) - { - hashout[t.src] ^= spot::wang32_hash(t.cond.id()); - hashout[t.src] ^= spot::wang32_hash(t.acc); - hashin[t.dst] ^= spot::wang32_hash(t.cond.id()); - hashin[t.dst] ^= spot::wang32_hash(t.acc); - } + hashout[t.src] ^= spot::wang32_hash(t.cond.id()); + hashout[t.src] ^= spot::wang32_hash(t.acc); + hashin[t.dst] ^= spot::wang32_hash(t.cond.id()); + hashin[t.dst] ^= spot::wang32_hash(t.acc); } for (unsigned i = 0; i < a->num_states(); ++i) @@ -147,12 +144,10 @@ namespace std::vector trans2; for (auto& t: a1->transitions()) - if (!(a1->is_dead_transition(t))) - trans1.push_back(t); + trans1.push_back(t); for (auto& t: a2->transitions()) - if (!(a2->is_dead_transition(t))) - trans2.push_back(t); + trans2.push_back(t); // Sort the vectors of transitions so that they can be compared. // To use the same metric, the transitions of a1 have to be mapped to diff --git a/src/tgbatest/degenlskip.test b/src/tgbatest/degenlskip.test index c2c81de3c..c05e03c9a 100755 --- a/src/tgbatest/degenlskip.test +++ b/src/tgbatest/degenlskip.test @@ -78,5 +78,5 @@ State: 2 --END-- EOF -test -n "`../../bin/autfilt -F out2 --isomorph expected2`" -test -n "`../../bin/autfilt -F out3 --isomorph expected3`" +run 0 ../../bin/autfilt -F out2 --isomorph expected2 +run 0 ../../bin/autfilt -F out3 --isomorph expected3 diff --git a/src/tgbatest/explpro2.test b/src/tgbatest/explpro2.test index 599c39b7f..2d71926a2 100755 --- a/src/tgbatest/explpro2.test +++ b/src/tgbatest/explpro2.test @@ -78,6 +78,6 @@ State: 2 EOF run 0 ../../bin/autfilt input1 --product input2 --hoa | tee stdout -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input1 input2 stdout expected diff --git a/src/tgbatest/explpro3.test b/src/tgbatest/explpro3.test index 4009ac185..2c6ad241b 100755 --- a/src/tgbatest/explpro3.test +++ b/src/tgbatest/explpro3.test @@ -78,5 +78,5 @@ State: 2 EOF run 0 ../../bin/autfilt input1 --product input2 --hoa | tee stdout -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input1 input2 stdout expected diff --git a/src/tgbatest/explpro4.test b/src/tgbatest/explpro4.test index 0ef9f84b7..dc3648fa8 100755 --- a/src/tgbatest/explpro4.test +++ b/src/tgbatest/explpro4.test @@ -72,6 +72,6 @@ State: 0 EOF run 0 ../../bin/autfilt input1 --product input2 --hoa | tee stdout -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input1 input2 stdout expected diff --git a/src/tgbatest/explprod.test b/src/tgbatest/explprod.test index bc856712c..45005779d 100755 --- a/src/tgbatest/explprod.test +++ b/src/tgbatest/explprod.test @@ -97,6 +97,6 @@ State: 0 EOF run 0 ../../bin/autfilt input1 --product input2 --hoa --small | tee stdout -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input1 input2 stdout expected diff --git a/src/tgbatest/isomorph.test b/src/tgbatest/isomorph.test index 22bbcada2..cfb9e41ce 100755 --- a/src/tgbatest/isomorph.test +++ b/src/tgbatest/isomorph.test @@ -21,116 +21,14 @@ . ./defs -set -e +for i in `seq 0 4`; do + ../../bin/randaut a --seed=$i -S4 --hoa >iso$i + ../../bin/autfilt -F iso$i --randomize --hoa >aut$i +done -../../bin/randaut a b -S10 --hoa >filt - -randomize() -{ - for i in `seq 1 5` - do - ../../bin/autfilt --seed=$i --randomize=$1 -F filt --hoa >> autiso +for i in `seq 0 4`; do + for j in `seq 0 4`; do + exp=$(test $i -eq $j; echo $?) + run $exp ../../bin/autfilt -F aut$i -I iso$j done -} - -randomize s -randomize t -randomize - -run 0 ../../bin/autfilt -F autiso --isomorph filt --hoa >out -test `grep HOA out | wc -l` -eq 15 - -cat >notiso <>notiso <out -test `grep HOA out | wc -l` -eq 0 || exit 1 +done diff --git a/src/tgbatest/neverclaimread.test b/src/tgbatest/neverclaimread.test index 2645b1daf..c42dd9aff 100755 --- a/src/tgbatest/neverclaimread.test +++ b/src/tgbatest/neverclaimread.test @@ -67,7 +67,7 @@ State: 2 {0} --END-- EOF -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input stdout expected @@ -112,7 +112,7 @@ State: 2 {0} --END-- EOF -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input stdout expected diff --git a/src/tgbatest/readsave.test b/src/tgbatest/readsave.test index 88b515057..5c32109dd 100755 --- a/src/tgbatest/readsave.test +++ b/src/tgbatest/readsave.test @@ -90,14 +90,14 @@ EOF run 0 ../../bin/autfilt --merge-transitions --hoa input > stdout cat stdout -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected # Likewise, with a randomly generated TGBA. run 0 ../../bin/randaut -S 20 a b -d 0.2 -a 0.2 -A 2 --hoa | tee input # the first read-write can renumber the states run 0 $autfilt --hoa --merge-transitions input > stdout -test -n "`../../bin/autfilt -F input --isomorph stdout`" +run 0 ../../bin/autfilt -F input --isomorph stdout # But this second output should be the same as the first run 0 $autfilt --hoa stdout > stdout2 diff --git a/src/tgbatest/tripprod.test b/src/tgbatest/tripprod.test index 396c7aad3..dc49ec618 100755 --- a/src/tgbatest/tripprod.test +++ b/src/tgbatest/tripprod.test @@ -107,6 +107,6 @@ EOF run 0 ../../bin/autfilt input1 --product input2 --product input3 --hoa | tee stdout -test -n "`../../bin/autfilt -F stdout --isomorph expected`" +run 0 ../../bin/autfilt -F stdout --isomorph expected rm input1 input2 input3 stdout expected