def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() self.dut_serial.repl("from dut_positioning import Positioning", 0.1) self.dut_serial.repl("from double_GPS import DOUBLE_GPS", 0.1)
def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_conf_time import ConfTime", 0.1) self.double_serial.repl("from double_DS3231 import DOUBLE_DS3231", 0.1)
def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_sensor import BLE_Sensor", 0.2) self.double_serial.repl("from double_cellphone import DOUBLE_cellphone", 0.2)
def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_master import Dut_master", 0.1) self.double_serial.repl("from double_slave import Double_slave", 0.1)
def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_blink import Blinker", 0.1) self.double_serial.repl("from double_led import Led", 0.1)
class Test_DS3231(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_conf_time import ConfTime", 0.1) self.double_serial.repl("from double_DS3231 import DOUBLE_DS3231", 0.1) def test_set_date_time_static(self): print("\nTesting the method set_date_time() in the static mode") expected_datetime = [ 2019, 10, 23, 4, 10, 51, 32 ] # datatime format: [Year, month, day, weekday, hour, minute, second] print("Set value: " + str(expected_datetime)) # 1 - Objects Creation self.double_serial.repl("ds3231 = DOUBLE_DS3231(21,22)", 0.2) self.dut_serial.repl("rtc_conf = ConfTime(21,22)", 0.2) # 2 - Input Injection self.dut_serial.repl( "rtc_conf.set_date_time(" + str(expected_datetime) + ")", 0.2) # 3 - Results gathering gotten_datetime = self.double_serial.repl("ds3231.DateTime()", 0.2)[2] # 4 - Assertion gotten_datetime = gotten_datetime.decode() print("Gotten value: " + gotten_datetime) gotten_datetime | should | equal_to(str(expected_datetime)) # Using an internal rtc from the double device def test_set_date_time_dynamic(self): print("\nTesting the method set_date_time in the dynamic mode") expected_datetime = [ 2019, 10, 23, 4, 10, 51, 32 ] # datatime format: [Year, month, day, weekday, hour, minute, second] my_delay = 2 print("Set value: " + str(expected_datetime)) print("Delay time: " + str(my_delay)) # 1 - Objects Creation self.double_serial.repl("ds3231 = DOUBLE_DS3231(21,22)", 0.2) self.dut_serial.repl("rtc_conf = ConfTime(21,22)", 0.2) # 2 - Input Injection self.dut_serial.repl( "rtc_conf.set_date_time(" + str(expected_datetime) + ")", 0.4) self.double_serial.repl("ds3231.use_internal_rtc()", 0.2) sleep(my_delay) # This increment was done because of the sleep time - rtc continues counting time expected_datetime[6] = expected_datetime[6] + my_delay # 3 - Results gathering gotten_datetime = self.double_serial.repl("ds3231.DateTime()", 0.2)[2] # 4 - Assertion gotten_datetime = gotten_datetime.decode() print("Gotten value: " + gotten_datetime) gotten_datetime | should | equal_to(str(expected_datetime)) def test_get_date_time(self): print("\nTesting the method get_date_time()") expected_datetime = [ 2019, 10, 23, 4, 10, 51, 32 ] # datatime format: [Year, month, day, weekday, hour, minute, second] print("Set value: " + str(expected_datetime)) # 1 - Objects Creation self.double_serial.repl("ds3231 = DOUBLE_DS3231(21,22)", 0.2) self.dut_serial.repl("rtc_conf = ConfTime(21,22)", 0.2) # 2 - Input Injection self.double_serial.repl( "ds3231.DateTime(" + str(expected_datetime) + ")", 0.2) # 3 - Results gathering gotten_datetime = self.dut_serial.repl("rtc_conf.get_date_time()", 0.2)[2] # 4 - Assertion gotten_datetime = gotten_datetime.decode() print("Gotten value: " + gotten_datetime) gotten_datetime | should | equal_to(str(expected_datetime)) # Test both set and get time, this case can be used along with a double device or the device itself (autotest) def test_set_get_date_time(self): print("\nTesting the methods set_date_time() and get_date_time()") expected_datetime = [2019, 10, 23, 4, 10, 51, 32] print("Set value: " + str(expected_datetime)) # 1 - Objects Creation self.double_serial.repl("ds3231 = DOUBLE_DS3231(21,22)", 0.2) self.dut_serial.repl("rtc_conf = ConfTime(21,22)", 0.2) # 2 - Input Injection self.dut_serial.repl( "rtc_conf.set_date_time(" + str(expected_datetime) + ")", 0.2) # 3 - Results gathering gotten_datetime = self.dut_serial.repl("rtc_conf.get_date_time()", 0.2)[2] # 4 - Assertion gotten_datetime = gotten_datetime.decode() print("Gotten value: " + gotten_datetime) gotten_datetime | should | equal_to(str(expected_datetime)) #closes serial and make the descomissioning def tearDown(self): # 5 - descomissioning self.dut_serial.repl("del rtc_conf; del ConfTime", 0.4) self.double_serial.repl( "ds3231.deinit(); del ds3231; del DOUBLE_DS3231", 0.4) self.dut_serial.close_serial() self.double_serial.close_serial()
auxiliar_code = "DS3231.py" build = "python -m mpy_cross -s -march=xtensa " DUT_PORT = "/dev/ttyUSB0" DOUBLE_PORT = "/dev/ttyUSB1" send = "ampy --delay 1 --port " # From set-up: # Building, connection and sending phase try: print("Building production code...") os.system(build + production_code) print("Building double code...") os.system(build + double_code) print("Building auxiliar code...") os.system(build + auxiliar_code) print("Cleaning the filesystem...") dut_serial = SerialInterface(DUT_PORT, 115200) dut_serial.connect_to_serial() dut_serial.clean_file_sys() dut_serial.close_serial() double_serial = SerialInterface(DOUBLE_PORT, 115200) double_serial.connect_to_serial() double_serial.clean_file_sys() double_serial.close_serial() print("Sending built production code...") os.system(send + DUT_PORT + " put " + production_code) #.replace(".py",".mpy")) print("Sending built auxiliar_code...") os.system(send + DUT_PORT + " put " + auxiliar_code) #.replace(".py",".mpy")) print("Sending built double code...") os.system(send + DOUBLE_PORT + " put " +
class Test_Template(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_template import Dut_class", 0.1) self.double_serial.repl("from double_template import Double_class", 0.1) # < Space for the test cases > #closes serial def tearDown(self): self.dut_serial.repl("del Dut_class", 0.2) self.double_serial.repl("del Double_class", 0.2) self.dut_serial.close_serial() self.double_serial.close_serial()
class Test_BLE(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_sensor import BLE_Sensor", 0.2) self.double_serial.repl("from double_cellphone import DOUBLE_cellphone", 0.2) def test_connection(self): print("Testing if the dut can connect properly to a central") advertising_name = "my_sensor" # 1 - Objects Creation and Input Injection self.dut_serial.repl("sensor = BLE_Sensor(\""+advertising_name+"\")", 0.2) self.double_serial.repl("cellphone = DOUBLE_cellphone()", 0.2) time.sleep(5) # 3 - Result Gathering connection = self.double_serial.repl("cellphone.check_connectivity()", 0.2)[2] connection = connection.decode() print("Connection Result", connection) connection |should| contain (str(True)) def test_read(self): print("Testing reading a value from the dut") advertising_name = "my_sensor" expected_value = 25 # 1 - Objects Creation and Input Injection self.dut_serial.repl("sensor = BLE_Sensor(\""+advertising_name+"\")", 0.2) self.double_serial.repl("cellphone = DOUBLE_cellphone()", 0.2) time.sleep(5) # 2 - Input Injection self.dut_serial.repl("sensor.set_value("+str(expected_value)+")", 0.2) self.double_serial.repl("cellphone.issue_reading()", 0.2) # 3 - Result Gathering time.sleep(1) gotten_value = self.double_serial.repl("cellphone.read_value()", 0.2)[2] gotten_value = gotten_value.decode() print("Expected value", expected_value,"Read value", gotten_value) gotten_value |should| contain (str(expected_value)) def test_notify(self): print("Testing the notification") advertising_name = "my_sensor" expected_value = 20 # 1 - Objects Creation and Input Injection self.dut_serial.repl("sensor = BLE_Sensor(\""+advertising_name+"\")", 0.2) self.double_serial.repl("cellphone = DOUBLE_cellphone()", 0.2) time.sleep(5) # 2 - Input Injection self.dut_serial.repl("sensor.set_value("+str(expected_value)+", True)", 0.2) # 3 - Result Gathering time.sleep(1) gotten_value = self.double_serial.repl("cellphone.read_value()", 0.2)[2] gotten_value = gotten_value.decode() print("Notified value", expected_value, "Read value", gotten_value) gotten_value |should| contain (str(expected_value)) #closes serial def tearDown(self): self.double_serial.repl("cellphone.deinit();del cellphone; del DOUBLE_cellphone;", 0.2) self.dut_serial.repl("sensor.deinit();del sensor; del BLE_Sensor", 0.2) self.dut_serial.close_serial() self.double_serial.close_serial() time.sleep(12)
class Test_Template(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_master import Dut_master", 0.1) self.double_serial.repl("from double_slave import Double_slave", 0.1) def test_reading_registers_without_indicating_address(self): print("\nTesting the method read_registers_wo_address()") expected_readings = [1,2,3] gotten_readings = [] print("Expected Readings "+str(expected_readings)) # 1 - Objects Creation self.double_serial.repl("slave = Double_slave(13,12,14,15)",0.2) self.dut_serial.repl("master = Dut_master(13,12,14,15)",0.2) # 2 - Input Injection self.double_serial.repl("slave.enable_transaction("+str(expected_readings)+")",0.2) # 3 - Results gathering gotten_readings = self.dut_serial.repl("master.read_registers_wo_address(3)",0.2)[2] gotten_readings = gotten_readings.decode() # 4 - Assertion print("Gotten value: "+gotten_readings) gotten_readings |should| equal_to (str(expected_readings)) def test_reading_registers_indicating_address(self): print("\nTesting the method read_registers_w_address()") expected_readings = [1,2,3] expected_written = [14,0,0,0] gotten_readings = [] print("Expected Readings "+str(expected_readings)) # 1 - Objects Creation self.double_serial.repl("slave = Double_slave(13,12,14,15)",0.2) self.dut_serial.repl("master = Dut_master(13,12,14,15)",0.2) # 2 - Input Injection self.double_serial.repl("slave.enable_transaction([0,1,2,3])",0.2) # 3 - Results gathering gotten_readings = self.dut_serial.repl("master.read_registers_w_address(14,3)",0.2)[2] gotten_readings = gotten_readings.decode() gotten_written = self.double_serial.repl("slave.get_received_buffer()",0.2)[2] gotten_written = gotten_written.decode() # 4 - Assertion print("Gotten value: "+gotten_readings) gotten_readings |should| equal_to (str(expected_readings)) gotten_written |should| equal_to (str(expected_written)) def test_writing_registers_without_indicating_address(self): print("\nTesting the method write_registers_wo_address()") expected_written = [1,2,3] gotten_values = [] print("Expected written values "+str(expected_written)) # 1 - Objects Creation self.double_serial.repl("slave = Double_slave(13,12,14,15)",0.2) self.dut_serial.repl("master = Dut_master(13,12,14,15)",0.2) # 2 - Input Injection self.double_serial.repl("slave.enable_transaction([0,0,0])",0.2) self.dut_serial.repl("master.write_registers_wo_address("+str(expected_written)+")",0.2) # 3 - Results gathering gotten_values = self.double_serial.repl("slave.get_received_buffer()", 0.2)[2] gotten_values = gotten_values.decode() # 4 - Assertion print("Gotten value: "+gotten_values) gotten_values |should| equal_to (str(expected_written)) def test_writing_registers_indicating_address(self): print("\nTesting the method write_registers_w_address()") expected_written = [1,2,3] address = 14 gotten_values = [] print("Expected written values "+str(expected_written)) # 1 - Objects Creation self.double_serial.repl("slave = Double_slave(13,12,14,15)",0.2) self.dut_serial.repl("master = Dut_master(13,12,14,15)",0.2) # 2 - Input Injection self.double_serial.repl("slave.enable_transaction([0,0,0,0])",0.2) self.dut_serial.repl("master.write_registers_w_address("+str(address)+","+str(expected_written)+")",0.2) # 3 - Results gathering gotten_values = self.double_serial.repl("slave.get_received_buffer()",0.2)[2] gotten_values = gotten_values.decode() # 4 - Assertion print("Gotten value: "+gotten_values) expected_written.insert(0,address) gotten_values |should| equal_to (str(expected_written)) #closes serial def tearDown(self): self.dut_serial.repl("master.deinit(); del master; del Dut_master;", 0.2) self.double_serial.repl("slave.deinit(); del slave; del Double_slave;", 0.2) self.dut_serial.close_serial() self.double_serial.close_serial()
class Test_Template(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_positioning import Positioning", 0.1) self.double_serial.repl("from double_GPS import DOUBLE_GPS", 0.1) def test_send_command_configuration(self): print( "\nTesting the method send_command() configuring GPS to send GGA and RMC info" ) expected_command = 'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0' print("Expected command: " + expected_command) # 1 - Objects Creation self.double_serial.repl("gps = DOUBLE_GPS(22,16,2)", 0.2) self.dut_serial.repl("tracker = Positioning(17,16,2)", 0.2) # 2 - Input Injection self.dut_serial.repl( "tracker.send_command('" + expected_command + "')", 0.2) # 3 - Results gathering gotten_command = self.double_serial.repl("gps.received_command()", 0.2)[2] # 4 - Assertion gotten_command = gotten_command.decode() gotten_command = gotten_command.replace('\'', '') print("Gotten command: " + gotten_command) gotten_command | should | equal_to(expected_command) def test_send_command_update_rate(self): print( "\nTesting the method send_command() updating GPS rate to 1 second" ) command = 'PMTK220,1000' expected_answer = '$GPRMC,141623.523,A,2143.963,S,04111.493,W,,,301019,000.0,W*7B\n' print("Expected answer: " + expected_answer) # 1 - Objects Creation self.double_serial.repl("gps = DOUBLE_GPS(22,16,2)", 0.2) self.dut_serial.repl("tracker = Positioning(17,16,2)", 0.2) # 2 - Input Injection self.dut_serial.repl("tracker.send_command('" + command + "')", 0.2) self.double_serial.repl("gps.received_command()", 0.2) sleep(1) # 3 - Results gathering gotten_answer = self.dut_serial.repl("tracker.received_command()", 0.2)[2] # 4 - Assertion gotten_answer = gotten_answer.decode( ) # To transform from array bytes to String gotten_answer = gotten_answer[1:] # To ignore the first char gotten_answer = gotten_answer.replace('\'', '') # To replace the char (') gotten_answer = gotten_answer.replace('\\n', '\n') print("Gotten answer: " + gotten_answer) gotten_answer | should | equal_to(expected_answer) def test_get_latitude(self): print("\nTesting the method get_latitude()") expected_latitude = -21.732717 print("Expected answer: " + str(expected_latitude)) # 1 - Objects Creation self.double_serial.repl("gps = DOUBLE_GPS(22,16,2)", 0.2) self.dut_serial.repl("tracker = Positioning(17,16,2)", 0.2) # 2 - Input Injection self.dut_serial.repl("tracker.send_command('PMTK220,1000')", 0.2) self.double_serial.repl("gps.received_command()", 0.2) sleep(1) # 3 - Results gathering gotten_answer = self.dut_serial.repl("tracker.get_latitude()", 0.2)[2] # 4 - Assertion gotten_answer = gotten_answer.decode( ) # To transform from array bytes to String gotten_answer = float(gotten_answer) print("Gotten answer: " + str(gotten_answer)) gotten_answer | should | close_to(expected_latitude, delta=0.000005) #Closes serial def tearDown(self): # 5 Descomissioning self.double_serial.repl("gps.deinit(); del gps; del DOUBLE_GPS", 0.2) self.dut_serial.repl("tracker.deinit(); del tracker; del Positioning", 0.2) self.dut_serial.close_serial() self.double_serial.close_serial() pass
class Test_Blinker(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() print("Connecting to DOUBLE device...") self.double_serial = SerialInterface(DOUBLE_PORT, 115200) self.double_serial.connect_to_serial() self.dut_serial.repl("from dut_blink import Blinker", 0.1) self.double_serial.repl("from double_led import Led", 0.1) def test_blink_blocking(self): led_pin_dut = "2" led_pin_double = "21" period_blink = "1000" blinking_times = "2" print("\nTesting blink_blocking with the following parameters: " + "period blinking: " + period_blink + "ms, blinking times: " + blinking_times + " x") # 1 - Objects Creation # Creates an object Led in the Double to be "blinked" in pin "led_pin_double" that expects to be blinked "blinking_times" - but doesn't starts the acquisition yet self.double_serial.repl( "red_led = Led(" + led_pin_double + "," + blinking_times + ")", 0.1) # Creates an object Blinker in the DUT to blink in pin "led_pin_dut", with a period equals to "period_blink" for 5 times - but doesn't starts it yet self.dut_serial.repl( "blinker = Blinker(" + led_pin_dut + "," + period_blink + "," + blinking_times + ")", 0.1) # 2 - Input Injection # Puts the led to wait for external pulses self.double_serial.repl("red_led.start_acquisition()", 0.1) # Calls the DUT to blink a led in the blocking mode self.dut_serial.repl("blinker.blink_blocking()", 0.1) # 3 - Results gathering # Waits the DUT to blink the led for the established time sleep((float(period_blink) * float(blinking_times)) / 1000.0) sleep(1) obtained_period = self.double_serial.repl( "red_led.get_average_period()", 0.2)[2] obtained_period = obtained_period.decode() obtained_period = float(obtained_period) period_blink = float(period_blink) print(obtained_period) # 4 - Assertion obtained_period | should | close_to(period_blink, delta=1) # 5 - descomissioning self.dut_serial.repl("del blinker", 0.1) self.double_serial.repl("del red_led", 0.1) # Only to be tested isolated or as the last one(because it blocks while blinking, and it blinks forever) # def test_blink_blocking_forever(self): # led_pin_dut = "2" # led_pin_double = "21" # period_blink = "500" # blinking_times = "5" # print("\nTesting blink_blocking forever with the following parameters: "+"period blinking: "+period_blink+"ms, blinking times: "+blinking_times+" x") # # 1 - Objects Creation # # Creates an object Led in the Double to be "blinked" in pin 21 and expects 5 pulses - but doesn't starts the acquisition yet # self.double_serial.repl("red_led = Led("+led_pin_double+","+blinking_times+")",0.1) # # Creates an object Blinker in the DUT to blink in pin 2, at 1Hz for 5 times - but doesn't starts it yet # self.dut_serial.repl("blinker = Blinker("+led_pin_dut+","+period_blink+")",0.1) # # 2 - Input Injection # # Puts the led to wait for external pulses # self.double_serial.repl("red_led.start_acquisition()",0.1) # # Calls the DUT to blink a led in the blocking mode # self.dut_serial.repl("blinker.blink_blocking()",0.1) # # 3 - Results gathering # # Waits the DUT to blink the led for the established time # sleep((float(period_blink)*float(blinking_times))/1000.0) # sleep(1) # obtained_period = self.double_serial.repl("red_led.get_average_period()",0.2)[2] # obtained_period = obtained_period.decode() # obtained_period = float(obtained_period) # period_blink = float(period_blink) # print(obtained_period) # # 4 - Assertion # obtained_period |should| close_to (period_blink, delta = 1) # # 5 - descomissioning # self.dut_serial.repl("del blinker", 0.1) # self.double_serial.repl("del red_led", 0.1) def test_blink_isr(self): led_pin_dut = "2" led_pin_double = "21" period_blink = "2000" blinking_times = "2" print("\nTesting blink_isr with the following parameters: " + "period blinking: " + period_blink + "ms, blinking times: " + blinking_times + " x") # 1 - Objects Creation # Creates an object Led in the Double to be "blinked" in pin "led_pin_double" that expects to be blinked "blinking_times" - but doesn't starts the acquisition yet self.double_serial.repl( "red_led = Led(" + led_pin_double + "," + blinking_times + ")", 0.1) # Creates an object Blinker in the DUT to blink in pin "led_pin_dut", with a period equals to "period_blink" for 5 times - but doesn't starts it yet self.dut_serial.repl( "blinker = Blinker(" + led_pin_dut + "," + period_blink + "," + blinking_times + ")", 0.1) # 2 - Input Injection # Puts the led to wait for external pulses self.double_serial.repl("red_led.start_acquisition()", 0.1) # Calls the DUT to blink a led in the blocking mode self.dut_serial.repl("blinker.blink_timer_isr()", 0.1) # 3 - Results gathering # Waits the DUT to blink the led for the established time sleep((float(period_blink) * float(blinking_times)) / 1000.0) sleep(1) obtained_period = self.double_serial.repl( "red_led.get_average_period()", 0.2)[2] obtained_period = obtained_period.decode() obtained_period = float(obtained_period) period_blink = float(period_blink) print(obtained_period) # 4 - Assertion obtained_period | should | close_to(period_blink, delta=1) # 5 - descomissioning self.dut_serial.repl("del blinker", 0.1) self.double_serial.repl("del red_led", 0.1) def test_blink_isr_forever(self): led_pin_dut = "2" led_pin_double = "21" period_blink = "1000" blinking_times = "2" print("\nTesting blink_isr forever with the following parameters: " + "period blinking: " + period_blink + "ms, blinking times: " + blinking_times + " x") # 1 - Objects Creation # Creates an object Led in the Double to be "blinked" in pin "led_pin_double" that expects to be blinked "blinking_times" - but doesn't starts the acquisition yet self.double_serial.repl( "red_led = Led(" + led_pin_double + "," + blinking_times + ")", 0.1) # Creates an object Blinker in the DUT to blink in pin "led_pin_dut", with a period equals to "period_blink" for 5 times - but doesn't starts it yet self.dut_serial.repl( "blinker = Blinker(" + led_pin_dut + "," + period_blink + ")", 0.1) # 2 - Input Injection # Puts the led to wait for external pulses self.double_serial.repl("red_led.start_acquisition()", 0.1) # Calls the DUT to blink a led in the blocking mode self.dut_serial.repl("blinker.blink_timer_isr()", 0.1) # 3 - Results gathering # Waits the DUT to blink the led for the established time sleep((float(period_blink) * float(blinking_times)) / 1000.0) sleep(1) obtained_period = self.double_serial.repl( "red_led.get_average_period()", 0.2)[2] obtained_period = obtained_period.decode() obtained_period = float(obtained_period) period_blink = float(period_blink) print(obtained_period) # 4 - Assertion obtained_period | should | close_to(period_blink, delta=1) # 5 - descomissioning self.dut_serial.repl("blinker.disable_isr();del blinker", 0.2) self.double_serial.repl("del red_led", 0.1) #closes serial and erase Classes def tearDown(self): self.dut_serial.repl("del Blinker", 0.2) self.double_serial.repl("del Led", 0.2) self.dut_serial.close_serial() self.double_serial.close_serial()
class Test_Template(unittest.TestCase): #Creates a serial connection and import the classes def setUp(self): print('\n') print("Connecting to DUT device...") self.dut_serial = SerialInterface(DUT_PORT, 115200) self.dut_serial.connect_to_serial() self.dut_serial.repl("from dut_positioning import Positioning", 0.1) self.dut_serial.repl("from double_GPS import DOUBLE_GPS", 0.1) def test_send_command_itself(self): print("\nTesting the method send_command()") expected_command = 'PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0' print("Expected command: " + expected_command) # 1 - Objects Creation self.dut_serial.repl("gps = DOUBLE_GPS(17,16,2)", 0.2) self.dut_serial.repl("tracker = Positioning(23,22,1)", 0.2) # 2 - Input Injection self.dut_serial.repl( "tracker.send_command('" + expected_command + "')", 0.2) # 3 - Results gathering gotten_datetime = self.dut_serial.repl("gps.received_command()", 0.2)[2] # 4 - Assertion gotten_datetime = gotten_datetime.decode() gotten_datetime = gotten_datetime.replace('\'', '') print("Gotten command: " + gotten_datetime) gotten_datetime | should | equal_to(expected_command) #Closes serial def tearDown(self): # 5 Descomissioning self.dut_serial.repl("gps.deinit(); del gps", 0.2)[2] self.dut_serial.repl("tracker.deinit(); del tracker", 0.2)[2] self.dut_serial.close_serial()