blob: 48bcd0164415566542f9987c682a8810813b9b86 [file] [log] [blame]
Tudor Timi2c270442019-12-23 19:14:29 +01001import os
Tudor Timi81be42d2019-12-23 19:17:57 +01002import pathlib
Tudor Timi2c270442019-12-23 19:14:29 +01003import subprocess
4
5
Tudor Timi81be42d2019-12-23 19:17:57 +01006def clean_paths(rm_paths):
7 for rm_path in rm_paths:
8 for p in pathlib.Path('.').glob(rm_path):
9 p.unlink()
10
11
Tudor Timi2c270442019-12-23 19:14:29 +010012def create_unit_test(name):
13 subprocess.check_call(['create_unit_test.pl', name])
14
15
16def golden_class_unit_test(FILE, MYNAME):
17 template = open('{}/test/templates/class_unit_test.gold'.format(os.environ['SVUNIT_INSTALL']))
18 with open('{}_unit_test.gold'.format(FILE), 'w') as output:
19 for line in template:
20 output.write(line.replace('FILE', FILE).replace('MYNAME', MYNAME))
21
Tudor Timi2c270442019-12-23 19:14:29 +010022def golden_testsuite_with_1_unittest(MYNAME):
23 template = open('{}/test/templates/testsuite_with_1_unittest.gold'.format(os.environ['SVUNIT_INSTALL']))
24 with open('testsuite.gold', 'w') as output:
25 for line in template:
26 output.write(line.replace('MYNAME', MYNAME))
27
28def golden_testrunner_with_1_testsuite():
29 template = open('{}/test/templates/testrunner_with_1_testsuite.gold'.format(os.environ['SVUNIT_INSTALL']))
30 with open('testrunner.gold', 'w') as output:
31 for line in template:
32 output.write(line)
33
34
35def verify_file(file0, file1):
36 result = subprocess.run(['diff', '-wbB', file0, file1], stdout=subprocess.PIPE)
37 assert result.returncode in [0, 1]
38 if result.returncode == 1:
39 assert result.stdout == b''
40
41def verify_testsute(testsuite, dir=''):
42 PWD = '_'
43 file = open(testsuite)
44 with open('.{}'.format(testsuite), 'w') as output:
45 for line in file:
46 output.write(line.replace('PWD', "{}{}".format(PWD, dir)))
47 verify_file(output.name, '.{}{}_testsuite.sv'.format(PWD, dir))
48
49def verify_testrunner(testrunner, ts0, ts1='', ts2='', ts3='', tr=''):
50 if tr == '':
51 tr = '.testrunner.sv'
52 file = open(testrunner)
53 with open('.{}'.format(testrunner), 'w') as output:
54 for line in file:
55 output.write(line.replace('TS0', ts0).replace('TS1', ts1).replace('TS2', ts2).replace('TS3', ts3))
56 verify_file(output.name, tr)