Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | set -e |
Ram Penugonda | 61d6218 | 2019-10-22 17:00:00 -0700 | [diff] [blame] | 6 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 7 | function usage() { |
| 8 | cat << USAGE |
| 9 | Usage: ./test/fpga_manual_test.sh -u <UART PORT ATTACHED> -n -p. |
| 10 | -n Controls whether a new fpga bitfile is built |
| 11 | -p Controls whether the existing bitfile at build/lowrisc_systems_top_earlgrey_nexysvideo_0.1 |
| 12 | is programmed. |
| 13 | |
| 14 | The following command builds the fpga, programs it onto the device and begins testing |
| 15 | ./test/fpga_manual_test.sh -u /dev/ttyUSB0 -n -p |
| 16 | |
| 17 | The following command assumes there exists a bitfile already, programs it and begins testing |
| 18 | ./test/fpga_manual_test.sh -u /dev/ttyUSB0 -p |
| 19 | |
| 20 | The following command assumes the bitfile is already programmed and begins testing |
| 21 | ./test/fpga_manual_test.sh -u /dev/ttyUSB0 |
| 22 | |
| 23 | USAGE |
| 24 | } |
| 25 | |
| 26 | FPGA_UART= |
| 27 | BUILD_FPGA=0 |
| 28 | PROGRAM_FPGA=0 |
| 29 | while getopts ':pnu:' opt; do |
| 30 | case "${opt}" in |
| 31 | u) FPGA_UART=$OPTARG;; |
| 32 | n) BUILD_FPGA=1;; |
| 33 | p) PROGRAM_FPGA=1;; |
| 34 | ?) usage && exit 1;; |
| 35 | *) usage |
| 36 | error "Unexpected option ${opt}" |
| 37 | ;; |
| 38 | esac |
| 39 | done |
| 40 | |
| 41 | # Double check a device has been specified |
| 42 | if [ -z "$FPGA_UART" ] ; then |
Ram Penugonda | 61d6218 | 2019-10-22 17:00:00 -0700 | [diff] [blame] | 43 | echo "Please make sure to pass FPGA's UART port as an argument to the script." |
Ram Penugonda | 61d6218 | 2019-10-22 17:00:00 -0700 | [diff] [blame] | 44 | echo "To find out which ttyUSB to use exactly, unplug/plug UART cable and find the last entry in dmesg" |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 45 | echo "Use -h for more usage details" |
Ram Penugonda | 61d6218 | 2019-10-22 17:00:00 -0700 | [diff] [blame] | 46 | exit 1; |
| 47 | fi |
| 48 | |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 49 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 50 | readonly TEST_TARGETS=("flash_ctrl/flash_test.bin" |
| 51 | "hmac/sha256_test.bin" |
| 52 | "rv_timer/rv_timer_test.bin" |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 53 | ) |
| 54 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 55 | BUILD_TARGET=${PWD}/build-fpga |
| 56 | ./meson_init.sh -f |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 57 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 58 | if [ ${BUILD_FPGA} -eq 1 ] ; then |
| 59 | echo "Compiling ROM - this is needed in order for the build step below to correctly infer ROM" |
| 60 | ninja -C ${BUILD_TARGET} sw/device/boot_rom/boot_rom.vmem |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 61 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 62 | echo "Building FPGA." |
| 63 | fusesoc --cores-root . build lowrisc:systems:top_earlgrey_nexysvideo \ |
| 64 | --ROM_INIT_FILE=${BUILD_TARGET}/sw/device/boot_rom/boot_rom.vmem |
| 65 | fi |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 66 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 67 | if [ ${PROGRAM_FPGA} -eq 1 ] ; then |
| 68 | echo "Splice latest boot ROM and program FPGA." |
| 69 | util/fpga/splice_nexysvideo.sh |
| 70 | fusesoc --cores-root . pgm lowrisc:systems:top_earlgrey_nexysvideo |
| 71 | fi |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 72 | |
Ram Penugonda | 61d6218 | 2019-10-22 17:00:00 -0700 | [diff] [blame] | 73 | echo "Build spiflash tool." |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 74 | ninja -C ${BUILD_TARGET} sw/host/spiflash/spiflash |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 75 | |
| 76 | for target in "${TEST_TARGETS[@]}"; do |
Ram Penugonda | 61d6218 | 2019-10-22 17:00:00 -0700 | [diff] [blame] | 77 | echo "Building ${target} binaries." |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 78 | |
| 79 | ninja -C ${BUILD_TARGET} sw/device/tests/${target}/ |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 80 | done |
| 81 | |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 82 | FAIL_TARGETS=() |
| 83 | |
| 84 | # Invoke self contained tests |
| 85 | |
| 86 | set +e |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 87 | for target in "${TEST_TARGETS[@]}"; do |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 88 | echo "Flashing binaries onto FPGA for tests." |
| 89 | pytest -s -v test/systemtest/functional_fpga_test.py \ |
| 90 | --test_bin ${BUILD_TARGET}/sw/device/tests/"${target}" \ |
| 91 | --fpga_uart ${FPGA_UART} \ |
| 92 | --spiflash sw/host/spiflash/spiflash |
| 93 | |
| 94 | if [[ $? == 1 ]]; then |
| 95 | FAIL_TARGETS=("${FAIL_TARGETS[@]}" "${target}") |
| 96 | fi |
| 97 | |
Timothy Chen | 50a2724 | 2019-10-18 16:49:22 -0700 | [diff] [blame] | 98 | done |
Timothy Chen | 4dda5f0 | 2019-10-29 17:17:05 -0700 | [diff] [blame] | 99 | |
| 100 | if [ ${#FAIL_TARGETS[@]} -eq 0 ]; then |
| 101 | echo "TESTS PASS!" |
| 102 | else |
| 103 | echo |
| 104 | echo "Failing targets:" |
| 105 | for target in "${FAIL_TARGETS[@]}"; do |
| 106 | echo "* ${target}" |
| 107 | done |
| 108 | echo |
| 109 | echo "TESTS FAILED!" |
| 110 | exit 1 |
| 111 | fi |