style: format python files with isort and double-quote-string-fixer

This commit is contained in:
Fu Hanxi
2021-01-26 10:49:01 +08:00
parent dc8402ea61
commit 0146f258d7
276 changed files with 8241 additions and 8162 deletions

View File

@@ -1,16 +1,14 @@
#!/usr/bin/env python
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division, print_function, unicode_literals
import ttfw_idf
@ttfw_idf.idf_example_test(env_tag="Example_TWAI1", target=['esp32', 'esp32s2'], ci_target=['esp32'])
@ttfw_idf.idf_example_test(env_tag='Example_TWAI1', target=['esp32', 'esp32s2'], ci_target=['esp32'])
def test_examples_gpio(env, extra_data):
app_name = "gpio"
dut = env.get_dut(app_name, "examples/peripherals/gpio/generic_gpio")
app_name = 'gpio'
dut = env.get_dut(app_name, 'examples/peripherals/gpio/generic_gpio')
dut.start_app()
res = dut.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
if not res:

View File

@@ -10,27 +10,27 @@ def test_i2ctools_example(env, extra_data):
# Get device under test, flash and start example. "i2ctool" must be defined in EnvConfig
dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools', dut_class=ttfw_idf.ESP32DUT)
dut.start_app()
dut.expect("i2c-tools>", timeout=EXPECT_TIMEOUT)
dut.expect('i2c-tools>', timeout=EXPECT_TIMEOUT)
# Get i2c address
dut.write("i2cdetect")
dut.expect("5b", timeout=EXPECT_TIMEOUT)
dut.write('i2cdetect')
dut.expect('5b', timeout=EXPECT_TIMEOUT)
# Get chip ID
dut.write("i2cget -c 0x5b -r 0x20 -l 1")
dut.expect("0x81", timeout=EXPECT_TIMEOUT)
dut.write('i2cget -c 0x5b -r 0x20 -l 1')
dut.expect('0x81', timeout=EXPECT_TIMEOUT)
# Reset sensor
dut.write("i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A")
dut.expect("OK", timeout=EXPECT_TIMEOUT)
dut.write('i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A')
dut.expect('OK', timeout=EXPECT_TIMEOUT)
# Get status
dut.write("i2cget -c 0x5b -r 0x00 -l 1")
dut.expect_any("0x10", timeout=EXPECT_TIMEOUT)
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
dut.expect_any('0x10', timeout=EXPECT_TIMEOUT)
# Change work mode
dut.write("i2cset -c 0x5b -r 0xF4")
dut.expect("OK", timeout=EXPECT_TIMEOUT)
dut.write("i2cset -c 0x5b -r 0x01 0x10")
dut.expect("OK", timeout=EXPECT_TIMEOUT)
dut.write('i2cset -c 0x5b -r 0xF4')
dut.expect('OK', timeout=EXPECT_TIMEOUT)
dut.write('i2cset -c 0x5b -r 0x01 0x10')
dut.expect('OK', timeout=EXPECT_TIMEOUT)
# Get new status
dut.write("i2cget -c 0x5b -r 0x00 -l 1")
dut.expect_any("0x98", "0x90", timeout=EXPECT_TIMEOUT)
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
dut.expect_any('0x98', '0x90', timeout=EXPECT_TIMEOUT)
if __name__ == '__main__':

View File

