diff mbox series

arm/lib: Specify the FVP environment variables explicitly

Message ID 20220909121206.3098601-1-peter.hoyes@arm.com
State New
Headers show
Series arm/lib: Specify the FVP environment variables explicitly | expand

Commit Message

Peter Hoyes Sept. 9, 2022, 12:12 p.m. UTC
From: Peter Hoyes <Peter.Hoyes@arm.com>

It is sometimes useful to be able to configure the behavior of FVPs
using environment variables, e.g. for licensing or plugins.

Add a new FVP option: FVP_ENV_PASSTHROUGH, which allows the Bitbake
variables to be passed to the environment to be specified explicitly (in
a similar way to BB_ENV_PASSTHROUGH). This ensures that:

 * FVPs launched via runfvp have a reproducable environment
 * FVPs launched via testimage (which run from an isolated Bitbake task)
   can receive environment variables

Issue-Id: SCM-4964
Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
Change-Id: Idf6ac6d41fda4cd5f950bc383c2fc1fa1acdf4e3
---
 documentation/runfvp.md          | 8 ++++++++
 meta-arm/classes/fvpboot.bbclass | 6 ++++++
 meta-arm/lib/fvp/runner.py       | 5 ++++-
 3 files changed, 18 insertions(+), 1 deletion(-)

Comments

Jon Mason Sept. 11, 2022, 12:59 a.m. UTC | #1
This patch is causing selftest to fail on both master and kirkstone.
See https://gitlab.com/jonmason00/meta-arm/-/jobs/3007871323

Thanks,
Jon

On Fri, Sep 09, 2022 at 01:12:06PM +0100, Peter Hoyes wrote:
> From: Peter Hoyes <Peter.Hoyes@arm.com>
> 
> It is sometimes useful to be able to configure the behavior of FVPs
> using environment variables, e.g. for licensing or plugins.
> 
> Add a new FVP option: FVP_ENV_PASSTHROUGH, which allows the Bitbake
> variables to be passed to the environment to be specified explicitly (in
> a similar way to BB_ENV_PASSTHROUGH). This ensures that:
> 
>  * FVPs launched via runfvp have a reproducable environment
>  * FVPs launched via testimage (which run from an isolated Bitbake task)
>    can receive environment variables
> 
> Issue-Id: SCM-4964
> Signed-off-by: Peter Hoyes <Peter.Hoyes@arm.com>
> Change-Id: Idf6ac6d41fda4cd5f950bc383c2fc1fa1acdf4e3
> ---
>  documentation/runfvp.md          | 8 ++++++++
>  meta-arm/classes/fvpboot.bbclass | 6 ++++++
>  meta-arm/lib/fvp/runner.py       | 5 ++++-
>  3 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/documentation/runfvp.md b/documentation/runfvp.md
> index c792f4e0..01b13693 100644
> --- a/documentation/runfvp.md
> +++ b/documentation/runfvp.md
> @@ -116,6 +116,14 @@ Arbitrary extra arguments that are passed directly to the FVP.  For example:
>  FVP_EXTRA_ARGS = "--simlimit 60"
>  ```
>  
> +### `FVP_ENV_PASSTHROUGH`
> +
> +The FVP is launched with an isolated set of environment variables. Add the name of a Bitbake variable to this list to pass it through to the FVP environment. For example:
> +
> +```
> +FVP_ENV_PASSTHROUGH = "ARMLMD_LICENSE_FILE FM_TRACE_PLUGINS"
> +```
> +
>  
>  [AEM]: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
>  [FVP]: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms
> diff --git a/meta-arm/classes/fvpboot.bbclass b/meta-arm/classes/fvpboot.bbclass
> index fbdfa965..78dabd73 100644
> --- a/meta-arm/classes/fvpboot.bbclass
> +++ b/meta-arm/classes/fvpboot.bbclass
> @@ -23,6 +23,8 @@ FVP_CONSOLE ?= ""
>  FVP_CONSOLES[default] ?= "${FVP_CONSOLE}"
>  # Arbitrary extra arguments
>  FVP_EXTRA_ARGS ?= ""
> +# Bitbake variables to pass to the FVP environment
> +FVP_ENV_PASSTHROUGH ?= ""
>  
>  EXTRA_IMAGEDEPENDS += "${FVP_PROVIDER}"
>  
> @@ -66,6 +68,10 @@ python do_write_fvpboot_conf() {
>      data["terminals"] = getFlags("FVP_TERMINALS")
>      data["args"] = shlex.split(d.getVar("FVP_EXTRA_ARGS") or "")
>  
> +    data["env"] = {}
> +    for var in d.getVar("FVP_ENV_PASSTHROUGH").split():
> +        data["env"][var] = d.getVar(var)
> +
>      os.makedirs(os.path.dirname(conffile), exist_ok=True)
>      with open(conffile, "wt") as f:
>          json.dump(data, f)
> diff --git a/meta-arm/lib/fvp/runner.py b/meta-arm/lib/fvp/runner.py
> index 7641cd67..8c6b4cad 100644
> --- a/meta-arm/lib/fvp/runner.py
> +++ b/meta-arm/lib/fvp/runner.py
> @@ -60,7 +60,10 @@ class FVPRunner:
>          cli = cli_from_config(config, terminal_choice)
>          cli += extra_args
>          self._logger.debug(f"Constructed FVP call: {cli}")
> -        self._fvp_process = await asyncio.create_subprocess_exec(*cli, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
> +        self._fvp_process = await asyncio.create_subprocess_exec(
> +            *cli,
> +            stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
> +            env=config['env'])
>  
>          def detect_terminals(line):
>              m = re.match(r"^(\S+): Listening for serial connection on port (\d+)$", line)
> -- 
> 2.25.1
> 
>
Jon Mason Sept. 14, 2022, 2:09 p.m. UTC | #2
On Fri, 9 Sep 2022 13:12:06 +0100, Peter Hoyes wrote:
> It is sometimes useful to be able to configure the behavior of FVPs
> using environment variables, e.g. for licensing or plugins.
> 
> Add a new FVP option: FVP_ENV_PASSTHROUGH, which allows the Bitbake
> variables to be passed to the environment to be specified explicitly (in
> a similar way to BB_ENV_PASSTHROUGH). This ensures that:
> 
> [...]

Applied, thanks!

[1/1] arm/lib: Specify the FVP environment variables explicitly
      commit: 820a55d348bab5d1953a6f1386383139772372fe

Best regards,
diff mbox series

Patch

diff --git a/documentation/runfvp.md b/documentation/runfvp.md
index c792f4e0..01b13693 100644
--- a/documentation/runfvp.md
+++ b/documentation/runfvp.md
@@ -116,6 +116,14 @@  Arbitrary extra arguments that are passed directly to the FVP.  For example:
 FVP_EXTRA_ARGS = "--simlimit 60"
 ```
 
