Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: plus_args as a dict rather than a list #256

Open
manunited10 opened this issue May 8, 2024 · 3 comments
Open

Discussion: plus_args as a dict rather than a list #256

manunited10 opened this issue May 8, 2024 · 3 comments

Comments

@manunited10
Copy link

I have recently started working with cocotb-test, trying to get away from the makefile method. It's amazing!

plus_args:

My understanding of plus_args usage (PLUSARGS in cocotb) is a way to send python parameters to python test - at least that's how I do it through makefile (e.g. to send x=1, y=10, etc to python). These values are accessible in python under cocotb.plusargs variable.

If what I think is true, shouldn't plus_args in cocotb-test be a dict (rather than a list) like below?

plus_args = {'x': 1, 'y': 10,}

And that means
in simulator.py under Class Questa(Simulator) we may need another method like

    def get_plus_args_commands(self, parameters): 
        return [f"+{name}={str(value)}" for name, value in parameters.items()]

which is basically (almost) identical to get_parameter_commands.
and then later we use this method like

if not self.compile_only:
    if self.toplevel_lang == "vhdl":
        cmd.append(
              ...
            + [as_tcl_value(v) for v in self.get_plus_args_commands(self.plus_args)]

Thank you in advance.

p.s. I'm using cocotb 1.8.1, cocotb-test 0.2.5 and python 3.10.14

@themperek
Copy link
Owner

You can do plus_args = {'x=1', 'y=10'} but I agree it is not intuitive as it is.
I am open to PR for this but I would like to keep compatibility with the list maybe with deprecation warning.

@manunited10
Copy link
Author

manunited10 commented May 8, 2024

Thank you for the quick response.
I'm not sure that would work at least on questa.
For starters, self.plus_args is only being used on the else where it is compile_only=True toplevel_lang != "vhdl" (I am using vhdl).
On top of that, I think the generated vsim command should be something like

vsim ... +x=1 +y=10

which means the script should add + to each of the args.

Please take a look at my local diff (which works for vhdl):

diff --git a/cocotb_test/simulator.py b/cocotb_test/simulator.py
index acf6f7d..6cb71f8 100644
--- a/cocotb_test/simulator.py
+++ b/cocotb_test/simulator.py
@@ -148,7 +148,7 @@ class Simulator:
         self.simulation_args = sim_args + extra_args

         if plus_args is None:
-            plus_args = []
+            plus_args = {}

         self.plus_args = plus_args
         self.force_compile = force_compile
@@ -541,6 +541,9 @@ class Questa(Simulator):
     def get_parameter_commands(self, parameters):
         return [f"-g{name}={str(value)}" for name, value in parameters.items()]

+    def get_plus_args_commands(self, parameters):
+        return [f"+{name}={str(value)}" for name, value in parameters.items()]
+
     def do_script(self):
         do_script = ""
         if self.waves:
@@ -599,6 +602,7 @@ class Questa(Simulator):
                     + self.simulation_args
                     + [as_tcl_value(v) for v in self.get_parameter_commands(self.parameters)]
                     + self.toplevel
+                    + [as_tcl_value(v) for v in self.get_plus_args_commands(self.plus_args)]
                     + ["-do", do_script]
                 )
                 if self.verilog_sources:

@themperek
Copy link
Owner

I will try to change this but not sure when.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants