3 source $(dirname $0)/../detect-build-env-vars.sh
5 [ -z "$CEPH_ROOT" ] && CEPH_ROOT=..
7 dir=$CEPH_ROOT/ceph-object-corpus
15 if [ -x ./ceph-dencoder ]; then
16 CEPH_DENCODER=./ceph-dencoder
18 CEPH_DENCODER=ceph-dencoder
21 myversion=`$CEPH_DENCODER version`
24 debug() { if [ "$DEBUG" -gt 0 ]; then echo "DEBUG: $*" >&2; fi }
32 tmp1=`mktemp /tmp/test_object_1-XXXXXXXXX`
33 tmp2=`mktemp /tmp/test_object_2-XXXXXXXXX`
36 if $CEPH_DENCODER type $type 2>/dev/null; then
38 echo " $vdir/objects/$type"
40 # is there a fwd incompat change between $arversion and $version?
44 for iv in `ls $dir/archive | sort -n`; do
45 if [ "$iv" = "$arversion" ]; then
49 if [ $sawarversion -eq 1 ] && [ -e "$dir/archive/$iv/forward_incompat/$type" ]; then
52 # Check if we'll be ignoring only specified objects, not whole type. If so, remember
53 # all paths for this type into variable. Assuming that this path won't contain any
54 # whitechars (implication of above for loop).
55 if [ -d "$dir/archive/$iv/forward_incompat/$type" ]; then
56 if [ -n "`ls $dir/archive/$iv/forward_incompat/$type/ | sort -n`" ]; then
57 incompat_paths="$incompat_paths $dir/archive/$iv/forward_incompat/$type"
59 echo "type $type directory empty, ignoring whole type instead of single objects"
64 if [ "$iv" = "$version" ]; then
70 if [ -n "$incompat" ]; then
71 if [ -z "$incompat_paths" ]; then
72 echo "skipping incompat $type version $arversion, changed at $incompat < code $myversion"
76 # If we are ignoring not whole type, but objects that are in $incompat_path,
77 # we don't skip here, just give info.
78 echo "postponed skip one of incompact $type version $arversion, changed at $incompat < code $myversion"
82 for f in `ls $vdir/objects/$type`; do
85 # Check if processed object $f of $type should be skipped (postponed skip)
86 if [ -n "$incompat_paths" ]; then
87 for i_path in $incompat_paths; do
88 # Check if $f is a symbolic link and if it's pointing to existing target
89 if [ -L "$i_path/$f" ]; then
90 echo "skipping object $f of type $type"
97 if [ $skip -ne 0 ]; then
101 $CEPH_DENCODER type $type import $vdir/objects/$type/$f decode dump_json > $tmp1 &
103 $CEPH_DENCODER type $type import $vdir/objects/$type/$f decode encode decode dump_json > $tmp2 &
105 #echo "\t$vdir/$type/$f"
106 if ! wait $pid1; then
107 echo "**** failed to decode $vdir/objects/$type/$f ****"
108 failed=$(($failed + 1))
112 if ! wait $pid2; then
113 echo "**** failed to decode+encode+decode $vdir/objects/$type/$f ****"
114 failed=$(($failed + 1))
119 # nondeterministic classes may dump
120 # nondeterministically. compare the sorted json
121 # output. this is a weaker test, but is better than
123 if ! $CEPH_DENCODER type $type is_deterministic; then
124 echo " sorting json output for nondeterministic object"
125 for f in $tmp1 $tmp2; do
126 sort $f | sed 's/,$//' > $f.new
131 if ! cmp $tmp1 $tmp2; then
132 echo "**** reencode of $vdir/objects/$type/$f resulted in a different dump ****"
134 failed=$(($failed + 1))
136 numtests=$(($numtests + 1))
140 echo "skipping unrecognized type $type"
144 echo "failed=$failed" > $output_file
145 echo "numtests=$numtests" >> $output_file
149 ## Wait for children to exit and indicate whether all exited with 0 status.
152 debug "Processes remaining: $*"
155 if kill -0 "$pid" 2>/dev/null; then
156 debug "$pid is still alive."
158 elif wait "$pid"; then
159 debug "$pid exited with zero exit status."
161 debug "$pid exited with non-zero exit status."
162 errors=$(($errors + 1))
165 [ $# -eq 0 ] && break
166 sleep ${WAITALL_DELAY:-1}
178 # Reading the output of jobs to compute failed & numtests
179 # Tests are run in parallel but sum should be done sequentialy to avoid
180 # races between threads
181 while [ "$running_jobs" -ge 0 ]; do
182 if [ -f $output_file.$running_jobs ]; then
183 read_failed=$(grep "^failed=" $output_file.$running_jobs | cut -d "=" -f 2)
184 read_numtests=$(grep "^numtests=" $output_file.$running_jobs | cut -d "=" -f 2)
185 rm -f $output_file.$running_jobs
186 failed=$(($failed + $read_failed))
187 numtests=$(($numtests + $read_numtests))
189 running_jobs=$(($running_jobs - 1))
194 # Using $MAX_PARALLEL_JOBS jobs if defined, unless the number of logical
196 if [ `uname` == FreeBSD ]; then
197 NPROC=`sysctl -n hw.ncpu`
198 max_parallel_jobs=${MAX_PARALLEL_JOBS:-${NPROC}}
200 max_parallel_jobs=${MAX_PARALLEL_JOBS:-$(nproc)}
203 output_file=`mktemp /tmp/output_file-XXXXXXXXX`
206 for arversion in `ls $dir/archive | sort -n`; do
207 vdir="$dir/archive/$arversion"
210 if [ ! -d "$vdir/objects" ]; then
214 for type in `ls $vdir/objects`; do
215 test_object $type $output_file.$running_jobs &
217 running_jobs=$(($running_jobs + 1))
219 # Once we spawned enough jobs, let's wait them to complete
220 # Every spawned job have almost the same execution time so
221 # it's not a big deal having them not ending at the same time
222 if [ "$running_jobs" -eq "$max_parallel_jobs" ]; then
225 rm -f ${output_file}*
231 if [ $failed -gt 0 ]; then
232 echo "FAILED $failed / $numtests tests."
235 echo "passed $numtests tests."