diff --git a/contrib/genio/bin/boot_partition.py b/contrib/genio/bin/boot_partition.py index 88f73bf0a..5f0e20296 100755 --- a/contrib/genio/bin/boot_partition.py +++ b/contrib/genio/bin/boot_partition.py @@ -8,16 +8,18 @@ def runcmd(command): - ret = subprocess.run(command, - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - encoding="utf-8", - timeout=1) + ret = subprocess.run( + command, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + timeout=1, + ) return ret -class TestPartedBootDevice(): +class TestPartedBootDevice: def __init__(self): self.path = None @@ -27,69 +29,31 @@ def __init__(self): "logical-sector-size": 4096, "physical-sector-size": 4096, "partitions": [ - { - "number": 1, - "name": "bootloaders" - }, { - "number": 2, - "name": "bootloaders_b" - }, { - "number": 3, - "name": "firmware" - }, { - "number": 4, - "name": "firmware_b" - }, { - "number": 5, - "name": "dramk" - }, { - "number": 6, - "name": "misc" - }, { - "number": 7, - "name": "bootassets" - }, { - "number": 8, - "name": "ubuntu-boot" - }, { - "number": 9, - "name": "writable" - } - ] + {"number": 1, "name": "bootloaders"}, + {"number": 2, "name": "bootloaders_b"}, + {"number": 3, "name": "firmware"}, + {"number": 4, "name": "firmware_b"}, + {"number": 5, "name": "dramk"}, + {"number": 6, "name": "misc"}, + {"number": 7, "name": "bootassets"}, + {"number": 8, "name": "ubuntu-boot"}, + {"number": 9, "name": "writable"}, + ], } self.expected_result_EMMC = { "logical-sector-size": 512, "physical-sector-size": 512, "partitions": [ - { - "number": 1, - "name": "bootloaders" - }, { - "number": 2, - "name": "bootloaders_b" - }, { - "number": 3, - "name": "firmware" - }, { - "number": 4, - "name": "firmware_b" - }, { - "number": 5, - "name": "dramk" - }, { - "number": 6, - "name": "misc" - }, { - "number": 7, - "name": "bootassets" - }, { - "number": 8, - "name": "ubuntu-boot" - }, { - "number": 9, - "name": "writable" - } - ] + {"number": 1, "name": "bootloaders"}, + {"number": 2, "name": "bootloaders_b"}, + {"number": 3, "name": "firmware"}, + {"number": 4, "name": "firmware_b"}, + {"number": 5, "name": "dramk"}, + {"number": 6, "name": "misc"}, + {"number": 7, "name": "bootassets"}, + {"number": 8, "name": "ubuntu-boot"}, + {"number": 9, "name": "writable"}, + ], } def check_is_block_device(self): @@ -97,8 +61,9 @@ def check_is_block_device(self): if pathlib.Path(self.path).is_block_device(): print("PASS: {} is a block device!".format(self.path)) else: - raise SystemExit("FAIL: {} is not a block device!" - .format(self.path)) + raise SystemExit( + "FAIL: {} is not a block device!".format(self.path) + ) def check_disk(self): print("\nChecking Parted...") @@ -119,10 +84,15 @@ def get_disk_information(self): def check_sector_size(self): print("\nChecking Logical Sector Size...") try: - if self.actual_result["logical-sector-size"] == \ - self.expected_result["logical-sector-size"]: - print("logical sector size: {}" - .format(self.actual_result["logical-sector-size"])) + if ( + self.actual_result["logical-sector-size"] + == self.expected_result["logical-sector-size"] + ): + print( + "logical sector size: {}".format( + self.actual_result["logical-sector-size"] + ) + ) print("PASS: Logical sector size is correct!") else: raise SystemExit("FAIL: Logical sector size is incorrect!") @@ -130,10 +100,15 @@ def check_sector_size(self): raise SystemExit("ERROR: logical-sector-size is not found") print("\nChecking Physical Sector Size...") try: - if self.actual_result["physical-sector-size"] == \ - self.expected_result["physical-sector-size"]: - print("physical sector size: {}" - .format(self.actual_result["physical-sector-size"])) + if ( + self.actual_result["physical-sector-size"] + == self.expected_result["physical-sector-size"] + ): + print( + "physical sector size: {}".format( + self.actual_result["physical-sector-size"] + ) + ) print("PASS: Physical sector size is correct!") else: raise SystemExit("FAIL: Physical sector size is incorrect!") @@ -147,8 +122,9 @@ def check_partitions(self): expected_partitions = self.expected_result["partitions"] if len(actual_partitions) != len(expected_partitions): raise SystemExit("ERROR: Partitions count is incorrect!") - for actual_partition, expected_partition in \ - zip(actual_partitions, expected_partitions): + for actual_partition, expected_partition in zip( + actual_partitions, expected_partitions + ): if actual_partition["number"] != expected_partition["number"]: raise SystemExit("ERROR: Partition number is incorrect!") if actual_partition["name"] != expected_partition["name"]: @@ -171,17 +147,22 @@ def check_device(self, exit_when_check_fail): raise SystemExit("ERROR: Cannot find sdc or mmcblk0 in dev") def main(self): - parser = ArgumentParser(description="Check if the disk information\ - is correct") - parser.add_argument('--path', - help='the device path for checking') - parser.add_argument("--check_device_name", - help="To check the device name", - action="store_true") - parser.add_argument("--exit_when_check_fail", - help="Exit with error code when the device check \ + parser = ArgumentParser( + description="Check if the disk information\ + is correct" + ) + parser.add_argument("--path", help="the device path for checking") + parser.add_argument( + "--check_device_name", + help="To check the device name", + action="store_true", + ) + parser.add_argument( + "--exit_when_check_fail", + help="Exit with error code when the device check \ failed", - action="store_true") + action="store_true", + ) args = parser.parse_args() if args.check_device_name: self.check_device(args.exit_when_check_fail) @@ -192,5 +173,5 @@ def main(self): self.check_disk() -if __name__ == '__main__': +if __name__ == "__main__": TestPartedBootDevice().main() diff --git a/contrib/genio/bin/brightness_test.py b/contrib/genio/bin/brightness_test.py index 90d25833f..86a0dae8f 100755 --- a/contrib/genio/bin/brightness_test.py +++ b/contrib/genio/bin/brightness_test.py @@ -42,12 +42,12 @@ class Brightness(object): - def __init__(self, path='/sys/class/backlight'): + def __init__(self, path="/sys/class/backlight"): self.sysfs_path = path self.interfaces = self._get_interfaces_from_path() def read_value(self, path): - '''Read the value from a file''' + """Read the value from a file""" # See if the source is a file or a file object # and act accordingly file = path @@ -55,25 +55,25 @@ def read_value(self, path): lines_list = [] else: # It's a file - if not hasattr(file, 'write'): - myfile = open(file, 'r') + if not hasattr(file, "write"): + myfile = open(file, "r") lines_list = myfile.readlines() myfile.close() # It's a file object else: lines_list = file.readlines() - return int(''.join(lines_list).strip()) + return int("".join(lines_list).strip()) def write_value(self, value, path, test=None): - '''Write a value to a file''' - value = '%d' % value + """Write a value to a file""" + value = "%d" % value # It's a file - if not hasattr(path, 'write'): + if not hasattr(path, "write"): if test: - path = open(path, 'a') + path = open(path, "a") else: - path = open(path, 'w') + path = open(path, "w") path.write(value) path.close() # It's a file object @@ -81,39 +81,42 @@ def write_value(self, value, path, test=None): path.write(value) def get_max_brightness(self, path): - full_path = os.path.join(path, 'max_brightness') + full_path = os.path.join(path, "max_brightness") return self.read_value(full_path) def get_actual_brightness(self, path): - full_path = os.path.join(path, 'actual_brightness') + full_path = os.path.join(path, "actual_brightness") return self.read_value(full_path) def get_last_set_brightness(self, path): - full_path = os.path.join(path, 'brightness') + full_path = os.path.join(path, "brightness") return self.read_value(full_path) def _get_interfaces_from_path(self): - '''check all the files in a directory looking for quirks''' + """check all the files in a directory looking for quirks""" interfaces = [] if os.path.isdir(self.sysfs_path): - for d in glob(os.path.join(self.sysfs_path, '*')): + for d in glob(os.path.join(self.sysfs_path, "*")): if os.path.isdir(d): interfaces.append(d) return interfaces def was_brightness_applied(self, interface): - '''See if the selected brightness was applied + """See if the selected brightness was applied Note: this doesn't guarantee that screen brightness changed. - ''' + """ if ( - abs(self.get_actual_brightness(interface) - - self.get_last_set_brightness(interface)) > 1 + abs( + self.get_actual_brightness(interface) + - self.get_last_set_brightness(interface) + ) + > 1 ): return 1 else: @@ -126,25 +129,28 @@ def brightness_test(self, target_interface): exit_status = 0 find_target_display = False - print('Available Interfaces: {}'.format(self.interfaces)) + print("Available Interfaces: {}".format(self.interfaces)) for interface in self.interfaces: if target_interface in interface: find_target_display = True # Get the current brightness which we can restore later original_brightness = self.get_actual_brightness(interface) - print('Current brightness: {}'.format(original_brightness)) + print("Current brightness: {}".format(original_brightness)) # Get the maximum value for brightness max_brightness = self.get_max_brightness(interface) - print('Maximum brightness: {}\n'.format(max_brightness)) + print("Maximum brightness: {}\n".format(max_brightness)) for m in [0, 0.25, 0.5, 0.75, 1]: # Set the brightness to half the max value current_brightness = math.ceil(max_brightness * m) - print('Set the brightness as {}'.format(current_brightness)) + print( + "Set the brightness as {}".format(current_brightness) + ) self.write_value( current_brightness, - os.path.join(interface, 'brightness')) + os.path.join(interface, "brightness"), + ) # Check that "actual_brightness" reports the same value we # set "brightness" to @@ -155,11 +161,11 @@ def brightness_test(self, target_interface): # Set the brightness back to its original value self.write_value( - original_brightness, - os.path.join(interface, 'brightness')) + original_brightness, os.path.join(interface, "brightness") + ) print( - 'Set brightness back to original value:' - '{}'.format(original_brightness) + "Set brightness back to original value:" + "{}".format(original_brightness) ) # Close the loop since the target display has been tested break @@ -175,14 +181,16 @@ def brightness_test(self, target_interface): def main(): parser = ArgumentParser(formatter_class=RawTextHelpFormatter) parser.add_argument( - "-p", "--platform", + "-p", + "--platform", help="Genio device platform type.", - choices=["G1200-evk", "G700", "G350"] + choices=["G1200-evk", "G700", "G350"], ) parser.add_argument( - "-d", "--display", + "-d", + "--display", choices=["dsi", "edp", "lvds"], - help="The type of built-in display" + help="The type of built-in display", ) args = parser.parse_args() @@ -204,23 +212,23 @@ def main(): # Make sure that we have root privileges if os.geteuid() != 0: - print('Error: please run this program as root', - file=sys.stderr) + print("Error: please run this program as root", file=sys.stderr) exit(1) print("Test the brightness of '{}' display".format(args.display)) - target_interface = '' + target_interface = "" try: target_interface = tables[args.platform][args.display] print("Interface: {}\n".format(target_interface)) except KeyError: raise SystemExit( - f"ERROR: no suitable interface of {args.display} display") + f"ERROR: no suitable interface of {args.display} display" + ) brightness = Brightness() brightness.brightness_test(target_interface) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/contrib/genio/bin/cpu_idle.py b/contrib/genio/bin/cpu_idle.py index 442be111e..849262cff 100755 --- a/contrib/genio/bin/cpu_idle.py +++ b/contrib/genio/bin/cpu_idle.py @@ -4,13 +4,13 @@ import argparse -GENERAL_PATH = 'cpu%d/cpuidle/state%d/%s' +GENERAL_PATH = "cpu%d/cpuidle/state%d/%s" def read_attr(attr): - path = os.path.join('/sys/devices/system/cpu', attr) + path = os.path.join("/sys/devices/system/cpu", attr) if not os.path.exists(path): - return '' + return "" with open(path) as f: tmp = f.read().strip() return tmp @@ -33,7 +33,7 @@ def read_idle_attr_num(cpu, state, attr): def error_handler(node_type, node_path, expect, reality): - if node_type == 'name' or node_type == 'disable': + if node_type == "name" or node_type == "disable": print( ( f"Failed: " @@ -41,7 +41,7 @@ def error_handler(node_type, node_path, expect, reality): f"should be '{expect}' but got '{reality}'" ) ) - if node_type == 'usage': + if node_type == "usage": print( ( f"Failed: " @@ -52,25 +52,29 @@ def error_handler(node_type, node_path, expect, reality): def output_checker(cpu, state, name, disable, usage): - ''' - @param:name, type: tuple. (reality value, expected value) - @param:disable, type: tuple. (reality value, expected value) - @param:usage - ''' + """ + @param:name, type: tuple. (reality value, expected value) + @param:disable, type: tuple. (reality value, expected value) + @param:usage + """ fail = 0 - print('CPU node: cpu/{}/cpuidle/state{}'.format(cpu, state)) - print('Got name: {}, disable: {}, usage: {}'.format(name[0], disable[0], usage)) + print("CPU node: cpu/{}/cpuidle/state{}".format(cpu, state)) + print( + "Got name: {}, disable: {}, usage: {}".format( + name[0], disable[0], usage + ) + ) if name[0] != name[1]: - node_path = GENERAL_PATH.format(cpu, state, 'name') - error_handler('name', node_path, name[0], name[1]) + node_path = GENERAL_PATH.format(cpu, state, "name") + error_handler("name", node_path, name[0], name[1]) fail = 1 if disable[0] != disable[1]: - node_path = GENERAL_PATH.format(cpu, state, 'disable') - error_handler('disable', node_path, disable[0], disable[1]) + node_path = GENERAL_PATH.format(cpu, state, "disable") + error_handler("disable", node_path, disable[0], disable[1]) fail = 1 if usage <= 0: - node_path = GENERAL_PATH.format(cpu, state, 'usage') - error_handler('usage', node_path) + node_path = GENERAL_PATH.format(cpu, state, "usage") + error_handler("usage", node_path) fail = 1 if fail: exit(1) @@ -79,186 +83,185 @@ def output_checker(cpu, state, name, disable, usage): def test_wfi(): cpu = 0 state = 0 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( - cpu, - state, - name=(name, 'WFI'), - disable=(disable, '0'), - usage=usage + cpu, state, name=(name, "WFI"), disable=(disable, "0"), usage=usage ) def test_mcdi_cpu(soc): - if soc != 'mt8365': + if soc != "mt8365": print(f"Isn't supported for '{soc}'") return cpu = 0 state = 1 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( cpu, state, - name=(name, 'mcdi-cpu'), - disable=(disable, '0'), - usage=usage + name=(name, "mcdi-cpu"), + disable=(disable, "0"), + usage=usage, ) def test_mcdi_cluster(soc): - if soc != 'mt8365': + if soc != "mt8365": print(f"Isn't supported for '{soc}'") return cpu = 0 state = 2 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( cpu, state, - name=(name, 'mcdi-cluster'), - disable=(disable, '0'), - usage=usage + name=(name, "mcdi-cluster"), + disable=(disable, "0"), + usage=usage, ) def test_dpidle(soc): - if soc != 'mt8365': + if soc != "mt8365": print(f"Isn't supported for '{soc}'") return cpu = 0 state = 3 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( - cpu, - state, - name=(name, 'dpidle'), - disable=(disable, '0'), - usage=usage + cpu, state, name=(name, "dpidle"), disable=(disable, "0"), usage=usage ) def test_clusteroff_l(soc): - if soc == 'mt8365': + if soc == "mt8365": print(f"Isn't supported for '{soc}'") return cpu = 0 state = 2 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( cpu, state, - name=(name, 'clusteroff-l' if soc == 'mt8390' else 'clusteroff_l'), - disable=(disable, '0'), - usage=usage + name=(name, "clusteroff-l" if soc == "mt8390" else "clusteroff_l"), + disable=(disable, "0"), + usage=usage, ) def test_clusteroff_b(soc): - if soc == 'mt8365': + if soc == "mt8365": print(f"Isn't supported for '{soc}'") return - cpu = 6 if soc == 'mt8390' else 4 + cpu = 6 if soc == "mt8390" else 4 state = 2 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( cpu, state, - name=(name, 'clusteroff-b' if soc == 'mt8390' else 'clusteroff_b'), - disable=(disable, '0'), - usage=usage + name=(name, "clusteroff-b" if soc == "mt8390" else "clusteroff_b"), + disable=(disable, "0"), + usage=usage, ) def test_cpuoff_l(soc): - if soc == 'mt8365': + if soc == "mt8365": print(f"Isn't supported for '{soc}'") return cpu = 0 state = 1 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( cpu, state, - name=(name, 'cpuoff-l' if soc == 'mt8390' else 'cpuoff_l'), - disable=(disable, '0'), - usage=usage + name=(name, "cpuoff-l" if soc == "mt8390" else "cpuoff_l"), + disable=(disable, "0"), + usage=usage, ) def test_cpuoff_b(soc): - if soc == 'mt8365': + if soc == "mt8365": print(f"Isn't supported for '{soc}'") return - cpu = 6 if soc == 'mt8390' else 4 + cpu = 6 if soc == "mt8390" else 4 state = 1 - name = read_idle_attr(cpu, state, 'name') - disable = read_idle_attr(cpu, state, 'disable') - usage = read_idle_attr_num(cpu, state, 'usage') + name = read_idle_attr(cpu, state, "name") + disable = read_idle_attr(cpu, state, "disable") + usage = read_idle_attr_num(cpu, state, "usage") output_checker( cpu, state, - name=(name, 'cpuoff-b' if soc == 'mt8390' else 'cpuoff_b'), - disable=(disable, '0'), - usage=usage + name=(name, "cpuoff-b" if soc == "mt8390" else "cpuoff_b"), + disable=(disable, "0"), + usage=usage, ) def main(): parser = argparse.ArgumentParser() parser.add_argument( - 'soc', - help='SoC type. e.g mt8395', - choices=['mt8395', 'mt8390', 'mt8365'] + "soc", + help="SoC type. e.g mt8395", + choices=["mt8395", "mt8390", "mt8365"], ) parser.add_argument( - '-c', '--case', - help='The available cases of CPU Idle', + "-c", + "--case", + help="The available cases of CPU Idle", choices=[ - 'wfi', 'mcdi-cpu', 'mcdi-cluster', 'dpidle', 'clusteroff-l', - 'clusteroff-b', 'cpuoff-l', 'cpuoff-b' + "wfi", + "mcdi-cpu", + "mcdi-cluster", + "dpidle", + "clusteroff-l", + "clusteroff-b", + "cpuoff-l", + "cpuoff-b", ], type=str, - required=True + required=True, ) args = parser.parse_args() - if args.case == 'wfi': + if args.case == "wfi": test_wfi() - if args.case == 'mcdi-cpu': + if args.case == "mcdi-cpu": test_mcdi_cpu(args.soc) - if args.case == 'mcdi-cluster': + if args.case == "mcdi-cluster": test_mcdi_cluster(args.soc) - if args.case == 'dpidle': + if args.case == "dpidle": test_dpidle(args.soc) - if args.case == 'clusteroff-l': + if args.case == "clusteroff-l": test_clusteroff_l(args.soc) - if args.case == 'clusteroff-b': + if args.case == "clusteroff-b": test_clusteroff_b(args.soc) - if args.case == 'cpuoff-l': + if args.case == "cpuoff-l": test_cpuoff_l(args.soc) - if args.case == 'cpuoff-b': + if args.case == "cpuoff-b": test_cpuoff_b(args.soc) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/contrib/genio/bin/dvfs_gpu_check_governors.py b/contrib/genio/bin/dvfs_gpu_check_governors.py index c8c254013..d8950bec5 100755 --- a/contrib/genio/bin/dvfs_gpu_check_governors.py +++ b/contrib/genio/bin/dvfs_gpu_check_governors.py @@ -20,9 +20,7 @@ def test_sysfs_attrs_read(soc): for node in f.read().strip().split(): if node not in GOVERNORS: fail = 1 - print( - f"Failed: found governor '{node}' out of expectation" - ) + print(f"Failed: found governor '{node}' out of expectation") return fail diff --git a/contrib/genio/bin/gpio_loopback_test.py b/contrib/genio/bin/gpio_loopback_test.py index a2abcf9a3..607360d3d 100755 --- a/contrib/genio/bin/gpio_loopback_test.py +++ b/contrib/genio/bin/gpio_loopback_test.py @@ -4,7 +4,7 @@ from argparse import ArgumentParser, RawTextHelpFormatter -class GPIOSysFsController(): +class GPIOSysFsController: TEST_STATES = (0, 1) ROOT_PATH = "/sys/class/gpio" @@ -13,32 +13,31 @@ def __init__(self): pass def get_gpio_base_number(self): - """ Get the base number of GPIO chip - """ + """Get the base number of GPIO chip""" print("Get GPIO Chips info") with open("/sys/kernel/debug/gpio", "r") as fp: value = fp.read().strip() print(value) - gpiochips = [i for i in value.split('\n') if 'gpiochip' in i] + gpiochips = [i for i in value.split("\n") if "gpiochip" in i] gpiochip_base_number_dict = {} for gc in gpiochips: - gc_splits = gc.split(' ') - gpiochip = gc_splits[0].replace(':', '') - base_number = gc_splits[2].split('-')[0] + gc_splits = gc.split(" ") + gpiochip = gc_splits[0].replace(":", "") + base_number = gc_splits[2].split("-")[0] gpiochip_base_number_dict.update({gpiochip: base_number}) - print('\n\nGPIO chip base number mapping:') + print("\n\nGPIO chip base number mapping:") print(gpiochip_base_number_dict) return gpiochip_base_number_dict def run_test( - self, - output_gpio_chip_number, - input_gpio_chip_number, - physical_output_port, - physical_input_port, - gpio_output_pin, - gpio_input_pin + self, + output_gpio_chip_number, + input_gpio_chip_number, + physical_output_port, + physical_input_port, + gpio_output_pin, + gpio_input_pin, ): """Launch GPIO test @@ -65,21 +64,35 @@ def run_test( """ base_number_mapping = self.get_gpio_base_number() output_base_number = int( - base_number_mapping['gpiochip{}'.format(output_gpio_chip_number)]) + base_number_mapping["gpiochip{}".format(output_gpio_chip_number)] + ) input_base_number = int( - base_number_mapping['gpiochip{}'.format(input_gpio_chip_number)]) + base_number_mapping["gpiochip{}".format(input_gpio_chip_number)] + ) output_pin_number = output_base_number + int(gpio_output_pin) input_pin_number = input_base_number + int(gpio_input_pin) print("\nOutput Base Number: {}".format(output_base_number)) print("Input Base Number: {}".format(input_base_number)) - print("Physical output port: {}, GPIO number: {}".format( - physical_output_port, gpio_output_pin)) - print("Physical input port: {}, GPIO number {}".format( - physical_input_port, gpio_input_pin)) - print("Output Pin Number: {} + Base Number = {}".format( - gpio_output_pin, output_pin_number)) - print("Input Pin Number: {} + Base Number = {}".format( - gpio_input_pin, input_pin_number)) + print( + "Physical output port: {}, GPIO number: {}".format( + physical_output_port, gpio_output_pin + ) + ) + print( + "Physical input port: {}, GPIO number {}".format( + physical_input_port, gpio_input_pin + ) + ) + print( + "Output Pin Number: {} + Base Number = {}".format( + gpio_output_pin, output_pin_number + ) + ) + print( + "Input Pin Number: {} + Base Number = {}".format( + gpio_input_pin, input_pin_number + ) + ) print("\n# Start GPIO loopback test") if not self.loopback_test(output_pin_number, input_pin_number): raise SystemExit("Failed: GPIO loopback test failed") @@ -126,8 +139,7 @@ def set_direction(self, port, value): """ print("# Set GPIO {} direction to {}".format(port, value)) with open( - "{}/gpio{}/direction".format(self.ROOT_PATH, port), - "w" + "{}/gpio{}/direction".format(self.ROOT_PATH, port), "w" ) as fp: fp.write("{}\n".format(value)) @@ -154,8 +166,10 @@ def configure_gpio(self, port, direction): self.set_direction(port, direction) except Exception as err: raise IOError( - "{} \nError: Failed to configure GPIO {} to {}".format - (err, port, direction)) + "{} \nError: Failed to configure GPIO {} to {}".format( + err, port, direction + ) + ) def loopback_test(self, out_port, in_port): """Launch GPIO loopback test @@ -174,8 +188,11 @@ def loopback_test(self, out_port, in_port): for state in self.TEST_STATES: print("Try to send and receive {}".format(state)) value = self.read_gpio(in_port) - print("The initial input GPIO {}'s value is {}".format( - in_port, value)) + print( + "The initial input GPIO {}'s value is {}".format( + in_port, value + ) + ) self.set_gpio(out_port, state) time.sleep(1) @@ -186,8 +203,10 @@ def loopback_test(self, out_port, in_port): result = False else: str_match = "match" - print("# Digital state {}. expected: {} real: {}\n".format( - str_match, state, real_state) + print( + "# Digital state {}. expected: {} real: {}\n".format( + str_match, state, real_state + ) ) return result @@ -195,42 +214,48 @@ def loopback_test(self, out_port, in_port): def main(): parser = ArgumentParser(formatter_class=RawTextHelpFormatter) parser.add_argument( - "-oc", "--output_gpio_chip_number", + "-oc", + "--output_gpio_chip_number", help="Provide the target gpio chip number for output.", - default=0 + default=0, ) parser.add_argument( - "-ic", "--input_gpio_chip_number", + "-ic", + "--input_gpio_chip_number", help="Provide the target gpio chip number for input.", - default=0 + default=0, ) parser.add_argument( - "-po", "--physical_output_port", + "-po", + "--physical_output_port", help=( "Provide the physical output port number/name." " It's used to provide a human readable content only" - ) + ), ) parser.add_argument( - "-pi", "--physical_input_port", + "-pi", + "--physical_input_port", help=( "Provide the physical input port number/name." " It's used to provide a human readable content only" - ) + ), ) parser.add_argument( - "-go", "--gpio_output_pin", + "-go", + "--gpio_output_pin", help=( "Provide the output gpio pin number. You can get this information" " from Schematic or User Guide of the DUT" - ) + ), ) parser.add_argument( - "-gi", "--gpio_input_pin", + "-gi", + "--gpio_input_pin", help=( "Provide the output gpio pin number. You can get this information" " from Schematic or User Guide of the DUT" - ) + ), ) args = parser.parse_args() @@ -241,7 +266,7 @@ def main(): args.physical_output_port, args.physical_input_port, args.gpio_output_pin, - args.gpio_input_pin + args.gpio_input_pin, ) diff --git a/contrib/genio/bin/pmic_regulator.py b/contrib/genio/bin/pmic_regulator.py index 81f9b5b64..cc0878717 100755 --- a/contrib/genio/bin/pmic_regulator.py +++ b/contrib/genio/bin/pmic_regulator.py @@ -6,25 +6,90 @@ MAIN_REGULATORS = ( - 'vs1', 'vgpu11', 'vmodem', 'vpu', 'vcore', 'vs2', 'vpa', 'vproc2', - 'vproc1', 'vgpu11_sshub', 'vaud18', 'vsim1', 'vibr', 'vrf12', 'vusb', - 'vsram_proc2', 'vio18', 'vcamio', 'vcn18', 'vfe28', 'vcn13', - 'vcn33_1_bt', 'vcn33_1_wifi', 'vaux18', 'vsram_others', 'vefuse', 'vxo22', - 'vrfck', 'vbif28', 'vio28', 'vemc', 'vcn33_2_bt', 'vcn33_2_wifi', 'va12', - 'va09', 'vrf18', 'vsram_md', 'vufs', 'vm18', 'vbbck', 'vsram_proc1', - 'vsim2', 'vsram_others_sshub') + "vs1", + "vgpu11", + "vmodem", + "vpu", + "vcore", + "vs2", + "vpa", + "vproc2", + "vproc1", + "vgpu11_sshub", + "vaud18", + "vsim1", + "vibr", + "vrf12", + "vusb", + "vsram_proc2", + "vio18", + "vcamio", + "vcn18", + "vfe28", + "vcn13", + "vcn33_1_bt", + "vcn33_1_wifi", + "vaux18", + "vsram_others", + "vefuse", + "vxo22", + "vrfck", + "vbif28", + "vio28", + "vemc", + "vcn33_2_bt", + "vcn33_2_wifi", + "va12", + "va09", + "vrf18", + "vsram_md", + "vufs", + "vm18", + "vbbck", + "vsram_proc1", + "vsim2", + "vsram_others_sshub", +) mt8365_MAIN_REGULATORS = ( - 'vproc', 'vcore', 'vmodem', 'vs1', 'vpa', 'vfe28', 'vxo22', 'vrf18', - 'vrf12', 'vefuse', 'vcn33-bt', 'vcn33-wifi', 'vcn28', 'vcn18', 'vcama', - 'vcamd', 'vcamio', 'vldo28', 'vsram-others', 'vsram-proc', 'vaux18', - 'vaud28', 'vio28', 'vio18', 'vdram', 'vmc', 'vmch', 'vemc', 'vsim1', - 'vsim2', 'vibr', 'vusb33') + "vproc", + "vcore", + "vmodem", + "vs1", + "vpa", + "vfe28", + "vxo22", + "vrf18", + "vrf12", + "vefuse", + "vcn33-bt", + "vcn33-wifi", + "vcn28", + "vcn18", + "vcama", + "vcamd", + "vcamio", + "vldo28", + "vsram-others", + "vsram-proc", + "vaux18", + "vaud28", + "vio28", + "vio18", + "vdram", + "vmc", + "vmch", + "vemc", + "vsim1", + "vsim2", + "vibr", + "vusb33", +) def read_attr(attr): - path = os.path.join('/sys/class/regulator', attr) + path = os.path.join("/sys/class/regulator", attr) if not os.path.exists(path): - return '' + return "" with open(path) as f: tmp = f.read().strip() return tmp @@ -39,7 +104,7 @@ def read_attr_name(attr): def read_name(reg): - return read_attr_name('regulator.%d/name' % reg) + return read_attr_name("regulator.%d/name" % reg) def read_all_name(): @@ -58,31 +123,34 @@ def read_all_name(): def test_regulator(soc): missing_node = False - expect_set = mt8365_MAIN_REGULATORS if soc == 'mt8365' else MAIN_REGULATORS + expect_set = mt8365_MAIN_REGULATORS if soc == "mt8365" else MAIN_REGULATORS current_set = read_all_name() for node in expect_set: - print('Checking the \'{0}\' node exists in System...'.format(node)) + print("Checking the '{0}' node exists in System...".format(node)) if node not in current_set: missing_node = True print( - ' - ERROR: expect the \'{0}\' node exist but it doesn\'t'.format(node)) + " - ERROR: expect the '{0}' node exist but it doesn't".format( + node + ) + ) if missing_node: - print('Test Fail') + print("Test Fail") sys.exit(1) - print('Test Pass') + print("Test Pass") def main(): parser = argparse.ArgumentParser() parser.add_argument( - 'soc', - help='SoC type. e.g mt8395', - choices=['mt8395', 'mt8390', 'mt8365'] + "soc", + help="SoC type. e.g mt8395", + choices=["mt8395", "mt8390", "mt8365"], ) args = parser.parse_args() test_regulator(args.soc) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/contrib/genio/bin/serialcheck.py b/contrib/genio/bin/serialcheck.py index 6dd6d49a5..90d1cafc2 100755 --- a/contrib/genio/bin/serialcheck.py +++ b/contrib/genio/bin/serialcheck.py @@ -17,34 +17,49 @@ def runcmd(command): def test_uart_by_serialcheck(soc): - base_path = os.environ.get('PLAINBOX_SESSION_SHARE', '/tmp') - file_path = '{}/binary'.format(base_path) - runcmd(['dd if=/dev/urandom of={} count=1 bs=4096'.format(file_path)]) + base_path = os.environ.get("PLAINBOX_SESSION_SHARE", "/tmp") + file_path = "{}/binary".format(base_path) + runcmd(["dd if=/dev/urandom of={} count=1 bs=4096".format(file_path)]) golden_msg = ( - 'cts: 0 dsr: 0 rng: 0 dcd: 0 rx: 12288' - ' tx: 12288 frame 0 ovr 0 par: 0 brk: 0 buf_ovrr: 0' + "cts: 0 dsr: 0 rng: 0 dcd: 0 rx: 12288" + " tx: 12288 frame 0 ovr 0 par: 0 brk: 0 buf_ovrr: 0" ) - print('Golden Sample:') + print("Golden Sample:") print(golden_msg) - tty_node = 'ttyS1' if soc == 'mt8395' else 'ttyS2' - cmd = 'genio-test-tool.serialcheck -d /dev/{} -f {} -m d -l 3 -b {}' + tty_node = "ttyS1" if soc == "mt8395" else "ttyS2" + cmd = "genio-test-tool.serialcheck -d /dev/{} -f {} -m d -l 3 -b {}" available_baudrate = [ - 3000000, 2000000, 921600, 576000, 460800, 230400, 115200, 57600, - 38400, 19200, 9600, 4800, 2400, 1200, 600, 300, 110 + 3000000, + 2000000, + 921600, + 576000, + 460800, + 230400, + 115200, + 57600, + 38400, + 19200, + 9600, + 4800, + 2400, + 1200, + 600, + 300, + 110, ] fail = False for br in available_baudrate: - print('\n' + '*' * 80) - print('Testing baudrate: {}\n'.format(br)) + print("\n" + "*" * 80) + print("Testing baudrate: {}\n".format(br)) ret = runcmd([cmd.format(tty_node, file_path, br)]) print(ret.stdout) - if ret.returncode != 0 or ret.stdout.split('\n')[-2] != golden_msg: + if ret.returncode != 0 or ret.stdout.split("\n")[-2] != golden_msg: fail = True - print('Fail: the output doesn\'t match the golden sample') + print("Fail: the output doesn't match the golden sample") if fail: raise SystemExit(1) @@ -53,13 +68,13 @@ def test_uart_by_serialcheck(soc): def main(): parser = argparse.ArgumentParser() parser.add_argument( - 'soc', - help='SoC type. e.g mt8395', - choices=['mt8395', 'mt8390', 'mt8365'] + "soc", + help="SoC type. e.g mt8395", + choices=["mt8395", "mt8390", "mt8365"], ) args = parser.parse_args() test_uart_by_serialcheck(args.soc) -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/contrib/genio/bin/spidev_test.py b/contrib/genio/bin/spidev_test.py index ee189d69f..bcb5d642c 100755 --- a/contrib/genio/bin/spidev_test.py +++ b/contrib/genio/bin/spidev_test.py @@ -4,7 +4,7 @@ import argparse import subprocess -PLAINBOX_PROVIDER_DATA = os.environ.get('PLAINBOX_PROVIDER_DATA') +PLAINBOX_PROVIDER_DATA = os.environ.get("PLAINBOX_PROVIDER_DATA") def runcmd(command): @@ -14,7 +14,7 @@ def runcmd(command): stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8", - timeout=1 + timeout=1, ) return ret @@ -28,40 +28,39 @@ def check_spi_node(path): def test_spi_content_consistency(platform): - spi_path = '/dev/spidev0.0' - if platform == 'G1200-evk': - spi_path = '/dev/spidev1.0' + spi_path = "/dev/spidev0.0" + if platform == "G1200-evk": + spi_path = "/dev/spidev1.0" check_spi_node(spi_path) - test_bin_path = '{}/spi/test.bin'.format(PLAINBOX_PROVIDER_DATA) - cmd = ( - 'genio-test-tool.spidev-test -D' - ' {} -s 400000 -i {} -v'.format(spi_path, test_bin_path) + test_bin_path = "{}/spi/test.bin".format(PLAINBOX_PROVIDER_DATA) + cmd = "genio-test-tool.spidev-test -D" " {} -s 400000 -i {} -v".format( + spi_path, test_bin_path ) - print('Run command: {}\n'.format(cmd)) + print("Run command: {}\n".format(cmd)) spi_ret = runcmd([cmd]) print(spi_ret.stdout) if not spi_ret.stdout: - raise SystemExit( - 'ERROR: no any output be reported') + raise SystemExit("ERROR: no any output be reported") - packets = spi_ret.stdout.split('\n') + packets = spi_ret.stdout.split("\n") for rx, tx in zip(packets[-2:-1], packets[-3:-2]): - tx_content = tx.split('|')[2] - rx_content = rx.split('|')[2] + tx_content = tx.split("|")[2] + rx_content = rx.split("|")[2] if tx_content != rx_content: raise SystemExit( - 'ERROR: the content is not consistent between TX and RX') + "ERROR: the content is not consistent between TX and RX" + ) def main(): parser = argparse.ArgumentParser() parser.add_argument( - 'platform', - help='Device platform. e.g G1200-evk', - choices=['G1200-evk', 'G700', 'G350'] + "platform", + help="Device platform. e.g G1200-evk", + choices=["G1200-evk", "G700", "G350"], ) args = parser.parse_args() test_spi_content_consistency(args.platform)