{"id":1207,"date":"2019-11-25T10:49:02","date_gmt":"2019-11-25T09:49:02","guid":{"rendered":"http:\/\/www.fabienm.eu\/flf\/?p=1207"},"modified":"2019-12-17T09:44:15","modified_gmt":"2019-12-17T08:44:15","slug":"cocotb-tips","status":"publish","type":"post","link":"http:\/\/www.fabienm.eu\/flf\/cocotb-tips\/","title":{"rendered":"Cocotb Tips"},"content":{"rendered":"\n<p>Some tips for python HDL test module <a href=\"https:\/\/github.com\/cocotb\/cocotb\">Cocotb<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Read and Write signal<\/h3>\n\n\n\n<p>Write:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>clk.value = 1\ndut.input_signal &lt;= 12\ndut.sub_block.memory.array[4] &lt;= 2<\/code><\/pre>\n\n\n\n<p>Read:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>count = dut.counter.value\nprint(count.binstr)\nprint(count.integer)\nprint(count.n_bits)\nprint(int(dut.counter))<\/code><\/pre>\n\n\n\n<p>See it under the <a href=\"https:\/\/cocotb.readthedocs.io\/en\/latest\/quickstart.html#assigning-values-to-signals\">official documentation<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Yielding a coroutine in a select list fashion<\/h3>\n\n\n\n<p>Question asked on <a href=\"https:\/\/stackoverflow.com\/questions\/52855216\/yielding-a-coroutine-in-a-list-with-cocotb\">stackoverflow<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Using latest python version with virtualenv<\/h3>\n\n\n\n<p>If you compile python yourself,<a href=\"https:\/\/github.com\/cocotb\/cocotb\/issues\/1139#issuecomment-539503847\"> don&rsquo;t forget to add option<\/a> <code>--enable-shared<\/code> at configure time (<code>.\/configure --enable-shared<\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ virtualenv --python=\/usr\/local\/bin\/python3.7 ~\/envp37\n$ source ~\/envp37\/bin\/activate\n$ python -m pip install cocotb<\/code><\/pre>\n\n\n\n<p>Do not forget to re-source your environnement each time you open a new terminal :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ source ~\/envp37\/bin\/activate<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Logging messages and main test class template<\/h3>\n\n\n\n<p>This is a template for declaring a class used for test in function @cocotb.test() :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import logging\nfrom cocotb import SimLog\n...\n\nclass MyDUTNameTest(object):\n    \"\"\" Test class for MyDUTName\"\"\"\n    LOGLEVEL = logging.INFO\n    # clock frequency is 50Mhz\n    PERIOD = (20, \"ns\")\n\n    def __init__(self):\n        if sys.version_info[0] &lt; 3: # because python 2.7 is obsolete\n            raise Exception(\"Must be using Python 3\")\n        self._dut = dut\n        self.log = SimLog(\"RmiiDebug.{}\".format(self.__class__.__name__))\n        self.log.setLevel(self.LOGLEVEL)\n        self._dut._log.setLevel(self.LOGLEVEL)\n        self.clock = Clock(self._dut.clock, self.PERIOD[0], self.PERIOD[1])\n        self._clock_thread = cocotb.fork(self.clock.start())\n\n# ....\n\n@cocotb.test()\ndef my_test(dut):\n    mdutn = MyDUTNameTest()\n    mdutn.log.info(\"Launching my test\")\n<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Some tips for python HDL test module Cocotb. Read and Write signal Write: Read: See it under the official documentation. Yielding a coroutine in a select list fashion Question asked on stackoverflow. Using latest python version with virtualenv If you compile python yourself, don&rsquo;t forget to add option &#8211;enable-shared at configure time (.\/configure &#8211;enable-shared) Do &hellip; <a href=\"http:\/\/www.fabienm.eu\/flf\/cocotb-tips\/\" class=\"more-link\">Continuer la lecture de <span class=\"screen-reader-text\">Cocotb Tips<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[65,1,9],"tags":[55,120,56,155,117],"class_list":["post-1207","post","type-post","status-publish","format-standard","hentry","category-cocotb","category-non-classe","category-outils","tag-cocotb","tag-hdl","tag-python","tag-python3","tag-tip"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"post-thumbnail":false},"uagb_author_info":{"display_name":"Fabien Marteau","author_link":"http:\/\/www.fabienm.eu\/flf\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"Some tips for python HDL test module Cocotb. Read and Write signal Write: Read: See it under the official documentation. Yielding a coroutine in a select list fashion Question asked on stackoverflow. Using latest python version with virtualenv If you compile python yourself, don&rsquo;t forget to add option --enable-shared at configure time (.\/configure --enable-shared) Do\u2026","_links":{"self":[{"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/posts\/1207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/comments?post=1207"}],"version-history":[{"count":12,"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/posts\/1207\/revisions"}],"predecessor-version":[{"id":1297,"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/posts\/1207\/revisions\/1297"}],"wp:attachment":[{"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/media?parent=1207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/categories?post=1207"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fabienm.eu\/flf\/wp-json\/wp\/v2\/tags?post=1207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}