-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_tests.py
122 lines (108 loc) · 3.75 KB
/
generate_tests.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2020-2022 F4PGA Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
import os
import subprocess
import sys
import math
def mylog2(n):
val = 0
while round(math.pow(2, val)) < n:
val += 1
return val
def main():
topdir = "./testing/tests"
master = os.path.join(topdir, 'master')
widths_to_test = [1, 2, 4, 8, 9, 16, 18, 32, 36, 64, 72]
depths_to_test = [
('128', 128),
('256', 256),
('512', 512),
('1k', 1024),
('2k', 2048),
('4k', 2048 * 2),
('8k', 2048 * 4),
('16k', 2048 * 8),
('32k', 2048 * 16) #, ('64k', 2048 * 32), ('128k', 2048 * 64)
]
weird_widths_to_test = [
3, 6, 11, 17, 19, 25, 34, 37, 69, 100, 127, 130, 200
]
weird_depths_to_test = [
('1027', 1027),
('5k', 5000),
('7k', 7000),
('1050', 1050),
('36k', 1024 * 36),
('36k+20', 1024 * 36 + 20),
('72k', 1024 * 72),
# do more later
]
widths = widths_to_test
depths = depths_to_test
for wid in widths:
for depth_tup in depths:
depthname = depth_tup[0]
depth = depth_tup[1]
totalBits = int(wid) * depth
# Specific to the xc7a50t part we are using...
if totalBits > 2457600:
print(
"\n===========================\n*****************\nMemory too large: {}b{} = {}, skipping...\n******************"
.format(depthname, wid, totalBits)
)
continue
totalPins = 2 + 2 * mylog2(depth) + 2 * int(wid)
if totalPins > 250:
print(
"\n===========================\n*****************\nMemory has too many pins: {}b{} = {}, skipping...\n******************"
.format(depthname, wid, totalPins)
)
continue
# Actually generate the test case
doGenerate(False, master, wid, depthname, depth)
def doGenerate(force, master, wid, depthname, depth):
design = '{}b{}'.format(depthname, wid)
batchdir = os.path.join(master, design)
batchbit = os.path.join(batchdir, 'vivado/{}.bit'.format(design))
altfasm = os.path.join(batchdir, 'alt.fasm')
print("\n=============================\nDoing: " + batchbit)
if not force and os.path.isfile(altfasm):
print(' Design {} already generated, skipping...'.format(design))
else:
command = r'./testing/generate_tests_script.sh {} {} {} {}'.format(
master, wid, depthname, depth
)
print("Generating by calling: " + command, flush=True)
v = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
universal_newlines=True
)
stdout, stderr = v.communicate()
print(stdout, flush=True)
if stderr is not None:
print(stderr, flush=True)
if __name__ == "__main__":
# Generate a series of tests
if (len(sys.argv) == 1):
main()
else:
print("\n Usage:\n python generate_tests.py\n", file=sys.stderr)
exit(1)