blob: b79e0fdcef67140fd75164664952158268815307 [file] [log] [blame]
Tudor Timi2c270442019-12-23 19:14:29 +01001import os
Tudor Timi81be42d2019-12-23 19:17:57 +01002import pathlib
Tudor Timi8788ae42019-12-27 17:32:06 +01003import shutil
Tudor Timi2c270442019-12-23 19:14:29 +01004import subprocess
5
6
Tudor Timi81be42d2019-12-23 19:17:57 +01007def clean_paths(rm_paths):
8 for rm_path in rm_paths:
9 for p in pathlib.Path('.').glob(rm_path):
10 p.unlink()
11
12
Tudor Timi2c270442019-12-23 19:14:29 +010013def create_unit_test(name):
14 subprocess.check_call(['create_unit_test.pl', name])
15
16
Tudor Timi8788ae42019-12-27 17:32:06 +010017def get_simulators():
18 result = []
19
20 if shutil.which('irun'):
21 result.append('irun')
22 if shutil.which('vcs'):
23 result.append('vcs')
24 if shutil.which('vlog'):
25 result.append('modelsim')
26
27 assert result, 'None of irun, modelsim or vcs are in your path. You need at least 1 simulator to regress svunit-code!'
28
29 return result
30
31
32def get_svunit_root():
33 return os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
34
35
Tudor Timi2c270442019-12-23 19:14:29 +010036def golden_class_unit_test(FILE, MYNAME):
37 template = open('{}/test/templates/class_unit_test.gold'.format(os.environ['SVUNIT_INSTALL']))
38 with open('{}_unit_test.gold'.format(FILE), 'w') as output:
39 for line in template:
40 output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME))
41
Tudor Timi63b4c812019-12-25 16:34:31 +010042def golden_module_unit_test(FILE, MYNAME):
43 template = open('{}/test/templates/module_unit_test.gold'.format(os.environ['SVUNIT_INSTALL']))
44 with open('{}_unit_test.gold'.format(FILE), 'w') as output:
45 for line in template:
46 output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME))
47
Tudor Timi4b574fc2019-12-25 16:38:01 +010048def golden_if_unit_test(FILE, MYNAME):
49 template = open('{}/test/templates/if_unit_test.gold'.format(os.environ['SVUNIT_INSTALL']))
50 with open('{}_unit_test.gold'.format(FILE), 'w') as output:
51 for line in template:
52 output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME))
53
Tudor Timi2c270442019-12-23 19:14:29 +010054def golden_testsuite_with_1_unittest(MYNAME):
55 template = open('{}/test/templates/testsuite_with_1_unittest.gold'.format(os.environ['SVUNIT_INSTALL']))
56 with open('testsuite.gold', 'w') as output:
57 for line in template:
58 output.write(line.replace('MYNAME', MYNAME))
59
60def golden_testrunner_with_1_testsuite():
61 template = open('{}/test/templates/testrunner_with_1_testsuite.gold'.format(os.environ['SVUNIT_INSTALL']))
62 with open('testrunner.gold', 'w') as output:
63 for line in template:
64 output.write(line)
65
Tudor Timi8f95e9b2019-12-24 14:42:04 +010066def golden_testrunner_with_2_testsuites():
67 template = open('{}/test/templates/testrunner_with_2_testsuite.gold'.format(os.environ['SVUNIT_INSTALL']))
68 with open('testrunner.gold', 'w') as output:
69 for line in template:
70 output.write(line)
71
Tudor Timibd0006b2019-12-25 16:22:04 +010072def golden_testrunner_with_3_testsuites():
73 template = open('{}/test/templates/testrunner_with_3_testsuite.gold'.format(os.environ['SVUNIT_INSTALL']))
74 with open('testrunner.gold', 'w') as output:
75 for line in template:
76 output.write(line)
77
Tudor Timi02cc3c12019-12-25 11:15:45 +010078def golden_testrunner_with_4_testsuites():
79 template = open('{}/test/templates/testrunner_with_4_testsuite.gold'.format(os.environ['SVUNIT_INSTALL']))
80 with open('testrunner.gold', 'w') as output:
81 for line in template:
82 output.write(line)
83
Tudor Timi2c270442019-12-23 19:14:29 +010084
85def verify_file(file0, file1):
86 result = subprocess.run(['diff', '-wbB', file0, file1], stdout=subprocess.PIPE)
87 assert result.returncode in [0, 1]
88 if result.returncode == 1:
89 assert result.stdout == b''
90
Tudor Timi4c2bea72020-01-02 18:30:10 +010091def verify_testsuite(testsuite, dir=''):
Tudor Timi2c270442019-12-23 19:14:29 +010092 PWD = '_'
93 file = open(testsuite)
94 with open('.{}'.format(testsuite), 'w') as output:
95 for line in file:
96 output.write(line.replace('PWD', "{}{}".format(PWD, dir)))
97 verify_file(output.name, '.{}{}_testsuite.sv'.format(PWD, dir))
98
99def verify_testrunner(testrunner, ts0, ts1='', ts2='', ts3='', tr=''):
100 if tr == '':
101 tr = '.testrunner.sv'
102 file = open(testrunner)
103 with open('.{}'.format(testrunner), 'w') as output:
104 for line in file:
105 output.write(line.replace('TS0', ts0).replace('TS1', ts1).replace('TS2', ts2).replace('TS3', ts3))
106 verify_file(output.name, tr)