forked from luuvish/amba3-vip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·146 lines (109 loc) · 4.6 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
================================================================================
The MIT License (MIT)
Copyright (c) 2014 Luuvish Hwang
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================================================
File : test.py
Author(s) : luuvish (github.com/luuvish/amba3-vip)
Modifier : luuvish ([email protected])
Descriptions : test python script
================================================================================
'''
from argparse import ArgumentParser
import os
import subprocess
import sys
ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
RTL_DIR = os.path.join(ROOT_DIR, '.')
LIB_DIR = os.path.join(ROOT_DIR, 'build', 'sim')
TEST_DIR = os.path.join(ROOT_DIR, 'test')
VLOG = 'ncvlog'
VLIB = 'ncelab'
VSIM = 'ncsim'
NCFLAGS = ['-nocopyright', '-nolog']
TB_AMBA_DIR = os.path.join(RTL_DIR, '.');
test_vectors = {
'options': {
'vlog': ['-sv', '-work', 'worklib', '+incdir+'+TB_AMBA_DIR],
'vlib': ['-dpiheader', 'dpi.h', '-access', 'r', '-timescale', '1ns/10ps'],
'vsim': ['-sv_root', LIB_DIR, '-sv_lib', 'dpi_amba3.so'],
'files': []
},
'worklib.tb_amba3_apb:module': {
'module': 'worklib.tb_amba3_apb',
'files': [os.path.join(TB_AMBA_DIR, 'tb_amba3_apb.sv')],
'args': ['+testname=tb_amba3_apb']
},
'worklib.tb_amba3_axi:module': {
'module': 'worklib.tb_amba3_axi',
'files': [os.path.join(TB_AMBA_DIR, 'tb_amba3_axi.sv')],
'args': ['+testname=tb_amba3_axi']
}
}
def main():
if not os.path.exists(LIB_DIR):
os.makedirs(LIB_DIR)
if not os.path.exists(TEST_DIR):
os.makedirs(TEST_DIR)
os.chdir(TEST_DIR)
with open('hdl.var', 'wt') as f:
f.write('DEFINE WORK worklib\n')
with open('cds.lib', 'wt') as f:
f.write('INCLUDE $CDS_INST_DIR/tools/inca/files/cds.lib\n')
f.write('DEFINE worklib %s\n' % os.path.join(LIB_DIR, 'worklib'))
f.write('DEFINE ambalib %s\n' % os.path.join(LIB_DIR, 'ambalib'))
args = parse_args(*(sys.argv[1:] if len(sys.argv) > 1 else ['-h']))
arguments = []
for (k, v) in args.items():
if type(v) == bool:
arguments += ['+' + k]
if type(v) in (int, str):
arguments += ['+' + k + '=' + str(v)]
test(test_vectors['worklib.tb_amba3_apb:module'], arguments)
test(test_vectors['worklib.tb_amba3_axi:module'], arguments)
def parse_args(*largs):
parser = ArgumentParser(prog='test.py', description='amba3 test', epilog='')
parser.add_argument('-v', '--verbose', help='verbose',
dest='verbose', action='store_true', default=False)
parser.add_argument('-m', '--monitor', help='monitor',
dest='monitor', action='store_true', default=False)
parser.add_argument('-w', '--waveform', help='waveform',
dest='waveform', action='store_true', default=False)
parser.add_argument('-u', '--unittest', help='unit test count',
dest='unittest', action='store', type=int, default=0)
args = parser.parse_args(args=largs)
return vars(args)
def test(sets, args=[]):
vlog(sets, args)
vlib(sets, args)
vsim(sets, args)
def vlog(sets, args=[]):
files = test_vectors['options']['files'] + sets.get('files', [])
options = test_vectors['options']['vlog']
subprocess.call([VLOG] + NCFLAGS + options + files)
def vlib(sets, args=[]):
module = [sets.get('module') + ':module']
options = test_vectors['options']['vlib']
subprocess.call([VLIB] + NCFLAGS + options + module)
def vsim(sets, args=[]):
module = [sets.get('module') + ':module']
options = test_vectors['options']['vsim'] + args
subprocess.call([VSIM] + NCFLAGS + options + module)
if __name__ == '__main__':
sys.exit(main())