Browse Source

mftest: Apply test changes and optionally build

Scott Lahteine 4 years ago
parent
commit
96d52649b8
1 changed files with 104 additions and 0 deletions
  1. 104
    0
      buildroot/share/git/mftest

+ 104
- 0
buildroot/share/git/mftest View File

@@ -0,0 +1,104 @@
1
+#!/usr/bin/env bash
2
+#
3
+# mftest [name] [index]
4
+#
5
+# Set configuration options based on a test
6
+# By default it will do megaatmega2560
7
+# Use 'mftest -' to pick from the list.
8
+#
9
+
10
+MFINFO=$(mfinfo) || exit 1
11
+[[ -d Marlin/src ]] || { echo "Please 'cd' up to repo root." ; exit 1 ; }
12
+
13
+TESTPATH=buildroot/share/tests
14
+
15
+shopt -s extglob nocasematch
16
+
17
+# Get test, allowing shorthand
18
+TESTENV=${1:-"mega"}
19
+case $TESTENV in
20
+     due) TESTENV='DUE' ;;
21
+     esp) TESTENV='esp32' ;;
22
+    lin*) TESTENV='linux_native' ;;
23
+ lpc?(8)) TESTENV='LPC1768' ;;
24
+    lpc9) TESTENV='LPC1769' ;;
25
+    mega) TESTENV='megaatmega2560' ;;
26
+     stm) TESTENV='STM32F1' ;;
27
+     t35) TESTENV='teensy35' ;;
28
+  teensy) TESTENV='teensy35' ;;
29
+esac
30
+
31
+# Matching patterns
32
+ISNUM='^[0-9]+$'
33
+ISCMD='^(restore|opt|exec|use|pins|env)_'
34
+ISEXEC='^exec_'
35
+
36
+# List available tests and ask for selection
37
+if [[ $1 == '-' ]]; then
38
+  IND=0
39
+  NAMES=()
40
+  for FILE in $( ls -1 $TESTPATH/*-tests )
41
+  do
42
+    let IND++
43
+    TNAME=${FILE/-tests/}
44
+    TNAME=${TNAME/$TESTPATH\//}
45
+    NAMES+=($TNAME)
46
+    echo " $IND) $TNAME"
47
+  done
48
+
49
+  echo
50
+  for (( ; ; ))
51
+  do
52
+    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 ; }
55
+    echo "Invalid selection."
56
+  done
57
+fi
58
+
59
+# Get the contents of the test file
60
+OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
61
+
62
+# Count up the number of tests
63
+# TODO: List test descriptions with numbers
64
+TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
65
+
66
+# Get the entered or interactive test index
67
+CHOICE=${2:-0}
68
+
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 ; }
80
+fi
81
+
82
+# Finally, run the specified test lines
83
+echo "$OUT" | {
84
+  IND=0
85
+  while IFS= read -r LINE
86
+  do
87
+    if [[ $LINE =~ $ISCMD ]]; then
88
+      ((!IND)) && let IND++
89
+      if [[ $LINE =~ $ISEXEC ]]; then
90
+        ((IND++ > CHOICE)) && break
91
+      else
92
+        ((!HEADER)) && {
93
+          HEADER=1
94
+          echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
95
+        }
96
+        ((IND == CHOICE)) && { echo "$LINE" ; eval "$LINE" ; }
97
+      fi
98
+    fi
99
+  done
100
+}
101
+
102
+# Build the test too?
103
+echo ; read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
104
+[[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && platformio run --project-dir . -e $TESTENV

Loading…
Cancel
Save