--- /dev/null
+nnas_include(TargetRequire)
+
+unset(REQUIRED_TARGETS)
+list(APPEND REQUIRED_TARGETS tf2tflite)
+list(APPEND REQUIRED_TARGETS tfkit)
+list(APPEND REQUIRED_TARGETS nnkit-run)
+list(APPEND REQUIRED_TARGETS nnkit_tf_backend)
+list(APPEND REQUIRED_TARGETS nnkit_tflite_backend)
+list(APPEND REQUIRED_TARGETS nnkit_randomize_action)
+list(APPEND REQUIRED_TARGETS nnkit_HDF5_export_action)
+list(APPEND REQUIRED_TARGETS nnkit_HDF5_import_action)
+list(APPEND REQUIRED_TARGETS i5diff)
+TargetRequire_Return(${REQUIRED_TARGETS})
+
+message(STATUS "tf2tflite-value-pbtxt-test: run tests")
+
+nncc_find_resource(TensorFlowTests)
+
+#
+# Copy [PREFIX]/test.pbtxt to PREFIX.pbtxt in binary folder
+# Copy [PREFIX]/test.info to PREFIX.info in binary folder
+# Copy [PREFIX]/customop.conf to PREFIX_customop.conf in binary folder
+# Encode PREFIX.pbtxt to PREFIX.pb
+#
+set(TEST_REPO "${TensorFlowTests_DIR}")
+set(TEST_PBTXT_FILENAME "test.pbtxt")
+set(TEST_INFO_FILENAME "test.info")
+set(TEST_CUSTOMOP_CONF_FILENAME "customop.conf")
+
+unset(TESTCASES)
+
+macro(add NAME)
+ list(APPEND TESTCASES ${NAME})
+endmacro(add)
+
+# Read "test.lst"
+include("test.lst")
+# Read "test.local.lst" if exists
+include("test.local.lst" OPTIONAL)
+
+unset(TEST_DEPS)
+unset(TEST_NAMES)
+
+foreach(PREFIX IN ITEMS ${TESTCASES})
+ if(NOT IS_DIRECTORY "${TEST_REPO}/${PREFIX}")
+ message(FATAL_ERROR "Missing '${PREFIX}' test")
+ endif()
+
+ set(PBTXT_SOURCE_PATH "${TEST_REPO}/${PREFIX}/${TEST_PBTXT_FILENAME}")
+ set(INFO_SOURCE_PATH "${TEST_REPO}/${PREFIX}/${TEST_INFO_FILENAME}")
+ set(CUSTOMOP_CONF_SOURCE_PATH "${TEST_REPO}/${PREFIX}/${TEST_CUSTOMOP_CONF_FILENAME}")
+
+ set(PBTXT_FILE "${PREFIX}.pbtxt")
+ set(PBTXT_PATH "${CMAKE_CURRENT_BINARY_DIR}/${PBTXT_FILE}")
+
+ set(INFO_FILE "${PREFIX}.info")
+ set(INFO_PATH "${CMAKE_CURRENT_BINARY_DIR}/${INFO_FILE}")
+
+ set(CUSTOMOP_CONF_FILE "${PREFIX}.${TEST_CUSTOMOP_CONF_FILENAME}") # ex) CustomOp_001.customop.conf
+ set(CUSTOMOP_CONF_PATH "${CMAKE_CURRENT_BINARY_DIR}/${CUSTOMOP_CONF_FILE}")
+
+ set(PB_FILE "${PREFIX}.pb")
+ set(PB_PATH "${CMAKE_CURRENT_BINARY_DIR}/${PB_FILE}")
+
+ # Copy .pbtxt
+ add_custom_command(OUTPUT ${PBTXT_PATH}
+ COMMAND ${CMAKE_COMMAND} -E copy "${PBTXT_SOURCE_PATH}" "${PBTXT_PATH}"
+ DEPENDS ${PBTXT_SOURCE_PATH}
+ COMMENT "Generate ${PBTXT_FILE}"
+ )
+
+ # Copy .info
+ add_custom_command(OUTPUT ${INFO_PATH}
+ COMMAND ${CMAKE_COMMAND} -E copy "${INFO_SOURCE_PATH}" "${INFO_PATH}"
+ DEPENDS ${INFO_SOURCE_PATH}
+ COMMENT "Generate ${INFO_FILE}"
+ )
+
+ # Generate .pb from .pbtxt
+ add_custom_command(OUTPUT ${PB_PATH}
+ COMMAND $<TARGET_FILE:tfkit> encode ${PBTXT_PATH} ${PB_PATH}
+ DEPENDS ${PBTXT_PATH}
+ COMMENT "Generate ${PB_FILE}"
+ )
+
+ list(APPEND TEST_DEPS ${INFO_PATH} ${PB_PATH})
+
+ if (EXISTS "${CUSTOMOP_CONF_SOURCE_PATH}")
+
+ # Copy customop.conf
+ add_custom_command(OUTPUT ${CUSTOMOP_CONF_PATH}
+ COMMAND ${CMAKE_COMMAND} -E copy "${CUSTOMOP_CONF_SOURCE_PATH}" "${CUSTOMOP_CONF_PATH}"
+ DEPENDS ${CUSTOMOP_CONF_SOURCE_PATH}
+ COMMENT "Generate ${CUSTOMOP_CONF_FILE}"
+ )
+
+ list(APPEND TEST_DEPS ${CUSTOMOP_CONF_PATH})
+
+ endif (EXISTS "${CUSTOMOP_CONF_SOURCE_PATH}")
+
+ list(APPEND TEST_NAMES ${PREFIX})
+endforeach(PREFIX)
+
+##
+## Copy testall
+##
+set(TEST_RUNNER "${CMAKE_CURRENT_BINARY_DIR}/testall.sh")
+set(TEST_RUNNER_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/testall.sh")
+
+add_custom_command(
+ OUTPUT ${TEST_RUNNER}
+ COMMAND ${CMAKE_COMMAND} -E copy "${TEST_RUNNER_SOURCE}" "${TEST_RUNNER}"
+ DEPENDS ${TEST_RUNNER_SOURCE}
+ COMMENT "Generate test runner"
+)
+
+list(APPEND TEST_DEPS "${TEST_RUNNER}")
+
+###
+### Generate test.config
+###
+set(TEST_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/test.config")
+
+add_custom_command(
+ OUTPUT ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E remove -f ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'NNKIT_RUN_PATH=\"$<TARGET_FILE:nnkit-run>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'TF_BACKEND_PATH=\"$<TARGET_FILE:nnkit_tf_backend>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'TFLITE_BACKEND_PATH=\"$<TARGET_FILE:nnkit_tflite_backend>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'TF2TFLITE_PATH=\"$<TARGET_FILE:tf2tflite>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'RANDOMIZE_ACTION_PATH=\"$<TARGET_FILE:nnkit_randomize_action>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'HDF5_EXPORT_ACTION_PATH=\"$<TARGET_FILE:nnkit_HDF5_export_action>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'HDF5_IMPORT_ACTION_PATH=\"$<TARGET_FILE:nnkit_HDF5_import_action>\"' >> ${TEST_CONFIG}
+ COMMAND ${CMAKE_COMMAND} -E echo 'I5DIFF_PATH=\"$<TARGET_FILE:i5diff>\"' >> ${TEST_CONFIG}
+ DEPENDS
+ nnkit-run
+ nnkit_tf_backend
+ nnkit_tflite_backend
+ tf2tflite
+ nnkit_randomize_action
+ nnkit_HDF5_export_action
+ nnkit_HDF5_import_action
+ i5diff
+ COMMENT "Generate test configuration"
+)
+
+list(APPEND TEST_DEPS "${TEST_CONFIG}")
+
+# This "tf2tflite_value_pbtxt_test_deps" target enforces CMake to generate all the dependencies during "build" phase
+add_custom_target(tf2tflite_value_pbtxt_test_deps ALL DEPENDS ${TEST_DEPS})
+
+# Run tests
+add_test(
+ NAME tf2tflite_value_pbtxt_test
+ COMMAND "${TEST_RUNNER}"
+ "${TEST_CONFIG}"
+ "${CMAKE_CURRENT_BINARY_DIR}"
+ ${TEST_NAMES}
+)
--- /dev/null
+#!/bin/bash
+
+# Need at least 2 arguments
+if [[ $# -lt 2 ]]; then
+ echo "USAGE: $0 ..."
+ echo
+ echo "ARGUMENTS:"
+ echo " [test.config path]"
+ echo " [WORKDIR]"
+ echo " [Prefix1]"
+ echo " [Prefix2]"
+ echo " ..."
+ exit 255
+fi
+
+CONFIG_PATH="$1"; shift
+WORKDIR="$1"; shift
+
+source "${CONFIG_PATH}"
+
+echo "-- Found nnkit-run: ${NNKIT_RUN_PATH}"
+echo "-- Found TF backend: ${TF_BACKEND_PATH}"
+echo "-- Found TFLITE backend: ${TFLITE_BACKEND_PATH}"
+echo "-- Found TF2TFLITE: ${TF2TFLITE_PATH}"
+echo "-- Found randomize action: ${RANDOMIZE_ACTION_PATH}"
+echo "-- Found HDF5 export action: ${HDF5_EXPORT_ACTION_PATH}"
+echo "-- Found HDF5 import action: ${HDF5_IMPORT_ACTION_PATH}"
+echo "-- Found i5diff: ${I5DIFF_PATH}"
+echo "-- Found workdir: ${WORKDIR}"
+
+TESTED=()
+PASSED=()
+FAILED=()
+
+pushd "${WORKDIR}"
+while [[ $# -ne 0 ]]; do
+ PREFIX="$1"; shift
+
+ TESTED+=("${PREFIX}")
+
+ PASSED_TAG="${PREFIX}.passed"
+
+ rm -f "${PASSED_TAG}"
+
+ cat > "${PREFIX}.log" <(
+ exec 2>&1
+
+ echo "-- Found pb: ${PREFIX}.pb"
+
+ # Exit immediately if any command fails
+ set -e
+ # Show commands
+ set -x
+
+ # Generate tflite
+ "${TF2TFLITE_PATH}" \
+ "${WORKDIR}/${PREFIX}.info" \
+ "${WORKDIR}/${PREFIX}.pb" \
+ "${WORKDIR}/${PREFIX}.tflite"
+
+ # Run TensorFlow
+ "${NNKIT_RUN_PATH}" \
+ --backend "${TF_BACKEND_PATH}" \
+ --backend-arg "${WORKDIR}/${PREFIX}.pb" \
+ --backend-arg "${WORKDIR}/${PREFIX}.info" \
+ --pre "${RANDOMIZE_ACTION_PATH}" \
+ --pre "${HDF5_EXPORT_ACTION_PATH}" \
+ --pre-arg "${WORKDIR}/${PREFIX}.input.h5" \
+ --post "${HDF5_EXPORT_ACTION_PATH}" \
+ --post-arg "${WORKDIR}/${PREFIX}.expected.h5"
+
+ # Run TensorFlow Lite
+ "${NNKIT_RUN_PATH}" \
+ --backend "${TFLITE_BACKEND_PATH}" \
+ --backend-arg "${WORKDIR}/${PREFIX}.tflite" \
+ --pre "${HDF5_IMPORT_ACTION_PATH}" \
+ --pre-arg "${WORKDIR}/${PREFIX}.input.h5" \
+ --post "${HDF5_EXPORT_ACTION_PATH}" \
+ --post-arg "${WORKDIR}/${PREFIX}.obtained.h5"
+
+ "${I5DIFF_PATH}" -d 0.001 "${PREFIX}.expected.h5" "${PREFIX}.obtained.h5"
+
+ if [[ $? -eq 0 ]]; then
+ touch "${PASSED_TAG}"
+ fi
+ )
+
+ if [[ -f "${PASSED_TAG}" ]]; then
+ PASSED+=("$PREFIX")
+ else
+ FAILED+=("$PREFIX")
+ fi
+done
+popd
+
+if [[ ${#TESTED[@]} -ne ${#PASSED[@]} ]]; then
+ echo "FAILED"
+ for TEST in "${FAILED[@]}"
+ do
+ echo "- ${TEST}"
+ done
+ exit 255
+fi
+
+echo "PASSED"
+exit 0