diff options
Diffstat (limited to 'test/py/tests/test_saveenv.py')
-rw-r--r-- | test/py/tests/test_saveenv.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/test/py/tests/test_saveenv.py b/test/py/tests/test_saveenv.py index 7faa3bdf93d..019b229d30e 100644 --- a/test/py/tests/test_saveenv.py +++ b/test/py/tests/test_saveenv.py @@ -28,15 +28,15 @@ import string import uuid # Setup the env -def setup_saveenv_env(u_boot_console): - if u_boot_console.config.env.get('env__saveenv_test_skip', False): +def setup_saveenv_env(ubman): + if ubman.config.env.get('env__saveenv_test_skip', False): pytest.skip('saveenv test is not enabled') - output = u_boot_console.run_command('echo $modeboot') + output = ubman.run_command('echo $modeboot') if output: bootmode = output else: - f = u_boot_console.config.env.get('env__saveenv_test', None) + f = ubman.config.env.get('env__saveenv_test', None) if not f: pytest.skip('bootmode cannot be determined') bootmode = f.get('bootmode', 'jtagboot') @@ -45,39 +45,39 @@ def setup_saveenv_env(u_boot_console): pytest.skip('skipping saveenv test due to jtag bootmode') # Check return code -def ret_code(u_boot_console): - return u_boot_console.run_command('echo $?') +def ret_code(ubman): + return ubman.run_command('echo $?') # Verify env variable -def check_env(u_boot_console, var_name, var_value): +def check_env(ubman, var_name, var_value): if var_value: - output = u_boot_console.run_command(f'printenv {var_name}') + output = ubman.run_command(f'printenv {var_name}') var_value = str(var_value) if (var_value.startswith("'") and var_value.endswith("'")) or ( var_value.startswith('"') and var_value.endswith('"') ): var_value = var_value.split(var_value[-1])[1] assert var_value in output - assert ret_code(u_boot_console).endswith('0') + assert ret_code(ubman).endswith('0') else: - u_boot_console.p.send(f'printenv {var_name}\n') - output = u_boot_console.p.expect(['not defined']) + ubman.p.send(f'printenv {var_name}\n') + output = ubman.p.expect(['not defined']) assert output == 0 - assert ret_code(u_boot_console).endswith('1') + assert ret_code(ubman).endswith('1') # Set env variable -def set_env(u_boot_console, var_name, var_value): - u_boot_console.run_command(f'setenv {var_name} {var_value}') - assert ret_code(u_boot_console).endswith('0') - check_env(u_boot_console, var_name, var_value) +def set_env(ubman, var_name, var_value): + ubman.run_command(f'setenv {var_name} {var_value}') + assert ret_code(ubman).endswith('0') + check_env(ubman, var_name, var_value) @pytest.mark.buildconfigspec('cmd_saveenv') @pytest.mark.buildconfigspec('hush_parser') -def test_saveenv(u_boot_console): +def test_saveenv(ubman): """Test the saveenv command in non-JTAG bootmode. It saves the U-Boot environment in persistent storage. """ - setup_saveenv_env(u_boot_console) + setup_saveenv_env(ubman) # Set env for random mac address rand_mac = '%02x:%02x:%02x:%02x:%02x:%02x' % ( @@ -88,50 +88,50 @@ def test_saveenv(u_boot_console): random.randint(0, 255), random.randint(0, 255), ) - set_env(u_boot_console, 'mac_addr', rand_mac) + set_env(ubman, 'mac_addr', rand_mac) # Set env for random IPv4 address rand_ipv4 = ipaddress.IPv4Address._string_from_ip_int( random.randint(0, ipaddress.IPv4Address._ALL_ONES) ) - set_env(u_boot_console, 'ipv4_addr', rand_ipv4) + set_env(ubman, 'ipv4_addr', rand_ipv4) # Set env for random IPv6 address rand_ipv6 = ipaddress.IPv6Address._string_from_ip_int( random.randint(0, ipaddress.IPv6Address._ALL_ONES) ) - set_env(u_boot_console, 'ipv6_addr', rand_ipv6) + set_env(ubman, 'ipv6_addr', rand_ipv6) # Set env for random number rand_num = random.randrange(1, 10**9) - set_env(u_boot_console, 'num_var', rand_num) + set_env(ubman, 'num_var', rand_num) # Set env for uuid uuid_str = uuid.uuid4().hex.lower() - set_env(u_boot_console, 'uuid_var', uuid_str) + set_env(ubman, 'uuid_var', uuid_str) # Set env for random string including special characters sc = "!#%&()*+,-./:;<=>?@[\\]^_`{|}~" rand_str = ''.join( random.choices(' ' + string.ascii_letters + sc + string.digits, k=300) ) - set_env(u_boot_console, 'str_var', f'"{rand_str}"') + set_env(ubman, 'str_var', f'"{rand_str}"') # Set env for empty string - set_env(u_boot_console, 'empty_var', '') + set_env(ubman, 'empty_var', '') # Save the env variables - u_boot_console.run_command('saveenv') - assert ret_code(u_boot_console).endswith('0') + ubman.run_command('saveenv') + assert ret_code(ubman).endswith('0') # Reboot - u_boot_console.run_command('reset', wait_for_reboot=True) + ubman.run_command('reset', wait_for_reboot=True) # Verify the saved env variables - check_env(u_boot_console, 'mac_addr', rand_mac) - check_env(u_boot_console, 'ipv4_addr', rand_ipv4) - check_env(u_boot_console, 'ipv6_addr', rand_ipv6) - check_env(u_boot_console, 'num_var', rand_num) - check_env(u_boot_console, 'uuid_var', uuid_str) - check_env(u_boot_console, 'str_var', rand_str) - check_env(u_boot_console, 'empty_var', '') + check_env(ubman, 'mac_addr', rand_mac) + check_env(ubman, 'ipv4_addr', rand_ipv4) + check_env(ubman, 'ipv6_addr', rand_ipv6) + check_env(ubman, 'num_var', rand_num) + check_env(ubman, 'uuid_var', uuid_str) + check_env(ubman, 'str_var', rand_str) + check_env(ubman, 'empty_var', '') |