cont_frame.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Software License Agreement (BSD License)
00004 #
00005 # Copyright (c) 2010, Willow Garage, Inc.
00006 # All rights reserved.
00007 #
00008 # Redistribution and use in source and binary forms, with or without
00009 # modification, are permitted provided that the following conditions
00010 # are met:
00011 #
00012 #  * Redistributions of source code must retain the above copyright
00013 #    notice, this list of conditions and the following disclaimer.
00014 #  * Redistributions in binary form must reproduce the above
00015 #    copyright notice, this list of conditions and the following
00016 #    disclaimer in the documentation and/or other materials provided
00017 #    with the distribution.
00018 #  * Neither the name of the Willow Garage nor the names of its
00019 #    contributors may be used to endorse or promote products derived
00020 #    from this software without specific prior written permission.
00021 #
00022 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 # POSSIBILITY OF SUCH DAMAGE.
00034 
00035 ##\author Kevin Watts
00036 ##\brief Allows qualification test to be run continuously
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 # May want to change to rostime
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         # Load the XRC resource
00069         xrc_path = os.path.join(roslib.packages.get_pkg_dir('qualification'), 'xrc/gui.xrc')
00070         self._res = xrc.XmlResource(xrc_path)
00071 
00072         # Load the main panel
00073         self._cont_panel = self._res.LoadPanel(self, 'continuous_test_panel')
00074 
00075         # Input
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         # Display
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         # Get tar filename, write to summary file
00139         results.write_results_to_file() # Write to temp dir   
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()


qualification
Author(s): Kevin Watts (watts@willowgarage.com), Josh Faust (jfaust@willowgarage.com)
autogenerated on Sat Dec 28 2013 17:57:34