1#!/bin/bash 2# Copyright 2019 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16# 17# Bash unit tests for the TensorFlow Lite Micro project generator. 18 19set -e 20 21INPUT_EXAMPLE_FILE=${TEST_TMPDIR}/input_example.cc 22cat << EOF > ${INPUT_EXAMPLE_FILE} 23#include <stdio.h> 24#include "baz.h" 25#include "tensorflow/lite/micro/examples/something/foo/fish.h" 26 27main() { 28 fprintf(stderr, "Hello World!\n"); 29 return 0; 30} 31EOF 32 33OUTPUT_EXAMPLE_FILE=${TEST_TMPDIR}/output_example.cc 34 35${TEST_SRCDIR}/tensorflow/lite/micro/tools/make/transform_source \ 36 --platform=esp \ 37 --is_example_source \ 38 --source_path="tensorflow/lite/micro/examples/something/input_example.cc" \ 39 < ${INPUT_EXAMPLE_FILE} \ 40 > ${OUTPUT_EXAMPLE_FILE} 41 42if ! grep -q '#include <stdio.h>' ${OUTPUT_EXAMPLE_FILE}; then 43 echo "ERROR: No stdio.h include found in output '${OUTPUT_EXAMPLE_FILE}'" 44 exit 1 45fi 46 47if ! grep -q '#include "baz.h"' ${OUTPUT_EXAMPLE_FILE}; then 48 echo "ERROR: No baz.h include found in output '${OUTPUT_EXAMPLE_FILE}'" 49 exit 1 50fi 51 52if ! grep -q '#include "foo/fish.h"' ${OUTPUT_EXAMPLE_FILE}; then 53 echo "ERROR: No foo/fish.h include found in output '${OUTPUT_EXAMPLE_FILE}'" 54 exit 1 55fi 56 57 58# 59# Example file in a sub directory. 60# 61 62mkdir -p "${TEST_TMPDIR}/subdir" 63INPUT_EXAMPLE_SUBDIR_FILE=${TEST_TMPDIR}/subdir/input_example.cc 64cat << EOF > ${INPUT_EXAMPLE_SUBDIR_FILE} 65#include <stdio.h> 66#include "baz.h" 67#include "tensorflow/lite/micro/examples/something/subdir/input_example.h" 68#include "tensorflow/lite/micro/examples/something/bleh.h" 69#include "tensorflow/lite/micro/examples/something/foo/fish.h" 70EOF 71 72OUTPUT_EXAMPLE_SUBDIR_FILE=${TEST_TMPDIR}/output_example.cc 73 74${TEST_SRCDIR}/tensorflow/lite/micro/tools/make/transform_source \ 75 --platform=esp \ 76 --is_example_source \ 77 --source_path="tensorflow/lite/micro/examples/something/subdir/input_example.cc" \ 78 < ${INPUT_EXAMPLE_SUBDIR_FILE} \ 79 > ${OUTPUT_EXAMPLE_SUBDIR_FILE} 80 81if ! grep -q '#include <stdio.h>' ${OUTPUT_EXAMPLE_SUBDIR_FILE}; then 82 echo "ERROR: No stdio.h include found in output '${OUTPUT_EXAMPLE_SUBDIR_FILE}'" 83 exit 1 84fi 85 86if ! grep -q '#include "baz.h"' ${OUTPUT_EXAMPLE_SUBDIR_FILE}; then 87 echo "ERROR: No baz.h include found in output '${OUTPUT_EXAMPLE_SUBDIR_FILE}'" 88 exit 1 89fi 90 91if ! grep -q '#include "input_example.h"' ${OUTPUT_EXAMPLE_SUBDIR_FILE}; then 92 echo "ERROR: No input_example.h include found in output '${OUTPUT_EXAMPLE_SUBDIR_FILE}'" 93 cat ${OUTPUT_EXAMPLE_SUBDIR_FILE} 94 exit 1 95fi 96 97if ! grep -q '#include "../bleh.h"' ${OUTPUT_EXAMPLE_SUBDIR_FILE}; then 98 echo "ERROR: No ../bleh.h include found in output '${OUTPUT_EXAMPLE_SUBDIR_FILE}'" 99 exit 1 100fi 101 102if ! grep -q '#include "../foo/fish.h"' ${OUTPUT_EXAMPLE_SUBDIR_FILE}; then 103 echo "ERROR: No ../foo/fish.h include found in output '${OUTPUT_EXAMPLE_SUBDIR_FILE}'" 104 exit 1 105fi 106 107echo 108echo "SUCCESS: transform_esp_source test PASSED" 109