Use common renode testing script for bluepill and stm32f4.

With this change, the unit tests for stm32f4 are also emabled as part of
the CI. These are the first set of unit tests of the cmsis-nn kernels.

Addresses http://b/172939049
This commit is contained in:
Jakub Jatczak 2020-11-27 16:11:05 +01:00 committed by Advait Jain
parent 4692525ffa
commit 0adfd77d66
9 changed files with 13 additions and 180 deletions

View File

@ -1,21 +0,0 @@
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# This docker configuration file lets you emulate a stm32f4 board
# on an x86 desktop or laptop, which can be useful for debugging and
# automated testing.
FROM antmicro/renode:latest
LABEL maintainer="Pete Warden <petewarden@google.com>"

View File

@ -1,46 +0,0 @@
*** Settings ***
Suite Setup Prepare Tests
Suite Teardown Teardown
Test Setup Reset Emulation
Test Teardown Teardown With Custom Message
Resource ${RENODEKEYWORDS}
*** Variables ***
${CREATE_SNAPSHOT_ON_FAIL} False
${UART} sysbus.cpu.uartSemihosting
${RESC} undefined_RESC
${RENODE_LOG} /tmp/renode.log
${UART_LINE_ON_SUCCESS} ~~~ALL TESTS PASSED~~~
${DIR_WITH_TESTS} undefined_DIR_WTH_TESTS
*** Keywords ***
Prepare Tests
[Documentation] List all binaries with _test suffix and make available from test cases
Setup
@{tests} = List Files In Directory ${DIR_WITH_TESTS} pattern=*_test absolute=True
Set Suite Variable @{tests}
Teardown With Custom Message
[Documentation] Replace robot fail message with shorter one to avoid duplicated UART output in log
Set Test Message ${file} - FAILED
Test Teardown
Test Binary
Remove File ${RENODE_LOG}
Execute Command $logfile = @${RENODE_LOG}
Execute Script ${RESC}
Create Terminal Tester ${UART} timeout=2
Start Emulation
Wait For Line On Uart ${UART_LINE_ON_SUCCESS}
*** Test Cases ***
Run All Bluepill Tests
[Documentation] Runs Bluepill tests and waits for a specific string on the semihosting UART
FOR ${TEST} IN @{tests}
Execute Command Clear
Execute Command $bin = @${TEST}
${_} ${file} = Split Path ${TEST}
Set Test Variable ${file}
Test Binary
Log \t${file} - PASSED console=True
END

View File

@ -1,4 +1,4 @@
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -21,13 +21,5 @@ machine LoadPlatformDescription @platforms/cpus/stm32f4.repl
# These lines are needed to show the results of DebugLog calls in the output.
machine LoadPlatformDescriptionFromString "uartSemihosting: UART.SemihostingUart @ cpu"
showAnalyzer cpu.uartSemihosting Antmicro.Renode.Analyzers.LoggingUartAnalyzer
logFile @/tmp/renode_stm32f4_log.txt
macro reset
"""
sysbus LoadELF $bin
"""
runMacro $reset
cpu.uartSemihosting CreateFileBackend $logfile true

View File

@ -1,23 +0,0 @@
*** Settings ***
Suite Setup Setup
Suite Teardown Teardown
Test Setup Reset Emulation
Resource /opt/renode/tests/renode-keywords.robot
*** Variables ***
${UART} sysbus.cpu.uartSemihosting
*** Test Cases ***
Should Run Stm32f4 Test
[Documentation] Runs a Stm32f4 test and waits for a specific string on the semihosting UART
[Tags] stm32f4 uart tensorflow arm
${BIN} = Get Environment Variable BIN
${SCRIPT} = Get Environment Variable SCRIPT
${EXPECTED} = Get Environment Variable EXPECTED
Execute Command $bin = @${BIN}
Execute Script ${SCRIPT}
Create Terminal Tester ${UART} timeout=60
Start Emulation
Wait For Line On Uart ${EXPECTED}

View File

