02_File.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os, sys, mmap, random, string, binascii
  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", "w") 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): " + binascii.hexlify(file_exist[0:40])) in res[0].log and
  23. ("Read Test 2 (0th - 40th): " + binascii.hexlify(file_exist[0:40])) in res[0].log and
  24. ("Read Test 3 (200th - 240th): " + binascii.hexlify(file_exist[200:240])) in res[0].log)
  25. def check_write(res):
  26. global file_exist
  27. with open("file_nonexist.tmp", "r") 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): " + binascii.hexlify(file_exist[0:40])) in res[0].log and
  38. ("Map Test 2 (200th - 240th): " + binascii.hexlify(file_exist[200:240])) in res[0].log and
  39. ("Map Test 3 (4096th - 4136th): " + binascii.hexlify(file_exist[4096:4136])) in res[0].log and
  40. ("Map Test 4 (4296th - 4336th): " +
  41. binascii.hexlify(file_exist[4296:4336])) in res[0].log)
  42. regression.add_check(name="Set File Length",
  43. check=lambda res: os.stat("file_nonexist.tmp").st_size == mmap.ALLOCATIONGRANULARITY)
  44. regression.add_check(name="File Deletion",
  45. check=lambda res: not os.path.exists("file_delete.tmp"))
  46. rv = regression.run_checks()
  47. if rv: sys.exit(rv)