diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/test/encoding/check-generated.sh | |
parent | Initial commit. (diff) | |
download | ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.tar.xz ceph-6d07fdb6bb33b1af39833b850bb6cf8af79fe293.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/encoding/check-generated.sh')
-rwxr-xr-x | src/test/encoding/check-generated.sh | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/test/encoding/check-generated.sh b/src/test/encoding/check-generated.sh new file mode 100755 index 000000000..2569bc1a5 --- /dev/null +++ b/src/test/encoding/check-generated.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +set -e + +source $(dirname $0)/../detect-build-env-vars.sh +source $CEPH_ROOT/qa/standalone/ceph-helpers.sh + +dir=$1 + +tmp1=`mktemp /tmp/typ-XXXXXXXXX` +tmp2=`mktemp /tmp/typ-XXXXXXXXX` +tmp3=`mktemp /tmp/typ-XXXXXXXXX` +tmp4=`mktemp /tmp/typ-XXXXXXXXX` + +failed=0 +numtests=0 +echo "checking ceph-dencoder generated test instances..." +echo "numgen type" +while read type; do + num=`ceph-dencoder type $type count_tests` + echo "$num $type" + for n in `seq 1 1 $num 2>/dev/null`; do + + pids="" + run_in_background pids save_stdout "$tmp1" ceph-dencoder type "$type" select_test "$n" dump_json + run_in_background pids save_stdout "$tmp2" ceph-dencoder type "$type" select_test "$n" encode decode dump_json + run_in_background pids save_stdout "$tmp3" ceph-dencoder type "$type" select_test "$n" copy dump_json + run_in_background pids save_stdout "$tmp4" ceph-dencoder type "$type" select_test "$n" copy_ctor dump_json + wait_background pids + + if [ $? -ne 0 ]; then + echo "**** $type test $n encode+decode check failed ****" + echo " ceph-dencoder type $type select_test $n encode decode" + failed=$(($failed + 3)) + continue + fi + + # nondeterministic classes may dump nondeterministically. compare + # the sorted json output. this is a weaker test, but is better + # than nothing. + deterministic=0 + if ceph-dencoder type "$type" is_deterministic; then + deterministic=1 + fi + + if [ $deterministic -eq 0 ]; then + echo " sorting json output for nondeterministic object" + for f in $tmp1 $tmp2 $tmp3 $tmp4; do + sort $f | sed 's/,$//' > $f.new + mv $f.new $f + done + fi + + if ! cmp $tmp1 $tmp2; then + echo "**** $type test $n dump_json check failed ****" + echo " ceph-dencoder type $type select_test $n dump_json > $tmp1" + echo " ceph-dencoder type $type select_test $n encode decode dump_json > $tmp2" + diff $tmp1 $tmp2 + failed=$(($failed + 1)) + fi + + if ! cmp $tmp1 $tmp3; then + echo "**** $type test $n copy dump_json check failed ****" + echo " ceph-dencoder type $type select_test $n dump_json > $tmp1" + echo " ceph-dencoder type $type select_test $n copy dump_json > $tmp2" + diff $tmp1 $tmp2 + failed=$(($failed + 1)) + fi + + if ! cmp $tmp1 $tmp4; then + echo "**** $type test $n copy_ctor dump_json check failed ****" + echo " ceph-dencoder type $type select_test $n dump_json > $tmp1" + echo " ceph-dencoder type $type select_test $n copy_ctor dump_json > $tmp2" + diff $tmp1 $tmp2 + failed=$(($failed + 1)) + fi + + if [ $deterministic -ne 0 ]; then + run_in_background pids ceph-dencoder type "$type" select_test $n encode export "$tmp1" + run_in_background pids ceph-dencoder type "$type" select_test $n encode decode encode export "$tmp2" + wait_background pids + + if ! cmp $tmp1 $tmp2; then + echo "**** $type test $n binary reencode check failed ****" + echo " ceph-dencoder type $type select_test $n encode export $tmp1" + echo " ceph-dencoder type $type select_test $n encode decode encode export $tmp2" + diff <(hexdump -C $tmp1) <(hexdump -C $tmp2) + failed=$(($failed + 1)) + fi + fi + + numtests=$(($numtests + 3)) + done +done < <(ceph-dencoder list_types) + +rm -f $tmp1 $tmp2 $tmp3 $tmp4 + +if [ $failed -gt 0 ]; then + echo "FAILED $failed / $numtests tests." + exit 1 +fi +echo "passed $numtests tests." |