test: fix problem with helper scripts being executed by `setup.py test`

This commit is contained in:
Jędrzej Boczar 2020-02-04 16:37:26 +01:00
parent fcd3d4ff6c
commit 7e0515c477
2 changed files with 48 additions and 40 deletions

View File

@ -3,28 +3,32 @@
import random import random
import argparse import argparse
desc = """ def main():
Generate random access pattern. desc = """
Each address in range [base, base+length) will be accessed only once, Generate random access pattern.
but in random order. This ensures that no data will be overwritten. Each address in range [base, base+length) will be accessed only once,
""" but in random order. This ensures that no data will be overwritten.
parser = argparse.ArgumentParser(description=desc) """
parser.add_argument('base', help='Base address') parser = argparse.ArgumentParser(description=desc)
parser.add_argument('length', help='Number of (address, data) pairs') parser.add_argument('base', help='Base address')
parser.add_argument('data_width', help='Width of data (used to determine max value)') parser.add_argument('length', help='Number of (address, data) pairs')
parser.add_argument('--seed', help='Use given random seed (int)') parser.add_argument('data_width', help='Width of data (used to determine max value)')
args = parser.parse_args() parser.add_argument('--seed', help='Use given random seed (int)')
args = parser.parse_args()
if args.seed: if args.seed:
random.seed(int(args.seed, 0)) random.seed(int(args.seed, 0))
base = int(args.base, 0) base = int(args.base, 0)
length = int(args.length, 0) length = int(args.length, 0)
data_width = int(args.data_width, 0) data_width = int(args.data_width, 0)
address = list(range(length)) address = list(range(length))
random.shuffle(address) random.shuffle(address)
data = [random.randrange(0, 2**data_width) for _ in range(length)] data = [random.randrange(0, 2**data_width) for _ in range(length)]
for a, d in zip(address, data): for a, d in zip(address, data):
print('0x{:08x},0x{:08x}'.format(a, d)) print('0x{:08x},0x{:08x}'.format(a, d))
if __name__ == "__main__":
main()

View File

@ -43,24 +43,28 @@ data_widths = [32]
bist_lengths = [1, 1024, 8192] bist_lengths = [1, 1024, 8192]
bist_randoms = [False] bist_randoms = [False]
parser = argparse.ArgumentParser(description='Generate configuration for all possible argument combinations.', def main():
formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser = argparse.ArgumentParser(description='Generate configuration for all possible argument combinations.',
parser.add_argument('--sdram-modules', nargs='+', default=modules, help='--sdram-module options') formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--sdram-data-widths', nargs='+', default=data_widths, help='--sdram-data-width options') parser.add_argument('--sdram-modules', nargs='+', default=modules, help='--sdram-module options')
parser.add_argument('--bist-lengths', nargs='+', default=bist_lengths, help='--bist-length options') parser.add_argument('--sdram-data-widths', nargs='+', default=data_widths, help='--sdram-data-width options')
parser.add_argument('--bist-randoms', nargs='+', default=bist_randoms, help='--bist-random options') parser.add_argument('--bist-lengths', nargs='+', default=bist_lengths, help='--bist-length options')
parser.add_argument('--name-format', default='test_%d', help='Name format for i-th test') parser.add_argument('--bist-randoms', nargs='+', default=bist_randoms, help='--bist-random options')
args = parser.parse_args() parser.add_argument('--name-format', default='test_%d', help='Name format for i-th test')
args = parser.parse_args()
product = itertools.product(args.sdram_modules, args.sdram_data_widths, args.bist_lengths, args.bist_randoms) product = itertools.product(args.sdram_modules, args.sdram_data_widths, args.bist_lengths, args.bist_randoms)
configurations = {} configurations = {}
for i, (module, data_width, bist_length, bist_random) in enumerate(product): for i, (module, data_width, bist_length, bist_random) in enumerate(product):
configurations[args.name_format % i] = { configurations[args.name_format % i] = {
'sdram_module': module, 'sdram_module': module,
'sdram_data_width': data_width, 'sdram_data_width': data_width,
'bist_length': bist_length, 'bist_length': bist_length,
'bist_random': bist_random, 'bist_random': bist_random,
} }
json_str = json.dumps(configurations, indent=4) json_str = json.dumps(configurations, indent=4)
print(json_str) print(json_str)
if __name__ == "__main__":
main()