00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 from __future__ import with_statement
00039
00040 PKG = 'qualification'
00041
00042 import roslib
00043 roslib.load_manifest(PKG)
00044
00045 import rospy
00046
00047 import os
00048 import sys
00049 import threading
00050
00051 from datetime import datetime
00052 import wx
00053 import time
00054 from wx import xrc
00055 from wx import html
00056
00057 from xml.dom import minidom
00058
00059 import result_dir
00060 import csv
00061
00062 class ContinuousTestFrame(wx.Frame):
00063 def __init__(self, parent):
00064 wx.Frame.__init__(self, parent, wx.ID_ANY, "Continuous Testing")
00065
00066 self._manager = parent
00067
00068
00069 xrc_path = os.path.join(roslib.packages.get_pkg_dir('qualification'), 'xrc/gui.xrc')
00070 self._res = xrc.XmlResource(xrc_path)
00071
00072
00073 self._cont_panel = self._res.LoadPanel(self, 'continuous_test_panel')
00074
00075
00076 self._submit_box = xrc.XRCCTRL(self._cont_panel, 'submit_box')
00077 self._pause_on_fail_box = xrc.XRCCTRL(self._cont_panel, 'pause_on_fail_box')
00078 self._abort_button = xrc.XRCCTRL(self._cont_panel, 'abort_button')
00079 self._abort_button.Bind(wx.EVT_BUTTON, self.abort)
00080
00081
00082 self._complete_text = xrc.XRCCTRL(self._cont_panel, 'completed_text')
00083 self._passed_text = xrc.XRCCTRL(self._cont_panel, 'passed_text')
00084 self._last_result_text = xrc.XRCCTRL(self._cont_panel, 'last_result_text')
00085 self._log_file_text = xrc.XRCCTRL(self._cont_panel, 'log_file_text')
00086
00087 self._last_result = 'N/A'
00088 self._total_tests = 0
00089 self._passed_tests = 0
00090
00091 date_str = datetime.now().strftime("%m%d%Y_%H%M")
00092 basename = '%s_cycle_log.csv' % date_str
00093 self._log = os.path.join(result_dir.RESULTS_DIR, basename.replace(' ', ''))
00094 with open(self._log, 'wb') as f:
00095 log_csv = csv.writer(f)
00096 log_csv.writerow(['Time', 'Cycle#', 'Successes', 'Result', 'Tar Name', 'Submit OK', 'Summary'])
00097 self._log_file_text.SetValue(basename)
00098
00099 self.Bind(wx.EVT_CLOSE, self.on_close)
00100
00101 @property
00102 def pause_on_fail(self): return self._pause_on_fail_box.IsChecked()
00103
00104 def on_close(self, event):
00105 if event.CanVeto():
00106 wx.MessageBox("Press \"Abort\" to stop continuous testing", "Use Abort Button",
00107 wx.OK|wx.ICON_ERROR, self)
00108 event.Veto()
00109 return
00110
00111 self.Destroy()
00112
00113 def abort(self, event):
00114 are_you_sure = wx.MessageDialog(self, "Are you sure you want to abort continuous testing?",
00115 "Confirm Abort", wx.OK|wx.CANCEL)
00116 if are_you_sure.ShowModal() != wx.ID_OK:
00117 return
00118
00119 wx.MessageBox('Continuous mode disabled. Data in %s.' % self._log, 'Continuous Mode Finished',
00120 wx.OK|wx.ICON_ERROR, self)
00121
00122 self._manager.stop_continuous_testing()
00123
00124 def new_results(self, results, invent):
00125 self._total_tests += 1
00126 failed_test = "Pass"
00127 if results.get_pass_bool():
00128 self._passed_tests += 1
00129 else:
00130 failed_test_num = len(results.get_subresults())
00131 if not failed_test_num:
00132 failed_test = "Pretest failed."
00133 else:
00134 failed_test_str = results.get_subresult(failed_test_num - 1)._summary
00135 failed_test = "Failed test %i: %s"%(failed_test_num, failed_test_str)
00136 self._last_result = results.get_test_result_str()
00137
00138
00139 results.write_results_to_file()
00140 tar_name = results.tar_name
00141
00142 submit_stat = 'N/A'
00143 if self._submit_box.IsChecked() and invent:
00144 res, msg = results.log_results(invent)
00145 if not res:
00146 submit_stat = 'FAIL: %s' % msg
00147 else:
00148 submit_stat = 'OK'
00149 else:
00150 results.write_results_to_file(temp = False, local_link = True)
00151
00152 with open(self._log, 'ab') as f:
00153 log_csv = csv.writer(f)
00154 log_csv.writerow([datetime.now().strftime("%m/%d/%Y %H:%M:%S"), self._total_tests, self._passed_tests, self._last_result, tar_name, submit_stat, failed_test])
00155
00156
00157 self._complete_text.SetValue(str(self._total_tests))
00158 self._passed_text.SetValue(str(self._passed_tests))
00159 self._last_result_text.SetValue(str(self._last_result))
00160
00161 success_rate = float(self._passed_tests) / self._total_tests
00162 sys.stdout.flush()
00163 sys.stderr.flush()
00164 print "Completed test %i: %s"%(self._total_tests, failed_test)
00165 print "Successes %i -> %.1f %% success rate."%(self._passed_tests, success_rate*100)
00166 print
00167 print
00168 print
00169 sys.stdout.flush()
00170 sys.stderr.flush()