02_File.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import os, sys, mmap, random, string
  2. from regression import Regression
  3. loader = os.environ['PAL_LOADER']
  4. def prepare_files(args):
  5. global file_exist
  6. file_exist = open('File', 'rb').read()
  7. if os.path.exists("file_nonexist.tmp"):
  8. os.remove("file_nonexist.tmp")
  9. with open("file_delete.tmp", "wb") as f:
  10. f.write(file_exist)
  11. # Running File
  12. regression = Regression(loader, "File", prepare_files)
  13. regression.add_check(name="Basic File Opening",
  14. check=lambda res: "File Open Test 1 OK" in res[0].log and
  15. "File Open Test 2 OK" in res[0].log and
  16. "File Open Test 3 OK" in res[0].log)
  17. regression.add_check(name="Basic File Creation",
  18. check=lambda res: "File Creation Test 1 OK" in res[0].log and
  19. "File Creation Test 2 OK" in res[0].log and
  20. "File Creation Test 3 OK" in res[0].log)
  21. regression.add_check(name="File Reading",
  22. check=lambda res: ("Read Test 1 (0th - 40th): " + file_exist[0:40].hex()) in res[0].log and
  23. ("Read Test 2 (0th - 40th): " + file_exist[0:40].hex()) in res[0].log and
  24. ("Read Test 3 (200th - 240th): " + file_exist[200:240].hex()) in res[0].log)
  25. def check_write(res):
  26. global file_exist
  27. with open("file_nonexist.tmp", "rb") as f:
  28. file_nonexist = f.read()
  29. return file_exist[0:40] == file_nonexist[200:240] and \
  30. file_exist[200:240] == file_nonexist[0:40]
  31. regression.add_check(name="File Writing", check=check_write)
  32. regression.add_check(name="File Attribute Query",
  33. check=lambda res: ("Query: type = 1, size = %d" % (len(file_exist))) in res[0].log)
  34. regression.add_check(name="File Attribute Query by Handle",
  35. check=lambda res: ("Query by Handle: type = 1, size = %d" % (len(file_exist))) in res[0].log)
  36. regression.add_check(name="File Mapping",
  37. check=lambda res: ("Map Test 1 (0th - 40th): " + file_exist[0:40].hex()) in res[0].log and
  38. ("Map Test 2 (200th - 240th): " + file_exist[200:240].hex()) in res[0].log and
  39. ("Map Test 3 (4096th - 4136th): " + file_exist[4096:4136].hex()) in res[0].log and
  40. ("Map Test 4 (4296th - 4336th): " + file_exist[4296:4336].hex()) in res[0].log)
  41. regression.add_check(name="Set File Length",
  42. check=lambda res: os.stat("file_nonexist.tmp").st_size == mmap.ALLOCATIONGRANULARITY)
  43. regression.add_check(name="File Deletion",
  44. check=lambda res: not os.path.exists("file_delete.tmp"))
  45. rv = regression.run_checks()
  46. if rv: sys.exit(rv)