blob: 21258a530f16820a5e3328078161c47ba2334901 [file] [log] [blame]
lowRISC Contributors802543a2019-08-31 12:12:56 +01001#!/usr/bin/env python3
2# Copyright lowRISC contributors.
3# Licensed under the Apache License, Version 2.0, see LICENSE for details.
4# SPDX-License-Identifier: Apache-2.0
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -07005r"""Command-line tool to generate boilerplate DV testbench.
6
7The generated objects are extended from dv_lib / cip_lib.
lowRISC Contributors802543a2019-08-31 12:12:56 +01008"""
9import argparse
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -070010import logging as log
11import re
12import sys
lowRISC Contributors802543a2019-08-31 12:12:56 +010013
Udi Jonnalagadda2c9d0f42020-03-17 17:25:33 -070014import gen_agent
15import gen_env
lowRISC Contributors802543a2019-08-31 12:12:56 +010016
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070017VENDOR_DEFAULT = "lowrisc"
18
lowRISC Contributors802543a2019-08-31 12:12:56 +010019
20def main():
21 parser = argparse.ArgumentParser(
22 description=__doc__,
23 formatter_class=argparse.RawDescriptionHelpFormatter)
24 parser.add_argument(
25 "name",
26 metavar="[ip/block name]",
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -070027 help="""Name of the ip/block for which the UVM TB is being generated.
28 This should just name the block, not the path to it.""")
lowRISC Contributors802543a2019-08-31 12:12:56 +010029
30 parser.add_argument(
31 "-a",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070032 "--gen-agent",
lowRISC Contributors802543a2019-08-31 12:12:56 +010033 action='store_true',
34 help="Generate UVM agent code extended from DV library")
35
36 parser.add_argument(
37 "-s",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070038 "--has-separate-host-device-driver",
lowRISC Contributors802543a2019-08-31 12:12:56 +010039 action='store_true',
40 help=
41 """IP / block agent creates a separate driver for host and device modes.
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -070042 (Ignored if -a switch is not passed.)""")
lowRISC Contributors802543a2019-08-31 12:12:56 +010043
Srikrishna Iyer607c4042019-10-23 17:48:05 -070044 parser.add_argument("-e",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070045 "--gen-env",
Srikrishna Iyer607c4042019-10-23 17:48:05 -070046 action='store_true',
47 help="Generate testbench UVM env code")
lowRISC Contributors802543a2019-08-31 12:12:56 +010048
49 parser.add_argument(
50 "-c",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070051 "--is-cip",
lowRISC Contributors802543a2019-08-31 12:12:56 +010052 action='store_true',
53 help=
54 """Is comportable IP - this will result in code being extended from CIP
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -070055 library. If switch is not passed, the code will be extended from DV
56 library instead. (Ignored if -e switch is not passed.)""")
lowRISC Contributors802543a2019-08-31 12:12:56 +010057
58 parser.add_argument(
Udi Jonnalagadda3e460cc2020-02-11 15:46:24 -080059 "-hr",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070060 "--has-ral",
Udi Jonnalagadda3e460cc2020-02-11 15:46:24 -080061 default=False,
62 action='store_true',
63 help="""Specify whether the DUT has CSRs and thus needs a UVM RAL model.
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -070064 This option is required if either --is_cip or --has_interrupts
65 are enabled.""")
Udi Jonnalagadda3e460cc2020-02-11 15:46:24 -080066
67 parser.add_argument(
Srikrishna Iyera8255fd2019-10-11 11:58:17 -070068 "-hi",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070069 "--has-interrupts",
Srikrishna Iyera8255fd2019-10-11 11:58:17 -070070 default=False,
71 action='store_true',
72 help="""CIP has interrupts. Create interrupts interface in tb""")
73
74 parser.add_argument(
75 "-ha",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070076 "--has-alerts",
Srikrishna Iyera8255fd2019-10-11 11:58:17 -070077 default=False,
78 action='store_true',
79 help="""CIP has alerts. Create alerts interface in tb""")
80
81 parser.add_argument(
Cindy Chen936ebfa2020-12-09 13:15:47 -080082 "-he",
83 "--has-edn",
84 default=False,
85 action='store_true',
86 help="""CIP has EDN connection. Create edn pull interface in tb""")
87
88 parser.add_argument(
lowRISC Contributors802543a2019-08-31 12:12:56 +010089 "-ea",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -070090 "--env-agents",
lowRISC Contributors802543a2019-08-31 12:12:56 +010091 nargs="+",
92 metavar="agt1 agt2",
93 help="""Env creates an interface agent specified here. They are
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -070094 assumed to already exist. Note that the list is space-separated,
95 and not comma-separated. (ignored if -e switch is not passed)"""
lowRISC Contributors802543a2019-08-31 12:12:56 +010096 )
97
98 parser.add_argument(
99 "-ao",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -0700100 "--agent-outdir",
lowRISC Contributors802543a2019-08-31 12:12:56 +0100101 metavar="[hw/dv/sv]",
102 help="""Path to place the agent code. A directory called <name>_agent is
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -0700103 created at this location. (default set to './<name>')""")
lowRISC Contributors802543a2019-08-31 12:12:56 +0100104
105 parser.add_argument(
106 "-eo",
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -0700107 "--env-outdir",
Srikrishna Iyer607c4042019-10-23 17:48:05 -0700108 metavar="[hw/ip/<ip>]",
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -0700109 help="""Path to place the full testbench code. It creates 3 directories
Srikrishna Iyer01c56b42021-08-02 12:50:11 -0700110 - dv, data, and doc. The DV doc and the testplan Hjson files are placed
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -0700111 in the doc and data directories respectively. These are to be merged
112 into the IP's root directory (with the existing data and doc
113 directories). Under dv, it creates 3 sub-directories - env, tb, and
114 tests - to place all of the testbench sources. (default set to
115 './<name>'.)""")
lowRISC Contributors802543a2019-08-31 12:12:56 +0100116
Srikrishna Iyer48a6d982020-01-15 01:26:43 -0800117 parser.add_argument(
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -0700118 "-v",
119 "--vendor",
120 default=VENDOR_DEFAULT,
121 help=
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -0700122 """Name of the vendor / entity developing the testbench. This is used
123 to set the VLNV of the FuseSoC core files.""")
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -0700124
lowRISC Contributors802543a2019-08-31 12:12:56 +0100125 args = parser.parse_args()
Guillermo Maturanaf61d25d2021-05-05 22:29:32 -0700126
127 # The name should be alphanumeric.
128 if re.search(r"\W", args.name):
129 log.error("The block name '%s' contains non-alphanumeric characters.",
130 args.name)
131 sys.exit(1)
132
Cindy Chen5aa43422020-09-15 11:29:58 -0700133 if not args.agent_outdir:
134 args.agent_outdir = args.name
135 if not args.env_outdir:
136 args.env_outdir = args.name
lowRISC Contributors802543a2019-08-31 12:12:56 +0100137
Srikrishna Iyer30ed4b02020-04-01 23:41:50 -0700138 # The has_ral option must be set if either is_cip or has_interrupts is set,
139 # as both require use of a RAL model. As such, it is disallowed to not have
140 # has_ral set if one of these options is set.
141 if not args.has_ral and (args.is_cip or args.has_interrupts):
142 args.has_ral = True
143 print("NOTE: --has_ral switch is enabled since either "
144 "--is_cip or --has_interrupts is set.")
Udi Jonnalagadda3e460cc2020-02-11 15:46:24 -0800145
lowRISC Contributors802543a2019-08-31 12:12:56 +0100146 if args.gen_agent:
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -0700147 gen_agent.gen_agent(args.name, args.has_separate_host_device_driver,
148 args.agent_outdir, args.vendor)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100149
150 if args.gen_env:
Cindy Chen5aa43422020-09-15 11:29:58 -0700151 if not args.env_agents:
152 args.env_agents = []
Srikrishna Iyere9aa88f2020-07-21 20:19:33 -0700153 gen_env.gen_env(args.name, args.is_cip, args.has_ral,
Canberk Topal40e87bc2021-10-25 13:07:00 +0100154 args.has_interrupts, args.has_alerts, args.num_edn,
Cindy Chen936ebfa2020-12-09 13:15:47 -0800155 args.env_agents, args.env_outdir, args.vendor)
lowRISC Contributors802543a2019-08-31 12:12:56 +0100156
157
158if __name__ == '__main__':
159 main()