Go to the documentation of this file.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 from __future__ import with_statement
00038
00039 PKG = 'pr2_computer_monitor'
00040
00041 import roslib; roslib.load_manifest(PKG)
00042 import unittest
00043
00044 import pr2_computer_monitor
00045
00046 import os, sys
00047
00048 TEXT_PATH = 'test/sample_output/nvidia_smi_out.txt'
00049 TEXT_HIGH_TEMP_PATH = 'test/sample_output/nvidia_smi_high_temp.txt'
00050
00051
00052
00053 class TestNominalParser(unittest.TestCase):
00054 def setUp(self):
00055 with open(os.path.join(roslib.packages.get_pkg_dir('pr2_computer_monitor'), TEXT_PATH), 'r') as f:
00056 self.data = f.read()
00057
00058 with open(os.path.join(roslib.packages.get_pkg_dir('pr2_computer_monitor'), TEXT_HIGH_TEMP_PATH), 'r') as f:
00059 self.high_temp_data = f.read()
00060
00061 def test_parse(self):
00062 gpu_stat = pr2_computer_monitor.parse_smi_output(self.data)
00063
00064
00065 self.assert_(self.data, "Unable to read sample output, no test to run")
00066
00067
00068 self.assert_(gpu_stat.pci_device_id, "No PCI Device ID found")
00069 self.assert_(gpu_stat.pci_location, "No PCI Location found")
00070 self.assert_(gpu_stat.display, "No Display found")
00071 self.assert_(gpu_stat.driver_version, "No Driver Version found")
00072 self.assert_(gpu_stat.product_name, "No Product Name found")
00073
00074 self.assert_(gpu_stat.temperature > 40 and gpu_stat.temperature < 90, "Invalid temperature readings. Temperature: %d" % gpu_stat.temperature)
00075 self.assert_(gpu_stat.fan_speed > 0 and gpu_stat.fan_speed < 471, "Invalid fan speed readings. Fan Speed %f" % gpu_stat.fan_speed)
00076
00077 diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
00078
00079 self.assert_(diag_stat.level == 0, "Diagnostics reports an error for nominal input. Message: %s" % diag_stat.message)
00080
00081 def test_high_temp_parse(self):
00082 gpu_stat = pr2_computer_monitor.parse_smi_output(self.high_temp_data)
00083
00084
00085 self.assert_(self.high_temp_data, "Unable to read sample output, no test to run")
00086
00087
00088 self.assert_(gpu_stat.pci_device_id, "No PCI Device ID found")
00089 self.assert_(gpu_stat.pci_location, "No PCI Location found")
00090 self.assert_(gpu_stat.display, "No Display found")
00091 self.assert_(gpu_stat.driver_version, "No Driver Version found")
00092 self.assert_(gpu_stat.product_name, "No Product Name found")
00093
00094 self.assert_(gpu_stat.temperature > 90, "Invalid temperature readings. Temperature: %d" % gpu_stat.temperature)
00095 self.assert_(gpu_stat.fan_speed > 0 and gpu_stat.fan_speed < 471, "Invalid fan speed readings. Fan Speed %s" % gpu_stat.fan_speed)
00096
00097 diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
00098
00099 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))
00100
00101
00102 def test_empty_parse(self):
00103 gpu_stat = pr2_computer_monitor.parse_smi_output('')
00104
00105 self.assert_(gpu_stat.temperature == 0, "Invalid temperature reading. Should be 0. Reading: %d" % gpu_stat.temperature)
00106
00107 diag_stat = pr2_computer_monitor.gpu_status_to_diag(gpu_stat)
00108
00109 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))
00110
00111
00112
00113 if __name__ == '__main__':
00114 if len(sys.argv) > 1 and sys.argv[1] == '-v':
00115
00116 suite = unittest.TestSuite()
00117 suite.addTest(TestNominalParser('test_parse'))
00118 suite.addTest(TestNominalParser('test_empty_parse'))
00119 suite.addTest(TestNominalParser('test_high_temp_parse'))
00120
00121 unittest.TextTestRunner(verbosity = 2).run(suite)
00122 else:
00123 import rostest
00124 rostest.unitrun(PKG, 'parse_nominal', TestNominalParser)
00125
00126