From: Quentin Schulz <quentin.schulz@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 2/2] test/py: add test for whitelist of variables while importing environment
Date: Fri, 18 May 2018 16:45:00 +0200 [thread overview]
Message-ID: <20180518144500.31436-2-quentin.schulz@bootlin.com> (raw)
In-Reply-To: <20180518144500.31436-1-quentin.schulz@bootlin.com>
This tests that the importing of an environment with a specified
whitelist works as intended.
If the variable whitelisted_vars is not set, the env importing should
fail with a given message.
For each variable separated by spaces in whitelisted_vars, if
- foo is bar in current env and bar2 in exported env, after importing
exported env, foo shall be bar2,
- foo does not exist in current env and foo is bar2 in exported env,
after importing exported env, foo shall be bar2,
- foo is bar in current env and does not exist in exported env (but is
in the whitelisted_vars), after importing exported env, foo shall be
empty,
Any variable not in whitelisted_vars should be left untouched.
Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
---
added in v2
test/py/tests/test_env.py | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index b7f960c755..d0a2e36876 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -6,6 +6,7 @@
# Test operation of shell commands relating to environment variables.
import pytest
+import u_boot_utils
# FIXME: This might be useful for other tests;
# perhaps refactor it into ConsoleBase or some other state object?
@@ -231,3 +232,42 @@ def test_env_expansion_spaces(state_test_env):
unset_var(state_test_env, var_space)
if var_test:
unset_var(state_test_env, var_test)
+
+def test_env_import_whitelist_empty(state_test_env):
+ """Test trying to import 0 variables from an environment"""
+ ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console)
+ addr = '%08x' % ram_base
+
+ set_var(state_test_env, "foo1", "bar1")
+
+ state_test_env.u_boot_console.run_command('env export %s' % addr)
+
+ c = state_test_env.u_boot_console
+ with c.disable_check('error_notification'):
+ response = c.run_command('env import -w %s' % addr)
+ assert(response.startswith('## Error: whitelisted_vars is not set'))
+
+def test_env_import_whitelist(state_test_env):
+ """Test importing only a handful of env variables from an environment"""
+ ram_base = u_boot_utils.find_ram_base(state_test_env.u_boot_console)
+ addr = '%08x' % ram_base
+
+ #no foo1 in current env, foo2 overridden, foo3 should be of the value
+ #before exporting and foo4 should be deleted
+ set_var(state_test_env, "whitelisted_vars", "foo1 foo2 foo4")
+ set_var(state_test_env, "foo1", "bar1")
+ set_var(state_test_env, "foo2", "bar2")
+ set_var(state_test_env, "foo3", "bar3")
+
+ state_test_env.u_boot_console.run_command('env export %s' % addr)
+
+ unset_var(state_test_env, "foo1")
+ set_var(state_test_env, "foo2", "test2")
+ set_var(state_test_env, "foo4", "bar4")
+
+ state_test_env.u_boot_console.run_command('env import -w %s' % addr)
+
+ validate_set(state_test_env, "foo1", "bar1")
+ validate_set(state_test_env, "foo2", "bar2")
+ validate_set(state_test_env, "foo3", "bar3")
+ validate_empty(state_test_env, "foo4")
--
2.14.1
next prev parent reply other threads:[~2018-05-18 14:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-18 14:44 [U-Boot] [PATCH v2 1/2] cmd: nvedit: add whitelist option for env import Quentin Schulz
2018-05-18 14:45 ` Quentin Schulz [this message]
2018-05-18 16:04 ` [U-Boot] [PATCH v2 2/2] test/py: add test for whitelist of variables while importing environment Stephen Warren
2018-05-21 7:43 ` Quentin Schulz
2018-05-22 23:29 ` Simon Glass
2018-05-18 16:00 ` [U-Boot] [PATCH v2 1/2] cmd: nvedit: add whitelist option for env import Stephen Warren
2018-05-21 8:01 ` Quentin Schulz
2018-05-21 11:56 ` Alex Kiernan
2018-05-21 12:06 ` Quentin Schulz
2018-05-21 12:26 ` Alex Kiernan
2018-05-21 12:34 ` Quentin Schulz
2018-05-21 12:51 ` Alex Kiernan
2018-05-21 12:36 ` Alex Kiernan
2018-05-21 12:41 ` Quentin Schulz
2018-05-20 13:01 ` Lothar Waßmann
2018-05-21 7:29 ` Quentin Schulz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180518144500.31436-2-quentin.schulz@bootlin.com \
--to=quentin.schulz@bootlin.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox