Browse Source

[*/regression] Migrate to Python 3

Simon Gaiser 5 years ago
parent
commit
79d6fb27ec

+ 1 - 0
Jenkinsfiles/ubuntu-16.04.dockerfile

@@ -18,6 +18,7 @@ RUN apt-get update \
        python \
        python-crypto \
        python-protobuf \
+       python3-minimal \
        texinfo \
        wget \
 

+ 4 - 4
LibOS/shim/test/regression/Makefile

@@ -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:

+ 10 - 11
Pal/regression/02_File.py

@@ -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']
@@ -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
@@ -27,13 +27,13 @@ regression.add_check(name="Basic File Creation",
                       "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]
@@ -47,11 +47,10 @@ regression.add_check(name="File Attribute Query by Handle",
     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)

+ 2 - 2
Pal/regression/04_Ipc.py

@@ -8,12 +8,12 @@ except KeyError:
     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):

+ 1 - 1
Pal/regression/05_Process.py

@@ -7,7 +7,7 @@ from regression import Regression
 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")

+ 1 - 1
Pal/regression/05_Reference_Monitor.py

@@ -4,7 +4,7 @@ from regression import Regression
 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

+ 6 - 6
Pal/regression/Makefile

@@ -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

+ 7 - 7
Scripts/regression.py

@@ -69,8 +69,8 @@ class Regression:
 
                 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))
 
@@ -80,14 +80,14 @@ class Regression:
                     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:
@@ -95,7 +95,7 @@ class Regression:
                     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: