Exemple #1
0
class TestBma280(unittest.TestCase):
    def setUp(self):
        self.vlab = Vlab(working_directory=dir, print_uart=True)
        self.vlab.load(fw_bin)
        self.uart = self.vlab.uart
        # self.vlab.run_for_ms(500)
        self.vlab.start()
        print('Virtual device is running')

    def tearDown(self):
        self.vlab.stop()

    def test_should_recognize_low_g(self):
        self.vlab.BMA280Device.set_interrupt('low_g')
        self.vlab.run_for_ms(1000)
        self.assertRegexpMatches(
            self.uart.read(), "Firmware recognized bma280 interrupt: low_g")

    def test_should_recognize_orient_xy(self):
        self.vlab.BMA280Device.set_interrupt('orient_xy')
        self.vlab.run_for_ms(1000)
        self.assertRegexpMatches(
            self.uart.read(),
            "Firmware recognized bma280 interrupt: orient_xy")

    def test_should_recognize_slope_x(self):
        self.vlab.BMA280Device.set_interrupt('slope_x')
        self.vlab.run_for_ms(1000)
        self.assertRegexpMatches(
            self.uart.read(), "Firmware recognized bma280 interrupt: slope_x")
Exemple #2
0
class TestClass(unittest.TestCase):
    _FAIL = False
    _PASS = True

    def setUp(self):
        ##########################
        # change these arguments #
        ##########################
        self.fw = 'BUILD/STM32_Button_Debounce.elf'  # TODO: YOUR FW HERE
        self.timeout = 10000
        self.timeout_result = self._FAIL
        self.uart_test = True
        self.uart_test_value = 'mBed boot done'
        self.uart_test_result = self._PASS
        self.gpio_test = False
        self.gpio_test_pin = None
        self.gpio_test_value = None
        self.gpio_test_result = None
        self._is_pass = False

        # set up the device simulation
        self.v = Vlab(working_directory=".",
                      print_uart=True,
                      token="demo-token-for-ci")
        self.v.load(self.fw)
        self.v.on_pin_level_event(self.pin_listener)
        # running for a while to get the BSP done
        self.v.start(0)
        self.uart_data = ''
        self._condition_found = False
        self.v.stop_after_ms(self.timeout)
        self.v.resume()

    def tearDown(self):
        self.v.stop()

    def pin_listener(self, pin_number, pin_level):
        if self.gpio_test and self.gpio_test_pin == pin_number and self.gpio_test_value == pin_level:
            self._is_pass = True if self.gpio_test_result == self._PASS else False
            self._condition_found = True

    def read_from_uart(self):
        self.uart_data += self.v.uart.read()
        if self.uart_test and self.uart_test_value in self.uart_data:
            self._is_pass = True if self.uart_test_result == self._PASS else False
            self._condition_found = True

    def test_debouncer(self):
        while self.v.get_state() == 'running' and not self._condition_found:
            self.read_from_uart()
            sleep(0.1)

        self.assertEqual(self._is_pass, True)
Exemple #3
0
class TestCLI(unittest.TestCase):
    def setUp(self):
        self.vlab = Vlab(working_directory=dir, print_uart=True)
        self.vlab.load(fw_bin)
        self.uart = self.vlab.uart
        self.vlab.start()
        print('Virtual device is running')

    def tearDown(self):
        self.vlab.stop()

    def test_cli(self):
        self.vlab.uart.write(b'log\r\n')
        self.vlab.uart.wait_until_uart_receives(b'status   :Logger status',
                                                500)
        self.vlab.uart.write(b'python\r\n')
        self.vlab.uart.wait_until_uart_receives(b'Nice joke ;)', 500)
        self.vlab.uart.write(b'history\r\n')
        self.vlab.uart.wait_until_uart_receives(b'[  2] history', 500)
Exemple #4
0
class SerialEmulator:
    def __init__(self):
        self.master, self.slave = pty.openpty()
        print os.ttyname(self.slave)

    def write(self, data):
        os.write(self.master, chr(data))

    def read(self):
        return os.read(self.master, 1)


#  set up the device simulation
v = Vlab(working_directory=".", print_uart=True, uarts_to_print=['UART5'], platform="stm32f446", gdb_mode=False)
v.load("cmake-build-simulate/Kromek.bin")
v.start()


def receive_uart(data):
    ser.write(data)


ser = SerialEmulator()
v.USART2.on_uart_data(receive_uart)


if __name__ == '__main__':
    while True:
        read = ser.read()
        v.USART2.write(read)