37 from __future__
import with_statement
39 PKG =
'pr2_computer_monitor' 41 import roslib; roslib.load_manifest(PKG)
44 import pr2_computer_monitor
48 TEXT_PATH =
'test/sample_output/nvidia_smi_out.txt' 49 TEXT_HIGH_TEMP_PATH =
'test/sample_output/nvidia_smi_high_temp.txt' 55 with open(os.path.join(roslib.packages.get_pkg_dir(
'pr2_computer_monitor'), TEXT_PATH),
'r') as f: 58 with open(os.path.join(roslib.packages.get_pkg_dir('pr2_computer_monitor'), TEXT_HIGH_TEMP_PATH),
'r') as f: 62 gpu_stat = pr2_computer_monitor.parse_smi_output(self.
data)
65 self.assert_(self.
data,
"Unable to read sample output, no test to run")
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")
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)
77 diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
79 self.assert_(diag_stat.level == 0,
"Diagnostics reports an error for nominal input. Message: %s" % diag_stat.message)
82 gpu_stat = pr2_computer_monitor.parse_smi_output(self.
high_temp_data)
85 self.assert_(self.
high_temp_data,
"Unable to read sample output, no test to run")
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")
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)
97 diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
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))
103 gpu_stat = pr2_computer_monitor.parse_smi_output(
'')
105 self.assert_(gpu_stat.temperature == 0,
"Invalid temperature reading. Should be 0. Reading: %d" % gpu_stat.temperature)
107 diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
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))
113 if __name__ ==
'__main__':
114 if len(sys.argv) > 1
and sys.argv[1] ==
'-v':
116 suite = unittest.TestSuite()
121 unittest.TextTestRunner(verbosity = 2).run(suite)
124 rostest.unitrun(PKG,
'parse_nominal', TestNominalParser)
def test_empty_parse(self)
Parses launch, tests.xml and configs.xml files in qualification.
def test_high_temp_parse(self)