Commit 3825c3e5 authored by Pavel Emelyanov's avatar Pavel Emelyanov

crit: Speed up jenkins test ~60 times

Running crit tool 4 times per test (decode, encode, decode --pretty
and encode back again) is way too slow. The majority of time, as
it turned out, goes on python load and arguments parsing. The en-
and de-coding works pretty fast.

So doing re-code logic in one python script for ALL images is way
way faster -- ~1 hour vs ~1 minute on my box.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1b87ae8f
...@@ -135,6 +135,9 @@ def encode_dev(field, value): ...@@ -135,6 +135,9 @@ def encode_dev(field, value):
else: else:
return dev[0] << kern_minorbits | dev[1] return dev[0] << kern_minorbits | dev[1]
def is_string(value):
return isinstance(value, unicode) or isinstance(value, str)
def _pb2dict_cast(field, value, pretty = False, is_hex = False): def _pb2dict_cast(field, value, pretty = False, is_hex = False):
if not is_hex: if not is_hex:
is_hex = _marked_as_hex(field) is_hex = _marked_as_hex(field)
...@@ -209,7 +212,7 @@ def _dict2pb_cast(field, value): ...@@ -209,7 +212,7 @@ def _dict2pb_cast(field, value):
return field.enum_type.values_by_name.get(value, None).number return field.enum_type.values_by_name.get(value, None).number
elif field.type in _basic_cast: elif field.type in _basic_cast:
cast = _basic_cast[field.type] cast = _basic_cast[field.type]
if (cast == int or cast == long) and isinstance(value, unicode): if (cast == int or cast == long) and is_string(value):
if _marked_as_dev(field): if _marked_as_dev(field):
return encode_dev(field, value) return encode_dev(field, value)
...@@ -241,7 +244,7 @@ def dict2pb(d, pb): ...@@ -241,7 +244,7 @@ def dict2pb(d, pb):
value = d[field.name] value = d[field.name]
if field.label == FD.LABEL_REPEATED: if field.label == FD.LABEL_REPEATED:
pb_val = getattr(pb, field.name, None) pb_val = getattr(pb, field.name, None)
if isinstance(value[0], unicode) and _marked_as_ip(field): if is_string(value[0]) and _marked_as_ip(field):
val = ipaddr.IPAddress(value[0]) val = ipaddr.IPAddress(value[0])
if val.version == 4: if val.version == 4:
pb_val.append(socket.htonl(int(val))) pb_val.append(socket.htonl(int(val)))
......
#!/bin/env python
import pycriu
import sys
import os
import subprocess
find = subprocess.Popen(['find', 'test/dump/', '-name', '*.img'],
stdout = subprocess.PIPE)
test_pass = True
def recode_and_check(imgf, o_img, pretty):
try:
pb = pycriu.images.loads(o_img, pretty)
except pycriu.images.MagicException as me:
print "%s magic %x error" % (imgf, me.magic)
return False
except:
print "%s %sdecode fails" % (imgf, pretty and 'pretty ' or '')
return False
try:
r_img = pycriu.images.dumps(pb)
except:
print "%s %sencode fails" % (imgf, pretty and 'pretty ' or '')
return False
if o_img != r_img:
print "%s %srecode mismatch" % (imgf, pretty and 'pretty ' or '')
return False
return True
for imgf in find.stdout.readlines():
imgf = imgf.strip()
imgf_b = os.path.basename(imgf)
if imgf_b.startswith('pages-'):
continue
if imgf_b.startswith('iptables-'):
continue
if imgf_b.startswith('ip6tables-'):
continue
if imgf_b.startswith('route-'):
continue
if imgf_b.startswith('route6-'):
continue
if imgf_b.startswith('ifaddr-'):
continue
if imgf_b.startswith('tmpfs-'):
continue
o_img = open(imgf).read()
if not recode_and_check(imgf, o_img, False):
test_pass = False
if not recode_and_check(imgf, o_img, True):
test_pass = False
find.wait()
if not test_pass:
print "FAIL"
sys.exit(1)
print "PASS"
...@@ -3,43 +3,5 @@ set -e ...@@ -3,43 +3,5 @@ set -e
source `dirname $0`/criu-lib.sh source `dirname $0`/criu-lib.sh
prep prep
./test/zdtm.py run --all -f best -x maps04 -x cgroup02 --norst --keep always || fail ./test/zdtm.py run --all -f best -x maps04 -x cgroup02 --norst --keep always || fail
PYTHONPATH="$(pwd)" ./test/crit-recode.py || fail
FAIL_LIST="" exit 0
images_list=$(find "test/dump/" -name '*.img')
crit="./crit"
function note()
{
FAIL_LIST="${FAIL_LIST}\n$*"
}
for x in $images_list
do
[[ "$(basename $x)" == pages* ]] && continue
[[ "$(basename $x)" == route* ]] && continue
[[ "$(basename $x)" == ifaddr* ]] && continue
[[ "$(basename $x)" == iptables* ]] && continue
[[ "$(basename $x)" == ip6tables* ]] && continue
[[ "$(basename $x)" == *tar.gz* ]] && continue
echo "Check $x"
$crit decode -o "$x"".json" < "$x" || note "dec $x"
$crit encode -i "$x"".json" > "${x}.json.img" || note "enc $x"
cmp "$x" "${x}.json.img" || note "cmp $x"
rm -f "${x}.json.img"
$crit decode -o "$x"".json" --pretty < "$x" || note "show $x"
$crit encode -i "$x"".json" > "${x}.json.img" || note "enc2 $x"
cmp "$x" "${x}.json.img" || note "cmp2 $x"
rm -f "${x}.json.img"
done
if [ -z "$FAIL_LIST" ]; then
echo "PASS"
exit 0
fi
echo -e "$FAIL_LIST"
echo "FAIL"
exit 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment