You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
7.4 KiB
Plaintext
234 lines
7.4 KiB
Plaintext
6 years ago
|
#!/usr/bin/env bash
|
||
|
#
|
||
5 years ago
|
# mftest Select a test to apply and build
|
||
5 years ago
|
# mftest -b [#] Build the auto-detected environment
|
||
|
# mftest -u [#] Upload the auto-detected environment
|
||
5 years ago
|
# mftest [name] [index] [-y] Set config options and optionally build a test
|
||
6 years ago
|
#
|
||
|
|
||
|
MFINFO=$(mfinfo) || exit 1
|
||
|
[[ -d Marlin/src ]] || { echo "Please 'cd' up to repo root." ; exit 1 ; }
|
||
|
|
||
|
TESTPATH=buildroot/share/tests
|
||
5 years ago
|
STATE_FILE=$( echo ./.pio/.mftestrc )
|
||
5 years ago
|
SED=$(which gsed || which sed)
|
||
6 years ago
|
|
||
|
shopt -s extglob nocasematch
|
||
|
|
||
5 years ago
|
# Matching patterns
|
||
|
ISNUM='^[0-9]+$'
|
||
|
ISCMD='^(restore|opt|exec|use|pins|env)_'
|
||
|
ISEXEC='^exec_'
|
||
|
ISCONT='\\ *$'
|
||
|
|
||
5 years ago
|
# Get the environment and test number from the command
|
||
6 years ago
|
TESTENV=${1:-'-'}
|
||
5 years ago
|
CHOICE=${2:-0}
|
||
5 years ago
|
AUTOENV=0
|
||
6 years ago
|
|
||
|
# Allow shorthand for test name
|
||
6 years ago
|
case $TESTENV in
|
||
5 years ago
|
tree) pio run -d . -e include_tree ; exit 1 ;;
|
||
6 years ago
|
due) TESTENV='DUE' ;;
|
||
|
esp) TESTENV='esp32' ;;
|
||
|
lin*) TESTENV='linux_native' ;;
|
||
|
lpc?(8)) TESTENV='LPC1768' ;;
|
||
|
lpc9) TESTENV='LPC1769' ;;
|
||
5 years ago
|
m128) TESTENV='mega1280' ;;
|
||
|
m256) TESTENV='mega2560' ;;
|
||
|
mega) TESTENV='mega2560' ;;
|
||
5 years ago
|
stm) TESTENV='STM32F103RE' ;;
|
||
5 years ago
|
f1) TESTENV='STM32F103RE' ;;
|
||
|
f4) TESTENV='STM32F4' ;;
|
||
|
f7) TESTENV='STM32F7' ;;
|
||
|
s6) TESTENV='FYSETC_S6' ;;
|
||
5 years ago
|
teensy) TESTENV='teensy31' ;;
|
||
|
t31) TESTENV='teensy31' ;;
|
||
|
t32) TESTENV='teensy31' ;;
|
||
6 years ago
|
t35) TESTENV='teensy35' ;;
|
||
5 years ago
|
t36) TESTENV='teensy35' ;;
|
||
5 years ago
|
|
||
|
-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
|
||
|
;;
|
||
|
|
||
5 years ago
|
# Build with the last-built env
|
||
|
-r) [[ -f "$STATE_FILE" ]] || { echo "No previous (-r) build state found." ; exit 1 ; }
|
||
|
read TESTENV <"$STATE_FILE"
|
||
5 years ago
|
pio run -d . -e $TESTENV
|
||
|
exit
|
||
|
;;
|
||
|
|
||
5 years ago
|
-[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 )
|
||
5 years ago
|
BNUM=$( $SED -E 's/^.+BOARD_[^ ]+ +([0-9]+).+$/\1/' <<<"$BLINE" )
|
||
|
BDESC=$( $SED -E 's/^.+\/\/ *(.+)$/\1/' <<<"$BLINE" )
|
||
5 years ago
|
[[ -z $BNUM ]] && { echo "Error - Can't find $MB in boards list." ; exit 1 ; }
|
||
5 years ago
|
readarray -t ENVS <<< $( grep -EA1 "MB\(.*\b$MB\b.*\)" Marlin/src/pins/pins.h | grep -E '#include.+//.+env:.+' | grep -oE 'env:[^ ]+' | $SED -E 's/env://' )
|
||
5 years ago
|
[[ -z $ENVS ]] && { echo "Error - Can't find target(s) for $MB ($BNUM)." ; exit 1 ; }
|
||
5 years ago
|
ECOUNT=${#ENVS[*]}
|
||
|
|
||
|
if [[ $ECOUNT == 1 ]]; then
|
||
|
TARGET=$ENVS
|
||
|
else
|
||
|
if [[ $CHOICE == 0 ]]; then
|
||
5 years ago
|
#
|
||
|
# List env names and numbers. Get selection.
|
||
|
#
|
||
5 years ago
|
echo "Available targets for \"$BDESC\" | $MB ($BNUM):"
|
||
|
|
||
5 years ago
|
IND=0 ; for ENV in "${ENVS[@]}"; do let IND++ ; echo " $IND) $ENV" ; done
|
||
5 years ago
|
|
||
|
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)."
|
||
5 years ago
|
[[ $CHOICE > $ECOUNT ]] && { echo "Environment selection out of range." ; exit 1 ; }
|
||
5 years ago
|
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
|
||
5 years ago
|
exit
|
||
|
;;
|
||
5 years ago
|
|
||
|
# The -y flag may come first
|
||
5 years ago
|
-y) TESTENV=${2:-'-'} ; CHOICE=${3:-0} ;;
|
||
5 years ago
|
|
||
5 years ago
|
-[a-z]) echo "Unknown flag $TESTENV" ; exit 1 ;;
|
||
6 years ago
|
-) ;;
|
||
6 years ago
|
esac
|
||
|
|
||
5 years ago
|
#
|
||
6 years ago
|
# List available tests and ask for selection
|
||
5 years ago
|
#
|
||
|
|
||
6 years ago
|
if [[ $TESTENV == '-' ]]; then
|
||
6 years ago
|
IND=0
|
||
|
NAMES=()
|
||
|
for FILE in $( ls -1 $TESTPATH/*-tests )
|
||
|
do
|
||
|
let IND++
|
||
|
TNAME=${FILE/-tests/}
|
||
|
TNAME=${TNAME/$TESTPATH\//}
|
||
|
NAMES+=($TNAME)
|
||
6 years ago
|
(( IND < 10 )) && echo -n " "
|
||
6 years ago
|
echo " $IND) $TNAME"
|
||
|
done
|
||
|
|
||
|
echo
|
||
|
for (( ; ; ))
|
||
|
do
|
||
|
read -p "Select a test to apply (1-$IND) : " NAMEIND
|
||
6 years ago
|
[[ -z "$NAMEIND" ]] && { echo '(canceled)' ; exit 1 ; }
|
||
|
[[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; }
|
||
6 years ago
|
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" )
|
||
|
|
||
6 years ago
|
# User entered a number?
|
||
5 years ago
|
(( CHOICE && CHOICE > TESTCOUNT )) && { echo "Invalid test selection '$CHOICE' (1-$TESTCOUNT)." ; exit 1 ; }
|
||
6 years ago
|
|
||
|
if [[ $CHOICE == 0 ]]; then
|
||
5 years ago
|
#
|
||
|
# List test descriptions with numbers and get selection
|
||
|
#
|
||
6 years ago
|
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
|
||
5 years ago
|
echo ">>> Invalid test selection '$CHOICE'."
|
||
6 years ago
|
done
|
||
|
fi
|
||
6 years ago
|
fi
|
||
|
|
||
5 years ago
|
#
|
||
|
# Run the specified test lines
|
||
|
#
|
||
6 years ago
|
echo "$OUT" | {
|
||
|
IND=0
|
||
6 years ago
|
GOTX=0
|
||
|
CMD=""
|
||
6 years ago
|
while IFS= read -r LINE
|
||
|
do
|
||
6 years ago
|
if [[ $LINE =~ $ISCMD || $GOTX == 1 ]]; then
|
||
6 years ago
|
((!IND)) && let IND++
|
||
|
if [[ $LINE =~ $ISEXEC ]]; then
|
||
|
((IND++ > CHOICE)) && break
|
||
|
else
|
||
|
((!HEADER)) && {
|
||
|
HEADER=1
|
||
|
echo -e "\n#\n# Test $TESTENV ($CHOICE) $DESC\n#"
|
||
|
}
|
||
6 years ago
|
((IND == CHOICE)) && {
|
||
|
GOTX=1
|
||
5 years ago
|
[[ $CMD == "" ]] && CMD="$LINE" || CMD=$( echo -e "$CMD$LINE" | $SED -e 's/\\//g' )
|
||
6 years ago
|
[[ $LINE =~ $ISCONT ]] || { echo $CMD ; eval "$CMD" ; CMD="" ; }
|
||
|
}
|
||
6 years ago
|
fi
|
||
|
fi
|
||
|
done
|
||
|
}
|
||
|
|
||
5 years ago
|
# Make clear it's a TEST
|
||
|
opt_set CUSTOM_MACHINE_NAME "\"$TESTENV-tests ($CHOICE)\""
|
||
|
|
||
5 years ago
|
# Get a -y parameter the lazy way
|
||
|
[[ "$2" == "-y" || "$3" == "-y" ]] && BUILD_YES='Y'
|
||
|
|
||
6 years ago
|
# Build the test too?
|
||
5 years ago
|
if [[ $BUILD_YES != 'Y' ]]; then
|
||
|
echo
|
||
|
read -p "Build $TESTENV test #$CHOICE (y/N) ? " BUILD_YES
|
||
|
fi
|
||
|
|
||
|
[[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && {
|
||
5 years ago
|
pio run -d . -e $TESTENV
|
||
5 years ago
|
echo "$TESTENV" >"$STATE_FILE"
|
||
|
}
|