@@ -1,43 +1,44 @@
from __future__ import print_function
from builtins import range
import os
import wave
import struct
import wave
from builtins import range
def get_wave_array_str(filename, target_bits):
wave_read = wave.open(filename, "r")
array_str = ""
wave_read = wave.open(filename, 'r')
array_str = ''
nchannels, sampwidth, framerate, nframes, comptype, compname = wave_read.getparams()
sampwidth *= 8
for i in range(wave_read.getnframes()):
val, = struct.unpack("<H", wave_read.readframes(1))
val, = struct.unpack('<H', wave_read.readframes(1))
scale_val = (1 << target_bits) - 1
cur_lim = (1 << sampwidth) - 1
# scale current data to 8-bit data
val = val * scale_val / cur_lim
val = int(val + ((scale_val + 1) // 2)) & scale_val
array_str += "0x%x, " % (val)
array_str += '0x%x, ' % (val)
if (i + 1) % 16 == 0:
array_str += "\n"
array_str += '\n'
return array_str
def gen_wave_table(wav_file_list, target_file_name, scale_bits=8):
with open(target_file_name, "w") as audio_table:
with open(target_file_name, 'w') as audio_table:
print('#include <stdio.h>', file=audio_table)
print('const unsigned char audio_table[] = {', file=audio_table)
for wav in wav_file_list:
print("processing: {}".format(wav))
print('processing: {}'.format(wav))
print(get_wave_array_str(filename=wav, target_bits=scale_bits), file=audio_table)
print('};\n', file=audio_table)
print("Done...")
print('Done...')
if __name__ == '__main__':
print("Generating audio array...")
print('Generating audio array...')
wav_list = []
for filename in os.listdir("./"):
if filename.endswith(".wav"):
for filename in os.listdir('./'):
if filename.endswith('.wav'):
wav_list.append(filename)
gen_wave_table(wav_file_list=wav_list, target_file_name="audio_example_file.h")
gen_wave_table(wav_file_list=wav_list, target_file_name='audio_example_file.h')

View File

@@ -8,19 +8,19 @@ EXPECT_TIMEOUT = 20
@ttfw_idf.idf_example_test(env_tag='Example_RMT_IR_PROTOCOLS')
def test_examples_rmt_ir_protocols(env, extra_data):
dut = env.get_dut('ir_protocols_example', 'examples/peripherals/rmt/ir_protocols', app_config_name='nec')
print("Using binary path: {}".format(dut.app.binary_path))
print('Using binary path: {}'.format(dut.app.binary_path))
dut.start_app()
dut.expect("example: Send command 0x20 to address 0x10", timeout=EXPECT_TIMEOUT)
dut.expect("Scan Code --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
dut.expect("Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
dut.expect('example: Send command 0x20 to address 0x10', timeout=EXPECT_TIMEOUT)
dut.expect('Scan Code --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
dut.expect('Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
env.close_dut(dut.name)
dut = env.get_dut('ir_protocols_example', 'examples/peripherals/rmt/ir_protocols', app_config_name='rc5')
print("Using binary path: {}".format(dut.app.binary_path))
print('Using binary path: {}'.format(dut.app.binary_path))
dut.start_app()
dut.expect("example: Send command 0x20 to address 0x10", timeout=EXPECT_TIMEOUT)
dut.expect("Scan Code --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
dut.expect("Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
dut.expect('example: Send command 0x20 to address 0x10', timeout=EXPECT_TIMEOUT)
dut.expect('Scan Code --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
dut.expect('Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
env.close_dut(dut.name)

View File

@@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from tiny_test_fw import TinyFW
import ttfw_idf
from tiny_test_fw import TinyFW
@ttfw_idf.idf_example_test(env_tag="Example_SDIO", ignore=True)
@ttfw_idf.idf_example_test(env_tag='Example_SDIO', ignore=True)
def test_example_sdio_communication(env, extra_data):
"""
Configurations
@@ -36,88 +36,88 @@ def test_example_sdio_communication(env, extra_data):
or use sdio test board, which has two wrover modules connect to a same FT3232
Assume that first dut is host and second is slave
"""
dut1 = env.get_dut("sdio_host", "examples/peripherals/sdio/host", dut_class=ttfw_idf.ESP32DUT)
dut2 = env.get_dut("sdio_slave", "examples/peripherals/sdio/slave", dut_class=ttfw_idf.ESP32DUT)
dut1 = env.get_dut('sdio_host', 'examples/peripherals/sdio/host', dut_class=ttfw_idf.ESP32DUT)
dut2 = env.get_dut('sdio_slave', 'examples/peripherals/sdio/slave', dut_class=ttfw_idf.ESP32DUT)
dut1.start_app()
# wait until the master is ready to setup the slave
dut1.expect("host ready, start initializing slave...")
dut1.expect('host ready, start initializing slave...')
dut2.start_app()
dut1.expect("0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37")
dut1.expect("3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00")
dut1.expect("6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97")
dut1.expect("9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7")
dut1.expect('0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37')
dut1.expect('3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00')
dut1.expect('6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97')
dut1.expect('9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7')
dut2.expect("================ JOB_WRITE_REG ================")
dut2.expect("0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37")
dut2.expect("3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00")
dut2.expect("6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97")
dut2.expect("9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7")
dut2.expect('================ JOB_WRITE_REG ================')
dut2.expect('0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37')
dut2.expect('3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00')
dut2.expect('6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97')
dut2.expect('9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7')
dut1.expect("host int: 0")
dut1.expect("host int: 1")
dut1.expect("host int: 2")
dut1.expect("host int: 3")
dut1.expect("host int: 4")
dut1.expect("host int: 5")
dut1.expect("host int: 6")
dut1.expect("host int: 7")
dut1.expect("host int: 0")
dut1.expect("host int: 1")
dut1.expect("host int: 2")
dut1.expect("host int: 3")
dut1.expect("host int: 4")
dut1.expect("host int: 5")
dut1.expect("host int: 6")
dut1.expect("host int: 7")
dut1.expect('host int: 0')
dut1.expect('host int: 1')
dut1.expect('host int: 2')
dut1.expect('host int: 3')
dut1.expect('host int: 4')
dut1.expect('host int: 5')
dut1.expect('host int: 6')
dut1.expect('host int: 7')
dut1.expect('host int: 0')
dut1.expect('host int: 1')
dut1.expect('host int: 2')
dut1.expect('host int: 3')
dut1.expect('host int: 4')
dut1.expect('host int: 5')
dut1.expect('host int: 6')
dut1.expect('host int: 7')
dut2.expect("================ JOB_SEND_INT ================")
dut2.expect("================ JOB_SEND_INT ================")
dut2.expect('================ JOB_SEND_INT ================')
dut2.expect('================ JOB_SEND_INT ================')
dut1.expect("send packet length: 3")
dut1.expect("send packet length: 6")
dut1.expect("send packet length: 12")
dut1.expect("send packet length: 128")
dut1.expect("send packet length: 511")
dut1.expect("send packet length: 512")
dut1.expect('send packet length: 3')
dut1.expect('send packet length: 6')
dut1.expect('send packet length: 12')
dut1.expect('send packet length: 128')
dut1.expect('send packet length: 511')
dut1.expect('send packet length: 512')
dut2.expect("recv len: 3")
dut2.expect("recv len: 6")
dut2.expect("recv len: 12")
dut2.expect("recv len: 128")
dut2.expect('recv len: 3')
dut2.expect('recv len: 6')
dut2.expect('recv len: 12')
dut2.expect('recv len: 128')
# 511
dut2.expect("recv len: 128")
dut2.expect("recv len: 128")
dut2.expect("recv len: 128")
dut2.expect("recv len: 127")
dut2.expect('recv len: 128')
dut2.expect('recv len: 128')
dut2.expect('recv len: 128')
dut2.expect('recv len: 127')
# 512
dut2.expect("recv len: 128")
dut2.expect("recv len: 128")
dut2.expect("recv len: 128")
dut2.expect("recv len: 128")
dut2.expect('recv len: 128')
dut2.expect('recv len: 128')
dut2.expect('recv len: 128')
dut2.expect('recv len: 128')
dut1.expect("receive data, size: 3")
dut1.expect("receive data, size: 6")
dut1.expect("receive data, size: 12")
dut1.expect("receive data, size: 128")
dut1.expect('receive data, size: 3')
dut1.expect('receive data, size: 6')
dut1.expect('receive data, size: 12')
dut1.expect('receive data, size: 128')
dut1.expect("receive data, size: 128")
dut1.expect("receive data, size: 128")
dut1.expect("receive data, size: 128")
dut1.expect("receive data, size: 127")
dut1.expect('receive data, size: 128')
dut1.expect('receive data, size: 128')
dut1.expect('receive data, size: 128')
dut1.expect('receive data, size: 127')
dut1.expect("receive data, size: 128")
dut1.expect("receive data, size: 128")
dut1.expect("receive data, size: 128")
dut1.expect("receive data, size: 128")
dut1.expect('receive data, size: 128')
dut1.expect('receive data, size: 128')
dut1.expect('receive data, size: 128')
dut1.expect('receive data, size: 128')
# the last valid line of one round
dut1.expect("ce d3 d8 dd e2 e7 ec f1 f6 fb 00 05 0a 0f 14 19")
dut1.expect('ce d3 d8 dd e2 e7 ec f1 f6 fb 00 05 0a 0f 14 19')
# the first 2 lines of the second round
dut1.expect("46 4b 50")
dut1.expect("5a 5f 64 69 6e 73")
dut1.expect('46 4b 50')
dut1.expect('5a 5f 64 69 6e 73')
if __name__ == '__main__':
TinyFW.set_default_config(env_config_file="EnvConfigTemplate.yml", dut=ttfw_idf.IDFDUT)
TinyFW.set_default_config(env_config_file='EnvConfigTemplate.yml', dut=ttfw_idf.IDFDUT)
test_example_sdio_communication()

View File

@@ -4,7 +4,7 @@ from __future__ import print_function
import ttfw_idf
# TWAI Self Test Example constants
STR_EXPECT = ("TWAI Alert and Recovery: Driver installed", "TWAI Alert and Recovery: Driver uninstalled")
STR_EXPECT = ('TWAI Alert and Recovery: Driver installed', 'TWAI Alert and Recovery: Driver uninstalled')
EXPECT_TIMEOUT = 20

View File

@@ -6,9 +6,9 @@ from threading import Thread
import ttfw_idf
# Define tuple of strings to expect for each DUT.
master_expect = ("TWAI Master: Driver installed", "TWAI Master: Driver uninstalled")
slave_expect = ("TWAI Slave: Driver installed", "TWAI Slave: Driver uninstalled")
listen_only_expect = ("TWAI Listen Only: Driver installed", "TWAI Listen Only: Driver uninstalled")
master_expect = ('TWAI Master: Driver installed', 'TWAI Master: Driver uninstalled')
slave_expect = ('TWAI Slave: Driver installed', 'TWAI Slave: Driver uninstalled')
listen_only_expect = ('TWAI Listen Only: Driver installed', 'TWAI Listen Only: Driver uninstalled')
def dut_thread_callback(**kwargs):
@@ -31,11 +31,11 @@ def dut_thread_callback(**kwargs):
def test_twai_network_example(env, extra_data):
# Get device under test. "dut1", "dut2", and "dut3" must be properly defined in EnvConfig
dut_master = env.get_dut("dut1", "examples/peripherals/twai/twai_network/twai_network_master",
dut_master = env.get_dut('dut1', 'examples/peripherals/twai/twai_network/twai_network_master',
dut_class=ttfw_idf.ESP32DUT)
dut_slave = env.get_dut("dut2", "examples/peripherals/twai/twai_network/twai_network_slave",
dut_slave = env.get_dut('dut2', 'examples/peripherals/twai/twai_network/twai_network_slave',
dut_class=ttfw_idf.ESP32DUT)
dut_listen_only = env.get_dut("dut3", "examples/peripherals/twai/twai_network/twai_network_listen_only",
dut_listen_only = env.get_dut('dut3', 'examples/peripherals/twai/twai_network/twai_network_listen_only',
dut_class=ttfw_idf.ESP32DUT)
# Flash app onto each DUT, each DUT is reset again at the start of each thread
@@ -45,14 +45,14 @@ def test_twai_network_example(env, extra_data):
# Create dict of keyword arguments for each dut
results = [[False], [False], [False]]
master_kwargs = {"dut": dut_master, "result": results[0], "expected": master_expect}
slave_kwargs = {"dut": dut_slave, "result": results[1], "expected": slave_expect}
listen_only_kwargs = {"dut": dut_listen_only, "result": results[2], "expected": listen_only_expect}
master_kwargs = {'dut': dut_master, 'result': results[0], 'expected': master_expect}
slave_kwargs = {'dut': dut_slave, 'result': results[1], 'expected': slave_expect}
listen_only_kwargs = {'dut': dut_listen_only, 'result': results[2], 'expected': listen_only_expect}
# Create thread for each dut
dut_master_thread = Thread(target=dut_thread_callback, name="Master Thread", kwargs=master_kwargs)
dut_slave_thread = Thread(target=dut_thread_callback, name="Slave Thread", kwargs=slave_kwargs)
dut_listen_only_thread = Thread(target=dut_thread_callback, name="Listen Only Thread", kwargs=listen_only_kwargs)
dut_master_thread = Thread(target=dut_thread_callback, name='Master Thread', kwargs=master_kwargs)
dut_slave_thread = Thread(target=dut_thread_callback, name='Slave Thread', kwargs=slave_kwargs)
dut_listen_only_thread = Thread(target=dut_thread_callback, name='Listen Only Thread', kwargs=listen_only_kwargs)
# Start each thread
dut_listen_only_thread.start()
@@ -67,7 +67,7 @@ def test_twai_network_example(env, extra_data):
# check each thread ran to completion
for result in results:
if result[0] is not True:
raise Exception("One or more threads did not run successfully")
raise Exception('One or more threads did not run successfully')
if __name__ == '__main__':

View File

@@ -3,9 +3,8 @@ from __future__ import print_function
import ttfw_idf
# TWAI Self Test Example constants
STR_EXPECT = ("TWAI Self Test: Driver installed", "TWAI Self Test: Driver uninstalled")
STR_EXPECT = ('TWAI Self Test: Driver installed', 'TWAI Self Test: Driver uninstalled')
EXPECT_TIMEOUT = 20