numam-spdk/test/json_config/json_diff.sh
Pawel Wodkowski 651d9158a0 test: consolidate tests for reading JSON config
This patch rework all JSON config file reading tests. This is needed as
current approach will require to modify each test to re-launch SPDK
applications for each test type. This is hard to do because tests are
not flexible and will require to be rewritten almost from scratch. Not
metioning time to relaunch each test separatly.

Instead, just replace all old tests with one test. Launch only one
target and only one initiator. Then configure it using RPC calls. Then
config is dumped and target and initiator application is relaunched to
reread the configuration from file. Then config is dumped again and
compared.

Change-Id: Id857089aed0e6f2197cbf3ae625a4e9f4b13e8bb
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/432318
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Pawel Kaminski <pawelx.kaminski@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
2019-01-16 14:17:10 +00:00

48 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -x
if [ $# -ne 2 ]; then
echo "This script need exactly two arguments"
exit 1
fi
rootdir=$(readlink -f $(dirname $0)/../..)
# FIXME: Remove this when python3 will be on FeeBSD machines
if [ $(uname -s) = "FreeBSD" ]; then
python_cmd=python
else
python_cmd=""
fi
# Compare two JSON files.
#
# NOTE: Order of objects in JSON can change by just doing loads -> dumps so all JSON objects (not arrays) are sorted by
# config_filter.py script. Sorted output is used to compare JSON output.
#
tmp_file_1=$(mktemp /tmp/$(basename ${1}).XXX)
tmp_file_2=$(mktemp /tmp/$(basename ${2}).XXX)
ret=0
cat $1 | $python_cmd $rootdir/test/json_config/config_filter.py -method "sort" > $tmp_file_1
cat $2 | $python_cmd $rootdir/test/json_config/config_filter.py -method "sort" > $tmp_file_2
if ! diff -u $tmp_file_1 $tmp_file_2; then
ret=1
echo "=== Start of file: $tmp_file_1 ==="
cat $tmp_file_1
echo "=== End of file: $tmp_file_1 ==="
echo ""
echo "=== Start of file: $tmp_file_2 ==="
cat $tmp_file_2
echo "=== End of file: $tmp_file_2 ==="
echo ""
else
echo "INFO: JSON config files are the same"
fi
rm $tmp_file_1 $tmp_file_2
exit $ret