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)
import os from jumper.vlab import Vlab CHIP_ID_REGISTER = 0xD0 TEMP_LSB_REGISTER = 0xFB TEMP_MSB_REGISTER = 0xFA dir = os.path.dirname(os.path.abspath(__file__)) fw_bin = os.path.join(dir, 'pca10040', 'blank', 'armgcc', '_build', 'nrf52832_xxaa.bin') vlab = Vlab(working_directory=dir, print_uart=False) vlab.load(fw_bin) vlab.run_for_ms(500) vlab.resume() print('Virtual device is running') print('Reading chip ID from register {}'.format(hex(CHIP_ID_REGISTER))) chip_id = vlab.BME280.get_register_value(CHIP_ID_REGISTER) print('Chip id is: {}'.format(hex(chip_id))) chip_id = 0xFF print('Setting chip ID to {}'.format(hex(chip_id))) vlab.BME280.set_register_value(CHIP_ID_REGISTER, chip_id) print('Reading chip ID from register {}'.format(hex(CHIP_ID_REGISTER))) chip_id = vlab.BME280.get_register_value(CHIP_ID_REGISTER) print('Chip id is: {}'.format(hex(chip_id))) vlab.pause() for i in range(10):