def test_pulse_cnt(dut: Dut) -> None: dut.expect_exact('Press ENTER to see the list of tests') dut.write('*') dut.expect_unity_test_output()
def test_ir_nec_example(dut: Dut) -> None: dut.expect_exact('example: Initialize EN + DIR GPIO') dut.expect_exact('example: Create RMT TX channel') dut.expect_exact('example: Set spin direction') dut.expect_exact('example: Enable step motor') dut.expect_exact('example: Create motor encoders') dut.expect_exact('example: Enable RMT channel') dut.expect_exact( 'example: Spin motor for 6000 steps: 500 accel + 5000 uniform + 500 decel' )
def test_light_sleep(dut: Dut) -> None: ENTERING_SLEEP_STR = 'Entering light sleep' EXIT_SLEEP_REGEX = r'Returned from light sleep, reason: (\w+), t=(\d+) ms, slept for (\d+) ms' WAITING_FOR_GPIO_STR = r'Waiting for GPIO\d to go high...' WAKEUP_INTERVAL_MS = 2000 # Ensure DTR and RTS are de-asserted for proper control of GPIO0 dut.serial.proc.setDTR(False) dut.serial.proc.setRTS(False) # enter sleep first time dut.expect_exact(ENTERING_SLEEP_STR, timeout=30) # don't check timing here, might be cache dependent dut.expect(EXIT_SLEEP_REGEX) logging.info('Got first sleep period') # enter sleep second time dut.expect_exact(ENTERING_SLEEP_STR) match = dut.expect(EXIT_SLEEP_REGEX) logging.info( 'Got second sleep period, wakeup from {}, slept for {}'.format( match.group(1), match.group(3))) # sleep time error should be less than 1ms assert (match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1) # this time we'll test gpio wakeup dut.expect_exact(ENTERING_SLEEP_STR) logging.info('Pulling GPIO0 low using DTR') dut.serial.proc.setDTR(True) time.sleep(1) match = dut.expect(EXIT_SLEEP_REGEX) logging.info('Got third sleep period, wakeup from {}, slept for {}'.format( match.group(1), match.group(3))) assert (match.group(1).decode('utf8') == 'pin' and int(match.group(3)) < WAKEUP_INTERVAL_MS) dut.expect(WAITING_FOR_GPIO_STR) logging.info('Is waiting for GPIO...') dut.serial.proc.setDTR(False) dut.expect_exact(ENTERING_SLEEP_STR) logging.info('Went to sleep again') # Write 'U' to uart, 'U' in ascii is 0x55 which contains 8 edges in total dut.write('U') time.sleep(1) match = dut.expect(EXIT_SLEEP_REGEX) logging.info('Got third sleep period, wakeup from {}, slept for {}'.format( match.group(1), match.group(3))) assert (match.group(1).decode('utf8') == 'uart' and int(match.group(3)) < WAKEUP_INTERVAL_MS) logging.info('Went to sleep again') match = dut.expect(EXIT_SLEEP_REGEX) assert (match.group(1).decode('utf8') == 'timer' and int(match.group(3)) >= WAKEUP_INTERVAL_MS - 1 and int(match.group(3)) <= WAKEUP_INTERVAL_MS + 1) logging.info('Woke up from timer again')
def test_led_strip_example(dut: Dut) -> None: dut.expect_exact('example: Create RMT TX channel') dut.expect_exact('example: Install led strip encoder') dut.expect_exact('example: Enable RMT TX channel') dut.expect_exact('example: Start LED rainbow chase')
def test_gptimer_example(dut: Dut) -> None: dut.expect_exact('Create timer handle', timeout=5) dut.expect_exact('Start timer, stop it at alarm event', timeout=5) res = dut.expect(r'Timer stopped, count=(\d+)', timeout=30) stopped_count = res.group(1).decode('utf8') assert (1000000 - 10) < int(stopped_count) < (1000000 + 10) dut.expect_exact('Set count value') dut.expect_exact('Get count value') res = dut.expect(r'Timer count value=(\d+)', timeout=5) count_val = res.group(1).decode('utf8') assert int(count_val) == 100 dut.expect_exact('Start timer, auto-reload at alarm event', timeout=5) res = dut.expect(r'Timer reloaded, count=(\d+)', timeout=5) reloaded_count = res.group(1).decode('utf8') assert 0 <= int(reloaded_count) < 10 dut.expect_exact('Stop timer') dut.expect_exact('Start timer, update alarm value dynamically') for i in range(1, 5): res = dut.expect(r'Timer alarmed, count=(\d+)', timeout=5) alarm_count = res.group(1).decode('utf8') assert (i * 1000000 - 10) < int(alarm_count) < (i * 1000000 + 10) dut.expect_exact('Stop timer') dut.expect_exact('Delete timer')
def test_examples_esp_local_ctrl(dut: Dut) -> None: rel_project_path = os.path.join('examples', 'protocols', 'esp_local_ctrl') idf_path = get_sdk_path() dut_ip = dut.expect(r'esp_netif_handlers: sta ip: (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')[1].decode() dut.expect('esp_https_server: Starting server') dut.expect('esp_https_server: Server listening on port 443') dut.expect('control: esp_local_ctrl service started with name : my_esp_ctrl_device') def dut_expect_read() -> None: dut.expect_exact('control: Reading property : timestamp (us)', timeout=20) dut.expect_exact('control: Reading property : property1') dut.expect_exact('control: Reading property : property2') dut.expect_exact('control: Reading property : property3') # Running mDNS services in docker is not a trivial task. Therefore, the script won't connect to the host name but # to IP address. However, the certificates were generated for the host name and will be rejected. cmd = ' '.join([sys.executable, os.path.join(idf_path, rel_project_path, 'scripts/esp_local_ctrl.py'), '--sec_ver 0', '--name', dut_ip, '--dont-check-hostname']) # don't reject the certificate because of the hostname esp_local_ctrl_log = os.path.join(idf_path, rel_project_path, 'esp_local_ctrl.log') with CustomProcess(cmd, esp_local_ctrl_log) as ctrl_py: def expect_properties(prop1: int, prop3: str) -> None: dut_expect_read() ctrl_py.pexpect_proc.expect_exact('==== Available Properties ====') ctrl_py.pexpect_proc.expect(re.compile(r'S.N. Name\s+Type\s+Flags\s+Value')) ctrl_py.pexpect_proc.expect(re.compile(r'\[ 1\] timestamp \(us\)\s+TIME\(us\)\s+Read-Only\s+\d+')) ctrl_py.pexpect_proc.expect(re.compile(r'\[ 2\] property1\s+INT32\s+{}'.format(prop1))) ctrl_py.pexpect_proc.expect(re.compile(r'\[ 3\] property2\s+BOOLEAN\s+Read-Only\s+(True)|(False)')) ctrl_py.pexpect_proc.expect(re.compile(r'\[ 4\] property3\s+STRING\s+{}'.format(prop3))) ctrl_py.pexpect_proc.expect_exact('Select properties to set (0 to re-read, \'q\' to quit) :') property1 = 123456789 property3 = '' ctrl_py.pexpect_proc.expect_exact('Connecting to {}'.format(dut_ip)) dut.expect('esp_https_server: performing session handshake', timeout=60) expect_properties(property1, property3) ctrl_py.pexpect_proc.sendline('1') ctrl_py.pexpect_proc.expect_exact('Enter value to set for property (timestamp (us)) :') ctrl_py.pexpect_proc.sendline('2') ctrl_py.pexpect_proc.expect_exact('Failed to set values!') dut.expect_exact('control: timestamp (us) is read-only') expect_properties(property1, property3) property1 = 638 ctrl_py.pexpect_proc.sendline('2') ctrl_py.pexpect_proc.expect_exact('Enter value to set for property (property1) :') ctrl_py.pexpect_proc.sendline(str(property1)) dut.expect_exact('control: Setting property1 value to {}'.format(property1)) expect_properties(property1, property3) property3 = 'test' ctrl_py.pexpect_proc.sendline('4') ctrl_py.pexpect_proc.expect_exact('Enter value to set for property (property3) :') ctrl_py.pexpect_proc.sendline(property3) dut.expect_exact('control: Setting property3 value to {}'.format(property3)) expect_properties(property1, property3) ctrl_py.pexpect_proc.sendline('q') ctrl_py.pexpect_proc.expect_exact('Quitting...')
def actual_test(dut: Dut) -> None: dut.expect_exact('Press ENTER to see the list of tests') dut.write('\n') dut.expect_exact('Enter test for running.') dut.write('"start_and_stop"') dut.expect_unity_test_output() dut.expect_exact("Enter next test, or 'enter' to see menu") dut.write('"get_set_mac"') dut.expect_unity_test_output() dut.expect_exact("Enter next test, or 'enter' to see menu") with configure_eth_if() as so: so.settimeout(30) dut.write('"ethernet_broadcast_transmit"') eth_frame = Ether(so.recv(1024)) for i in range(0, 1010): if eth_frame.load[i] != i & 0xff: raise Exception('Packet content mismatch') dut.expect_unity_test_output() dut.expect_exact("Enter next test, or 'enter' to see menu") dut.write('"recv_pkt"') res = dut.expect( r'([\s\S]*)' r'DUT MAC: ([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})' ) send_eth_packet('ff:ff:ff:ff:ff:ff') # broadcast frame send_eth_packet('01:00:00:00:00:00') # multicast frame send_eth_packet(res.group(2)) # unicast frame dut.expect_unity_test_output(extra_before=res.group(1)) dut.expect_exact("Enter next test, or 'enter' to see menu") dut.write('"start_stop_stress_test"') res = dut.expect( r'([\s\S]*)' r'DUT MAC: ([0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2}:[0-9A-Fa-f]{2})' ) # Start/stop under heavy Tx traffic for tx_i in range(10): recv_resp_poke(tx_i) # Start/stop under heavy Rx traffic pipe_rcv, pipe_send = Pipe(False) tx_proc = Process(target=traffic_gen, args=( res.group(2), pipe_rcv, )) tx_proc.start() try: for rx_i in range(10): recv_resp_poke(rx_i) finally: pipe_send.send(0) tx_proc.join() dut.expect_unity_test_output()
def test_custom_bootloader_hooks_example(dut: Dut) -> None: # Expect to read both hooks messages dut.expect_exact('This hook is called BEFORE bootloader initialization') dut.expect_exact('This hook is called AFTER bootloader initialization')
def test_musical_buzzer_example(dut: Dut) -> None: dut.expect_exact('example: Create RMT TX channel') dut.expect_exact('example: Install musical score encoder') dut.expect_exact('example: Enable RMT TX channel') dut.expect_exact("example: Playing Beethoven's Ode to joy")
def test_legacy_timer_driver(dut: Dut) -> None: dut.expect_exact('Press ENTER to see the list of tests') dut.write('*') dut.expect_unity_test_output(timeout=120)
def test_task_watchdog(dut: Dut) -> None: dut.expect_exact('Example complete')