02_File.py 2.6 KB

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