From 0adfd77d664e62a11724d10a0b27fbc14901f47f Mon Sep 17 00:00:00 2001 From: Jakub Jatczak Date: Fri, 27 Nov 2020 16:11:05 +0100 Subject: [PATCH] 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 --- .../lite/micro/testing/Dockerfile.stm32f4 | 21 ------- .../lite/micro/testing/bluepill.robot.txt | 46 -------------- tensorflow/lite/micro/testing/stm32f4.resc | 12 +--- .../lite/micro/testing/stm32f4.robot.txt | 23 ------- .../lite/micro/testing/test_stm32f4_binary.sh | 60 ------------------- ...bluepill_binary.sh => test_with_renode.sh} | 3 +- .../lite/micro/tools/ci_build/test_stm32f4.sh | 9 +-- .../tools/make/targets/bluepill_makefile.inc | 6 +- .../tools/make/targets/stm32f4_makefile.inc | 13 ++-- 9 files changed, 13 insertions(+), 180 deletions(-) delete mode 100644 tensorflow/lite/micro/testing/Dockerfile.stm32f4 delete mode 100644 tensorflow/lite/micro/testing/bluepill.robot.txt delete mode 100644 tensorflow/lite/micro/testing/stm32f4.robot.txt delete mode 100755 tensorflow/lite/micro/testing/test_stm32f4_binary.sh rename tensorflow/lite/micro/testing/{test_bluepill_binary.sh => test_with_renode.sh} (98%) diff --git a/tensorflow/lite/micro/testing/Dockerfile.stm32f4 b/tensorflow/lite/micro/testing/Dockerfile.stm32f4 deleted file mode 100644 index 75e6118c5ef..00000000000 --- a/tensorflow/lite/micro/testing/Dockerfile.stm32f4 +++ /dev/null @@ -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 " \ No newline at end of file diff --git a/tensorflow/lite/micro/testing/bluepill.robot.txt b/tensorflow/lite/micro/testing/bluepill.robot.txt deleted file mode 100644 index 0a31f085d38..00000000000 --- a/tensorflow/lite/micro/testing/bluepill.robot.txt +++ /dev/null @@ -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 diff --git a/tensorflow/lite/micro/testing/stm32f4.resc b/tensorflow/lite/micro/testing/stm32f4.resc index 45f213c22b1..024c948ce4b 100644 --- a/tensorflow/lite/micro/testing/stm32f4.resc +++ b/tensorflow/lite/micro/testing/stm32f4.resc @@ -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 diff --git a/tensorflow/lite/micro/testing/stm32f4.robot.txt b/tensorflow/lite/micro/testing/stm32f4.robot.txt deleted file mode 100644 index 0833c0b0e11..00000000000 --- a/tensorflow/lite/micro/testing/stm32f4.robot.txt +++ /dev/null @@ -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} diff --git a/tensorflow/lite/micro/testing/test_stm32f4_binary.sh b/tensorflow/lite/micro/testing/test_stm32f4_binary.sh deleted file mode 100755 index de7d7492260..00000000000 --- a/tensorflow/lite/micro/testing/test_stm32f4_binary.sh +++ /dev/null @@ -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 diff --git a/tensorflow/lite/micro/testing/test_bluepill_binary.sh b/tensorflow/lite/micro/testing/test_with_renode.sh similarity index 98% rename from tensorflow/lite/micro/testing/test_bluepill_binary.sh rename to tensorflow/lite/micro/testing/test_with_renode.sh index 4cecf7c99d5..1dea545e66f 100755 --- a/tensorflow/lite/micro/testing/test_bluepill_binary.sh +++ b/tensorflow/lite/micro/testing/test_with_renode.sh @@ -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}/.. diff --git a/tensorflow/lite/micro/tools/ci_build/test_stm32f4.sh b/tensorflow/lite/micro/tools/ci_build/test_stm32f4.sh index ba2dee3d810..2e7de8a2a01 100755 --- a/tensorflow/lite/micro/tools/ci_build/test_stm32f4.sh +++ b/tensorflow/lite/micro/tools/ci_build/test_stm32f4.sh @@ -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 diff --git a/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc b/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc index 2eaf5f48752..863e2e1d1b5 100644 --- a/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc +++ b/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc @@ -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) diff --git a/tensorflow/lite/micro/tools/make/targets/stm32f4_makefile.inc b/tensorflow/lite/micro/tools/make/targets/stm32f4_makefile.inc index 7f76f07a652..6ae0dda254f 100644 --- a/tensorflow/lite/micro/tools/make/targets/stm32f4_makefile.inc +++ b/tensorflow/lite/micro/tools/make/targets/stm32f4_makefile.inc @@ -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)