parse_test.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2010, Willow Garage, Inc.
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of the Willow Garage nor the names of its
19 # contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 
35 ##\author Kevin Watts
36 
37 from __future__ import with_statement
38 
39 PKG = 'pr2_computer_monitor'
40 
41 import roslib; roslib.load_manifest(PKG)
42 import unittest
43 
44 import pr2_computer_monitor
45 
46 import os, sys
47 
48 TEXT_PATH = 'test/sample_output/nvidia_smi_out.txt'
49 TEXT_HIGH_TEMP_PATH = 'test/sample_output/nvidia_smi_high_temp.txt'
50 
51 
52 ##\brief Parses launch, tests.xml and configs.xml files in qualification
53 class TestNominalParser(unittest.TestCase):
54  def setUp(self):
55  with open(os.path.join(roslib.packages.get_pkg_dir('pr2_computer_monitor'), TEXT_PATH), 'r') as f:
56  self.data = f.read()
57 
58  with open(os.path.join(roslib.packages.get_pkg_dir('pr2_computer_monitor'), TEXT_HIGH_TEMP_PATH), 'r') as f:
59  self.high_temp_data = f.read()
60 
61  def test_parse(self):
62  gpu_stat = pr2_computer_monitor.parse_smi_output(self.data)
63 
64  # Check valid
65  self.assert_(self.data, "Unable to read sample output, no test to run")
66 
67  # Check all string fields of message
68  self.assert_(gpu_stat.pci_device_id, "No PCI Device ID found")
69  self.assert_(gpu_stat.pci_location, "No PCI Location found")
70  self.assert_(gpu_stat.display, "No Display found")
71  self.assert_(gpu_stat.driver_version, "No Driver Version found")
72  self.assert_(gpu_stat.product_name, "No Product Name found")
73 
74  self.assert_(gpu_stat.temperature > 40 and gpu_stat.temperature < 90, "Invalid temperature readings. Temperature: %d" % gpu_stat.temperature)
75  self.assert_(gpu_stat.fan_speed > 0 and gpu_stat.fan_speed < 471, "Invalid fan speed readings. Fan Speed %f" % gpu_stat.fan_speed)
76 
77  diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
78 
79  self.assert_(diag_stat.level == 0, "Diagnostics reports an error for nominal input. Message: %s" % diag_stat.message)
80 
82  gpu_stat = pr2_computer_monitor.parse_smi_output(self.high_temp_data)
83 
84  # Check valid
85  self.assert_(self.high_temp_data, "Unable to read sample output, no test to run")
86 
87  # Check all string fields of message
88  self.assert_(gpu_stat.pci_device_id, "No PCI Device ID found")
89  self.assert_(gpu_stat.pci_location, "No PCI Location found")
90  self.assert_(gpu_stat.display, "No Display found")
91  self.assert_(gpu_stat.driver_version, "No Driver Version found")
92  self.assert_(gpu_stat.product_name, "No Product Name found")
93 
94  self.assert_(gpu_stat.temperature > 90, "Invalid temperature readings. Temperature: %d" % gpu_stat.temperature)
95  self.assert_(gpu_stat.fan_speed > 0 and gpu_stat.fan_speed < 471, "Invalid fan speed readings. Fan Speed %s" % gpu_stat.fan_speed)
96 
97  diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
98 
99  self.assert_(diag_stat.level == 1, "Diagnostics didn't report warning for high temp input. Level %d, Message: %s" % (diag_stat.level, diag_stat.message))
100 
101 
102  def test_empty_parse(self):
103  gpu_stat = pr2_computer_monitor.parse_smi_output('')
104 
105  self.assert_(gpu_stat.temperature == 0, "Invalid temperature reading. Should be 0. Reading: %d" % gpu_stat.temperature)
106 
107  diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
108 
109  self.assert_(diag_stat.level == 2, "Diagnostics didn't reports an error for empty input. Level: %d, Message: %s" % (diag_stat.level, diag_stat.message))
110 
111 
112 
113 if __name__ == '__main__':
114  if len(sys.argv) > 1 and sys.argv[1] == '-v':
115  # Use to run tests verbosly
116  suite = unittest.TestSuite()
117  suite.addTest(TestNominalParser('test_parse'))
118  suite.addTest(TestNominalParser('test_empty_parse'))
119  suite.addTest(TestNominalParser('test_high_temp_parse'))
120 
121  unittest.TextTestRunner(verbosity = 2).run(suite)
122  else:
123  import rostest
124  rostest.unitrun(PKG, 'parse_nominal', TestNominalParser)
125 
126 
Parses launch, tests.xml and configs.xml files in qualification.
Definition: parse_test.py:53


pr2_computer_monitor
Author(s): Kevin Watts (watts@willowgarage.com)
autogenerated on Tue Jun 1 2021 02:50:51