From 26539eb3ec9c2ac61068ddaf6ba03cc99b4e43dd Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Wed, 16 Oct 2019 15:54:10 +0200 Subject: [PATCH 1/3] tests/periph_i2c: Remove obsolete python tests --- tests/periph_i2c/README.md | 17 +- tests/periph_i2c/tests/README.md | 35 --- tests/periph_i2c/tests/periph_i2c_if.py | 137 --------- tests/periph_i2c/tests/test.py | 358 ------------------------ 4 files changed, 13 insertions(+), 534 deletions(-) delete mode 100644 tests/periph_i2c/tests/README.md delete mode 100644 tests/periph_i2c/tests/periph_i2c_if.py delete mode 100644 tests/periph_i2c/tests/test.py diff --git a/tests/periph_i2c/README.md b/tests/periph_i2c/README.md index 2533d4ff4cbb..42b17c24993e 100644 --- a/tests/periph_i2c/README.md +++ b/tests/periph_i2c/README.md @@ -1,6 +1,7 @@ Expected result =============== -This test enables you to test all available low-level I2C functions using the shell. Consult the 'help' shell command for available actions. +This test enables you to test all available low-level I2C functions using the shell. +Consult the `help` shell command for available actions. Background ========== @@ -8,8 +9,16 @@ Test for the low-level I2C driver. Can be run manually or using python script i Glossary ========== -DEV - The I2C device number, this is usually 0. Consult the board header file for more information.
-ADDR - The address of the slave I2C device, this is usually the sensor. Information on the slave address should be found in the sensor datasheet.
-REG - The register of the slave device/sensor. Not all sensors follow this access method. A I2C_NOSTOP (0x04) may be needed.
+DEV - The I2C device number, this is usually 0. +Consult the board header file for more information.
+ADDR - The address of the slave I2C device, this is usually the sensor. +Information on the slave address should be found in the sensor datasheet.
+REG - The register of the slave device/sensor. +Not all sensors follow this access method. +A I2C_NOSTOP (0x04) may be needed.
LEN - The length to read or write.
FLAG - Flags set for the I2C, more information is available in driver/include/periph/i2c.h + +_note: Automated tests can be found in the +[RobotFW-tests](https://github.com/RIOT-OS/RobotFW-tests/tree/master/tests/periph_i2c) +repository_ diff --git a/tests/periph_i2c/tests/README.md b/tests/periph_i2c/tests/README.md deleted file mode 100644 index 1b0d4ed762b4..000000000000 --- a/tests/periph_i2c/tests/README.md +++ /dev/null @@ -1,35 +0,0 @@ -*deprecated: BPT is renamed to PHiLIP, more information found [here](https://github.com/MrKevinWeiss/PHiLIP)* - -How To Run -========== -Connect the DUT (device under test) I2C0 to the BPT (bluepill tester). Information for BPT setup can be found [here](https://github.com/MrKevinWeiss/Testing). - -### Example Test With Nucleo-F401RE -1. Flash the periph_i2c firmware on the nucleo-f401 with `make BOARD=nucleo-f401 flash` in the periph_i2c directory -2. Connect the [BPT](https://github.com/MrKevinWeiss/Testing/blob/master/resources/bptpinout.jpg) to the cpu using a USB to Serial converter
-(BPT IF_TX = PA9)
-(BPT IF_RX = PA10) -3. Connect the BPT to the DUT
-(DUT SCL/D15 <=> BPT SCL1/PB6)
-(DUT SDA/D14 <=> BPT SDA1/PB7)
-(DUT NRST <=> BPT PB1)
-4. Run the test.py from the periph_i2c/tests directory (with various options)
-`python test.py` for basic tests with autoconnect
-`python3 test.py` for python 3
-`python test.py --log=DEBUG` to see all debug messages
-`python test.py --dut_port="/dev/ttyACM0"` to specify the port
-`python test.py --log=DEBUG --dut_port="/dev/ttyACM0" --dut_baud=9600 --bpt_port="/dev/ttyACM1" > nucleo-f401_test.txt` for all the fix'ns
- -Flags -========== ---log=DEBUG -> allows for debug output
---dut_port -> the port name of the DUT
---dut_baud -> the baud rate of the DUT
---bpt_port -> the port name of the BPT - -Notes -========== -- If no serial connection to the BPT the test should still be able to run, it just will not be able to reset. -- Connect the SDA, SCL and if possible the DUT reset pin. -- Autoconnect *may* work if no ports are specified. -- Default baud rate is 115200 diff --git a/tests/periph_i2c/tests/periph_i2c_if.py b/tests/periph_i2c/tests/periph_i2c_if.py deleted file mode 100644 index 0143c809ca0d..000000000000 --- a/tests/periph_i2c/tests/periph_i2c_if.py +++ /dev/null @@ -1,137 +0,0 @@ -# Copyright (c) 2018 Kevin Weiss, for HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. -"""@package PyToAPI -This module handles parsing of information from RIOT periph_i2c test. -""" -import logging -try: - from riot_pal import DutShell -except ImportError: - raise ImportError('Cannot find riot_pal, try "pip install riot_pal"') - - -class PeriphI2CIf(DutShell): - """Interface to the a node with periph_i2c firmware.""" - FW_ID = 'periph_i2c' - DEFAULT_DEV = 0 - DEFAULT_ADDR = 85 - DEFAULT_REG = 152 - DEFAULT_LEN = 10 - DEFAULT_DATA = [0, 1, 2] - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - def is_connected_to_board(self): - """Checks if board is connected.""" - return self.i2c_get_id()["data"] == [self.FW_ID] - - def i2c_acquire(self, dev=DEFAULT_DEV): - """Get access to the I2C bus.""" - return self.send_cmd('i2c_acquire {}'.format(dev)) - - def i2c_release(self, dev=DEFAULT_DEV): - """Release to the I2C bus.""" - return self.send_cmd('i2c_release {}'.format(dev)) - - def i2c_read_reg(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, reg=DEFAULT_REG, - flag=0): - """Read byte from register.""" - return self.send_cmd('i2c_read_reg' - ' {} {} {} {}'.format(dev, addr, reg, flag)) - - def i2c_read_regs(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, reg=DEFAULT_REG, - leng=DEFAULT_LEN, flag=0): - """Read bytes from registers.""" - return self.send_cmd('i2c_read_regs' - ' {} {} {} {} {}'.format(dev, addr, reg, - leng, flag)) - - def i2c_read_byte(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, flag=0): - """Read byte from the I2C device.""" - return self.send_cmd('i2c_read_byte {} {} {}'.format(dev, addr, flag)) - - def i2c_read_bytes(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, leng=DEFAULT_LEN, - flag=0): - """Read bytes from the I2C device.""" - return self.send_cmd('i2c_read_bytes' - ' {} {} {} {}'.format(dev, addr, leng, flag)) - - def i2c_write_reg(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, reg=DEFAULT_REG, - data=DEFAULT_DATA, flag=0): - """Write byte to the I2C device.""" - if isinstance(data, list): - data = data[0] - return self.send_cmd('i2c_write_reg' - ' {} {} {} {} {}'.format(dev, addr, reg, - data, flag)) - - def i2c_write_regs(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, reg=DEFAULT_REG, - data=DEFAULT_DATA, flag=0): - """Write byte to register.""" - stri = ' '.join(str(x) for x in data) - return self.send_cmd('i2c_write_regs' - ' {} {} {} {} {}'.format(dev, addr, reg, flag, stri)) - - def i2c_write_byte(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, data=DEFAULT_DATA, - flag=0): - """Write bytes to registers.""" - if isinstance(data, list): - data = data[0] - return self.send_cmd('i2c_write_byte' - ' {} {} {} {}'.format(dev, addr, data, flag)) - - def i2c_write_bytes(self, dev=DEFAULT_DEV, addr=DEFAULT_ADDR, - data=DEFAULT_DATA, flag=0): - """Write bytes to registers.""" - stri = ' '.join(str(x) for x in data) - return self.send_cmd('i2c_write_bytes' - ' {} {} {} {}'.format(dev, addr, flag, stri)) - - def i2c_get_devs(self): - """Gets amount of supported i2c devices.""" - return self.send_cmd('i2c_get_devs') - - def i2c_get_id(self): - """Get the id of the fw.""" - return self.send_cmd('i2c_get_id') - - def get_command_list(self): - """List of all commands.""" - cmds = list() - cmds.append(self.i2c_get_devs) - cmds.append(self.i2c_get_id) - cmds.append(self.i2c_acquire) - cmds.append(self.i2c_read_reg) - cmds.append(self.i2c_read_regs) - cmds.append(self.i2c_read_byte) - cmds.append(self.i2c_read_bytes) - cmds.append(self.i2c_write_reg) - cmds.append(self.i2c_write_regs) - cmds.append(self.i2c_write_byte) - cmds.append(self.i2c_write_bytes) - cmds.append(self.i2c_release) - return cmds - - -def main(): - """Test for I2C.""" - - logging.getLogger().setLevel(logging.DEBUG) - try: - i2c = PeriphI2CIf() - cmds = i2c.get_command_list() - logging.debug("======================================================") - for cmd in cmds: - cmd() - logging.debug("--------------------------------------------------") - logging.debug("======================================================") - except Exception as exc: - logging.debug(exc) - - -if __name__ == "__main__": - main() diff --git a/tests/periph_i2c/tests/test.py b/tests/periph_i2c/tests/test.py deleted file mode 100644 index 345109cb0b83..000000000000 --- a/tests/periph_i2c/tests/test.py +++ /dev/null @@ -1,358 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (c) 2018 Kevin Weiss, for HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. - -"""@package PyToAPI -A test that can be used for now but should be adapted to a framework. -TODO: REMOVE and adapt to a proper testing platform -""" -import argparse -import time -import logging - -from periph_i2c_if import PeriphI2CIf -from if_lib import PhilipIf - -BPT_ADDR = 85 -BPT_USER_REG = 152 - - -def kwexpect(val1, val2, level="WARN"): - """A poor mans pexpect""" - res = level - try: - if isinstance(val1, str) and isinstance(val2, str): - if val1.lower() == val2.lower(): - res = "PASS" - elif isinstance(val1, list): - if len(val1) == 0: - return [res, val1, val2] - err = False - if len(val1) != len(val2): - err = True - for test_index in range(0, len(val1)): - if val1[test_index] != val2[test_index]: - err = True - if err is False: - res = "PASS" - else: - return [level, val1, val2] - elif (val1 == val2) or (val1 is val2): - res = "PASS" - except TypeError: - res = 'TypeError' - except Exception as exc: - res = 'Unknown Error' - logging.debug(exc) - - return [res, val1, val2] - - -class TestParam: - """A poor mans way to store test params because I didn't know about dict""" - test_num = None - action = None - expect_res = None - - -class Test: - """A poor mans way to run tests""" - name = "" - desc = "" - notes = "" - result = "" - cmd_log = None - num = 0 - - def __init__(self, name, desc, cmd_list): - self.name = name - self.desc = desc - self.cmd_log = cmd_list - self.result = "PASS" - - def run_test(self, action, ex_res=None, ex_data=None, - res_lvl="WARN", data_lvl="WARN"): - tp = TestParam() - tp.test_num = self.num - tp.action = action - if 'data' not in action: - tp.action['data'] = [] - tp.expect_res = list() - if ex_res is not None: - tp.expect_res.append(kwexpect(action['result'], ex_res, res_lvl)) - if tp.expect_res[-1][0] == "FAIL": - self.result = tp.expect_res[-1][0] - if tp.expect_res[-1][0] == "WARN" and self.result != "FAIL": - self.result = tp.expect_res[-1][0] - if ex_data is not None: - - tp.expect_res.append(kwexpect(action['data'], ex_data, data_lvl)) - if tp.expect_res[-1][0] == "FAIL": - self.result = tp.expect_res[-1][0] - if tp.expect_res[-1][0] == "WARN" and self.result != "FAIL": - self.result = tp.expect_res[-1][0] - self.num += 1 - self.cmd_log.append(tp) - return action['data'] - - def skip_test(self, skipped_fxn): - tp = TestParam() - - tp.test_num = self.num - self.num += 1 - tp.action = skipped_fxn - tp.expect_res = "SKIP" - self.cmd_log.append(tp) - - def manual_test(self, action): - tp = TestParam() - - tp.test_num = self.num - self.num += 1 - tp.action = action - tp.expect_res = "PASS" - self.cmd_log.append(tp) - - -def setup_test(t, i2c, bpt): - bpt.reset_mcu() - t.manual_test("Reset BPT") - - bpt.set_sys_cr(1) - bpt.execute_changes() - time.sleep(0.01) - bpt.set_sys_cr(0) - bpt.execute_changes() - t.manual_test("Try to reset the DUT") - time.sleep(2) - - -def mutex_test(i2c, bpt): - cmd_log = [] - t = Test('mutex test', 'Tests mutex aquire/release functionality', cmd_log) - t.notes += 'Cannot test since it can still be used without mutex\n' - t.notes += 'Cannot test expected timeout due to no reset\n' - t.notes += 'Do we need double release failure check?\n' - t.notes += 'Does not check multiple busses acquired\n' - - setup_test(t, i2c, bpt) - - num_of_dev = t.run_test(i2c.i2c_get_devs(), "Success")[0] - - for d_num in range(0, num_of_dev): - t.run_test(i2c.i2c_release(d_num), "Success") - - t.run_test(i2c.i2c_acquire(d_num), "Success") - - if d_num == 0: - t.run_test(i2c.i2c_read_reg(d_num, BPT_ADDR, BPT_USER_REG), - "Success", [0]) - - t.run_test(i2c.i2c_release(d_num), "Success") - - t.skip_test("i2c.i2c_read_byte(d_num, BPT_ADDR), Error") - t.skip_test("i2c.i2c_acquire(d_num), Success") - t.skip_test("i2c.i2c_acquire(d_num), Timeout") - - return t - - -def read_test(i2c, bpt): - cmd_log = [] - t = Test('read test', 'Tests the read functionality for default i2c bus \ -(0) with the bpt', cmd_log) - t.notes += 'Does not check flags\n' - - setup_test(t, i2c, bpt) - - d_num = 0 - t.run_test(i2c.i2c_release(d_num), "Success") - t.run_test(i2c.i2c_acquire(d_num), "Success") - t.run_test(i2c.i2c_read_reg(d_num, BPT_ADDR, BPT_USER_REG), "Success", [0]) - t.run_test(i2c.i2c_read_reg(d_num, BPT_ADDR+1, BPT_USER_REG), "Error") - t.run_test(i2c.i2c_read_reg(d_num, BPT_ADDR, BPT_USER_REG+1), - "Success", [1]) - t.run_test(i2c.i2c_read_regs(d_num, BPT_ADDR, BPT_USER_REG, 1), - "Success", [0]) - t.run_test(i2c.i2c_read_regs(d_num, BPT_ADDR, BPT_USER_REG+1, 1), - "Success", [1]) - t.run_test(i2c.i2c_read_regs(d_num, BPT_ADDR, BPT_USER_REG, 2), - "Success", [0, 1]) - t.run_test(i2c.i2c_read_regs(d_num, BPT_ADDR, BPT_USER_REG, 3), - "Success", [0, 1, 2]) - t.run_test(i2c.i2c_read_regs(d_num, BPT_ADDR-1, BPT_USER_REG, 1), "Error") - t.run_test(i2c.i2c_read_byte(d_num, BPT_ADDR,), "Success", [0]) - t.run_test(i2c.i2c_read_byte(d_num, BPT_ADDR-2), "Error") - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1), "Success", [0]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 2), "Success", [0, 1]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 3), "Success", [0, 1, 2]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR+4, 3), "Error") - t.run_test(i2c.i2c_release(d_num), "Success") - return t - - -def check_write_reg(t, d_num, addr, reg, val, i2c): - t.run_test(i2c.i2c_write_reg(d_num, addr, reg, val[0]), "Success") - t.run_test(i2c.i2c_read_reg(d_num, addr, reg), "Success", val) - - -def check_write_regs(t, d_num, addr, reg, val, i2c): - t.run_test(i2c.i2c_write_regs(d_num, addr, reg, val), "Success") - t.run_test(i2c.i2c_read_regs(d_num, addr, reg, len(val)), "Success", val) - - -def write_test(i2c, bpt): - cmd_log = [] - t = Test('write test', 'Tests the write functionality for default i2c bus \ -(0) with the bpt', cmd_log) - t.notes += 'Does not check flags\n' - - setup_test(t, i2c, bpt) - - d_num = 0 - - t.run_test(i2c.i2c_release(d_num), "Success") - t.run_test(i2c.i2c_acquire(d_num), "Success") - - check_write_reg(t, d_num, BPT_ADDR, BPT_USER_REG, [42], i2c) - check_write_reg(t, d_num, BPT_ADDR, BPT_USER_REG, [0], i2c) - check_write_reg(t, d_num, BPT_ADDR, BPT_USER_REG+1, [41], i2c) - check_write_reg(t, d_num, BPT_ADDR, BPT_USER_REG+1, [1], i2c) - t.run_test(i2c.i2c_write_reg(d_num, BPT_ADDR-4, BPT_USER_REG, 0), "Error") - - check_write_regs(t, d_num, BPT_ADDR, BPT_USER_REG, [44], i2c) - check_write_regs(t, d_num, BPT_ADDR, BPT_USER_REG, [0], i2c) - check_write_regs(t, d_num, BPT_ADDR, BPT_USER_REG+1, [45, 46], i2c) - check_write_regs(t, d_num, BPT_ADDR, BPT_USER_REG+1, [1, 2], i2c) - check_write_regs(t, d_num, BPT_ADDR, BPT_USER_REG, [47, 48, 49], i2c) - check_write_regs(t, d_num, BPT_ADDR, BPT_USER_REG, [0, 1, 2], i2c) - t.run_test(i2c.i2c_write_regs(d_num, BPT_ADDR-5, BPT_USER_REG, [0]), - "Error") - - t.run_test(i2c.i2c_write_byte(d_num, BPT_ADDR, BPT_USER_REG+1), "Success") - t.run_test(i2c.i2c_read_byte(d_num, BPT_ADDR), "Success", [1]) - t.run_test(i2c.i2c_write_byte(d_num, BPT_ADDR, BPT_USER_REG), "Success") - t.run_test(i2c.i2c_read_byte(d_num, BPT_ADDR), "Success", [0]) - t.run_test(i2c.i2c_write_byte(d_num, BPT_ADDR+5, 0), "Error") - - t.run_test(i2c.i2c_write_bytes(d_num, BPT_ADDR, [BPT_USER_REG+1]), - "Success") - t.run_test(i2c.i2c_read_byte(d_num, BPT_ADDR), "Success", [1]) - t.run_test(i2c.i2c_write_bytes(d_num, BPT_ADDR, [BPT_USER_REG, 50]), - "Success") - t.run_test(i2c.i2c_read_byte(d_num, BPT_ADDR), "Success", [50]) - t.run_test(i2c.i2c_write_bytes(d_num, BPT_ADDR, [BPT_USER_REG+1, 51, 52]), - "Success") - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 2), "Success", [51, 52]) - t.run_test(i2c.i2c_write_bytes(d_num, BPT_ADDR, [BPT_USER_REG, 0, 1, 2]), - "Success") - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 3), "Success", [0, 1, 2]) - - t.run_test(i2c.i2c_write_bytes(d_num, BPT_ADDR-7, [47, 48, 49]), "Error") - - t.run_test(i2c.i2c_release(d_num), "Success") - return t - - -def read_flag_test(i2c, bpt): - cmd_log = [] - t = Test('read flag test', 'Tests the read flag functionality', cmd_log) - t.notes += 'Not a comprehesive test but tests a proper frame\n' - - setup_test(t, i2c, bpt) - - d_num = 0 - - t.run_test(i2c.i2c_release(d_num), "Success") - t.run_test(i2c.i2c_acquire(d_num), "Success") - t.run_test(i2c.i2c_read_reg(d_num, BPT_ADDR, BPT_USER_REG), "Success", [0]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 4), "Success", [0]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 12), "Success", [1]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 8), "Success", [2]) - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 8), "Error") - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 12), "Error") - t.skip_test("i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 4), Success, [0]") - t.skip_test("i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 4), Error, [0]") - t.skip_test("RESET DUT") - t.run_test(i2c.i2c_read_bytes(d_num, BPT_ADDR, 1, 1)) - - return t - - -def print_full_result(test): - print('==================================================================') - print('Name:\t\t' + test.name) - print('Desc:\t\t' + test.desc) - print('Result:\t\t' + test.result) - print('Notes:\t\t' + test.notes) - print('------------------------------------------------------------------') - for test_param in test.cmd_log: - print('Test Number:\t***%d***' % test_param.test_num) - if not isinstance(test_param.action, str): - print('Command:\t' + test_param.action['cmd']) - if 'msg' in test_param.action: - print('Message:\t' + test_param.action['msg']) - if test_param.action['data'] is not None: - print('Data:\t\t[%s]' % ', '.join(map(str, - test_param.action['data']))) - print('Result:\t\t' + test_param.action['result']) - else: - print('Command:\t' + test_param.action) - if isinstance(test_param.expect_res, str): - print('Expect Result:\t%s' % (test_param.expect_res)) - else: - for res in test_param.expect_res: - print('Expect Result:\t%s (%s/%s)' % (res[0], res[1], res[2])) - print('----------') - - -def print_results(test_list): - print('') - print('==================================================================') - for x in test_list: - print('Name:\t\t' + x.name) - print('Result:\t\t' + x.result + '\n') - - -def main(): - - parser = argparse.ArgumentParser() - parser.add_argument("--log", help='Set the log level (DEBUG, INFO, WARN)') - parser.add_argument("--dut_port", help='Port for device under test') - parser.add_argument("--bpt_port", help='Port for the bluepill tester') - parser.add_argument("--dut_baud", help='Baud rate for device under test') - args = parser.parse_args() - - if args.log is not None: - loglevel = args.log - numeric_level = getattr(logging, loglevel.upper(), None) - if not isinstance(numeric_level, int): - raise ValueError('Invalid log level: %s' % loglevel) - logging.basicConfig(level=loglevel) - baud = 115200 - if args.dut_baud is not None: - baud = int(args.dut_baud, 0) - - bpt = PhilipIf(port=args.bpt_port) - i2c = PeriphI2CIf(port=args.dut_port, baudrate=baud) - - print('Starting Test periph_i2c') - test_list = [] - test_list.append(mutex_test(i2c, bpt)) - print_full_result(test_list[-1]) - test_list.append(read_test(i2c, bpt)) - print_full_result(test_list[-1]) - test_list.append(write_test(i2c, bpt)) - print_full_result(test_list[-1]) - test_list.append(read_flag_test(i2c, bpt)) - print_full_result(test_list[-1]) - - print_results(test_list) - - -if __name__ == "__main__": - main() From 2c2e1fcc16309968ba5f1620de6843a1fa94d89d Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Wed, 16 Oct 2019 15:54:36 +0200 Subject: [PATCH 2/3] tests/periph_uart: Remove obsolete python tests --- tests/periph_uart/README.md | 3 + tests/periph_uart/tests/README.md | 29 -- tests/periph_uart/tests/periph_uart_if.py | 29 -- tests/periph_uart/tests/test.py | 394 ---------------------- 4 files changed, 3 insertions(+), 452 deletions(-) create mode 100644 tests/periph_uart/README.md delete mode 100644 tests/periph_uart/tests/README.md delete mode 100644 tests/periph_uart/tests/periph_uart_if.py delete mode 100644 tests/periph_uart/tests/test.py diff --git a/tests/periph_uart/README.md b/tests/periph_uart/README.md new file mode 100644 index 000000000000..4fd1eeda8d43 --- /dev/null +++ b/tests/periph_uart/README.md @@ -0,0 +1,3 @@ +_note Automated tests can be found in the +[RobotFW-tests](https://github.com/RIOT-OS/RobotFW-tests/tree/master/tests/periph_uart) +repository_ diff --git a/tests/periph_uart/tests/README.md b/tests/periph_uart/tests/README.md deleted file mode 100644 index 351bc35e1a81..000000000000 --- a/tests/periph_uart/tests/README.md +++ /dev/null @@ -1,29 +0,0 @@ -*deprecated: BPT is renamed to PHiLIP, more information found [here](https://github.com/MrKevinWeiss/PHiLIP)* - -How To Run -========== -Connect the DUT (device under test) UART6 to the BPT (bluepill tester). -Information for BPT setup can be found [here](https://github.com/MrKevinWeiss/Testing). - -### Example Test With Nucleo-F401RE -1. Flash the periph_uart firmware on the nucleo-f401 with `make BOARD=nucleo-f401 flash` in the periph_uart directory -2. Connect the [BPT](https://github.com/MrKevinWeiss/Testing/blob/master/resources/bptpinout.jpg) to the cpu using a USB to Serial converter
-(BPT IF_TX = PA9)
-(BPT IF_RX = PA10) -3. Connect the BPT to the DUT
-(DUT RX/PA12 <=> BPT TX3/PB10)
-(DUT TX/PA11 <=> BPT RX3/PB11)
-4. `test.py` requires the path to `$RIOTBASE/dist/tests` to be added to `PYTHONPATH` environment variable. Either modify `PYTHONPATH` permanently in the `.bashrc` or modify it temporary before invocation:
-`PYTHONPATH=$PYTHONPATH:$RIOTBASE/dist/tests python3 test.py` -5. Run the `test.py` from the `periph_uart/tests` directory (with various options)
-`python3 test.py` for python 3
-`python3 test.py --log=DEBUG` to see all debug messages
-`python3 test.py --dut_port="/dev/ttyACM0"` to specify the port
-`python3 test.py --log=DEBUG --dut_port="/dev/ttyACM0" --dut_uart=6 --bpt_port="/dev/ttyACM1" > nucleo-f401_test.txt` for all the fix'ns
- -Flags -========== ---log=DEBUG -> allows for debug output
---dut_port -> the port name of the DUT
---dut_uart -> DUT UART number to test
---bpt_port -> the port name of the BPT diff --git a/tests/periph_uart/tests/periph_uart_if.py b/tests/periph_uart/tests/periph_uart_if.py deleted file mode 100644 index 6f1544b12c26..000000000000 --- a/tests/periph_uart/tests/periph_uart_if.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright (c) 2018 Kevin Weiss, for HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. -"""@package PyToAPI -This module handles parsing of information from RIOT periph_uart test. -""" -try: - from riot_pal import DutShell -except ImportError: - raise ImportError('Cannot find riot_pal, try "pip install riot_pal"') - - -class PeriphUartIf(DutShell): - """Interface to the node with periph_uart firmware.""" - - def uart_init(self, dev, baud): - """Initialize DUT's UART.""" - return self.send_cmd("init {} {}".format(dev, baud)) - - def uart_mode(self, dev, data_bits, parity, stop_bits): - """Setup databits, parity and stopbits.""" - return self.send_cmd( - "mode {} {} {} {}".format(dev, data_bits, parity, stop_bits)) - - def uart_send_string(self, dev, test_string): - """Send data via DUT's UART.""" - return self.send_cmd("send {} {}".format(dev, test_string)) diff --git a/tests/periph_uart/tests/test.py b/tests/periph_uart/tests/test.py deleted file mode 100644 index c5b7caca4802..000000000000 --- a/tests/periph_uart/tests/test.py +++ /dev/null @@ -1,394 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright (c) 2018 Kevin Weiss, for HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. - -"""@package PyToAPI -A test that can be used for now but should be adapted to a framework. -TODO: REMOVE and adapt to a proper testing platform -""" -import argparse -import errno -import logging -import random -import string - -from periph_uart_if import PeriphUartIf -from riot_pal import LLMemMapIf, PHILIP_MEM_MAP_PATH - - -def kwexpect(val1, val2, level="WARN"): - """A poor mans pexpect""" - res = level - try: - if isinstance(val1, str) and isinstance(val2, str): - if val1.lower() == val2.lower(): - res = "PASS" - elif isinstance(val1, list): - if len(val1) == 0: - return [res, val1, val2] - err = False - if len(val1) != len(val2): - err = True - for test_index in range(0, len(val1)): - if val1[test_index] != val2[test_index]: - err = True - if err is False: - res = "PASS" - else: - return [level, val1, val2] - elif (val1 == val2) or (val1 is val2): - res = "PASS" - except TypeError: - res = 'TypeError' - except Exception as exc: - res = 'Unknown Error' - logging.debug(exc) - - return [res, val1, val2] - - -class TestParam: - """A poor mans way to store test params because I didn't know about dict""" - test_num = None - action = None - expect_res = None - - -class Test: - name = "" - desc = "" - notes = "" - result = "" - cmd_log = None - num = 0 - - def __init__(self, name, desc, cmd_list): - self.name = name - self.desc = desc - self.cmd_log = cmd_list - self.result = "PASS" - - def run_test(self, action, ex_res=None, ex_data=None, - res_lvl="WARN", data_lvl="WARN"): - tp = TestParam() - tp.test_num = self.num - tp.action = action - if 'data' not in action: - tp.action['data'] = [] - tp.expect_res = list() - if ex_res is not None: - tp.expect_res.append(kwexpect(action['result'], ex_res, res_lvl)) - if tp.expect_res[-1][0] == "FAIL": - self.result = tp.expect_res[-1][0] - if tp.expect_res[-1][0] == "WARN" and self.result != "FAIL": - self.result = tp.expect_res[-1][0] - if ex_data is not None: - - tp.expect_res.append(kwexpect(action['data'], ex_data, data_lvl)) - if tp.expect_res[-1][0] == "FAIL": - self.result = tp.expect_res[-1][0] - if tp.expect_res[-1][0] == "WARN" and self.result != "FAIL": - self.result = tp.expect_res[-1][0] - self.num += 1 - self.cmd_log.append(tp) - return action['data'] - - def skip_test(self, skipped_fxn): - tp = TestParam() - - tp.test_num = self.num - self.num += 1 - tp.action = skipped_fxn - tp.expect_res = "SKIP" - self.cmd_log.append(tp) - - def manual_test(self, action): - tp = TestParam() - - tp.test_num = self.num - self.num += 1 - tp.action = action - tp.expect_res = "PASS" - self.cmd_log.append(tp) - - -def setup_test(bpt, t): - bpt.reset_mcu() - t.manual_test("Reset BPT") - - bpt.write_reg('uart.baud', 115200) - bpt.execute_changes() - t.manual_test("BPT: setup default baudrate") - - -def increment_data(data): - """Increment each character.""" - return ''.join(chr(ord(n) + 1) for n in data) - - -def create_random_data(data_len): - """Generate random data with specified length.""" - return 't' + ''.join([random.choice( - string.digits) for n in range(data_len)]) - - -def echo_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('echo test', - 'Tests DUT receive/transmit functionality in loopback mode', - cmd_log) - - setup_test(bpt, t) - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Success", ["t111"]) - data = create_random_data(100) - t.run_test(uart.uart_send_string(dut_uart, data), "Success", [data]) - t.run_test(uart.uart_init(dut_uart, 38400), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Timeout") - - return t - - -def even_parity_8_bits_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('even parity and 8 bits test', - 'Tests DUT receive/transmit functionality with enabled even parity and 8 bits', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.ctrl.parity', 1) - bpt.execute_changes() - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 8, "E", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Success", ["t111"]) - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 8, "O", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Timeout") - - return t - - -def odd_parity_8_bits_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('odd parity and 8 bits test', - 'Tests DUT receive/transmit functionality with enabled odd parity and 8 bits', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.ctrl.parity', 2) - bpt.execute_changes() - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 8, "O", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Success", ["t111"]) - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 8, "E", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Timeout") - - return t - - -def even_parity_7_bits_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('even parity and 7 bits test', - 'Tests DUT receive/transmit functionality with enabled even parity and 7 bits', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.ctrl.parity', 1) - bpt.write_reg('uart.ctrl.data_bits', 1) - bpt.execute_changes() - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 7, "E", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Success", ["t111"]) - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 7, "O", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Timeout") - - return t - - -def odd_parity_7_bits_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('odd parity and 7 bits test', - 'Tests DUT receive/transmit functionality with enabled odd parity and 7 bits', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.ctrl.parity', 2) - bpt.write_reg('uart.ctrl.data_bits', 1) - bpt.execute_changes() - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 7, "O", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Success", ["t111"]) - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 7, "E", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Timeout") - - return t - - -def two_stop_bits_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('two stop bits test', - 'Tests DUT receive/transmit functionality with two stop bits', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.ctrl.parity', 2) - bpt.write_reg('uart.ctrl.data_bits', 0) - bpt.execute_changes() - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 8, "N", 2), "Success") - t.run_test(uart.uart_send_string(dut_uart, "tttt"), "Success", ["tttt"]) - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_mode(dut_uart, 8, "N", 1), "Success") - t.run_test(uart.uart_send_string(dut_uart, "tttt"), "Timeout") - - return t - - -def echo_ext_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('echo ext test', - 'Tests DUT receive/transmit functionality in ext loopback mode', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.mode', 1) - bpt.execute_changes() - t.manual_test("BPT: set echo ext mode") - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_send_string(dut_uart, "t111"), "Success", ["u222"]) - data = create_random_data(100) - t.run_test(uart.uart_send_string(dut_uart, data), "Success", [increment_data(data)]) - - return t - - -def register_read_test(bpt, uart, dut_uart, support_reset=False): - cmd_log = list() - t = Test('register read test', - 'Tests DUT receive/transmit functionality via reading BPT registers', - cmd_log) - - setup_test(bpt, t) - - bpt.write_reg('uart.mode', 2) - bpt.execute_changes() - t.manual_test("BPT: set echo ext mode") - - t.run_test(uart.uart_init(dut_uart, 115200), "Success") - t.run_test(uart.uart_send_string( - dut_uart, "\"wr 1 10 1\""), "Success") - t.run_test(uart.uart_send_string( - dut_uart, "\"rr 1 1\""), "Success", ["0,0x0A"]) - t.run_test(uart.uart_send_string( - dut_uart, "\"rr -1 10\""), "Success", [errno.EINVAL]) - - return t - - -def print_full_result(test): - """Print full test results.""" - print('==================================================================') - print('Name:\t\t' + test.name) - print('Desc:\t\t' + test.desc) - print('Result:\t\t' + test.result) - print('Notes:\t\t' + test.notes) - print('------------------------------------------------------------------') - for test_param in test.cmd_log: - print('Test Number:\t***%d***' % test_param.test_num) - if not isinstance(test_param.action, str): - print('Command:\t' + test_param.action['cmd']) - if 'msg' in test_param.action: - print('Message:\t' + test_param.action['msg']) - if test_param.action['data'] is not None: - print('Data:\t\t[%s]' % ', '.join(map(str, - test_param.action['data']))) - print('Result:\t\t' + test_param.action['result']) - else: - print('Command:\t' + test_param.action) - if isinstance(test_param.expect_res, str): - print('Expect Result:\t%s' % (test_param.expect_res)) - else: - for res in test_param.expect_res: - print('Expect Result:\t%s (%s/%s)' % (res[0], res[1], res[2])) - print('----------') - - -def print_results(test_list): - """Print brief test results.""" - print('') - print('==================================================================') - for test in test_list: - print('Name:\t\t' + test.name) - print('Result:\t\t' + test.result + '\n') - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument("--log", help='Set the log level (DEBUG, INFO, WARN)') - parser.add_argument("--bpt_port", help='Port for the bluepill tester') - parser.add_argument("--dut_port", help='Port for device under test') - parser.add_argument("--dut_uart", - help='DUT UART number to test', - type=int, - default=1) - args = parser.parse_args() - - if args.log is not None: - loglevel = args.log - numeric_level = getattr(logging, loglevel.upper(), None) - if not isinstance(numeric_level, int): - raise ValueError('Invalid log level: %s' % loglevel) - logging.basicConfig(level=loglevel) - - bpt = LLMemMapIf(PHILIP_MEM_MAP_PATH, 'serial', args.bpt_port) - uart = PeriphUartIf(port=args.dut_port) - - print('Starting Test periph_uart') - test_list = list() - test_list.append(echo_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(even_parity_8_bits_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(odd_parity_8_bits_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(even_parity_7_bits_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(odd_parity_7_bits_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(two_stop_bits_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(echo_ext_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - test_list.append(register_read_test(bpt, uart, args.dut_uart)) - print_full_result(test_list[-1]) - - print_results(test_list) - - -if __name__ == "__main__": - main() From 7a0e7e378d21fcf2e6dd91398fd9b947932cd933 Mon Sep 17 00:00:00 2001 From: MrKevinWeiss Date: Wed, 16 Oct 2019 15:57:23 +0200 Subject: [PATCH 3/3] dist/tests/if_lib: Remove if_lib since we use philip_pal All if_lib tests are no longer in use so the if_lib is obsolete. It is replace by robot framework tests, riot_pal, and philip_pal. Check the RF_Tests repo for more information --- dist/tests/if_lib/README.md | 10 - dist/tests/if_lib/__init__.py | 3 - dist/tests/if_lib/philip_if.py | 732 --------------------------------- 3 files changed, 745 deletions(-) delete mode 100644 dist/tests/if_lib/README.md delete mode 100644 dist/tests/if_lib/__init__.py delete mode 100644 dist/tests/if_lib/philip_if.py diff --git a/dist/tests/if_lib/README.md b/dist/tests/if_lib/README.md deleted file mode 100644 index 9c396fa6fb5b..000000000000 --- a/dist/tests/if_lib/README.md +++ /dev/null @@ -1,10 +0,0 @@ -Test Simulator Interface Library -================================ - -Introduction ------------- - -This library provides a Python interface to the test simulator board -using a serial link. - -*Moving out of RIOT to RIOT-OS/lib_if repo* diff --git a/dist/tests/if_lib/__init__.py b/dist/tests/if_lib/__init__.py deleted file mode 100644 index 2e4da2028a9c..000000000000 --- a/dist/tests/if_lib/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .philip_if import PhilipIf - -__all__ = ['PhilipIf'] diff --git a/dist/tests/if_lib/philip_if.py b/dist/tests/if_lib/philip_if.py deleted file mode 100644 index e7043ae94d1a..000000000000 --- a/dist/tests/if_lib/philip_if.py +++ /dev/null @@ -1,732 +0,0 @@ -# Copyright (c) 2018 Kevin Weiss, for HAW Hamburg -# -# This file is subject to the terms and conditions of the GNU Lesser -# General Public License v2.1. See the file LICENSE in the top level -# directory for more details. -"""@package PyToAPI -This module handles offset and sizes dictated by the memory map for the BPT. - -This module is autogenerated based on the memory map. -""" -import logging -try: - from riot_pal import LLShell -except ImportError: - raise ImportError('Cannot find riot_pal, try "pip install riot_pal"') - - -class PhilipIf(LLShell): - """Getters and setters for the memory map.""" - DEVICE_NUM = 0x42A5 - - def get_sys_sn_12(self): - """Unique ID of the device""" - return self.read_bytes(0, 12) - - def get_sys_fw_rev(self): - """Firmware revision""" - return self.read_bytes(12, 4) - - def get_sys_build_time_second(self): - """The seconds in decimal""" - return self.read_bytes(16, 1) - - def get_sys_build_time_minute(self): - """The minutes in decimal""" - return self.read_bytes(17, 1) - - def get_sys_build_time_hour(self): - """The hours in decimal""" - return self.read_bytes(18, 1) - - def get_sys_build_time_day_of_month(self): - """The months in decimal""" - return self.read_bytes(19, 1) - - def get_sys_build_time_day_of_week(self): - """The week in decimal""" - return self.read_bytes(20, 1) - - def get_sys_build_time_month(self): - """The month in decimal""" - return self.read_bytes(21, 1) - - def get_sys_build_time_year(self): - """The last two digits of the year in decimal (20xx)""" - return self.read_bytes(22, 1) - - def get_sys_build_time_res_1(self): - """Reserved bytes""" - return self.read_bytes(23, 1) - - def get_sys_device_num(self): - """A constant number that should always be the same""" - return self.read_bytes(24, 4) - - def set_sys_device_num(self, data=0): - """A constant number that should always be the same""" - return self.write_bytes(24, data, 4) - - def get_sys_cr(self): - """Specific modes for I2C""" - return self.read_bytes(28, 1) - - def set_sys_cr(self, data=0): - """Specific modes for I2C""" - return self.write_bytes(28, data, 1) - - def get_sys_cr_dut_rst(self): - """resets the DUT""" - return self.read_bits(28, 1, 1) - - def set_sys_cr_dut_rst(self, data=0): - """resets the DUT""" - return self.write_bits(28, 1, 1, data) - - def get_sys_res_3(self): - """Reserved bytes""" - return self.read_bytes(29, 3) - - def get_i2c_mode(self): - """Specific modes for I2C""" - return self.read_bytes(32, 1) - - def set_i2c_mode(self, data=0): - """Specific modes for I2C""" - return self.write_bytes(32, data, 1) - - def get_i2c_mode_addr_10_bit(self): - """10 bit address enable""" - return self.read_bits(32, 1, 1) - - def set_i2c_mode_addr_10_bit(self, data=0): - """10 bit address enable""" - return self.write_bits(32, 1, 1, data) - - def get_i2c_mode_general_call(self): - """general call enable""" - return self.read_bits(32, 2, 1) - - def set_i2c_mode_general_call(self, data=0): - """general call enable""" - return self.write_bits(32, 2, 1, data) - - def get_i2c_mode_no_clk_stretch(self): - """disable for clk stretch""" - return self.read_bits(32, 3, 1) - - def set_i2c_mode_no_clk_stretch(self, data=0): - """disable for clk stretch""" - return self.write_bits(32, 3, 1, data) - - def get_i2c_mode_reg_16_bit(self): - """16 bit register access mode""" - return self.read_bits(32, 4, 1) - - def set_i2c_mode_reg_16_bit(self, data=0): - """16 bit register access mode""" - return self.write_bits(32, 4, 1, data) - - def get_i2c_mode_nack_data(self): - """Forces a data nack""" - return self.read_bits(32, 5, 1) - - def set_i2c_mode_nack_data(self, data=0): - """Forces a data nack""" - return self.write_bits(32, 5, 1, data) - - def get_i2c_status(self): - """Specific modes for I2C""" - return self.read_bytes(33, 1) - - def set_i2c_status(self, data=0): - """Specific modes for I2C""" - return self.write_bytes(33, data, 1) - - def get_i2c_status_OVR(self): - """Overrun/Underrun: Request for new byte when not ready""" - return self.read_bits(33, 1, 1) - - def set_i2c_status_OVR(self, data=0): - """Overrun/Underrun: Request for new byte when not ready""" - return self.write_bits(33, 1, 1, data) - - def get_i2c_status_AF(self): - """Acknowledge failure""" - return self.read_bits(33, 2, 1) - - def set_i2c_status_AF(self, data=0): - """Acknowledge failure""" - return self.write_bits(33, 2, 1, data) - - def get_i2c_status_BERR(self): - """Bus error: Non-valid position during a byte transfer""" - return self.read_bits(33, 3, 1) - - def set_i2c_status_BERR(self, data=0): - """Bus error: Non-valid position during a byte transfer""" - return self.write_bits(33, 3, 1, data) - - def get_i2c_status_GENCALL(self): - """General call address recieved""" - return self.read_bits(33, 4, 1) - - def set_i2c_status_GENCALL(self, data=0): - """General call address recieved""" - return self.write_bits(33, 4, 1, data) - - def get_i2c_status_BUSY(self): - """Forces a data nack""" - return self.read_bits(33, 5, 1) - - def set_i2c_status_BUSY(self, data=0): - """Forces a data nack""" - return self.write_bits(33, 5, 1, data) - - def get_i2c_status_RSR(self): - """Repeated start detected""" - return self.read_bits(33, 6, 1) - - def set_i2c_status_RSR(self, data=0): - """Repeated start detected""" - return self.write_bits(33, 6, 1, data) - - def get_i2c_clk_stretch_delay(self): - """delay in us for clock stretch""" - return self.read_bytes(34, 2) - - def set_i2c_clk_stretch_delay(self, data=0): - """delay in us for clock stretch""" - return self.write_bytes(34, data, 2) - - def get_i2c_slave_addr_1(self): - """Primary slave address""" - return self.read_bytes(36, 2) - - def set_i2c_slave_addr_1(self, data=85): - """Primary slave address""" - return self.write_bytes(36, data, 2) - - def get_i2c_slave_addr_2(self): - """Secondary slave address""" - return self.read_bytes(38, 2) - - def set_i2c_slave_addr_2(self, data=64): - """Secondary slave address""" - return self.write_bytes(38, data, 2) - - def get_i2c_r_count(self): - """last read frame byte count""" - return self.read_bytes(40, 1) - - def set_i2c_r_count(self, data=0): - """last read frame byte count""" - return self.write_bytes(40, data, 1) - - def get_i2c_w_count(self): - """last write frame byte count""" - return self.read_bytes(41, 1) - - def set_i2c_w_count(self, data=0): - """last write frame byte count""" - return self.write_bytes(41, data, 1) - - def get_i2c_res_6(self): - """Reserved bytes""" - return self.read_bytes(42, 6) - - def get_spi_mode(self): - """""" - return self.read_bytes(48, 1) - - def set_spi_mode(self, data=0): - """""" - return self.write_bytes(48, data, 1) - - def get_spi_error_code(self): - """""" - return self.read_bytes(49, 4) - - def set_spi_error_code(self, data=0): - """""" - return self.write_bytes(49, data, 4) - - def get_spi_res_11(self): - """Reserved bytes""" - return self.read_bytes(53, 11) - - def get_uart_mode(self): - """Test mode""" - return self.read_bytes(64, 1) - - def set_uart_mode(self, data=0): - """Test mode""" - return self.write_bytes(64, data, 1) - - def get_uart_baud(self): - """Baudrate""" - return self.read_bytes(65, 4) - - def set_uart_baud(self, data=0): - """Baudrate""" - return self.write_bytes(65, data, 4) - - def get_uart_rx_count(self): - """Number of received bytes""" - return self.read_bytes(69, 2) - - def set_uart_rx_count(self, data=0): - """Number of received bytes""" - return self.write_bytes(69, data, 2) - - def get_uart_tx_count(self): - """Number of transmitted bytes""" - return self.read_bytes(71, 2) - - def set_uart_tx_count(self, data=0): - """Number of transmitted bytes""" - return self.write_bytes(71, data, 2) - - def get_uart_ctrl(self): - """UART control register""" - return self.read_bytes(73, 1) - - def set_uart_ctrl(self, data=0): - """UART control register""" - return self.write_bytes(73, data, 1) - - def get_uart_ctrl_stop_bits(self): - """Number of stop bits""" - return self.read_bits(73, 1, 1) - - def set_uart_ctrl_stop_bits(self, data=0): - """Number of stop bits""" - return self.write_bits(73, 1, 1, data) - - def get_uart_ctrl_parity(self): - """Parity""" - return self.read_bits(73, 3, 2) - - def set_uart_ctrl_parity(self, data=0): - """Parity""" - return self.write_bits(73, 3, 2, data) - - def get_uart_ctrl_rts(self): - """RTS pin state""" - return self.read_bits(73, 4, 1) - - def set_uart_ctrl_rts(self, data=0): - """RTS pin state""" - return self.write_bits(73, 4, 1, data) - - def get_uart_status(self): - """UART status register""" - return self.read_bytes(74, 1) - - def set_uart_status(self, data=0): - """UART status register""" - return self.write_bytes(74, data, 1) - - def get_uart_status_cts(self): - """CTS pin state""" - return self.read_bits(74, 1, 1) - - def set_uart_status_cts(self, data=0): - """CTS pin state""" - return self.write_bits(74, 1, 1, data) - - def get_uart_res_5(self): - """Reserved bytes""" - return self.read_bytes(75, 5) - - def get_rtc_second(self): - """The seconds in decimal""" - return self.read_bytes(80, 1) - - def set_rtc_second(self, data=0): - """The seconds in decimal""" - return self.write_bytes(80, data, 1) - - def get_rtc_minute(self): - """The minutes in decimal""" - return self.read_bytes(81, 1) - - def set_rtc_minute(self, data=0): - """The minutes in decimal""" - return self.write_bytes(81, data, 1) - - def get_rtc_hour(self): - """The hours in decimal""" - return self.read_bytes(82, 1) - - def set_rtc_hour(self, data=0): - """The hours in decimal""" - return self.write_bytes(82, data, 1) - - def get_rtc_day_of_month(self): - """The months in decimal""" - return self.read_bytes(83, 1) - - def set_rtc_day_of_month(self, data=0): - """The months in decimal""" - return self.write_bytes(83, data, 1) - - def get_rtc_day_of_week(self): - """The week in decimal""" - return self.read_bytes(84, 1) - - def set_rtc_day_of_week(self, data=0): - """The week in decimal""" - return self.write_bytes(84, data, 1) - - def get_rtc_month(self): - """The month in decimal""" - return self.read_bytes(85, 1) - - def set_rtc_month(self, data=0): - """The month in decimal""" - return self.write_bytes(85, data, 1) - - def get_rtc_year(self): - """The last two digits of the year in decimal (20xx)""" - return self.read_bytes(86, 1) - - def set_rtc_year(self, data=0): - """The last two digits of the year in decimal (20xx)""" - return self.write_bytes(86, data, 1) - - def get_rtc_res_1(self): - """Reserved bytes""" - return self.read_bytes(87, 1) - - def get_adc_0_mode(self): - """""" - return self.read_bytes(88, 1) - - def set_adc_0_mode(self, data=0): - """""" - return self.write_bytes(88, data, 1) - - def get_adc_0_error_code(self): - """""" - return self.read_bytes(89, 2) - - def set_adc_0_error_code(self, data=0): - """""" - return self.write_bytes(89, data, 2) - - def get_adc_0_sample_rate(self): - """""" - return self.read_bytes(91, 1) - - def set_adc_0_sample_rate(self, data=0): - """""" - return self.write_bytes(91, data, 1) - - def get_adc_0_value(self): - """""" - return self.read_bytes(92, 4) - - def set_adc_0_value(self, data=0): - """""" - return self.write_bytes(92, data, 4) - - def get_adc_0_res_8(self): - """Reserved bytes""" - return self.read_bytes(96, 8) - - def get_adc_1_mode(self): - """""" - return self.read_bytes(104, 1) - - def set_adc_1_mode(self, data=0): - """""" - return self.write_bytes(104, data, 1) - - def get_adc_1_error_code(self): - """""" - return self.read_bytes(105, 2) - - def set_adc_1_error_code(self, data=0): - """""" - return self.write_bytes(105, data, 2) - - def get_adc_1_sample_rate(self): - """""" - return self.read_bytes(107, 1) - - def set_adc_1_sample_rate(self, data=0): - """""" - return self.write_bytes(107, data, 1) - - def get_adc_1_value(self): - """""" - return self.read_bytes(108, 4) - - def set_adc_1_value(self, data=0): - """""" - return self.write_bytes(108, data, 4) - - def get_adc_1_res_8(self): - """Reserved bytes""" - return self.read_bytes(112, 8) - - def get_pwm_mode(self): - """""" - return self.read_bytes(120, 1) - - def set_pwm_mode(self, data=0): - """""" - return self.write_bytes(120, data, 1) - - def get_pwm_error_code(self): - """""" - return self.read_bytes(121, 2) - - def set_pwm_error_code(self, data=0): - """""" - return self.write_bytes(121, data, 2) - - def get_pwm_duty(self): - """""" - return self.read_bytes(123, 1) - - def set_pwm_duty(self, data=0): - """""" - return self.write_bytes(123, data, 1) - - def get_pwm_freq(self): - """""" - return self.read_bytes(124, 4) - - def set_pwm_freq(self, data=0): - """""" - return self.write_bytes(124, data, 4) - - def get_pwm_res_8(self): - """Reserved bytes""" - return self.read_bytes(128, 8) - - def get_tmr_mode(self): - """""" - return self.read_bytes(136, 1) - - def set_tmr_mode(self, data=0): - """""" - return self.write_bytes(136, data, 1) - - def get_tmr_error_code(self): - """""" - return self.read_bytes(137, 2) - - def set_tmr_error_code(self, data=0): - """""" - return self.write_bytes(137, data, 2) - - def get_tmr_duty(self): - """""" - return self.read_bytes(139, 1) - - def set_tmr_duty(self, data=0): - """""" - return self.write_bytes(139, data, 1) - - def get_tmr_freq(self): - """""" - return self.read_bytes(140, 4) - - def set_tmr_freq(self, data=0): - """""" - return self.write_bytes(140, data, 4) - - def get_tmr_hi_us(self): - """""" - return self.read_bytes(144, 4) - - def set_tmr_hi_us(self, data=0): - """""" - return self.write_bytes(144, data, 4) - - def get_tmr_lo_us(self): - """""" - return self.read_bytes(148, 4) - - def set_tmr_lo_us(self, data=0): - """""" - return self.write_bytes(148, data, 4) - - def get_user_reg_64(self): - """Writeable registers for user testing""" - return self.read_bytes(152, 64) - - def set_user_reg_64(self, data=0): - """Writeable registers for user testing""" - return self.write_bytes(152, data, 64) - - def get_res_40(self): - """Reserved bytes""" - return self.read_bytes(216, 40) - - def get_command_list(self): - """A list of all possible commands""" - cmds = list() - cmds.append(self.get_sys_sn_12) - cmds.append(self.get_sys_fw_rev) - cmds.append(self.get_sys_build_time_second) - cmds.append(self.get_sys_build_time_minute) - cmds.append(self.get_sys_build_time_hour) - cmds.append(self.get_sys_build_time_day_of_month) - cmds.append(self.get_sys_build_time_day_of_week) - cmds.append(self.get_sys_build_time_month) - cmds.append(self.get_sys_build_time_year) - cmds.append(self.get_sys_build_time_res_1) - cmds.append(self.get_sys_device_num) - cmds.append(self.set_sys_device_num) - cmds.append(self.get_sys_cr) - cmds.append(self.set_sys_cr) - cmds.append(self.get_sys_cr_dut_rst) - cmds.append(self.set_sys_cr_dut_rst) - cmds.append(self.get_sys_res_3) - cmds.append(self.get_i2c_mode) - cmds.append(self.set_i2c_mode) - cmds.append(self.get_i2c_mode_addr_10_bit) - cmds.append(self.set_i2c_mode_addr_10_bit) - cmds.append(self.get_i2c_mode_general_call) - cmds.append(self.set_i2c_mode_general_call) - cmds.append(self.get_i2c_mode_no_clk_stretch) - cmds.append(self.set_i2c_mode_no_clk_stretch) - cmds.append(self.get_i2c_mode_reg_16_bit) - cmds.append(self.set_i2c_mode_reg_16_bit) - cmds.append(self.get_i2c_mode_nack_data) - cmds.append(self.set_i2c_mode_nack_data) - cmds.append(self.get_i2c_status) - cmds.append(self.set_i2c_status) - cmds.append(self.get_i2c_status_OVR) - cmds.append(self.set_i2c_status_OVR) - cmds.append(self.get_i2c_status_AF) - cmds.append(self.set_i2c_status_AF) - cmds.append(self.get_i2c_status_BERR) - cmds.append(self.set_i2c_status_BERR) - cmds.append(self.get_i2c_status_GENCALL) - cmds.append(self.set_i2c_status_GENCALL) - cmds.append(self.get_i2c_status_BUSY) - cmds.append(self.set_i2c_status_BUSY) - cmds.append(self.get_i2c_status_RSR) - cmds.append(self.set_i2c_status_RSR) - cmds.append(self.get_i2c_clk_stretch_delay) - cmds.append(self.set_i2c_clk_stretch_delay) - cmds.append(self.get_i2c_slave_addr_1) - cmds.append(self.set_i2c_slave_addr_1) - cmds.append(self.get_i2c_slave_addr_2) - cmds.append(self.set_i2c_slave_addr_2) - cmds.append(self.get_i2c_r_count) - cmds.append(self.set_i2c_r_count) - cmds.append(self.get_i2c_w_count) - cmds.append(self.set_i2c_w_count) - cmds.append(self.get_i2c_res_6) - cmds.append(self.get_spi_mode) - cmds.append(self.set_spi_mode) - cmds.append(self.get_spi_error_code) - cmds.append(self.set_spi_error_code) - cmds.append(self.get_spi_res_11) - cmds.append(self.get_uart_mode) - cmds.append(self.set_uart_mode) - cmds.append(self.get_uart_baud) - cmds.append(self.set_uart_baud) - cmds.append(self.get_uart_rx_count) - cmds.append(self.set_uart_rx_count) - cmds.append(self.get_uart_tx_count) - cmds.append(self.set_uart_tx_count) - cmds.append(self.get_uart_ctrl) - cmds.append(self.set_uart_ctrl) - cmds.append(self.get_uart_ctrl_stop_bits) - cmds.append(self.set_uart_ctrl_stop_bits) - cmds.append(self.get_uart_ctrl_parity) - cmds.append(self.set_uart_ctrl_parity) - cmds.append(self.get_uart_ctrl_rts) - cmds.append(self.set_uart_ctrl_rts) - cmds.append(self.get_uart_status) - cmds.append(self.set_uart_status) - cmds.append(self.get_uart_status_cts) - cmds.append(self.set_uart_status_cts) - cmds.append(self.get_uart_res_5) - cmds.append(self.get_rtc_second) - cmds.append(self.set_rtc_second) - cmds.append(self.get_rtc_minute) - cmds.append(self.set_rtc_minute) - cmds.append(self.get_rtc_hour) - cmds.append(self.set_rtc_hour) - cmds.append(self.get_rtc_day_of_month) - cmds.append(self.set_rtc_day_of_month) - cmds.append(self.get_rtc_day_of_week) - cmds.append(self.set_rtc_day_of_week) - cmds.append(self.get_rtc_month) - cmds.append(self.set_rtc_month) - cmds.append(self.get_rtc_year) - cmds.append(self.set_rtc_year) - cmds.append(self.get_rtc_res_1) - cmds.append(self.get_adc_0_mode) - cmds.append(self.set_adc_0_mode) - cmds.append(self.get_adc_0_error_code) - cmds.append(self.set_adc_0_error_code) - cmds.append(self.get_adc_0_sample_rate) - cmds.append(self.set_adc_0_sample_rate) - cmds.append(self.get_adc_0_value) - cmds.append(self.set_adc_0_value) - cmds.append(self.get_adc_0_res_8) - cmds.append(self.get_adc_1_mode) - cmds.append(self.set_adc_1_mode) - cmds.append(self.get_adc_1_error_code) - cmds.append(self.set_adc_1_error_code) - cmds.append(self.get_adc_1_sample_rate) - cmds.append(self.set_adc_1_sample_rate) - cmds.append(self.get_adc_1_value) - cmds.append(self.set_adc_1_value) - cmds.append(self.get_adc_1_res_8) - cmds.append(self.get_pwm_mode) - cmds.append(self.set_pwm_mode) - cmds.append(self.get_pwm_error_code) - cmds.append(self.set_pwm_error_code) - cmds.append(self.get_pwm_duty) - cmds.append(self.set_pwm_duty) - cmds.append(self.get_pwm_freq) - cmds.append(self.set_pwm_freq) - cmds.append(self.get_pwm_res_8) - cmds.append(self.get_tmr_mode) - cmds.append(self.set_tmr_mode) - cmds.append(self.get_tmr_error_code) - cmds.append(self.set_tmr_error_code) - cmds.append(self.get_tmr_duty) - cmds.append(self.set_tmr_duty) - cmds.append(self.get_tmr_freq) - cmds.append(self.set_tmr_freq) - cmds.append(self.get_tmr_hi_us) - cmds.append(self.set_tmr_hi_us) - cmds.append(self.get_tmr_lo_us) - cmds.append(self.set_tmr_lo_us) - cmds.append(self.get_user_reg_64) - cmds.append(self.set_user_reg_64) - cmds.append(self.get_res_40) - return cmds - - -def main(): - """Tests all functions with default values.""" - logging.getLogger().setLevel(logging.DEBUG) - - if1 = PhilipIf() - if2 = PhilipIf.copy_driver(if1) - if1.execute_changes() - if2.execute_changes() - if1.reset_mcu() - cmds = if1.get_command_list() - logging.debug("==========================================================") - for cmd in cmds: - cmd() - logging.debug("------------------------------------------------------") - logging.debug("==========================================================") - if1.reset_mcu() - - -if __name__ == "__main__": - main()