forked from OERV-BSP/u-boot
test/py: Shorten u_boot_console
This fixture name is quite long and results in lots of verbose code. We know this is U-Boot so the 'u_boot_' part is not necessary. But it is also a bit of a misnomer, since it provides access to all the information available to tests. It is not just the console. It would be too confusing to use con as it would be confused with config and it is probably too short. So shorten it to 'ubman'. Signed-off-by: Simon Glass <sjg@chromium.org> Link: https://lore.kernel.org/u-boot/CAFLszTgPa4aT_J9h9pqeTtLCVn4x2JvLWRcWRD8NaN3uoSAtyA@mail.gmail.com/
This commit is contained in:
@@ -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,13 +171,13 @@ 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
|
||||
cons = ubman
|
||||
builddir = 'O=' + cons.config.build_dir
|
||||
envfile = cons.config.build_dir + '/u-boot-initial-env'
|
||||
|
||||
@@ -215,7 +215,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 +277,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 = u_boot_utils.find_ram_base(state_test_env.ubman)
|
||||
addr = '%08x' % ram_base
|
||||
|
||||
with c.disable_check('error_notification'):
|
||||
@@ -290,8 +290,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 = u_boot_utils.find_ram_base(state_test_env.ubman)
|
||||
addr = '%08x' % ram_base
|
||||
|
||||
with c.disable_check('error_notification'):
|
||||
@@ -302,8 +302,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 = u_boot_utils.find_ram_base(state_test_env.ubman)
|
||||
addr = '%08x' % ram_base
|
||||
|
||||
set_var(state_test_env, 'foo1', 'bar1')
|
||||
@@ -339,8 +339,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 = u_boot_utils.find_ram_base(state_test_env.ubman)
|
||||
addr = '%08x' % ram_base
|
||||
|
||||
set_var(state_test_env, 'foo1', 'bar1')
|
||||
@@ -373,7 +373,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 +410,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 +435,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
|
||||
@@ -467,7 +467,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 +545,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):
|
||||
@@ -567,7 +567,7 @@ def test_env_text(u_boot_console):
|
||||
else:
|
||||
assert result == ''
|
||||
|
||||
cons = u_boot_console
|
||||
cons = ubman
|
||||
script = os.path.join(cons.config.source_dir, 'scripts', 'env2string.awk')
|
||||
|
||||
# simple script with a single var
|
||||
|
||||
Reference in New Issue
Block a user