+### `FVP_ENV_PASSTHROUGH`
+
+The FVP is launched with an isolated set of environment variables. Add the name of a Bitbake variable to this list to pass it through to the FVP environment. For example:
+
+```
+FVP_ENV_PASSTHROUGH = "ARMLMD_LICENSE_FILE FM_TRACE_PLUGINS"
+```
+
 
 [AEM]: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms/arm-ecosystem-models
 [FVP]: https://developer.arm.com/tools-and-software/simulation-models/fixed-virtual-platforms
diff --git a/meta-arm/classes/fvpboot.bbclass b/meta-arm/classes/fvpboot.bbclass
index fbdfa965..78dabd73 100644
--- a/meta-arm/classes/fvpboot.bbclass
+++ b/meta-arm/classes/fvpboot.bbclass
@@ -23,6 +23,8 @@  FVP_CONSOLE ?= ""
 FVP_CONSOLES[default] ?= "${FVP_CONSOLE}"
 # Arbitrary extra arguments
 FVP_EXTRA_ARGS ?= ""
+# Bitbake variables to pass to the FVP environment
+FVP_ENV_PASSTHROUGH ?= ""
 
 EXTRA_IMAGEDEPENDS += "${FVP_PROVIDER}"
 
@@ -66,6 +68,10 @@  python do_write_fvpboot_conf() {
     data["terminals"] = getFlags("FVP_TERMINALS")
     data["args"] = shlex.split(d.getVar("FVP_EXTRA_ARGS") or "")
 
+    data["env"] = {}
+    for var in d.getVar("FVP_ENV_PASSTHROUGH").split():
+        data["env"][var] = d.getVar(var)
+
     os.makedirs(os.path.dirname(conffile), exist_ok=True)
     with open(conffile, "wt") as f:
         json.dump(data, f)
diff --git a/meta-arm/lib/fvp/runner.py b/meta-arm/lib/fvp/runner.py
index 7641cd67..8c6b4cad 100644
--- a/meta-arm/lib/fvp/runner.py
+++ b/meta-arm/lib/fvp/runner.py
@@ -60,7 +60,10 @@  class FVPRunner:
         cli = cli_from_config(config, terminal_choice)
         cli += extra_args
         self._logger.debug(f"Constructed FVP call: {cli}")
-        self._fvp_process = await asyncio.create_subprocess_exec(*cli, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+        self._fvp_process = await asyncio.create_subprocess_exec(
+            *cli,
+            stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+            env=config['env'])
 
         def detect_terminals(line):
             m = re.match(r"^(\S+): Listening for serial connection on port (\d+)$", line)