def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'Serial ports', config, hw_info, logger) self._rs232test = None self._rs485test_a = None self._rs485test_b = None model = self._hw_info.model() if model in ('1500', '2500'): self._rs232test = _RS232Tester(config, hw_info, logger, '/dev/ttyS8', '/dev/ttyS9') if model in ('1200', '2400'): ### # Don't get confused by this. On ZF's we have either the RS232 # ports *OR* the extra RS485 ports, but not both. It seems that # we mostly use the RS485 (have a peek in /etc/rc.mpx), so we # test those... *STM* os.system('/bin/rs485init >/dev/null') self._rs485test_a = _RS485Tester(config, hw_info, logger, '/dev/ttyS4', '/dev/ttyS5') else: self._rs485test_a = _RS485Tester(config, hw_info, logger, '/dev/ttySa', '/dev/ttySb') if model in ('2400', '2500'): if model in ('2400', ): self._rs485test_b = _RS485Tester(config, hw_info, logger, '/dev/ttyS6', '/dev/ttyS7') else: self._rs485test_b = _RS485Tester(config, hw_info, logger, '/dev/ttySc', '/dev/ttySd') return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'Serial ports', config, hw_info, logger) self._rs232test = None self._rs485test_a = None self._rs485test_b = None model = self._hw_info.model() if model in ('1500', '2500'): self._rs232test = _RS232Tester(config, hw_info, logger, '/dev/ttyS8', '/dev/ttyS9') if model in ('1200', '2400'): ### # Don't get confused by this. On ZF's we have either the RS232 # ports *OR* the extra RS485 ports, but not both. It seems that # we mostly use the RS485 (have a peek in /etc/rc.mpx), so we # test those... *STM* os.system('/bin/rs485init >/dev/null') self._rs485test_a = _RS485Tester(config, hw_info, logger, '/dev/ttyS4', '/dev/ttyS5') else: self._rs485test_a = _RS485Tester(config, hw_info, logger, '/dev/ttySa', '/dev/ttySb') if model in ('2400', '2500'): if model in ('2400',): self._rs485test_b = _RS485Tester(config, hw_info, logger, '/dev/ttyS6', '/dev/ttyS7') else: self._rs485test_b = _RS485Tester(config, hw_info, logger, '/dev/ttySc', '/dev/ttySd') return
def __init__(self, config, hw_info, logger, stress=False): TestMethods.__init__(self, 'System RAM test', config, hw_info, logger) if not stress: self._testprog = config.memtester() else: self._testprog = config.stressmemtester() self._test_prog_logged = 0 return
def __init__(self, config, hw_info, logger, eth_port, netperf_server, netperf_server_port, ping_host, ping_count): TestMethods.__init__(self, 'Ethernet', config, hw_info, logger) self._eth_port = eth_port self._netperf_server = netperf_server self._netperf_server_port = netperf_server_port self._ping_host = ping_host self._ping_count = ping_count
def __init__(self, config, hw_info, logger, avr): TestMethods.__init__(self, 'Dallas temp sensors', config, hw_info, logger) self._num_dallas_busses = 2 if hw_info.model() in ('2400', '2500'): self._num_dallas_busses = 4 self._avr = avr return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'I2C RAM', config, hw_info, logger) self._detected = 0 ### # The i2c RAM lives at address 0x50 on bus 0; look for it. result, spewage = execute_command('/usr/bin/i2cdetect 0 | grep -q 50') if result: self._detected = 1 return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, "I2C RAM", config, hw_info, logger) self._detected = 0 ### # The i2c RAM lives at address 0x50 on bus 0; look for it. result, spewage = execute_command("/usr/bin/i2cdetect 0 | grep -q 50") if result: self._detected = 1 return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'NetworkTester', config, hw_info, logger) # So we only show the netperf performance notice once during testing. self._netperf_notice = 0 self._eth0 = None self._eth1 = None self._eth0 = _EthernetPort(config, hw_info, logger, 0, self._config.netperf_eth0(), self._config.netperf_eth0_port(), self._config.ping_host_eth0(), self._config.ping_count_eth0()) if self._hw_info.model() in ('TSWS', '2400', '2500'): self._eth1 = _EthernetPort(config, hw_info, logger, 1, self._config.netperf_eth1(), self._config.netperf_eth1_port() , self._config.ping_host_eth1(), self._config.ping_count_eth1())
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'NetworkTester', config, hw_info, logger) # So we only show the netperf performance notice once during testing. self._netperf_notice = 0 self._eth0 = None self._eth1 = None self._eth0 = _EthernetPort(config, hw_info, logger, 0, self._config.netperf_eth0(), self._config.netperf_eth0_port(), self._config.ping_host_eth0(), self._config.ping_count_eth0()) if self._hw_info.model() in ('TSWS', '2400', '2500'): self._eth1 = _EthernetPort(config, hw_info, logger, 1, self._config.netperf_eth1(), self._config.netperf_eth1_port(), self._config.ping_host_eth1(), self._config.ping_count_eth1())
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'Modem', config, hw_info, logger) self._detect_done = 0 self._modem_present = 0 #### # This is a countdown variable, we only want to execute the modem # tests a certain number of times. self._test_iterations = config.modem_test_iterations() model = self._hw_info.model() if model in ('1200', '2400'): self._modemdev = '/dev/ttyS1' elif model in ('1500', '2500'): self._modemdev = '/dev/ttySe' else: # <-- Prevent execution on anything else (TSWS, S1, ...). self._detect_done = 1 self._modem_present = 0 self._modemdev = None return
class GraphsTestCase(unittest.TestCase): def setUp(self): self.graphs = Graphs() self.test_methods = TestMethods() self.data_processing = DataProcessing() def test_write_grap(self): title = "write_test" file = "templates/graphs/write_test.html" self.graphs.write_graph_to_html(figure=go.Figure(), title=title) search = os.path.abspath(file) self.assertIn(title, search) self.assertTrue(os.path.exists(search)) os.remove(file) self.assertFalse(os.path.isfile(file)) def test_figure(self): country_id = self.test_methods.get_country_id() self.assertTrue(isinstance(country_id, int)) data = self.data_processing.all_cases_per_day_where_country_id_equal( country_id=country_id) self.assertTrue(isinstance(data, list)) self.assertTrue(isinstance(data[0], tuple)) assert len(data) > 0 dataframe = self.data_processing.get_dateframe(data=data) self.assertTrue(isinstance(dataframe, pandas.DataFrame)) alpha_3_code = ConnectToDb().select_one_record( query= r"SELECT co.alpha_3_code from countries as co join cases as ca on co.country_id = ca.country_id group by co.country_id having co.country_id = ?", parameter=(country_id, ), ) self.assertTrue(isinstance(alpha_3_code[0], str)) figure = self.graphs.creating_figure_with_data( figure=go.Figure(), dataframe=dataframe, alpha_3_code=alpha_3_code[0]) self.assertTrue(isinstance(figure, plotly.graph_objects.Figure)) def test_graph(self): country_id = self.test_methods.get_country_id() data = self.data_processing.all_cases_per_day_where_country_id_equal( country_id=country_id) dataframe = self.data_processing.get_dateframe(data=data) graph = self.graphs.get_graph(country_id=country_id, dataframe=dataframe, diff=False, write=False) self.assertTrue(isinstance(graph, tuple)) self.assertTrue(isinstance(graph[1], str)) self.assertTrue(isinstance(graph[0], plotly.graph_objects.Figure)) def test_diff_graph(self): country_id = self.test_methods.get_country_id() data = self.data_processing.all_cases_per_day_where_country_id_equal( country_id=country_id) dataframe = self.data_processing.get_dateframe_diff(data=data) path = "tests/test-diff.csv" dataframe.to_csv(path_or_buf=path, encoding="utf-8") search = os.path.abspath(path) self.assertTrue(os.path.exists(search)) os.remove(search) graph = self.graphs.get_graph(country_id=country_id, dataframe=dataframe, diff=True, write=False) self.assertTrue(isinstance(graph, tuple)) self.assertTrue(isinstance(graph[1], str)) self.assertTrue(isinstance(graph[0], plotly.graph_objects.Figure)) def test_join_graphs(self): country_id1 = self.test_methods.get_country_id() country_id2 = self.test_methods.get_country_id() graph = self.graphs.join_two_graphs(first_country_id=country_id1, second_country_id=country_id2) self.assertTrue(isinstance(graph, tuple)) self.assertTrue(isinstance(graph[1], str)) self.assertTrue(isinstance(graph[0], plotly.graph_objects.Figure)) os.remove("templates/graphs/" + graph[1] + ".html") def test_cases_world(self): world = self.graphs.cases_of_the_world(write=False) self.assertTrue(world) self.assertTrue(isinstance(world, tuple)) self.assertTrue(isinstance(world[0], plotly.graph_objects.Figure))
def __init__(self, config, hw_info, logger, ttydev1, ttydev2): TestMethods.__init__(self, 'RS232', config, hw_info, logger) self._ttydev1 = ttydev1 self._ttydev2 = ttydev2 return
def setUp(self): self.graphs = Graphs() self.test_methods = TestMethods() self.data_processing = DataProcessing()
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'Boot log', config, hw_info, logger) return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'I2CBus', config, hw_info, logger) #self._i2cmem = _I2CMemory(config, hw_info, logger) self._i2crtc = _I2CRtc(config, hw_info, logger)
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'USB', config, hw_info, logger)
class DataProcessingTestCase(unittest.TestCase): def setUp(self): self.conn = ConnectToDb() self.data_processing = DataProcessing() self.test_methods = TestMethods() def test_get_icon_color(self): self.assertEqual(self.data_processing.get_icon_color(1), "#29a329") self.assertEqual(self.data_processing.get_icon_color(999), "#29a329") self.assertEqual(self.data_processing.get_icon_color(1000), "#196619") self.assertEqual(self.data_processing.get_icon_color(4999), "#196619") self.assertEqual(self.data_processing.get_icon_color(5000), "#f2c718") self.assertEqual(self.data_processing.get_icon_color(9999), "#f2c718") self.assertEqual(self.data_processing.get_icon_color(10000), "#ffcc00") self.assertEqual(self.data_processing.get_icon_color(24999), "#ffcc00") self.assertEqual(self.data_processing.get_icon_color(25000), "#ff9900") self.assertEqual(self.data_processing.get_icon_color(49999), "#ff9900") self.assertEqual(self.data_processing.get_icon_color(50000), "#ff5c33") self.assertEqual(self.data_processing.get_icon_color(99999), "#ff5c33") self.assertEqual(self.data_processing.get_icon_color(100000), "#ff3300") self.assertEqual(self.data_processing.get_icon_color(149999), "#ff3300") self.assertEqual(self.data_processing.get_icon_color(150000), "#ff3333") self.assertEqual(self.data_processing.get_icon_color(249999), "#ff3333") self.assertEqual(self.data_processing.get_icon_color(250000), "#ff0000") self.assertEqual(self.data_processing.get_icon_color(100**4), "#ff0000") def test_select_all_records_where_declare_id(self): country_id = self.test_methods.get_country_id() query = self.conn.select_all_records( query="SELECT *, max(last_update) FROM cases WHERE country_id = ?", parameter=(country_id, ), ) self.assertIsNotNone(query) self.assertEqual(query[0][2], country_id) self.assertTrue(query, list) def test_dataframe_diff(self): country_id = self.test_methods.get_country_id() data = self.data_processing.all_cases_per_day_where_country_id_equal( country_id=country_id) self.assertIsNotNone(data) self.assertNotEqual(data, []) df = self.data_processing.get_dateframe(data=data) verify_df = str(type(df)).replace(">", "").replace("'", "").split(".") self.assertIn("DataFrame", verify_df) self.assertIsNotNone(df) self.assertListEqual(["Confirmed", "Deaths", "Recovered", "Date"], [x for x in df.columns]) df_diff = self.data_processing.get_dateframe_diff(data=data) self.assertIsNotNone(df_diff) self.assertEqual(df_diff.columns[-1], "Date") df.to_csv(path_or_buf="tests/poland_df.csv", encoding="utf-8") search = os.path.abspath("tests/poland_df.csv") self.assertTrue(os.path.exists(search)) assert "poland_df.csv" in search df_diff.to_csv(path_or_buf="tests/poland_diff.csv", encoding="utf-8") search2 = os.path.abspath("tests/poland_diff.csv") self.assertIn("poland_diff.csv", search2) self.assertTrue(os.path.exists(search2)) def test_dataframe(self): country_id = self.test_methods.get_country_id() data = self.data_processing.all_cases_per_day_where_country_id_equal( country_id=country_id) df = self.data_processing.get_dateframe(data=data) self.assertIsNotNone(df) self.assertTrue(isinstance(df, pandas.DataFrame)) def test_coordinates(self): location = self.test_methods.get_location() test_location = self.data_processing.slice_location(location) self.assertTrue(isinstance(test_location[0], float)) self.assertTrue(isinstance(test_location[1], float)) test_location_str = str(test_location) self.assertEqual(test_location_str, location) test_location2 = self.data_processing.slice_location("[54.0, -2.0]") self.assertEqual(test_location2, [54.0, -2.0]) def test_total_current_cases(self): data = self.data_processing.total_current_cases() self.assertIsNotNone(data) self.assertTrue(isinstance(data, list)) assert data.__len__() > 0 verify_data = data[0] self.assertTrue(isinstance(verify_data[0], int)) self.assertTrue(isinstance(verify_data[1], str)) self.assertTrue(isinstance(verify_data[2], str)) self.assertTrue(isinstance(verify_data[3], int)) self.assertTrue(isinstance(verify_data[4], int)) self.assertTrue(isinstance(verify_data[5], int)) self.assertTrue(isinstance(verify_data[6], str)) self.assertTrue(isinstance(verify_data[7], str)) self.assertTrue(isinstance(verify_data[8], str)) self.assertIn("https", verify_data[8]) def test_total_per_day(self): data = self.data_processing.total_cases_per_day() self.assertIsNotNone(data) self.assertTrue(isinstance(data, list)) self.assertTrue(isinstance(data[0][0], int)) self.assertTrue(isinstance(data[0][1], int)) self.assertTrue(isinstance(data[0][2], int)) self.assertTrue(isinstance(data[0][3], str)) self.assertTrue(isinstance(data[0], tuple)) assert data.__len__() > 0 self.assertTrue(time.strftime(data[0][3])) def test_name_3code_country(self): country_id = self.test_methods.get_country_id() print(country_id) data = self.data_processing.get_name_and_3code_country( country_id=country_id) self.assertTrue(isinstance(data[0], str)) self.assertTrue(isinstance(data[1], str)) self.assertTrue(isinstance(data, tuple)) self.assertIsNotNone(data) def test_id_name_countries(self): data = self.data_processing.get_id_and_name_of_countries() self.assertIsNotNone(data) self.assertTrue(isinstance(data, list)) self.assertTrue(isinstance(data[0], tuple)) self.assertTrue(data[0][0], int) self.assertTrue(data[0][1], str) assert data.__len__() > 0
def setUp(self): self.conn = ConnectToDb() self.data_processing = DataProcessing() self.test_methods = TestMethods()
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, 'I2C RTC', config, hw_info, logger) self._detected = 0 self._rtc_regs = _I2CRtc_Registers() ### # I have seen during tests, the chip will occasionally look like it # has gone south (see _I2CRtc_Registers::is_dead), but then magically # resurrects itself. We'll allow this to happen a certain number of # *consecutive* times before pronouncing the chip fubar. self._rtc_death_watch = 0 self._rtc_death_toll = 0 self._rtc_num_lives = 5 ##### # This is currently not working, do not use. ##### #print 'Quick I2C RTC memory test...' #sys.stdout.flush() #self._rtc_regs.write_buf('Hello World!') #buff, nbytes = self._rtc_regs.read_buf(12) #print 'Read %d bytes from I2C RTC: \"%s\"' % (nbytes, buff) #time.sleep(10) ### # We have to be careful about this. I think the time.sleep() uses # the system clock, anything longer than this and we might see # too much drift in wall time. self._rtc_test_duration = 30 self._rtc_test_tolerance = 5 ### # The i2c RTC lives at address 0x68 on bus 0; look for it. result, spewage = execute_command('/usr/bin/i2cdetect 0 | grep -q 68') if result: self._detected = 1 #### # Benchmark the overhead of the system call so we can deduct this # overhead from the final RTC time tests. Ten iterations should be # sufficient, we're not controlling nuclear power. # # TBD: Measure this once and store, or each time we test the RTC? # # I would prefer to err on the side of caution and measure it each # iteration, but so far results have proven reliable measuring once # and storing the overhead. delta_t = 0.0 for iteration in range(0, 10): start_t = time.clock() sec, min, hrs = self._rtc_regs.get_time() end_t = time.clock() ### # The value we get back from 'clocks' is in processor units. On # x86 Linux, there are 100 processor units per second in # userspace (HZ in include/asm-i386/param.h). delta_t += ((end_t - start_t) * 100) self.overhead = int(math.ceil(delta_t / 10.0)) return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, "I2C RTC", config, hw_info, logger) self._detected = 0 self._rtc_regs = _I2CRtc_Registers() ### # I have seen during tests, the chip will occasionally look like it # has gone south (see _I2CRtc_Registers::is_dead), but then magically # resurrects itself. We'll allow this to happen a certain number of # *consecutive* times before pronouncing the chip fubar. self._rtc_death_watch = 0 self._rtc_death_toll = 0 self._rtc_num_lives = 5 ##### # This is currently not working, do not use. ##### # print 'Quick I2C RTC memory test...' # sys.stdout.flush() # self._rtc_regs.write_buf('Hello World!') # buff, nbytes = self._rtc_regs.read_buf(12) # print 'Read %d bytes from I2C RTC: \"%s\"' % (nbytes, buff) # time.sleep(10) ### # We have to be careful about this. I think the time.sleep() uses # the system clock, anything longer than this and we might see # too much drift in wall time. self._rtc_test_duration = 30 self._rtc_test_tolerance = 5 ### # The i2c RTC lives at address 0x68 on bus 0; look for it. result, spewage = execute_command("/usr/bin/i2cdetect 0 | grep -q 68") if result: self._detected = 1 #### # Benchmark the overhead of the system call so we can deduct this # overhead from the final RTC time tests. Ten iterations should be # sufficient, we're not controlling nuclear power. # # TBD: Measure this once and store, or each time we test the RTC? # # I would prefer to err on the side of caution and measure it each # iteration, but so far results have proven reliable measuring once # and storing the overhead. delta_t = 0.0 for iteration in range(0, 10): start_t = time.clock() sec, min, hrs = self._rtc_regs.get_time() end_t = time.clock() ### # The value we get back from 'clocks' is in processor units. On # x86 Linux, there are 100 processor units per second in # userspace (HZ in include/asm-i386/param.h). delta_t += (end_t - start_t) * 100 self.overhead = int(math.ceil(delta_t / 10.0)) return
def __init__(self, config, hw_info, logger): TestMethods.__init__(self, "I2CBus", config, hw_info, logger) # self._i2cmem = _I2CMemory(config, hw_info, logger) self._i2crtc = _I2CRtc(config, hw_info, logger)
def __init__(self, config, hw_info, logger, avr): TestMethods.__init__(self, 'Counters and Relays', config, hw_info, logger) self._avr = avr return