[CRIU] [PATCH] crit: Speed up jenkins test ~60 times
Pavel Emelyanov
xemul at parallels.com
Thu Dec 10 06:05:52 PST 2015
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: Pavel Emelyanov <xemul at parallels.com>
---
pycriu/images/pb2dict.py | 7 +++--
test/crit-recode.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++
test/jenkins/crit.sh | 42 ++----------------------------
3 files changed, 74 insertions(+), 42 deletions(-)
create mode 100755 test/crit-recode.py
diff --git a/pycriu/images/pb2dict.py b/pycriu/images/pb2dict.py
index 57e6dc6..177cda3 100644
--- a/pycriu/images/pb2dict.py
+++ b/pycriu/images/pb2dict.py
@@ -135,6 +135,9 @@ def encode_dev(field, value):
else:
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):
if not is_hex:
is_hex = _marked_as_hex(field)
@@ -209,7 +212,7 @@ def _dict2pb_cast(field, value):
return field.enum_type.values_by_name.get(value, None).number
elif field.type in _basic_cast:
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):
return encode_dev(field, value)
@@ -241,7 +244,7 @@ def dict2pb(d, pb):
value = d[field.name]
if field.label == FD.LABEL_REPEATED:
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])
if val.version == 4:
pb_val.append(socket.htonl(int(val)))
diff --git a/test/crit-recode.py b/test/crit-recode.py
new file mode 100755
index 0000000..6b9b234
--- /dev/null
+++ b/test/crit-recode.py
@@ -0,0 +1,67 @@
+#!/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"
diff --git a/test/jenkins/crit.sh b/test/jenkins/crit.sh
index f58f483..e551358 100755
--- a/test/jenkins/crit.sh
+++ b/test/jenkins/crit.sh
@@ -3,43 +3,5 @@ set -e
source `dirname $0`/criu-lib.sh
prep
./test/zdtm.py run --all -f best -x maps04 -x cgroup02 --norst --keep always || fail
-
-FAIL_LIST=""
-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
+PYTHONPATH="$(pwd)" ./test/crit-recode.py || fail
+exit 0
--
1.9.3
More information about the CRIU
mailing list