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
21INPUT1_DIR=${TEST_TMPDIR}/input1
22mkdir -p ${INPUT1_DIR}
23touch ${INPUT1_DIR}/a.txt
24touch ${INPUT1_DIR}/b.txt
25mkdir ${INPUT1_DIR}/sub1/
26touch ${INPUT1_DIR}/sub1/c.txt
27mkdir ${INPUT1_DIR}/sub2/
28touch ${INPUT1_DIR}/sub2/d.txt
29INPUT1_ZIP=${TEST_TMPDIR}/input1.zip
30pushd ${INPUT1_DIR}
31zip -q -r ${INPUT1_ZIP} *
32popd
33
34INPUT2_DIR=${TEST_TMPDIR}/input2
35mkdir -p ${INPUT2_DIR}
36touch ${INPUT2_DIR}/a.txt
37touch ${INPUT2_DIR}/e.txt
38mkdir ${INPUT2_DIR}/sub1/
39touch ${INPUT2_DIR}/sub1/f.txt
40mkdir ${INPUT2_DIR}/sub3/
41touch ${INPUT2_DIR}/sub3/g.txt
42INPUT2_ZIP=${TEST_TMPDIR}/input2.zip
43pushd ${INPUT2_DIR}
44zip -q -r ${INPUT2_ZIP} *
45popd
46
47OUTPUT_DIR=${TEST_TMPDIR}/output/
48OUTPUT_ZIP=${OUTPUT_DIR}/output.zip
49
50${TEST_SRCDIR}/tensorflow/lite/micro/tools/make/merge_arduino_zips \
51  ${OUTPUT_ZIP} ${INPUT1_ZIP} ${INPUT2_ZIP}
52
53if [[ ! -f ${OUTPUT_ZIP} ]]; then
54  echo "${OUTPUT_ZIP} wasn't created."
55fi
56
57pushd ${OUTPUT_DIR}
58unzip -q ${OUTPUT_ZIP}
59popd
60
61for EXPECTED_FILE in a.txt b.txt sub1/c.txt sub2/d.txt e.txt sub1/f.txt sub3/g.txt
62do
63  if [[ ! -f ${OUTPUT_DIR}/${EXPECTED_FILE} ]]; then
64    echo "${OUTPUT_DIR}/${EXPECTED_FILE} wasn't created."
65    exit 1
66  fi
67done
68
69echo
70echo "SUCCESS: merge_arduino_zips test PASSED"
71