UnitTest.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import re
  2. import time
  3. from TCAction import PerformanceTCBase
  4. from TCAction import TCActionBase
  5. from NativeLog import NativeLog
  6. class UnitTest(PerformanceTCBase.PerformanceTCBase):
  7. def __init__(self, name, test_env, cmd_set, timeout=30, log_path=TCActionBase.LOG_PATH):
  8. PerformanceTCBase.PerformanceTCBase.__init__(self, name, test_env, cmd_set=cmd_set,
  9. timeout=timeout, log_path=log_path)
  10. self.test_case = None
  11. self.test_timeout = 20
  12. # load param from excel
  13. for i in range(1, len(cmd_set)):
  14. if cmd_set[i][0] != "dummy":
  15. cmd_string = "self." + cmd_set[i][0]
  16. exec cmd_string
  17. self.result_cntx = TCActionBase.ResultCheckContext(self, test_env, self.tc_name)
  18. pass
  19. def send_commands(self):
  20. self.flush_data("UT1")
  21. try:
  22. # add case select by name mark " before case name
  23. self.serial_write_line("UT1", "\"" + self.test_case)
  24. data = ""
  25. for _ in range(self.timeout):
  26. time.sleep(1) #wait for test to run before reading result
  27. data += self.serial_read_data("UT1")
  28. if re.search('[^0] Tests 0 F', data): #check that number of tests run != 0 and number of tests failed == 0
  29. self.set_result("Succeed")
  30. break
  31. else:
  32. self.set_result("Fail")
  33. except StandardError,e:
  34. NativeLog.add_exception_log(e)
  35. def execute(self):
  36. TCActionBase.TCActionBase.execute(self)
  37. self.send_commands()
  38. def main():
  39. pass
  40. if __name__ == '__main__':
  41. pass