2019-07-07 06:04:49 -05:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
2020-02-09 20:48:03 -06:00
|
|
|
# mftest Select a test to apply and build
|
2020-02-15 01:23:36 -06:00
|
|
|
# mftest -b [#] Build the auto-detected environment
|
|
|
|
# mftest -u [#] Upload the auto-detected environment
|
2020-02-09 20:48:03 -06:00
|
|
|
# mftest [name] [index] [-y] Set config options and optionally build a test
|
2019-07-07 06:04:49 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
MFINFO=$(mfinfo) || exit 1
|
|
|
|
[[ -d Marlin/src ]] || { echo "Please 'cd' up to repo root." ; exit 1 ; }
|
|
|
|
|
|
|
|
TESTPATH=buildroot/share/tests
|
2019-10-06 21:03:11 -05:00
|
|
|
STATE_FILE=$( echo ./.pio/.mftestrc )
|
2020-02-09 20:48:03 -06:00
|
|
|
SED=$(which gsed || which sed)
|
2019-07-07 06:04:49 -05:00
|
|
|
|
|
|
|
shopt -s extglob nocasematch
|
|
|
|
|
2020-02-09 20:48:03 -06:00
|
|
|
# Matching patterns
|
|
|
|
ISNUM='^[0-9]+$'
|
|
|
|
ISCMD='^(restore|opt|exec|use|pins|env)_'
|
|
|
|
ISEXEC='^exec_'
|
|
|
|
ISCONT='\\ *$'
|
|
|
|
|
2019-10-06 21:03:11 -05:00
|
|
|
# Get the environment and test number from the command
|
2019-07-10 05:55:51 -05:00
|
|
|
TESTENV=${1:-'-'}
|
2019-10-06 21:03:11 -05:00
|
|
|
CHOICE=${2:-0}
|
2020-02-09 20:48:03 -06:00
|
|
|
AUTOENV=0
|
2019-07-10 05:55:51 -05:00
|
|
|
|
|
|
|
# Allow shorthand for test name
|
2019-07-07 06:04:49 -05:00
|
|
|
case $TESTENV in
|
2020-02-09 20:48:03 -06:00
|
|
|
tree) pio run -d . -e include_tree ; exit 1 ;;
|
2019-07-07 06:04:49 -05:00
|
|
|
due) TESTENV='DUE' ;;
|
|
|
|
esp) TESTENV='esp32' ;;
|
|
|
|
lin*) TESTENV='linux_native' ;;
|
|
|
|
lpc?(8)) TESTENV='LPC1768' ;;
|
|
|
|
lpc9) TESTENV='LPC1769' ;;
|
2019-09-11 20:49:15 -05:00
|
|
|
m128) TESTENV='megaatmega1280' ;;
|
|
|
|
m256) TESTENV='megaatmega2560' ;;
|
2019-07-07 06:04:49 -05:00
|
|
|
mega) TESTENV='megaatmega2560' ;;
|
2019-09-29 02:04:53 -05:00
|
|
|
stm) TESTENV='STM32F103RE' ;;
|
2020-02-15 01:23:36 -06:00
|
|
|
f1) TESTENV='STM32F103RE' ;;
|
|
|
|
f4) TESTENV='STM32F4' ;;
|
|
|
|
f7) TESTENV='STM32F7' ;;
|
|
|
|
s6) TESTENV='FYSETC_S6' ;;
|
2019-08-02 11:30:30 -05:00
|
|
|
teensy) TESTENV='teensy31' ;;
|
|
|
|
t31) TESTENV='teensy31' ;;
|
|
|
|
t32) TESTENV='teensy31' ;;
|
2019-07-07 06:04:49 -05:00
|
|
|
t35) TESTENV='teensy35' ;;
|
2019-08-02 11:30:30 -05:00
|
|
|
t36) TESTENV='teensy35' ;;
|
2020-02-15 01:23:36 -06:00
|
|
|
|
|
|
|
-h|--help) echo -e "$(basename $0) : Marlin Firmware test, build, and upload\n"
|
|
|
|
echo "Usage: $(basename $0) ................. Select env and test to apply / run"
|
|
|
|
echo " $(basename $0) [-y] env ........ Select a test for env to apply / run"
|
|
|
|
echo " $(basename $0) [-y] env test ... Apply / run the specified env test"
|
|
|
|
echo " $(basename $0) -b [variant] .... Auto-build the specified variant"
|
|
|
|
echo " $(basename $0) -u [variant] .... Auto-build and upload the specified variant"
|
|
|
|
echo
|
|
|
|
echo "env shortcuts: tree due esp lin lpc|lpc8 lpc9 m128 m256|mega stm|f1 f4 f7 s6 teensy|t31|t32 t35|t36"
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
2019-10-06 21:03:11 -05:00
|
|
|
# Build with the last-built env
|
|
|
|
-r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
|
|
|
|
read TESTENV <"$STATE_FILE"
|
2020-02-09 20:48:03 -06:00
|
|
|
pio run -d . -e $TESTENV
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
2020-02-15 01:23:36 -06:00
|
|
|
-[bu]) MB=$( grep -E "^\s*#define MOTHERBOARD" Marlin/Configuration.h | awk '{ print $3 }' | $SED 's/BOARD_//' )
|
|
|
|
[[ -z $MB ]] && { echo "Error - Can't read MOTHERBOARD setting." ; exit 1 ; }
|
|
|
|
BLINE=$( grep -E "define\s+BOARD_$MB\b" Marlin/src/core/boards.h )
|
2020-02-09 20:48:03 -06:00
|
|
|
BNUM=$( $SED -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
|
|
|
|
BDESC=$( $SED -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
|
2020-02-15 01:23:36 -06:00
|
|
|
[[ -z $BNUM ]] && { echo "Error - Can't find $MB in boards list." ; exit 1 ; }
|
|
|
|
readarray -t ENVS <<< $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | $SED -n '2 p' | grep -oE 'env:[^ ]+' | $SED -E 's/env://' )
|
|
|
|
[[ -z $ENVS ]] && { echo "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
|
2020-02-09 20:48:03 -06:00
|
|
|
ECOUNT=${#ENVS[*]}
|
|
|
|
|
|
|
|
if [[ $ECOUNT == 1 ]]; then
|
|
|
|
TARGET=$ENVS
|
|
|
|
else
|
|
|
|
if [[ $CHOICE == 0 ]]; then
|
2020-02-15 01:23:36 -06:00
|
|
|
#
|
|
|
|
# List env names and numbers. Get selection.
|
|
|
|
#
|
2020-02-09 20:48:03 -06:00
|
|
|
echo "Available targets for \"$BDESC\" | $MB ($BNUM):"
|
|
|
|
|
2020-02-15 01:23:36 -06:00
|
|
|
IND=0 ; for ENV in "${ENVS[@]}"; do let IND++ ; echo " $IND) $ENV" ; done
|
2020-02-09 20:48:03 -06:00
|
|
|
|
|
|
|
if [[ $ECOUNT > 1 ]]; then
|
|
|
|
for (( ; ; ))
|
|
|
|
do
|
|
|
|
read -p "Select a target for '$MB' (1-$ECOUNT) : " CHOICE
|
|
|
|
[[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
|
|
|
|
[[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= ECOUNT)) && break
|
|
|
|
echo ">>> Invalid environment choice '$CHOICE'."
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Detected \"$BDESC\" | $MB ($BNUM)."
|
2020-02-15 01:23:36 -06:00
|
|
|
[[ $CHOICE > $ECOUNT ]] && { echo "Environment selection out of range." ; exit 1 ; }
|
2020-02-09 20:48:03 -06:00
|
|
|
fi
|
|
|
|
TARGET="${ENVS[$CHOICE-1]}"
|
|
|
|
echo "Selected $TARGET"
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$TARGET" >"$STATE_FILE"
|
|
|
|
|
|
|
|
if [[ $TESTENV == "-u" ]]; then
|
|
|
|
echo "Build/Uploading environment $TARGET for board $MB ($BNUM)..." ; echo
|
|
|
|
pio run -t upload -e $TARGET
|
|
|
|
else
|
|
|
|
echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo
|
|
|
|
pio run -e $TARGET
|
|
|
|
fi
|
2019-10-06 21:03:11 -05:00
|
|
|
exit
|
|
|
|
;;
|
2020-02-09 20:48:03 -06:00
|
|
|
|
|
|
|
# The -y flag may come first
|
2019-10-06 21:03:11 -05:00
|
|
|
-y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
|
2020-02-09 20:48:03 -06:00
|
|
|
|
2019-10-06 21:03:11 -05:00
|
|
|
-[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
|
2019-07-10 05:55:51 -05:00
|
|
|
-) ;;
|
2019-07-07 06:04:49 -05:00
|
|
|
esac
|
|
|
|
|
2020-02-09 20:48:03 -06:00
|
|
|
#
|
2019-07-07 06:04:49 -05:00
|
|
|
# List available tests and ask for selection
|
2020-02-09 20:48:03 -06:00
|
|
|
#
|
|
|
|
|
2019-07-10 05:55:51 -05:00
|
|
|
if [[ $TESTENV == '-' ]]; then
|
2019-07-07 06:04:49 -05:00
|
|
|
IND=0
|
|
|
|
NAMES=()
|
|
|
|
for FILE in $( ls -1 $TESTPATH/*-tests )
|
|
|
|
do
|
|
|
|
let IND++
|
|
|
|
TNAME=${FILE/-tests/}
|
|
|
|
TNAME=${TNAME/$TESTPATH\//}
|
|
|
|
NAMES+=($TNAME)
|
2019-07-10 05:55:51 -05:00
|
|
|
(( IND < 10 )) && echo -n " "
|
2019-07-07 06:04:49 -05:00
|
|
|
echo " $IND) $TNAME"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo
|
|
|
|
for (( ; ; ))
|
|
|
|
do
|
|
|
|
read -p "Select a test to apply (1-$IND) : " NAMEIND
|
2019-07-10 05:55:51 -05:00
|
|
|
[[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
|
|
|
|
[[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
|
2019-07-07 06:04:49 -05:00
|
|
|
echo "Invalid selection."
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Get the contents of the test file
|
|
|
|
OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { echo "Can't find test '$TESTENV'." ; exit 1 ; }
|
|
|
|
|
|
|
|
# Count up the number of tests
|
|
|
|
TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" )
|
|
|
|
|
2019-07-10 05:55:51 -05:00
|
|
|
# User entered a number?
|
2020-02-09 20:48:03 -06:00
|
|
|
(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test selection '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
|
2019-07-10 05:55:51 -05:00
|
|
|
|
|
|
|
if [[ $CHOICE == 0 ]]; then
|
2020-02-09 20:48:03 -06:00
|
|
|
#
|
|
|
|
# List test descriptions with numbers and get selection
|
|
|
|
#
|
2019-07-10 05:55:51 -05:00
|
|
|
echo "Available '$TESTENV' tests:" ; echo "$OUT" | {
|
|
|
|
IND=0
|
|
|
|
while IFS= read -r LINE
|
|
|
|
do
|
|
|
|
if [[ $LINE =~ $ISEXEC ]]; then
|
|
|
|
DESC=$( "$SED" -E 's/^.+"(.*)".*$/\1/g' <<<"$LINE" )
|
|
|
|
(( ++IND < 10 )) && echo -n " "
|
|
|
|
echo " $IND) $DESC"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
CHOICE=1
|
|
|
|
if [[ $TESTCOUNT > 1 ]]; then
|
|
|
|
for (( ; ; ))
|
|
|
|
do
|
|
|
|
read -p "Select a '$TESTENV' test (1-$TESTCOUNT) : " CHOICE
|
|
|
|
[[ -z "$CHOICE" ]] && { echo '(canceled)' ; exit 1 ; }
|
|
|
|
[[ $CHOICE =~ $ISNUM ]] && ((CHOICE >= 1 && CHOICE <= TESTCOUNT)) && break
|
2020-02-09 20:48:03 -06:00
|
|
|
echo ">>> Invalid test selection '$CHOICE'."
|
2019-07-10 05:55:51 -05:00
|
|
|
done
|
|
|
|
fi
|
2019-07-07 06:04:49 -05:00
|
|
|
fi
|
|
|
|
|
2020-02-09 20:48:03 -06:00
|
|
|
#
|
|
|
|
# Run the specified test lines
|
|
|
|
#
|
2019-07-07 06:04:49 -05:00
|
|
|
echo "$OUT" | {
|
|
|
|
IND=0
|
2019-07-14 11:36:44 -05:00
|
|
|
GOTX=0
|
|
|
|
CMD=""
|
2019-07-07 06:04:49 -05:00
|
|
|
while IFS= read -r LINE
|
|
|
|
do
|
2019-07-14 11:36:44 -05:00
|
|
|
if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
|
2019-07-07 06:04:49 -05:00
|
|
|
((!IND)) && let IND++
|
|
|
|
if [[ $LINE =~ $ISEXEC ]]; then
|
|
|
|
((IND++ > CHOICE)) && break
|
|
|
|
else
|
|
|
|
((!HEADER)) && {
|
|
|
|
HEADER=1
|
|
|
|
echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
|
|
|
|
}
|
2019-07-14 11:36:44 -05:00
|
|
|
((IND == CHOICE)) && {
|
|
|
|
GOTX=1
|
2020-02-09 20:48:03 -06:00
|
|
|
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' )
|
2019-07-14 11:36:44 -05:00
|
|
|
[[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
|
|
|
|
}
|
2019-07-07 06:04:49 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-10-06 21:03:11 -05:00
|
|
|
# Get a -y parameter the lazy way
|
|
|
|
[[ "$2" == "-y" || "$3" == "-y" ]] && BUILD_YES='Y'
|
|
|
|
|
2019-07-07 06:04:49 -05:00
|
|
|
# Build the test too?
|
2019-10-06 21:03:11 -05:00
|
|
|
if [[ $BUILD_YES != 'Y' ]]; then
|
|
|
|
echo
|
|
|
|
read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
|
|
|
|
fi
|
|
|
|
|
|
|
|
[[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
|
2020-02-09 20:48:03 -06:00
|
|
|
pio run -d . -e $TESTENV
|
2019-10-06 21:03:11 -05:00
|
|
|
echo "$TESTENV" >"$STATE_FILE"
|
|
|
|
}
|