02_File.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/python
  2. import os, sys, mmap, random, string
  3. from regression import Regression
  4. loader = '../src/pal'
  5. def prepare_files(args):
  6. global file_exist
  7. file_exist = ''.join([random.choice(string.ascii_letters) for i in range(mmap.PAGESIZE)])
  8. with open("file_exist.tmp", "w") as f:
  9. f.write(file_exist)
  10. if os.path.exists("file_nonexist.tmp"):
  11. os.remove("file_nonexist.tmp")
  12. with open("file_delete.tmp", "w") as f:
  13. f.write(file_exist)
  14. # Running File
  15. regression = Regression(loader, "File", prepare_files)
  16. regression.add_check(name="Basic File Opening",
  17. check=lambda res: "File Open Test 1 OK" in res[0].log and
  18. "File Open Test 2 OK" in res[0].log and
  19. "File Open Test 3 OK" in res[0].log)
  20. regression.add_check(name="Basic File Creation",
  21. check=lambda res: "File Creation Test 1 OK" in res[0].log and
  22. "File Creation Test 2 OK" in res[0].log and
  23. "File Creation Test 3 OK" in res[0].log)
  24. regression.add_check(name="File Reading",
  25. check=lambda res: ("Read Test 1 (0th - 40th): " + file_exist[0:40]) in res[0].log and
  26. ("Read Test 2 (0th - 40th): " + file_exist[0:40]) in res[0].log and
  27. ("Read Test 3 (200th - 240th): " + file_exist[200:240]) in res[0].log)
  28. def check_write(res):
  29. global file_exist
  30. with open("file_nonexist.tmp", "r") as f:
  31. file_nonexist = f.read()
  32. return file_exist[0:40] == file_nonexist[200:240] and \
  33. file_exist[200:240] == file_nonexist[0:40]
  34. regression.add_check(name="File Writing", check=check_write)
  35. regression.add_check(name="File Attribute Query",
  36. check=lambda res: ("Query: type = 1, size = %d" % (mmap.PAGESIZE)) in res[0].log)
  37. regression.add_check(name="File Attribute Query by Handle",
  38. check=lambda res: ("Query by Handle: type = 1, size = %d" % (mmap.PAGESIZE)) in res[0].log)
  39. regression.add_check(name="File Mapping",
  40. check=lambda res: ("Map Test 1 (0th - 40th): " + file_exist[0:40]) in res[0].log and
  41. ("Map Test 2 (200th - 240th): " + file_exist[200:240]) 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. regression.run_checks()