REST/NAMESTORE: rework API
[oweals/gnunet.git] / src / cadet / loopcheck.sh
1 #!/usr/bin/env bash
2 # This script is in the public domain
3 # POSIX shell solution for named pipes and pipestatus,
4 # http://shell.cfajohnson.com/cus-faq-2.html#Q11
5 # run() {
6 #     j=1
7 #     while eval "\${pipestatus_$j+:} false"; do
8 #         unset pipestatus_$j
9 #         j=$(($j+1))
10 #     done
11 #     j=1 com= k=1 l=
12 #     for a; do
13 #         if [ "x$a" = 'x|' ]; then
14 #             com="$com { $l "'3>&-
15 #                          echo "pipestatus_'$j'=$?" >&3
16 #                        } 4>&- |'
17 #             j=$(($j+1)) l=
18 #         else
19 #             l="$l \"\$$k\""
20 #         fi
21 #         k=$(($k+1))
22 #     done
23 #     com="$com $l"' 3>&- >&4 4>&-
24 #                     echo "pipestatus_'$j'=$?"'
25 #     exec 4>&1
26 #     eval "$(exec 3>&1; eval "$com")"
27 #     exec 4>&-
28 #     j=1
29 #     while eval "\${pipestatus_$j+:} false"; do
30 #         eval "[ \$pipestatus_$j -eq 0 ]" || return 1
31 #         j=$(($j+1))
32 #     done
33 #     return 0
34 # }
35
36 # # https://mywiki.wooledge.org/Bashism has another solution:
37 # # mkfifo fifo; command2 <fifo & command1 >fifo; echo "$?"
38
39 while true; do
40     if [ "$1" = "" ]; then
41         echo All
42         taskset 1 make check || break;
43     else
44         echo One
45         LOGFILE="test_`date "+%m.%d-%H:%M:%S"`.log"
46         taskset 01 $1 2>&1 | tee $LOGFILE | grep -v DEBUG;
47         # TODO: Replace $PIPESTATUS with more portable code
48         if [ "${PIPESTATUS[0]}" != "0" ]; then
49             echo "Failed";
50             date;
51             break;
52         fi
53     fi
54     grep cadet test_*.log | grep -B 10 ERROR && break
55     grep cadet test_*.log | grep -B 10 Assert && break
56     ls core* > /dev/null 2>&1 && break
57 done