blob: 48acb5dd5c7692813d727063c2a26c1a7e7cda57 [file] [log] [blame]
Timothy Chen50a27242019-10-18 16:49:22 -07001#!/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
5set -e
Ram Penugonda61d62182019-10-22 17:00:00 -07006
Timothy Chen4dda5f02019-10-29 17:17:05 -07007function usage() {
8 cat << USAGE
9Usage: ./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
12is programmed.
13
14The 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
17The following command assumes there exists a bitfile already, programs it and begins testing
18./test/fpga_manual_test.sh -u /dev/ttyUSB0 -p
19
20The following command assumes the bitfile is already programmed and begins testing
21./test/fpga_manual_test.sh -u /dev/ttyUSB0
22
23USAGE
24}
25
26FPGA_UART=
27BUILD_FPGA=0
28PROGRAM_FPGA=0
29while 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
39done
40
41# Double check a device has been specified
42if [ -z "$FPGA_UART" ] ; then
Ram Penugonda61d62182019-10-22 17:00:00 -070043 echo "Please make sure to pass FPGA's UART port as an argument to the script."
Ram Penugonda61d62182019-10-22 17:00:00 -070044 echo "To find out which ttyUSB to use exactly, unplug/plug UART cable and find the last entry in dmesg"
Timothy Chen4dda5f02019-10-29 17:17:05 -070045 echo "Use -h for more usage details"
Ram Penugonda61d62182019-10-22 17:00:00 -070046 exit 1;
47fi
48
Timothy Chen50a27242019-10-18 16:49:22 -070049
Timothy Chen4dda5f02019-10-29 17:17:05 -070050readonly TEST_TARGETS=("flash_ctrl/flash_test.bin"
51 "hmac/sha256_test.bin"
52 "rv_timer/rv_timer_test.bin"
Timothy Chen50a27242019-10-18 16:49:22 -070053)
54
Timothy Chen4dda5f02019-10-29 17:17:05 -070055BUILD_TARGET=${PWD}/build-fpga
56./meson_init.sh -f
Timothy Chen50a27242019-10-18 16:49:22 -070057
Timothy Chen4dda5f02019-10-29 17:17:05 -070058if [ ${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 Chen50a27242019-10-18 16:49:22 -070061
Timothy Chen4dda5f02019-10-29 17:17:05 -070062 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
65fi
Timothy Chen50a27242019-10-18 16:49:22 -070066
Timothy Chen4dda5f02019-10-29 17:17:05 -070067if [ ${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
71fi
Timothy Chen50a27242019-10-18 16:49:22 -070072
Ram Penugonda61d62182019-10-22 17:00:00 -070073echo "Build spiflash tool."
Timothy Chen4dda5f02019-10-29 17:17:05 -070074ninja -C ${BUILD_TARGET} sw/host/spiflash/spiflash
Timothy Chen50a27242019-10-18 16:49:22 -070075
76for target in "${TEST_TARGETS[@]}"; do
Ram Penugonda61d62182019-10-22 17:00:00 -070077 echo "Building ${target} binaries."
Timothy Chen4dda5f02019-10-29 17:17:05 -070078
79 ninja -C ${BUILD_TARGET} sw/device/tests/${target}/
Timothy Chen50a27242019-10-18 16:49:22 -070080done
81
Timothy Chen4dda5f02019-10-29 17:17:05 -070082FAIL_TARGETS=()
83
84# Invoke self contained tests
85
86set +e
Timothy Chen50a27242019-10-18 16:49:22 -070087for target in "${TEST_TARGETS[@]}"; do
Timothy Chen4dda5f02019-10-29 17:17:05 -070088 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 Chen50a27242019-10-18 16:49:22 -070098done
Timothy Chen4dda5f02019-10-29 17:17:05 -070099
100if [ ${#FAIL_TARGETS[@]} -eq 0 ]; then
101 echo "TESTS PASS!"
102else
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
111fi