02_Directory.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/python
  2. import os, sys, mmap, random, string, shutil
  3. from regression import Regression
  4. loader = os.environ['PAL_LOADER']
  5. def prepare_dirs(args):
  6. if os.path.exists("dir_exist.tmp"):
  7. shutil.rmtree("dir_exist.tmp")
  8. if os.path.exists("dir_nonexist.tmp"):
  9. shutil.rmtree("dir_nonexist.tmp")
  10. if os.path.exists("dir_delete.tmp"):
  11. shutil.rmtree("dir_delete.tmp")
  12. global dir_files
  13. os.mkdir("dir_exist.tmp")
  14. dir_files = []
  15. for i in range(5):
  16. file = ''.join([random.choice(string.ascii_letters) for i in range(8)])
  17. f = open("dir_exist.tmp/" + file, "w")
  18. f.close()
  19. dir_files.append(file)
  20. os.mkdir("dir_delete.tmp")
  21. regression = Regression(loader, "Directory", prepare_dirs)
  22. regression.add_check(name="Basic Directory Opening",
  23. check=lambda res: "Directory Open Test 1 OK" in res[0].log and
  24. "Directory Open Test 2 OK" in res[0].log and
  25. "Directory Open Test 3 OK" in res[0].log)
  26. regression.add_check(name="Basic Directory Creation",
  27. check=lambda res: "Directory Creation Test 1 OK" in res[0].log and
  28. "Directory Creation Test 2 OK" in res[0].log and
  29. "Directory Creation Test 3 OK" in res[0].log)
  30. def check_read(res):
  31. global dir_files
  32. for file in dir_files:
  33. if ("Read Directory: " + file) not in res[0].log:
  34. return False
  35. return True
  36. regression.add_check(name="Directory Reading", check=check_read)
  37. regression.add_check(name="Directory Attribute Query",
  38. check=lambda res: "Query: type = 7" in res[0].log)
  39. regression.add_check(name="Directory Attribute Query by Handle",
  40. check=lambda res: "Query by Handle: type = 7" in res[0].log)
  41. regression.add_check(name="Directory Deletion",
  42. check=lambda res: not os.path.exists("dir_delete.tmp"))
  43. rv = regression.run_checks()
  44. if rv: sys.exit(rv)