question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve assignment mechanism to simulator handles

See original GitHub issue

Currently Cocotb provides the following constructs to assign variables to signals:

Overloaded le

@cocotb.test()
def my_test(dut):
    # Assignment form 1: overloaded __le__ method
    dut.clk <= 1

This a slightly cheeky way to provide RTL-like syntax in Python. For people familiar with Python it’s counter-intuitive (and “un-pythonic”: https://twitter.com/jandecaluwe/status/370597832971259904). However it doesn’t alias any functionality since it’s not valid to compare a handle to anything other than direct equality to another handle (for example to check whether clk == dut.clk). If attempting to compare the actual value of a signal the signal value would have to be read:

if dut.clk.value <= 1:
    # do something

although we should probably support the following to avoid the value aliasing problem described below:

if int(dut.clk) <= 1:
    # do something

Value property

@cocotb.test()
def my_test(dut):
    # Assignment form 2: use the "value" property
    dut.clk.value = 0

This form will cause problems if an object in the RTL hierarchy is called “value”, for example if we had a port named value we wouldn’t be able to read or write to it.

Possible enhancement

There is a third possible mechanism - to use the __setattr__ method. This also has limitations in that it will only work if descending at least one level into the hierarchy.

@cocotb.test()
def my_test(dut):
    # Assignment form 3: Use __setattr__
    dut.clk = 1

    # limitation - doesn't work if we only have a handle to the signal
    clk = dut.clk
    clk = 0      # Reassigns clk, doesn't drive a value

What is the best way to tidy this up?

Discuss.

Issue Analytics

  • State:open
  • Created 10 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbarrettcommented, Apr 6, 2020

I’ve mentioned this before. Because we start the user, we can easily enforce it’s loading.

dut.signal = 4
0reactions
ktbarrettcommented, Aug 20, 2021

We have recently deprecated the __setattr__ and <= syntax. Only .value remains. The problems with it can be side-stepped by traversing the hierarchy with a different syntax than the syntax used to access handle operators:

dut["a"]["b"'][0].value = 0
# or maybe as a convenience
dut["a.b[0]"].value = 0

We shouldn’t let pretty syntax get in the way of things working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CS 3733 UTSA Operating Systems OS Address Translation ...
This assignment is on memory memory management, where we design a simulator that implements the OS's address translation mechanisms.
Read more >
assignment is on memory memory management, where we ...
Question: assignment is on memory memory management, where we design a simulator that implements the OS's address translation mechanisms.
Read more >
Modeling and Simulation
Successful input modeling requires a close match between the input model and the true underlying probabilistic mechanism associated with the system. The input ......
Read more >
CS 3733 Operating Systems
Objectives: This assignment will practice the following items: 1. Practise the address translation that is usually performed by the hardware.
Read more >
Chapter 2. Simulation Basics
The AWR Design Environment platform determines what simulators to run based ... Note that EM simulations are not set using this mechanism; they...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found