--- /dev/null
+#
+# copy rule-lib.sh (a library of shell script functions)
+#
+set(SOURCE_RULE_LIB "${CMAKE_CURRENT_SOURCE_DIR}/rule-lib.sh")
+set(TARGET_RULE_LIB "${CMAKE_CURRENT_BINARY_DIR}/rule-lib.sh")
+
+add_custom_command(
+ OUTPUT ${TARGET_RULE_LIB}
+ COMMAND ${CMAKE_COMMAND} -E copy "${SOURCE_RULE_LIB}" "${TARGET_RULE_LIB}"
+ DEPENDS ${SOURCE_RULE_LIB}
+ COMMENT "Generate rule lib"
+)
+
+# Generate dependencies
+add_custom_target(dredd_rule_lib ALL DEPENDS ${TARGET_RULE_LIB})
+
+# How to get the path of rule-lib.sh in other CMakeLists.txt
+#
+# get_target_property(DREDD_RULE_LIB_DIR
+# dredd_rule_lib BINARY_DIR)
+# set(RULE_LIB_PATH "${DREDD_RULE_LIB_DIR}/rule-lib.sh")
--- /dev/null
+#!/bin/bash
+
+ERROR_FLAG="Error"
+
+#
+# Define rule
+#
+# - Params: rule name (metric), actual value, condition, expected value
+# - condition is '=', '!=', '<', '>', '<=', '>='. Refer to "man expr"
+# - Return
+# - 0 : success
+# - 1 : fail (condition check fail)
+# - 10 : error while getting actual value
+# - 11 : error while running expected value
+# - 20 : wrong param count
+#
+
+RULE()
+{
+ if [ "$#" -ne 4 ];then
+ echo "** [Error] count of RULE parameter should be 4"
+ return 20
+ fi
+
+ RULE_NAME=$1
+ ACTUAL=$2
+ COND=$3
+ EXPECTED=$4
+
+ # not to exit when expr result with 0
+ set +e
+
+ # check if ACTUAL or EXPECTED has "ERROR" string
+ expr match "${ACTUAL}" ${ERROR_FLAG}
+ if [ $? = 0 ]; then
+ echo "** Error in ACTUAL"
+ return 10
+ fi
+
+ expr match "${EXPECTED}" ${ERROR_FLAG}
+ if [ $? = 0 ]; then
+ echo "** Error in EXPECTED"
+ return 11
+ fi
+
+ expr ${ACTUAL} ${COND} ${EXPECTED}
+ RESULT=$?
+
+ # roll-back
+ set -e
+
+ # Note: return value of 'expr'
+ # - 0 : result is true
+ # - 1 : result is false
+ # - 2 : error
+
+ if [ ${RESULT} -eq 0 ];then
+ echo -e "\n** [${RULE_NAME}] \t success \t ([actual: ${ACTUAL}] ${COND} [expected: ${EXPECTED}])\n"
+ elif [ ${RESULT} -eq 1 ];then
+ echo -e "\n** [${RULE_NAME}] \t ** fail \t ([actual: ${ACTUAL}] ${COND} [expected: ${EXPECTED}])\n"
+ else
+ echo -e "\t** Error in [expr ${ACTUAL} ${COND} ${EXPECTED}]"
+ fi
+
+ return ${RESULT}
+}
+
+#
+# Define each function to get quality value
+#
+
+# Note: These function is called by a sub-shell.
+# So return value should be passed through "echo return_value"
+# tip: for debugging, surround the code with "set -x" and "set +x"
+
+file_size()
+{
+ if [ ! -f ${TFLITE_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
+ else
+ echo `cat ${TFLITE_PATH} | wc -c`
+ fi
+}
+
+all_op_count()
+{
+ if [ ! -f ${TFLITE_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
+ elif [ ! -f ${TFL_INSPECT_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFL_INSPECT_PATH} does not exist"
+ else
+ echo `${TFL_INSPECT_PATH} --operators ${TFLITE_PATH} | wc -l`
+ fi
+}
+
+op_count()
+{
+ if [ "$#" -ne 1 ];then
+ echo "${ERROR_FLAG} - Wrong argument number"
+ elif [ ! -f ${TFLITE_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
+ elif [ ! -f ${TFL_INSPECT_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFL_INSPECT_PATH} does not exist"
+ else
+ echo `${TFL_INSPECT_PATH} --operators ${TFLITE_PATH} | grep -w "$1" | wc -l`
+ fi
+}
+
+conv2d_weight_not_constant()
+{
+ if [ ! -f ${TFLITE_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFLITE_PATH} does not exist"
+ elif [ ! -f ${TFL_INSPECT_PATH} ]; then
+ echo "${ERROR_FLAG} - ${TFL_INSPECT_PATH} does not exist"
+ else
+ echo `${TFL_INSPECT_PATH} --conv2d_weight ${TFLITE_PATH} | awk -F, '{ if ($2 != "CONST") print $0}' | wc -l`
+ fi
+}
+
+# TODO define more qullity test function