diff options
author | Tom Rini <trini@konsulko.com> | 2025-04-07 16:40:02 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-04-08 11:43:23 -0600 |
commit | ff61d6bfd1c9534d3fc2397846a5899639f2e55d (patch) | |
tree | dcfe4bc52848a5637c975a3352b57885e5b8a06d /test/py/tests/test_env.py | |
parent | 34820924edbc4ec7803eb89d9852f4b870fa760a (diff) | |
parent | f892a7f397a66d8d09f418d1e0e06dfb48bac27d (diff) |
Merge branch 'next'
Note that this undoes the changes of commit cf6d4535cc4c ("x86:
emulation: Disable bloblist for now") as that was intended only for the
release due to time.
Diffstat (limited to 'test/py/tests/test_env.py')
-rw-r--r-- | test/py/tests/test_env.py | 82 |
1 files changed, 40 insertions, 42 deletions
diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py index 4471db7d9cb..383e26c03b0 100644 --- a/test/py/tests/test_env.py +++ b/test/py/tests/test_env.py @@ -13,7 +13,7 @@ from subprocess import call, CalledProcessError import tempfile import pytest -import u_boot_utils +import utils # FIXME: This might be useful for other tests; # perhaps refactor it into ConsoleBase or some other state object? @@ -23,17 +23,17 @@ class StateTestEnv(object): names. """ - def __init__(self, u_boot_console): + def __init__(self, ubman): """Initialize a new StateTestEnv object. Args: - u_boot_console: A U-Boot console. + ubman: A U-Boot console. Returns: Nothing. """ - self.u_boot_console = u_boot_console + self.ubman = ubman self.get_env() self.set_var = self.get_non_existent_var() @@ -47,12 +47,12 @@ class StateTestEnv(object): Nothing. """ - if self.u_boot_console.config.buildconfig.get( + if self.ubman.config.buildconfig.get( 'config_version_variable', 'n') == 'y': - with self.u_boot_console.disable_check('main_signon'): - response = self.u_boot_console.run_command('printenv') + with self.ubman.disable_check('main_signon'): + response = self.ubman.run_command('printenv') else: - response = self.u_boot_console.run_command('printenv') + response = self.ubman.run_command('printenv') self.env = {} for l in response.splitlines(): if not '=' in l: @@ -92,12 +92,12 @@ class StateTestEnv(object): ste = None @pytest.fixture(scope='function') -def state_test_env(u_boot_console): +def state_test_env(ubman): """pytest fixture to provide a StateTestEnv object to tests.""" global ste if not ste: - ste = StateTestEnv(u_boot_console) + ste = StateTestEnv(ubman) return ste def unset_var(state_test_env, var): @@ -114,7 +114,7 @@ def unset_var(state_test_env, var): Nothing. """ - state_test_env.u_boot_console.run_command('setenv %s' % var) + state_test_env.ubman.run_command('setenv %s' % var) if var in state_test_env.env: del state_test_env.env[var] @@ -133,7 +133,7 @@ def set_var(state_test_env, var, value): Nothing. """ - bc = state_test_env.u_boot_console.config.buildconfig + bc = state_test_env.ubman.config.buildconfig if bc.get('config_hush_parser', None): quote = '"' else: @@ -141,7 +141,7 @@ def set_var(state_test_env, var, value): if ' ' in value: pytest.skip('Space in variable value on non-Hush shell') - state_test_env.u_boot_console.run_command( + state_test_env.ubman.run_command( 'setenv %s %s%s%s' % (var, quote, value, quote)) state_test_env.env[var] = value @@ -155,7 +155,7 @@ def validate_empty(state_test_env, var): Nothing. """ - response = state_test_env.u_boot_console.run_command('echo ${%s}' % var) + response = state_test_env.ubman.run_command('echo ${%s}' % var) assert response == '' def validate_set(state_test_env, var, value): @@ -171,15 +171,14 @@ def validate_set(state_test_env, var, value): # echo does not preserve leading, internal, or trailing whitespace in the # value. printenv does, and hence allows more complete testing. - response = state_test_env.u_boot_console.run_command('printenv %s' % var) + response = state_test_env.ubman.run_command('printenv %s' % var) assert response == ('%s=%s' % (var, value)) @pytest.mark.boardspec('sandbox') -def test_env_initial_env_file(u_boot_console): +def test_env_initial_env_file(ubman): """Test that the u-boot-initial-env make target works""" - cons = u_boot_console - builddir = 'O=' + cons.config.build_dir - envfile = cons.config.build_dir + '/u-boot-initial-env' + builddir = 'O=' + ubman.config.build_dir + envfile = ubman.config.build_dir + '/u-boot-initial-env' # remove if already exists from an older run try: @@ -187,7 +186,7 @@ def test_env_initial_env_file(u_boot_console): except: pass - u_boot_utils.run_and_log(cons, ['make', builddir, 'u-boot-initial-env']) + utils.run_and_log(ubman, ['make', builddir, 'u-boot-initial-env']) assert os.path.exists(envfile) @@ -215,7 +214,7 @@ def test_env_printenv_non_existent(state_test_env): """Test printenv error message for non-existant variables.""" var = state_test_env.set_var - c = state_test_env.u_boot_console + c = state_test_env.ubman with c.disable_check('error_notification'): response = c.run_command('printenv %s' % var) assert response == '## Error: "%s" not defined' % var @@ -277,8 +276,8 @@ def test_env_import_checksum_no_size(state_test_env): """Test that omitted ('-') size parameter with checksum validation fails the env import function. """ - c = state_test_env.u_boot_console - ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console) + c = state_test_env.ubman + ram_base = utils.find_ram_base(state_test_env.ubman) addr = '%08x' % ram_base with c.disable_check('error_notification'): @@ -290,8 +289,8 @@ def test_env_import_whitelist_checksum_no_size(state_test_env): """Test that omitted ('-') size parameter with checksum validation fails the env import function when variables are passed as parameters. """ - c = state_test_env.u_boot_console - ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console) + c = state_test_env.ubman + ram_base = utils.find_ram_base(state_test_env.ubman) addr = '%08x' % ram_base with c.disable_check('error_notification'): @@ -302,8 +301,8 @@ def test_env_import_whitelist_checksum_no_size(state_test_env): @pytest.mark.buildconfigspec('cmd_importenv') def test_env_import_whitelist(state_test_env): """Test importing only a handful of env variables from an environment.""" - c = state_test_env.u_boot_console - ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console) + c = state_test_env.ubman + ram_base = utils.find_ram_base(state_test_env.ubman) addr = '%08x' % ram_base set_var(state_test_env, 'foo1', 'bar1') @@ -339,8 +338,8 @@ def test_env_import_whitelist_delete(state_test_env): deletion if a var A that is passed to env import is not in the environment to be imported. """ - c = state_test_env.u_boot_console - ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console) + c = state_test_env.ubman + ram_base = utils.find_ram_base(state_test_env.ubman) addr = '%08x' % ram_base set_var(state_test_env, 'foo1', 'bar1') @@ -373,7 +372,7 @@ def test_env_info(state_test_env): """Test 'env info' command with all possible options. """ - c = state_test_env.u_boot_console + c = state_test_env.ubman response = c.run_command('env info') nb_line = 0 @@ -410,7 +409,7 @@ def test_env_info_sandbox(state_test_env): """Test 'env info' command result with several options on sandbox with a known ENV configuration: ready & default & persistent """ - c = state_test_env.u_boot_console + c = state_test_env.ubman response = c.run_command('env info') assert 'env_ready = true' in response @@ -435,7 +434,7 @@ def test_env_info_sandbox(state_test_env): def mk_env_ext4(state_test_env): """Create a empty ext4 file system volume.""" - c = state_test_env.u_boot_console + c = state_test_env.ubman filename = 'env.ext4.img' persistent = c.config.persistent_data_dir + '/' + filename fs_img = c.config.result_dir + '/' + filename @@ -446,16 +445,16 @@ def mk_env_ext4(state_test_env): # Some distributions do not add /sbin to the default PATH, where mkfs.ext4 lives os.environ["PATH"] += os.pathsep + '/sbin' try: - u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent) - u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent) - sb_content = u_boot_utils.run_and_log(c, 'tune2fs -l %s' % persistent) + utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' % persistent) + utils.run_and_log(c, 'mkfs.ext4 %s' % persistent) + sb_content = utils.run_and_log(c, 'tune2fs -l %s' % persistent) if 'metadata_csum' in sb_content: - u_boot_utils.run_and_log(c, 'tune2fs -O ^metadata_csum %s' % persistent) + utils.run_and_log(c, 'tune2fs -O ^metadata_csum %s' % persistent) except CalledProcessError: call('rm -f %s' % persistent, shell=True) raise - u_boot_utils.run_and_log(c, ['cp', '-f', persistent, fs_img]) + utils.run_and_log(c, ['cp', '-f', persistent, fs_img]) return fs_img @pytest.mark.boardspec('sandbox') @@ -467,7 +466,7 @@ def mk_env_ext4(state_test_env): def test_env_ext4(state_test_env): """Test ENV in EXT4 on sandbox.""" - c = state_test_env.u_boot_console + c = state_test_env.ubman fs_img = '' try: fs_img = mk_env_ext4(state_test_env) @@ -545,7 +544,7 @@ def test_env_ext4(state_test_env): if fs_img: call('rm -f %s' % fs_img, shell=True) -def test_env_text(u_boot_console): +def test_env_text(ubman): """Test the script that converts the environment to a text file""" def check_script(intext, expect_val): @@ -560,15 +559,14 @@ def test_env_text(u_boot_console): fname = os.path.join(path, 'infile') with open(fname, 'w') as inf: print(intext, file=inf) - result = u_boot_utils.run_and_log(cons, ['awk', '-f', script, fname]) + result = utils.run_and_log(ubman, ['awk', '-f', script, fname]) if expect_val is not None: expect = '#define CONFIG_EXTRA_ENV_TEXT "%s"\n' % expect_val assert result == expect else: assert result == '' - cons = u_boot_console - script = os.path.join(cons.config.source_dir, 'scripts', 'env2string.awk') + script = os.path.join(ubman.config.source_dir, 'scripts', 'env2string.awk') # simple script with a single var check_script('fred=123', 'fred=123\\0') |