Revert "test: Remove complicated JSON->shell dict logic" This reverts commit 60b4d237fb9f56ee86c14147af3db61209f99717. Using a bash associative array provides a significant performance improvement (~40s / 43% reduction). Re-add that functionality but use jq to do the processing instead of python. Change-Id: Ib49cf69676c3187ceb1e26ac1ca3686609484036
diff --git a/test/lib/lib_helper.sh b/test/lib/lib_helper.sh index cccf432..5c834d4 100644 --- a/test/lib/lib_helper.sh +++ b/test/lib/lib_helper.sh
@@ -34,13 +34,10 @@ result "$name" "$(diff <(echo "$expected") <(echo "$actual"))" } -result_root() { # group root expected_file actual +result_root() { # group root local root=$(echo "$2" | sed -es'/Root //') local name="$1 - $root" - local expected_file=$3 actual=$4 - local expected_root=$(json_val_by_key "$(cat "$expected_file")" "$root") - local actual_root=$(json_val_by_key "$actual" "$root") - result_out "$name" "$expected_root" "$actual_root" + result_out "$name" "${EXPECTED_ROOTS[$root]}" "${OUTPUT_ROOTS[$root]}" } # -------- Git Config @@ -245,6 +242,23 @@ strip_non_applicable() { ensure "$MYDIR"/strip_non_applicable.py ; } # < json > json strip_non_invalid() { ensure "$MYDIR"/strip_non_invalid.py ; } # < json > json +define_jsonByRoot() { # task_plugin_ouptut > jsonByRoot_array_definition + local record root='' + local -A jsonByRoot + while IFS= read -r -d '' record ; do + if [ -z "$root" ] ; then + root=$record + else + jsonByRoot[$root]=$record + root='' + fi + done < <(jq -r --indent 3 --sort-keys \ + '.plugins[0].roots[] | "\(.name)\u0000\(.)\u0000"') + + local def=$(declare -p jsonByRoot) + echo "${def#*=}" # declare -A jsonByRoot='(...)' > '(...)' +} + get_plugins() { # < change_json > plugins_json jq --indent 3 --sort-keys '{plugins: .plugins}' } @@ -314,9 +328,12 @@ results_suite() { # name expected_file plugins_json local name=$1 expected_file=$2 actual=$3 + local -A EXPECTED_ROOTS=$(define_jsonByRoot < "$expected_file") + local -A OUTPUT_ROOTS=$(echo "$actual" | define_jsonByRoot) + local out root echo "$ROOTS" | while read root ; do - result_root "$name" "$root" "$expected_file" "$actual" + result_root "$name" "$root" done out=$(diff "$expected_file" <(echo "$actual") | head -15) [ -z "$out" ]