4 source $
(dirname $0)/..
/detect-build-env-vars.sh
6 [ -z "$CEPH_ROOT" ] && CEPH_ROOT
=..
8 dir
=$CEPH_ROOT/ceph-object-corpus
14 if [ -x .
/ceph-dencoder
]; then
15 CEPH_DENCODER
=.
/ceph-dencoder
17 CEPH_DENCODER
=ceph-dencoder
20 myversion
=`$CEPH_DENCODER version`
23 debug
() { if [ "$DEBUG" -gt 0 ]; then echo "DEBUG: $*" >&2; fi }
31 tmp1
=`mktemp /tmp/test_object_1-XXXXXXXXX`
32 tmp2
=`mktemp /tmp/test_object_2-XXXXXXXXX`
35 if $CEPH_DENCODER type $type 2>/dev
/null
; then
37 echo " $vdir/objects/$type"
39 # is there a fwd incompat change between $arversion and $version?
43 for iv
in `ls $dir/archive | sort -n`; do
44 if [ "$iv" = "$arversion" ]; then
48 if [ $sawarversion -eq 1 ] && [ -e "$dir/archive/$iv/forward_incompat/$type" ]; then
51 # Check if we'll be ignoring only specified objects, not whole type. If so, remember
52 # all paths for this type into variable. Assuming that this path won't contain any
53 # whitechars (implication of above for loop).
54 if [ -d "$dir/archive/$iv/forward_incompat/$type" ]; then
55 if [ -n "`ls $dir/archive/$iv/forward_incompat/$type/ | sort -n`" ]; then
56 incompat_paths
="$incompat_paths $dir/archive/$iv/forward_incompat/$type"
58 echo "type $type directory empty, ignoring whole type instead of single objects"
63 if [ "$iv" = "$version" ]; then
69 if [ -n "$incompat" ]; then
70 if [ -z "$incompat_paths" ]; then
71 echo "skipping incompat $type version $arversion, changed at $incompat < code $myversion"
75 # If we are ignoring not whole type, but objects that are in $incompat_path,
76 # we don't skip here, just give info.
77 echo "postponed skip one of incompact $type version $arversion, changed at $incompat < code $myversion"
81 for f
in `ls $vdir/objects/$type`; do
84 # Check if processed object $f of $type should be skipped (postponed skip)
85 if [ -n "$incompat_paths" ]; then
86 for i_path
in $incompat_paths; do
87 # Check if $f is a symbolic link and if it's pointing to existing target
88 if [ -L "$i_path/$f" ]; then
89 echo "skipping object $f of type $type"
96 if [ $skip -ne 0 ]; then
100 $CEPH_DENCODER type $type import
$vdir/objects
/$type/$f decode dump_json
> $tmp1 &
102 $CEPH_DENCODER type $type import
$vdir/objects
/$type/$f decode encode decode dump_json
> $tmp2 &
104 #echo "\t$vdir/$type/$f"
105 if ! wait $pid1; then
106 echo "**** failed to decode $vdir/objects/$type/$f ****"
107 failed
=$
(($failed + 1))
111 if ! wait $pid2; then
112 echo "**** failed to decode+encode+decode $vdir/objects/$type/$f ****"
113 failed
=$
(($failed + 1))
118 # nondeterministic classes may dump
119 # nondeterministically. compare the sorted json
120 # output. this is a weaker test, but is better than
122 if ! $CEPH_DENCODER type $type is_deterministic
; then
123 echo " sorting json output for nondeterministic object"
124 for f
in $tmp1 $tmp2; do
125 sort $f |
sed 's/,$//' > $f.new
130 if ! cmp $tmp1 $tmp2; then
131 echo "**** reencode of $vdir/objects/$type/$f resulted in a different dump ****"
133 failed
=$
(($failed + 1))
135 numtests
=$
(($numtests + 1))
139 echo "skipping unrecognized type $type"
143 echo "failed=$failed" > $output_file
144 echo "numtests=$numtests" >> $output_file
148 ## Wait for children to exit and indicate whether all exited with 0 status.
151 debug
"Processes remaining: $*"
154 if kill -0 "$pid" 2>/dev
/null
; then
155 debug
"$pid is still alive."
157 elif wait "$pid"; then
158 debug
"$pid exited with zero exit status."
160 debug
"$pid exited with non-zero exit status."
161 errors
=$
(($errors + 1))
164 [ $# -eq 0 ] && break
165 sleep ${WAITALL_DELAY:-1}
177 # Reading the output of jobs to compute failed & numtests
178 # Tests are run in parallel but sum should be done sequentialy to avoid
179 # races between threads
180 while [ "$running_jobs" -ge 0 ]; do
181 if [ -f $output_file.
$running_jobs ]; then
182 read_failed
=$
(grep "^failed=" $output_file.
$running_jobs | cut
-d "=" -f 2)
183 read_numtests
=$
(grep "^numtests=" $output_file.
$running_jobs | cut
-d "=" -f 2)
184 rm -f $output_file.
$running_jobs
185 failed
=$
(($failed + $read_failed))
186 numtests
=$
(($numtests + $read_numtests))
188 running_jobs
=$
(($running_jobs - 1))
193 # Using $MAX_PARALLEL_JOBS jobs if defined, unless the number of logical
195 if [ `uname` == FreeBSD
-o `uname` == Darwin
]; then
196 NPROC
=`sysctl -n hw.ncpu`
197 max_parallel_jobs
=${MAX_PARALLEL_JOBS:-${NPROC}}
199 max_parallel_jobs
=${MAX_PARALLEL_JOBS:-$(nproc)}
202 output_file
=`mktemp /tmp/output_file-XXXXXXXXX`
205 for arversion
in `ls $dir/archive | sort -n`; do
206 vdir="$dir/archive/$arversion"
209 if [ ! -d "$vdir/objects" ]; then
213 for type in `ls $vdir/objects`; do
214 test_object
$type $output_file.
$running_jobs &
216 running_jobs
=$
(($running_jobs + 1))
218 # Once we spawned enough jobs, let's wait them to complete
219 # Every spawned job have almost the same execution time so
220 # it's not a big deal having them not ending at the same time
221 if [ "$running_jobs" -eq "$max_parallel_jobs" ]; then
224 rm -f ${output_file}*
230 if [ $failed -gt 0 ]; then
231 echo "FAILED $failed / $numtests tests."
235 if [ $numtests -eq 0 ]; then
236 echo "FAILED: no tests found to run!"
240 echo "passed $numtests tests."