@ -1,60 +0,0 @@
#!/bin/bash -e
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
#
# Tests a 'stm32f4' STM32F4 ELF by parsing the log output of Renode emulation.
#
# First argument is the ELF location.
# Second argument is a regular expression that's required to be in the output logs
# for the test to pass.
#
# This script must be run from the top-level folder of the tensorflow github
# repository as it mounts `pwd` to the renode docker image (via docker run -v)
# and paths in the docker run command assume the entire tensorflow repo is mounted.
declare -r ROOT_DIR=`pwd`
declare -r TEST_TMPDIR=/tmp/test_stm32f4_binary/
declare -r MICRO_LOG_PATH=${TEST_TMPDIR}
declare -r MICRO_LOG_FILENAME=${MICRO_LOG_PATH}/logs.txt
mkdir -p ${MICRO_LOG_PATH}
docker build -t renode_stm32f4 \
-f ${ROOT_DIR}/tensorflow/lite/micro/testing/Dockerfile.stm32f4 \
${ROOT_DIR}/tensorflow/lite/micro/testing/
exit_code=0
# running in `if` to avoid setting +e
if ! docker run \
--log-driver=none -a stdout -a stderr \
-v ${ROOT_DIR}:/workspace \
-v /tmp:/tmp \
-e BIN=/workspace/$1 \
-e SCRIPT=/workspace/tensorflow/lite/micro/testing/stm32f4.resc \
-e EXPECTED="$2" \
-it renode_stm32f4 \
/bin/bash -c "/opt/renode/tests/test.sh /workspace/tensorflow/lite/micro/testing/stm32f4.robot 2>&1 >${MICRO_LOG_FILENAME}"
then
exit_code=1
fi
echo "LOGS:"
cat ${MICRO_LOG_FILENAME}
if [ $exit_code -eq 0 ]
then
echo "$1: PASS"
else
echo "$1: FAIL - '$2' not found in logs."
fi
exit $exit_code

View File

@ -17,10 +17,11 @@
#
# Parameters:
# ${1} - path to a binary to test or directory (all *_test will be run).
# ${2} - target (bluepill, stm32f4 etc.)
set -e
TARGET=bluepill
TARGET=${2}
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TFLM_ROOT_DIR=${SCRIPT_DIR}/..

View File

@ -39,11 +39,4 @@ readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=re
# Next, build w/o release so that we can run the tests and get additional
# debugging info on failures.
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TAGS=${TAGS} TARGET=${TARGET} build
# TODO(b/149597202): Running tests via renode are disabled as part of the
# continuous integration until we can get Docker running inside Docker. However,
# if this script is run locally, the tests will still be run.
if [[ ${1} != "PRESUBMIT" ]]; then
readable_run make -f tensorflow/lite/micro/tools/make/Makefile TAGS=${TAGS} TARGET=${TARGET} test
fi
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TAGS=${TAGS} TARGET=${TARGET} test

View File

@ -62,12 +62,10 @@ EXCLUDED_EXAMPLE_TESTS := \
tensorflow/lite/micro/examples/image_recognition_experimental/Makefile.inc
MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS))
TEST_SCRIPT := tensorflow/lite/micro/testing/test_bluepill_binary.sh
TEST_SCRIPT := tensorflow/lite/micro/testing/test_with_renode.sh
# We are setting this variable to non-zero to allow us to have a custom
# implementation of `make test` for bluepill
TARGET_SPECIFIC_MAKE_TEST := 1
test: build
$(TEST_SCRIPT) $(BINDIR)
$(TEST_SCRIPT) $(BINDIR) $(TARGET)

View File

@ -64,7 +64,6 @@ EXCLUDED_SRCS := \
$(MAKEFILE_DIR)/downloads/stm32_bare_lib/source/debug_log.c
THIRD_PARTY_CC_SRCS := $(filter-out $(EXCLUDED_SRCS), $(THIRD_PARTY_CC_SRCS))
MICROLITE_CC_SRCS := $(filter-out $(EXCLUDED_SRCS), $(MICROLITE_CC_SRCS))
TEST_SCRIPT := tensorflow/lite/micro/testing/test_stm32f4_binary.sh
# TODO(b/158324045): Examine why some tests fail here.
EXCLUDED_TESTS := \
@ -83,11 +82,11 @@ EXCLUDED_EXAMPLE_TESTS := \
tensorflow/lite/micro/examples/image_recognition_experimental/Makefile.inc
MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS))
# These are microcontroller-specific rules for converting the ELF output
# of the linker into a binary image that can be loaded directly.
OBJCOPY := $(TARGET_TOOLCHAIN_PREFIX)objcopy
TEST_SCRIPT := tensorflow/lite/micro/testing/test_with_renode.sh
$(BINDIR)/%.bin: $(BINDIR)/%
@mkdir -p $(dir $@)
$(OBJCOPY) $< $@ -O binary
# We are setting this variable to non-zero to allow us to have a custom
# implementation of `make test` for bluepill
TARGET_SPECIFIC_MAKE_TEST := 1
test: build
$(TEST_SCRIPT) $(BINDIR) $(TARGET)