15
15
16
16
logger = logging .getLogger ()
17
17
18
+
18
19
class rv32emu (pluginTemplate ):
19
20
__model__ = "rv32emu"
20
21
__version__ = "dev"
21
22
22
23
def __init__ (self , * args , ** kwargs ):
23
24
sclass = super ().__init__ (* args , ** kwargs )
24
25
25
- config = kwargs .get (' config' )
26
+ config = kwargs .get (" config" )
26
27
27
28
# If the config node for this DUT is missing or empty. Raise an error. At minimum we need
28
29
# the paths to the ispec and pspec files
@@ -34,25 +35,27 @@ def __init__(self, *args, **kwargs):
34
35
# test-bench produced by a simulator (like verilator, vcs, incisive, etc). In case of an iss or
35
36
# emulator, this variable could point to where the iss binary is located. If 'PATH variable
36
37
# is missing in the config.ini we can hardcode the alternate here.
37
- self .dut_exe = os .path .join (config ['PATH' ] if 'PATH' in config else "" ,"rv32emu" )
38
+ self .dut_exe = os .path .join (
39
+ config ["PATH" ] if "PATH" in config else "" , "rv32emu"
40
+ )
38
41
39
42
# Number of parallel jobs that can be spawned off by RISCOF
40
43
# for various actions performed in later functions, specifically to run the tests in
41
44
# parallel on the DUT executable. Can also be used in the build function if required.
42
- self .num_jobs = str (config [' jobs' ] if ' jobs' in config else 1 )
45
+ self .num_jobs = str (config [" jobs" ] if " jobs" in config else 1 )
43
46
44
47
# Path to the directory where this python file is located. Collect it from the config.ini
45
- self .pluginpath = os .path .abspath (config [' pluginpath' ])
48
+ self .pluginpath = os .path .abspath (config [" pluginpath" ])
46
49
47
50
# Collect the paths to the riscv-config absed ISA and platform yaml files. One can choose
48
51
# to hardcode these here itself instead of picking it from the config.ini file.
49
- self .isa_spec = os .path .abspath (config [' ispec' ])
50
- self .platform_spec = os .path .abspath (config [' pspec' ])
52
+ self .isa_spec = os .path .abspath (config [" ispec" ])
53
+ self .platform_spec = os .path .abspath (config [" pspec" ])
51
54
52
55
# We capture if the user would like the run the tests on the target or
53
56
# not. If you are interested in just compiling the tests and not running
54
57
# them on the target, then following variable should be set to False
55
- if ' target_run' in config and config [' target_run' ] == '0' :
58
+ if " target_run" in config and config [" target_run" ] == "0" :
56
59
self .target_run = False
57
60
else :
58
61
self .target_run = True
@@ -72,36 +75,57 @@ def initialise(self, suite, work_dir, archtest_env):
72
75
# Note the march is not hardwired here, because it will change for each
73
76
# test. Similarly the output elf name and compile macros will be assigned later in the
74
77
# runTests function
75
- self .compile_cmd = os .getenv ("CROSS_COMPILE" ) + 'gcc -march={0}\
78
+ self .compile_cmd = (
79
+ os .getenv ("CROSS_COMPILE" )
80
+ + "gcc -march={0}\
76
81
-static -mcmodel=medany -fvisibility=hidden -nostdlib -nostartfiles -g\
77
- -T '+ self .pluginpath + '/env/link.ld\
78
- -I '+ self .pluginpath + '/env/\
79
- -I ' + archtest_env + ' {2} -o {3} {4}'
82
+ -T "
83
+ + self .pluginpath
84
+ + "/env/link.ld\
85
+ -I "
86
+ + self .pluginpath
87
+ + "/env/\
88
+ -I "
89
+ + archtest_env
90
+ + " {2} -o {3} {4}"
91
+ )
80
92
81
93
def build (self , isa_yaml , platform_yaml ):
82
94
# load the isa yaml as a dictionary in python.
83
- ispec = utils .load_yaml (isa_yaml )[' hart0' ]
95
+ ispec = utils .load_yaml (isa_yaml )[" hart0" ]
84
96
85
97
# capture the XLEN value by picking the max value in 'supported_xlen' field of isa yaml. This
86
98
# will be useful in setting integer value in the compiler string (if not already hardcoded);
87
- self .xlen = ('64' if 64 in ispec ['supported_xlen' ] else '32' )
88
-
89
- if 'E' not in ispec ['ISA' ]:
90
- self .compile_cmd = self .compile_cmd + ' -mabi=' + ('lp64 ' if 64 in ispec ['supported_xlen' ] else 'ilp32 ' )
99
+ self .xlen = "64" if 64 in ispec ["supported_xlen" ] else "32"
100
+
101
+ if "E" not in ispec ["ISA" ]:
102
+ self .compile_cmd = (
103
+ self .compile_cmd
104
+ + " -mabi="
105
+ + ("lp64 " if 64 in ispec ["supported_xlen" ] else "ilp32 " )
106
+ )
91
107
else :
92
- self .compile_cmd = self .compile_cmd + ' -mabi=' + ('lp64e ' if 64 in ispec ['supported_xlen' ] else 'ilp32e ' )
93
- self .compile_cmd += '-D RV32E '
108
+ self .compile_cmd = (
109
+ self .compile_cmd
110
+ + " -mabi="
111
+ + ("lp64e " if 64 in ispec ["supported_xlen" ] else "ilp32e " )
112
+ )
113
+ self .compile_cmd += "-D RV32E "
94
114
95
115
def runTests (self , testList ):
96
116
# Delete Makefile if it already exists.
97
- if os .path .exists (self .work_dir + "/Makefile." + self .name [:- 1 ]):
98
- os .remove (self .work_dir + "/Makefile." + self .name [:- 1 ])
117
+ if os .path .exists (self .work_dir + "/Makefile." + self .name [:- 1 ]):
118
+ os .remove (self .work_dir + "/Makefile." + self .name [:- 1 ])
99
119
# create an instance the makeUtil class that we will use to create targets.
100
- make = utils .makeUtil (makefilePath = os .path .join (self .work_dir , "Makefile." + self .name [:- 1 ]))
120
+ make = utils .makeUtil (
121
+ makefilePath = os .path .join (
122
+ self .work_dir , "Makefile." + self .name [:- 1 ]
123
+ )
124
+ )
101
125
102
126
# set the make command that will be used. The num_jobs parameter was set in the __init__
103
127
# function earlier
104
- make .makeCommand = ' make -j' + self .num_jobs
128
+ make .makeCommand = " make -j" + self .num_jobs
105
129
106
130
# we will iterate over each entry in the testList. Each entry node will be refered to by the
107
131
# variable testname.
@@ -110,14 +134,14 @@ def runTests(self, testList):
110
134
testentry = testList [testname ]
111
135
112
136
# we capture the path to the assembly file of this test
113
- test = testentry [' test_path' ]
137
+ test = testentry [" test_path" ]
114
138
115
139
# capture the directory where the artifacts of this test will be dumped/created. RISCOF is
116
140
# going to look into this directory for the signature files
117
- test_dir = testentry [' work_dir' ]
141
+ test_dir = testentry [" work_dir" ]
118
142
119
143
# name of the elf file after compilation of the test
120
- elf = ' my.elf'
144
+ elf = " my.elf"
121
145
122
146
# name of the signature file as per requirement of RISCOF. RISCOF expects the signature to
123
147
# be named as DUT-<dut-name>.signature. The below variable creates an absolute path of
@@ -127,22 +151,26 @@ def runTests(self, testList):
127
151
# for each test there are specific compile macros that need to be enabled. The macros in
128
152
# the testList node only contain the macros/values. For the gcc toolchain we need to
129
153
# prefix with "-D". The following does precisely that.
130
- compile_macros = ' -D' + " -D" .join (testentry [' macros' ])
154
+ compile_macros = " -D" + " -D" .join (testentry [" macros" ])
131
155
132
156
# substitute all variables in the compile command that we created in the initialize function
133
- cmd = self .compile_cmd .format (testentry ['isa' ].lower (), self .xlen , test , elf , compile_macros )
157
+ cmd = self .compile_cmd .format (
158
+ testentry ["isa" ].lower (), self .xlen , test , elf , compile_macros
159
+ )
134
160
135
- # if the user wants to disable running the tests and only compile the tests, then
161
+ # if the user wants to disable running the tests and only compile the tests, then
136
162
# the "else" clause is executed below assigning the sim command to simple no action
137
163
# echo statement.
138
164
if self .target_run :
139
- # set up the simulation command. Template is for spike. Please change.
140
- simcmd = self .dut_exe + ' -a {0} {1}' .format (sig_file , elf )
165
+ # set up the simulation command. Template is for spike. Please change.
166
+ simcmd = self .dut_exe + " -a {0} {1}" .format (sig_file , elf )
141
167
else :
142
168
simcmd = 'echo "NO RUN"'
143
169
144
170
# concatenate all commands that need to be executed within a make-target.
145
- execute = '@cd {0}; {1}; {2};' .format (testentry ['work_dir' ], cmd , simcmd )
171
+ execute = "@cd {0}; {1}; {2};" .format (
172
+ testentry ["work_dir" ], cmd , simcmd
173
+ )
146
174
147
175
# create a target. The makeutil will create a target with the name "TARGET<num>" where num
148
176
# starts from 0 and increments automatically for each new target that is added
0 commit comments