Selaa lähdekoodia

Fix and improve mftest

Scott Lahteine 6 vuotta sitten
vanhempi
commit
d4c210f21b
1 muutettua tiedostoa jossa 36 lisäystä ja 16 poistoa
  1. 36
    16
      buildroot/share/git/mftest

+ 36
- 16
buildroot/share/git/mftest Näytä tiedosto

14
 
14
 
15
 shopt -s extglob nocasematch
15
 shopt -s extglob nocasematch
16
 
16
 
17
-# Get test, allowing shorthand
18
-TESTENV=${1:-"mega"}
17
+# Get test
18
+TESTENV=${1:-'-'}
19
+
20
+# Allow shorthand for test name
19
 case $TESTENV in
21
 case $TESTENV in
20
      due) TESTENV='DUE' ;;
22
      due) TESTENV='DUE' ;;
21
      esp) TESTENV='esp32' ;;
23
      esp) TESTENV='esp32' ;;
26
      stm) TESTENV='STM32F1' ;;
28
      stm) TESTENV='STM32F1' ;;
27
      t35) TESTENV='teensy35' ;;
29
      t35) TESTENV='teensy35' ;;
28
   teensy) TESTENV='teensy35' ;;
30
   teensy) TESTENV='teensy35' ;;
31
+       -) ;;
29
 esac
32
 esac
30
 
33
 
31
 # Matching patterns
34
 # Matching patterns
34
 ISEXEC='^exec_'
37
 ISEXEC='^exec_'
35
 
38
 
36
 # List available tests and ask for selection
39
 # List available tests and ask for selection
37
-if [[ $1 == '-' ]]; then
40
+if [[ $TESTENV == '-' ]]; then
38
   IND=0
41
   IND=0
39
   NAMES=()
42
   NAMES=()
40
   for FILE in $( ls -1 $TESTPATH/*-tests )
43
   for FILE in $( ls -1 $TESTPATH/*-tests )
43
     TNAME=${FILE/-tests/}
46
     TNAME=${FILE/-tests/}
44
     TNAME=${TNAME/$TESTPATH\//}
47
     TNAME=${TNAME/$TESTPATH\//}
45
     NAMES+=($TNAME)
48
     NAMES+=($TNAME)
49
+    (( IND < 10 )) && echo -n " "
46
     echo " $IND) $TNAME"
50
     echo " $IND) $TNAME"
47
   done
51
   done
48
 
52
 
50
   for (( ; ; ))
54
   for (( ; ; ))
51
   do
55
   do
52
     read -p "Select a test to apply (1-$IND) : " NAMEIND
56
     read -p "Select a test to apply (1-$IND) : " NAMEIND
53
-    [[ -z "$NAMEIND" ]] && { echo "Quitting." ; exit 1 ; }
54
-    [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; break ; }
57
+    [[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
58
+    [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
55
     echo "Invalid selection."
59
     echo "Invalid selection."
56
   done
60
   done
57
 fi
61
 fi
66
 # Get the entered or interactive test index
70
 # Get the entered or interactive test index
67
 CHOICE=${2:-0}
71
 CHOICE=${2:-0}
68
 
72
 
69
-if [[ $TESTCOUNT > 1 && ( $CHOICE == 0 || $1 == '-' ) ]]; then
70
-  for (( ; ; ))
71
-  do
72
-    read -p "Test '$TESTENV' index (1-$TESTCOUNT) : " CHOICE
73
-    [[ -z "$CHOICE" ]] && CHOICE=1
74
-    [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
75
-    echo "Invalid test index '$CHOICE'."
76
-  done
77
-else
78
-  # Confirm a manually-entered test index
79
-  ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) || { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
73
+# User entered a number?
74
+(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test index '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
75
+
76
+if [[ $CHOICE == 0 ]]; then
77
+  # List test descriptions with numbers
78
+  echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
79
+    IND=0
80
+    SED=$(which gsed || which sed)
81
+    while IFS= read -r LINE
82
+    do
83
+      if [[ $LINE =~ $ISEXEC ]]; then
84
+        DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
85
+        (( ++IND < 10 )) && echo -n " "
86
+        echo " $IND) $DESC"
87
+      fi
88
+    done
89
+  }
90
+  CHOICE=1
91
+  if [[ $TESTCOUNT > 1 ]]; then
92
+    for (( ; ; ))
93
+    do
94
+      read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
95
+      [[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
96
+      [[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
97
+      echo ">>> Invalid test index '$CHOICE'."
98
+    done
99
+  fi
80
 fi
100
 fi
81
 
101
 
82
 # Finally, run the specified test lines
102
 # Finally, run the specified test lines

Loading…
Peruuta
Tallenna