diff --git a/automated/linux/uart-loopback/uart-loopback.arm64 b/automated/linux/uart-loopback/uart-loopback.arm64 new file mode 100755 index 000000000..62a6cba48 Binary files /dev/null and b/automated/linux/uart-loopback/uart-loopback.arm64 differ diff --git a/automated/linux/uart-loopback/uart-loopback.armeabi b/automated/linux/uart-loopback/uart-loopback.armeabi new file mode 100755 index 000000000..c333ce0d2 Binary files /dev/null and b/automated/linux/uart-loopback/uart-loopback.armeabi differ diff --git a/automated/linux/uart-loopback/uart-loopback.sh b/automated/linux/uart-loopback/uart-loopback.sh new file mode 100755 index 000000000..57f346855 --- /dev/null +++ b/automated/linux/uart-loopback/uart-loopback.sh @@ -0,0 +1,169 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Linaro Ltd. + +# shellcheck disable=SC1091 +. ../../lib/sh-test-lib +OUTPUT="$(pwd)/output" +RESULT_FILE="${OUTPUT}/result.txt" + +usage() { + echo "\ + Usage: $0 + [-t ] [-r : + The transmit UART used for the loopback tests + : + The receive UART used for the loopback tests + + This test will perform loopback transmission between two UARTs, + using various baud rates, parity and stop bit settings. + " +} + + +while getopts "t:r:h" opts; do + case "$opts" in + t) TXUART="${OPTARG}" ;; + r) RXUART="${OPTARG}" ;; + h|*) usage ; exit 1 ;; + esac +done + +param_err=0 +if [[ -z "${TXUART}" ]]; then + echo "ERROR: you must use option -t to specify TXUART" + param_err=1 +fi + +if [[ -z "${RXUART}" ]]; then + echo "ERROR: you must use option -r to specify RXUART" + param_err=1 +fi + +if [[ ! param_err -eq 0 ]]; then + usage + exit 1 +fi + +char_device_exists () { + local device=$1 + + if [[ -c ${device} ]]; then + echo true + else + echo false + fi +} + +wait_for_device () { + local device=$1 + local retries=20 + + if [[ -z ${device} ]]; then + echo "You must specifiy a valid device" + exit 1 + fi + + echo -n "Waiting for ${device}: " + for ((i=0;i> "${RESULT_FILE}" + exit 1 +} + +test_one () { + LENGTH=$1 + detect_abi + # shellcheck disable=SC2154 + case "$abi" in + armeabi|arm64|x86_64) ;; + *) warn_msg "Unsupported architecture"; exit 1 ;; + esac + + DIR="$( dirname "$0" )" + if ! "${DIR}"/uart-loopback."${abi}" -o "${TXUART}" -i "${RXUART}" -s "${LENGTH}" -r + then + ERRORS=$((ERRORS+1)); + fi +} + +# Test transfers of lengths that typically throw problems +test_one_cfg () { + local settings="$*" + local errors="${ERRORS}" + + # shellcheck disable=SC2086 + stty -F "${TXUART}" ${settings} + # shellcheck disable=SC2086 + stty -F "${RXUART}" ${settings} + + for length in $(seq 1 33); do + test_one "${length}" + done + + test_one 4095 + test_one 4096 + test_one 4097 + + if [ "${errors}" = "${ERRORS}" ]; then + echo " pass" + else + echo " fail" + fi +} + +uart-loopback () { + # Note that we specify the _changes_ to the tty settings, so don't comment one out! + baudrates=(9600 38400 115200 230400) + for baud in "${baudrates[@]}" ; + do + echo -n "${baud}:8n1:raw" + test_one_cfg "${baud} -parenb -cstopb -crtscts cs8 -ignbrk -brkint -parmrk -istrip -inlcr -igncr -icrnl -ixon -opost -echo -echonl -icanon -isig -iexten" + + echo -n "${baud}:8o1" + test_one_cfg "parenb parodd" + + echo -n "${baud}:8e1" + test_one_cfg "-parodd" + + echo -n "${baud}:8n2" + test_one_cfg "-parenb cstopb" + + echo -n "${baud}:8n1:CTS/RTS" + test_one_cfg "-cstopb crtscts" + + # This is the same as the first test, putting the UART back into 115200 + echo -n "${baud}:8n1:raw" + test_one_cfg "-crtscts" + done + + echo + echo "Tests complete with ${ERRORS} Errors." +} + +loopback_test () { + local logfile + logfile=$(mktemp "/tmp/uart-loopback.log.XXXXXXXXXXXX") + + echo "Testing data transfer from ${TXUART} to ${RXUART}" | tee "${logfile}" + uart-loopback "${TXUART}" "${RXUART}" | tee -a "${logfile}" + sed -i 's/\.//g' "${logfile}" + grep -e "pass" -e "fail" "${logfile}" >> "${RESULT_FILE}" +} + +create_out_dir "${OUTPUT}" +wait_for_device "${TXUART}" +wait_for_device "${RXUART}" +loopback_test diff --git a/automated/linux/uart-loopback/uart-loopback.x86_64 b/automated/linux/uart-loopback/uart-loopback.x86_64 new file mode 100755 index 000000000..ac106f37b Binary files /dev/null and b/automated/linux/uart-loopback/uart-loopback.x86_64 differ diff --git a/automated/linux/uart-loopback/uart-loopback.yaml b/automated/linux/uart-loopback/uart-loopback.yaml new file mode 100644 index 000000000..cc4ae5691 --- /dev/null +++ b/automated/linux/uart-loopback/uart-loopback.yaml @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright (C) 2019 Schneider Electric +metadata: + format: Lava-Test Test Definition 1.0 + name: uart-loopback + description: "UART functional test. + This runs a functional test across two connected UARTs. + It tests baud rates from 9600 to 230400, a selection of + parity, CTS/RTS, and stop bit settings." + maintainer: + - ryan.harkin@linaro.org + os: + - debian + - ubuntu + - fedora + - centos + - openembedded + scope: + - functional + - uart + - loopback + devices: + - rzn1d + - soca9 + +params: + TXUART: "/dev/ttyS1" + RXUART: "/dev/ttyUSB0" + +run: + steps: + - cd ./automated/linux/uart-loopback + - ./uart-loopback.sh -t "${TXUART}" -r "${RXUART}" + - ../../utils/send-to-lava.sh ./output/result.txt