Commit b54fe4c0 authored by Thibaud Michaud's avatar Thibaud Michaud Committed by Alexandre Duret-Lutz
Browse files

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.
parent 68adcc70
...@@ -49,7 +49,10 @@ ...@@ -49,7 +49,10 @@
static const char argp_program_doc[] ="\ static const char argp_program_doc[] ="\
Convert, transform, and filter Büchi automata.\n\ 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 #define OPT_TGBA 1
...@@ -151,6 +154,7 @@ static const struct argp_child children[] = ...@@ -151,6 +154,7 @@ static const struct argp_child children[] =
static enum output_format { Dot, Lbtt, Lbtt_t, Spin, Spot, Stats, Hoa } static enum output_format { Dot, Lbtt, Lbtt_t, Spin, Spot, Stats, Hoa }
format = Dot; format = Dot;
static bool one_match = false;
static const char* stats = ""; static const char* stats = "";
static const char* hoa_opt = 0; static const char* hoa_opt = 0;
static spot::option_map extra_options; static spot::option_map extra_options;
...@@ -412,8 +416,8 @@ namespace ...@@ -412,8 +416,8 @@ namespace
auto aut = haut->aut; auto aut = haut->aut;
// Do this first, because it is cheap and will help most // Preprocessing.
// algorithms.
if (opt_merge) if (opt_merge)
{ {
aut->merge_transitions(); aut->merge_transitions();
...@@ -421,12 +425,23 @@ namespace ...@@ -421,12 +425,23 @@ namespace
opt_are_isomorphic->merge_transitions(); opt_are_isomorphic->merge_transitions();
} }
if (opt_product) // Filters.
aut = spot::product(std::move(aut), opt_product);
bool matched = true;
if (opt_isomorph)
matched &= !are_isomorphic(aut, opt_isomorph).empty();
one_match |= matched;
if (opt_isomorph && are_isomorphic(aut, opt_isomorph).empty()) if (!matched)
return 0; return 0;
// Postprocessing.
if (opt_product)
aut = spot::product(std::move(aut), opt_product);
aut = post.run(aut, nullptr); aut = post.run(aut, nullptr);
if (randomize_st || randomize_tr) if (randomize_st || randomize_tr)
...@@ -534,5 +549,5 @@ main(int argc, char** argv) ...@@ -534,5 +549,5 @@ main(int argc, char** argv)
{ {
error(2, 0, "%s", e.what()); error(2, 0, "%s", e.what());
} }
return 0; return one_match ? 0 : 1;
} }
...@@ -74,13 +74,10 @@ namespace ...@@ -74,13 +74,10 @@ namespace
for (auto& t: a->transitions()) 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);
hashout[t.src] ^= spot::wang32_hash(t.cond.id()); hashin[t.dst] ^= spot::wang32_hash(t.cond.id());
hashout[t.src] ^= spot::wang32_hash(t.acc); hashin[t.dst] ^= 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) for (unsigned i = 0; i < a->num_states(); ++i)
...@@ -147,12 +144,10 @@ namespace ...@@ -147,12 +144,10 @@ namespace
std::vector<trans_storage_t> trans2; std::vector<trans_storage_t> trans2;
for (auto& t: a1->transitions()) for (auto& t: a1->transitions())
if (!(a1->is_dead_transition(t))) trans1.push_back(t);
trans1.push_back(t);
for (auto& t: a2->transitions()) 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. // 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 // To use the same metric, the transitions of a1 have to be mapped to
......
...@@ -78,5 +78,5 @@ State: 2 ...@@ -78,5 +78,5 @@ State: 2
--END-- --END--
EOF EOF
test -n "`../../bin/autfilt -F out2 --isomorph expected2`" run 0 ../../bin/autfilt -F out2 --isomorph expected2
test -n "`../../bin/autfilt -F out3 --isomorph expected3`" run 0 ../../bin/autfilt -F out3 --isomorph expected3
...@@ -78,6 +78,6 @@ State: 2 ...@@ -78,6 +78,6 @@ State: 2
EOF EOF
run 0 ../../bin/autfilt input1 --product input2 --hoa | tee stdout 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 rm input1 input2 stdout expected
...@@ -78,5 +78,5 @@ State: 2 ...@@ -78,5 +78,5 @@ State: 2
EOF EOF
run 0 ../../bin/autfilt input1 --product input2 --hoa | tee stdout 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 rm input1 input2 stdout expected
...@@ -72,6 +72,6 @@ State: 0 ...@@ -72,6 +72,6 @@ State: 0
EOF EOF
run 0 ../../bin/autfilt input1 --product input2 --hoa | tee stdout 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 rm input1 input2 stdout expected
...@@ -97,6 +97,6 @@ State: 0 ...@@ -97,6 +97,6 @@ State: 0
EOF EOF
run 0 ../../bin/autfilt input1 --product input2 --hoa --small | tee stdout 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 rm input1 input2 stdout expected
...@@ -21,116 +21,14 @@ ...@@ -21,116 +21,14 @@
. ./defs . ./defs
set -e for i in `seq 0 4`; do
../../bin/randaut a --seed=$i -S4 --hoa >iso$i
../../bin/randaut a b -S10 --hoa >filt ../../bin/autfilt -F iso$i --randomize --hoa >aut$i
done
randomize()
{ for i in `seq 0 4`; do
for i in `seq 1 5` for j in `seq 0 4`; do
do exp=$(test $i -eq $j; echo $?)
../../bin/autfilt --seed=$i --randomize=$1 -F filt --hoa >> autiso run $exp ../../bin/autfilt -F aut$i -I iso$j
done done
} 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 <<EOF
HOA: v1
States: 10
Start: 0
AP: 2 "a" "b"
acc-name: all
Acceptance: 0 t
properties: trans-labels explicit-labels state-acc
--BODY--
State: 0
[!0&1] 1
[0&1] 2
State: 1
[!0&!1] 2
[0&!1] 3
[!0&1] 4
State: 2
[0&1] 5
[0&!1] 1
State: 3
[!0&!1] 5
[!0&!1] 1
[!0&1] 0
[0&!1] 6
State: 4
[0&1] 5
[0&1] 0
[!0&1] 7
State: 5
[0&1] 5
[!0&1] 8
State: 6
[0&1] 9
State: 7
[0&!1] 9
[0&1] 1
State: 8
[!0&1] 8
[0&!1] 5
State: 9
[!0&!1] 5
[!0&1] 8
--END--
EOF
cat >>notiso <<EOF
HOA: v1
States: 10
Start: 0
AP: 2 "a" "b"
acc-name: all
Acceptance: 0 t
properties: trans-labels explicit-labels state-acc
--BODY--
State: 0
[!0&1] 1
State: 1
[!0&1] 2
[!0&1] 3
[!0&1] 4
[!0&1] 5
[!0&1] 6
State: 2
[0&1] 7
[!0&1] 0
State: 3
[!0&!1] 0
[!0&1] 6
[0&!1] 8
State: 4
[!0&1] 3
[!0&!1] 9
[!0&!1] 0
State: 5
[0&1] 0
State: 6
[!0&!1] 9
State: 7
[0&!1] 0
[!0&1] 7
[!0&!1] 6
State: 8
[0&1] 6
[!0&!1] 1
[!0&!1] 0
State: 9
[0&!1] 7
[!0&1] 2
[0&1] 1
--END--
EOF
run 0 ../../bin/autfilt -F notiso --isomorph filt --hoa >out
test `grep HOA out | wc -l` -eq 0 || exit 1
...@@ -67,7 +67,7 @@ State: 2 {0} ...@@ -67,7 +67,7 @@ State: 2 {0}
--END-- --END--
EOF EOF
test -n "`../../bin/autfilt -F stdout --isomorph expected`" run 0 ../../bin/autfilt -F stdout --isomorph expected
rm input stdout expected rm input stdout expected
...@@ -112,7 +112,7 @@ State: 2 {0} ...@@ -112,7 +112,7 @@ State: 2 {0}
--END-- --END--
EOF EOF
test -n "`../../bin/autfilt -F stdout --isomorph expected`" run 0 ../../bin/autfilt -F stdout --isomorph expected
rm input stdout expected rm input stdout expected
......
...@@ -90,14 +90,14 @@ EOF ...@@ -90,14 +90,14 @@ EOF
run 0 ../../bin/autfilt --merge-transitions --hoa input > stdout run 0 ../../bin/autfilt --merge-transitions --hoa input > stdout
cat 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. # 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 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 # the first read-write can renumber the states
run 0 $autfilt --hoa --merge-transitions input > stdout 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 # But this second output should be the same as the first
run 0 $autfilt --hoa stdout > stdout2 run 0 $autfilt --hoa stdout > stdout2
......
...@@ -107,6 +107,6 @@ EOF ...@@ -107,6 +107,6 @@ EOF
run 0 ../../bin/autfilt input1 --product input2 --product input3 --hoa | run 0 ../../bin/autfilt input1 --product input2 --product input3 --hoa |
tee stdout tee stdout
test -n "`../../bin/autfilt -F stdout --isomorph expected`" run 0 ../../bin/autfilt -F stdout --isomorph expected
rm input1 input2 input3 stdout expected rm input1 input2 input3 stdout expected
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment