Skip to content

Commit

Permalink
[*/regression] Migrate to Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
HW42 authored and mkow committed Apr 15, 2019
1 parent 3d60004 commit 79d6fb2
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions Jenkinsfiles/ubuntu-16.04.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apt-get update \
python \
python-crypto \
python-protobuf \
python3-minimal \
texinfo \
wget \

Expand Down
8 changes: 4 additions & 4 deletions LibOS/shim/test/regression/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ endif
.PHONY: regression
regression: $(target)
@echo "\n\nBasic Bootstrapping:"
@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@echo "\n\nSyscall Support:"
@for f in $(wildcard 30_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@for f in $(wildcard 30_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@echo "\n\nSocket Support:"
@for f in $(wildcard 80_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@for f in $(wildcard 80_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@echo "\n\nLarge File Support:"
@for f in $(wildcard 90_*.py); do env $(PYTHONENV) python $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done
@for f in $(wildcard 90_*.py); do env $(PYTHONENV) python3 $$f $(RUNTIME)/pal-$(PAL_HOST) || exit $$?; done

.PHONY: clean-tmp
clean-tmp:
Expand Down
21 changes: 10 additions & 11 deletions Pal/regression/02_File.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys, mmap, random, string, binascii
import os, sys, mmap, random, string
from regression import Regression

loader = os.environ['PAL_LOADER']
Expand All @@ -10,7 +10,7 @@ def prepare_files(args):
if os.path.exists("file_nonexist.tmp"):
os.remove("file_nonexist.tmp")

with open("file_delete.tmp", "w") as f:
with open("file_delete.tmp", "wb") as f:
f.write(file_exist)

# Running File
Expand All @@ -27,13 +27,13 @@ def prepare_files(args):
"File Creation Test 3 OK" in res[0].log)

regression.add_check(name="File Reading",
check=lambda res: ("Read Test 1 (0th - 40th): " + binascii.hexlify(file_exist[0:40])) in res[0].log and
("Read Test 2 (0th - 40th): " + binascii.hexlify(file_exist[0:40])) in res[0].log and
("Read Test 3 (200th - 240th): " + binascii.hexlify(file_exist[200:240])) in res[0].log)
check=lambda res: ("Read Test 1 (0th - 40th): " + file_exist[0:40].hex()) in res[0].log and
("Read Test 2 (0th - 40th): " + file_exist[0:40].hex()) in res[0].log and
("Read Test 3 (200th - 240th): " + file_exist[200:240].hex()) in res[0].log)

def check_write(res):
global file_exist
with open("file_nonexist.tmp", "r") as f:
with open("file_nonexist.tmp", "rb") as f:
file_nonexist = f.read()
return file_exist[0:40] == file_nonexist[200:240] and \
file_exist[200:240] == file_nonexist[0:40]
Expand All @@ -47,11 +47,10 @@ def check_write(res):
check=lambda res: ("Query by Handle: type = 1, size = %d" % (len(file_exist))) in res[0].log)

regression.add_check(name="File Mapping",
check=lambda res: ("Map Test 1 (0th - 40th): " + binascii.hexlify(file_exist[0:40])) in res[0].log and
("Map Test 2 (200th - 240th): " + binascii.hexlify(file_exist[200:240])) in res[0].log and
("Map Test 3 (4096th - 4136th): " + binascii.hexlify(file_exist[4096:4136])) in res[0].log and
("Map Test 4 (4296th - 4336th): " +
binascii.hexlify(file_exist[4296:4336])) in res[0].log)
check=lambda res: ("Map Test 1 (0th - 40th): " + file_exist[0:40].hex()) in res[0].log and
("Map Test 2 (200th - 240th): " + file_exist[200:240].hex()) in res[0].log and
("Map Test 3 (4096th - 4136th): " + file_exist[4096:4136].hex()) in res[0].log and
("Map Test 4 (4296th - 4336th): " + file_exist[4296:4336].hex()) in res[0].log)

regression.add_check(name="Set File Length",
check=lambda res: os.stat("file_nonexist.tmp").st_size == mmap.ALLOCATIONGRANULARITY)
Expand Down
4 changes: 2 additions & 2 deletions Pal/regression/04_Ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
sgx = 0

if sgx:
print "Bulk IPC not supported on SGX"
print("Bulk IPC not supported on SGX")
exit(0)

## XXX Should really be running these tests as part of CI
if not os.path.exists('/dev/gipc'):
print "GIPC not loaded; skipping these tests\n"
print("GIPC not loaded; skipping these tests\n")
exit(0)

def prepare_files(args):
Expand Down
2 changes: 1 addition & 1 deletion Pal/regression/05_Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
loader = os.environ['PAL_SEC']

if not os.path.exists(loader):
print "Reference monitor mode is not available on this platform"
print("Reference monitor mode is not available on this platform")
exit(0)

regression = Regression(loader, "Process")
Expand Down
2 changes: 1 addition & 1 deletion Pal/regression/05_Reference_Monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
loader = os.environ['PAL_SEC']

if not os.path.exists(loader):
print "Reference monitor mode is not available on this platform"
print("Reference monitor mode is not available on this platform")
exit(0)

# Running Bootstrap
Expand Down
12 changes: 6 additions & 6 deletions Pal/regression/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ endif

regression: $(call expand_target,$(target))
@printf "\n\nBasic Bootstrapping:\n"
@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python $$f || exit $$?; done
@for f in $(wildcard 00_*.py); do env $(PYTHONENV) python3 $$f || exit $$?; done
@printf "\n\nException Handling:\n"
@for f in $(wildcard 01_*.py); do env $(PYTHONENV) python $$f || exit $$?; done
@for f in $(wildcard 01_*.py); do env $(PYTHONENV) python3 $$f || exit $$?; done
@printf "\n\nSingle-Process Functionalities:\n"
@for f in $(wildcard 02_*.py); do env $(PYTHONENV) python $$f || exit $$?; done
@for f in $(wildcard 02_*.py); do env $(PYTHONENV) python3 $$f || exit $$?; done
@printf "\n\nProcess Creation:\n"
@for f in $(wildcard 03_*.py); do env $(PYTHONENV) python $$f || exit $$?; done
@for f in $(wildcard 03_*.py); do env $(PYTHONENV) python3 $$f || exit $$?; done
@printf "\n\nMulti-Process Functionalities:\n"
@for f in $(wildcard 04_*.py); do env $(PYTHONENV) python $$f || exit $$?; done
@for f in $(wildcard 04_*.py); do env $(PYTHONENV) python3 $$f || exit $$?; done
@printf "\n\nReference Monitor (Optional):\n"
@for f in $(wildcard 05_*.py); do env $(PYTHONENV) python $$f || exit $$?; done
@for f in $(wildcard 05_*.py); do env $(PYTHONENV) python3 $$f || exit $$?; done
@printf "\n\n"

.PHONY: clean
Expand Down
14 changes: 7 additions & 7 deletions Scripts/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def run_checks(self):

time.sleep(0.1)

out = p.stdout.read()
log = p.stderr.read()
out = p.stdout.read().decode('utf-8')
log = p.stderr.read().decode('utf-8')

outputs.append(Result(out, log, p.returncode))

Expand All @@ -80,22 +80,22 @@ def run_checks(self):
if run_times == times:
result = check(outputs)
if not timed_out and result:
print '\033[92m[Success ]\033[0m', name
print('\033[92m[Success ]\033[0m', name)
else:
if ignore_failure:
print '[Fail (Ignored)]', name
print('[Fail (Ignored)]', name)
else:
print '\033[93m[Fail ]\033[0m', name
print('\033[93m[Fail ]\033[0m', name)
something_failed = 1
if timed_out : print 'Test timed out!'
if timed_out : print('Test timed out!')
keep_log = True

if self.keep_log and keep_log:
sargs = [re.sub(r"\W", '_', a).strip('_') for a in args]
filename = 'log-' + '_'.join(sargs) + '_' + time.strftime("%Y%m%d_%H%M%S")
with open(filename, 'w') as f:
f.write(log + out)
print 'keep log to %s' % (filename)
print('keep log to %s' % (filename))
if something_failed:
return -1
else:
Expand Down

0 comments on commit 79d6fb2

Please sign in to comment.