1#!/usr/bin/env bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright (C) 2018 Intel Corporation 4# All rights reserved. 5# 6set -x 7 8if [ $# -ne 2 ]; then 9 echo "This script need exactly two arguments" 10 exit 1 11fi 12 13rootdir=$(readlink -f $(dirname $0)/../..) 14 15# Compare two JSON files. 16# 17# NOTE: Order of objects in JSON can change by just doing loads -> dumps so all JSON objects (not arrays) are sorted by 18# config_filter.py script. Sorted output is used to compare JSON output. 19# 20 21tmp_file_1=$(mktemp /tmp/$(basename ${1}).XXX) 22tmp_file_2=$(mktemp /tmp/$(basename ${2}).XXX) 23ret=0 24 25$rootdir/test/json_config/config_filter.py -method "sort" < $1 > $tmp_file_1 26$rootdir/test/json_config/config_filter.py -method "sort" < $2 > $tmp_file_2 27 28if ! diff -u $tmp_file_1 $tmp_file_2; then 29 ret=1 30 31 echo "=== Start of file: $tmp_file_1 ===" 32 cat $tmp_file_1 33 echo "=== End of file: $tmp_file_1 ===" 34 echo "" 35 echo "=== Start of file: $tmp_file_2 ===" 36 cat $tmp_file_2 37 echo "=== End of file: $tmp_file_2 ===" 38 echo "" 39else 40 echo "INFO: JSON config files are the same" 41fi 42 43rm $tmp_file_1 $tmp_file_2 44exit $ret 45