2023-06-22 00:06:53 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-06-02 00:02:53 +03:00
|
|
|
import pycriu
|
2015-12-10 17:05:00 +03:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
find = subprocess.Popen(
|
|
|
|
['find', 'test/dump/', '-size', '+0', '-name', '*.img'],
|
|
|
|
stdout=subprocess.PIPE)
|
2015-12-10 17:05:00 +03:00
|
|
|
|
|
|
|
test_pass = True
|
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
|
2015-12-10 17:05:00 +03:00
|
|
|
def recode_and_check(imgf, o_img, pretty):
|
2019-09-07 15:46:22 +03:00
|
|
|
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 Exception as e:
|
|
|
|
print("%s %sdecode fails: %s" % (imgf, pretty and 'pretty ' or '', e))
|
|
|
|
return False
|
2015-12-10 17:05:00 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
try:
|
|
|
|
r_img = pycriu.images.dumps(pb)
|
|
|
|
except Exception as e:
|
|
|
|
r_img = pycriu.images.dumps(pb)
|
|
|
|
print("%s %s encode fails: %s" % (imgf, pretty and 'pretty ' or '', e))
|
|
|
|
return False
|
2015-12-10 17:05:00 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
if o_img != r_img:
|
|
|
|
print("%s %s recode mismatch" % (imgf, pretty and 'pretty ' or ''))
|
|
|
|
return False
|
2015-12-10 17:05:00 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
return True
|
2015-12-10 17:05:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
for imgf in find.stdout.readlines():
|
2019-09-07 15:46:22 +03:00
|
|
|
imgf = imgf.strip()
|
|
|
|
imgf_b = os.path.basename(imgf)
|
2015-12-10 17:05:00 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
if imgf_b.startswith(b'pages-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'iptables-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'ip6tables-'):
|
|
|
|
continue
|
2020-03-10 17:40:57 +03:00
|
|
|
if imgf_b.startswith(b'nftables-'):
|
|
|
|
continue
|
2019-09-07 15:46:22 +03:00
|
|
|
if imgf_b.startswith(b'route-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'route6-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'ifaddr-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'tmpfs-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'netns-ct-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'netns-exp-'):
|
|
|
|
continue
|
|
|
|
if imgf_b.startswith(b'rule-'):
|
|
|
|
continue
|
2015-12-10 17:05:00 +03:00
|
|
|
|
2019-09-07 15:46:22 +03:00
|
|
|
o_img = open(imgf.decode(), "rb").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
|
2015-12-10 17:05:00 +03:00
|
|
|
|
|
|
|
find.wait()
|
|
|
|
|
|
|
|
if not test_pass:
|
2019-09-07 15:46:22 +03:00
|
|
|
print("FAIL")
|
|
|
|
sys.exit(1)
|
2015-12-10 17:05:00 +03:00
|
|
|
|
2018-06-02 00:02:55 +03:00
|
|
|
print("PASS")
|