summaryrefslogtreecommitdiff
path: root/tools/test_driver/print_to_json.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test_driver/print_to_json.sh')
-rwxr-xr-xtools/test_driver/print_to_json.sh152
1 files changed, 152 insertions, 0 deletions
diff --git a/tools/test_driver/print_to_json.sh b/tools/test_driver/print_to_json.sh
new file mode 100755
index 000000000..857fa0423
--- /dev/null
+++ b/tools/test_driver/print_to_json.sh
@@ -0,0 +1,152 @@
+#!/bin/bash
+#
+# Copyright (c) 2018 Samsung Electronics Co., Ltd. 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.
+
+function echo_to_file
+{
+ echo -e "$1" >> $RESULT_JSON
+}
+
+function print_comma() # ,
+{
+ echo_to_file ","
+}
+
+function print_brace_start() # {
+{
+ echo_to_file "{"
+}
+
+function print_brace_end() # }
+{
+ echo_to_file "}"
+}
+
+function print_bracket_start() # "$NAME": [
+{
+ local NAME=$1
+ echo_to_file "\"$NAME\":["
+}
+
+function print_bracket_end() # ]
+{
+ echo_to_file "]"
+}
+
+function print_key_value() # "$KEY": "$VALUE"
+{
+ local KEY=$1
+ local VALUE=$2
+ echo_to_file "\"$KEY\": \"$VALUE\""
+}
+
+function print_key_value_no_quot() # "$KEY": $VALUE
+{
+ local KEY=$1
+ local VALUE=$2
+ echo_to_file "\"$KEY\": $VALUE"
+}
+
+function print_key_value_dbl() # "dblValue": $VALUE
+{
+ local VALUE=$1
+ echo_to_file "\"dblValue\": $VALUE" # value should not include ""
+}
+
+function print_results()
+{
+ local NAME=$1
+ local MEAN=$2
+
+ print_bracket_start "results"
+ print_brace_start
+ print_key_value "name" "Mean_of_$NAME"
+ print_comma
+ print_key_value "unit" "ms"
+ print_comma
+ print_key_value_dbl "$MEAN"
+ print_brace_end
+ print_bracket_end
+}
+
+function print_test()
+{
+ local NAME=$1
+ local RESULT=$2
+
+ print_brace_start
+ print_key_value "name" "$NAME"
+ print_comma
+ print_results "$NAME" "$RESULT"
+ print_brace_end
+}
+
+function print_tests()
+{
+ local MODEL=$1
+ local REPORT_MODEL_DIR=$ARTIFACT_PATH/report/benchmark/$MODEL
+ local TEST_RESULTS=$(find $REPORT_MODEL_DIR -name "*.result" -exec basename {} \;)
+ local TEST_NUM=$(find $REPORT_MODEL_DIR -name "*.result" | wc -l)
+
+ print_bracket_start "tests"
+
+ local i=0
+ for TEST in $TEST_RESULTS; do
+ local NAME=$(cat $REPORT_MODEL_DIR/$TEST | awk '{print $1}')
+ local RESULT=$(cat $REPORT_MODEL_DIR/$TEST | awk '{print $2}')
+ print_test $NAME $RESULT
+ if [[ $i -ne $TEST_NUM-1 ]]; then
+ print_comma
+ fi
+ i=$((i+1))
+ done
+
+ print_bracket_end
+}
+
+function print_groups()
+{
+ local MODEL_NUM=$(cat $MODELS_FILE | wc -l)
+ local MODELS=$(cat $MODELS_FILE | awk '{print $1}' | uniq)
+
+ print_bracket_start "groups"
+
+ local i=0
+ for MODEL in $MODELS; do
+ print_brace_start
+ print_key_value "name" " $MODEL"
+ print_comma
+ print_tests $MODEL
+ print_brace_end
+ if [[ $i -ne $MODEL_NUM-1 ]]; then
+ print_comma
+ fi
+ i=$((i+1))
+ done
+
+ print_bracket_end
+}
+
+function print_to_json()
+{
+ RESULT_JSON=$ARTIFACT_PATH/report/benchmark_result.json
+ rm -f $RESULT_JSON
+
+ MODELS_FILE=$ARTIFACT_PATH/report/benchmark/benchmark_models.txt
+
+ print_brace_start
+ print_groups
+ print_brace_end
+}