diff --git a/test/gen_access_pattern.py b/test/gen_access_pattern.py index f6cd200..186dc1e 100755 --- a/test/gen_access_pattern.py +++ b/test/gen_access_pattern.py @@ -3,28 +3,32 @@ import random import argparse -desc = """ -Generate random access pattern. -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.add_argument('length', help='Number of (address, data) pairs') -parser.add_argument('data_width', help='Width of data (used to determine max value)') -parser.add_argument('--seed', help='Use given random seed (int)') -args = parser.parse_args() +def main(): + desc = """ + Generate random access pattern. + 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.add_argument('length', help='Number of (address, data) pairs') + parser.add_argument('data_width', help='Width of data (used to determine max value)') + parser.add_argument('--seed', help='Use given random seed (int)') + args = parser.parse_args() -if args.seed: - random.seed(int(args.seed, 0)) + if args.seed: + random.seed(int(args.seed, 0)) -base = int(args.base, 0) -length = int(args.length, 0) -data_width = int(args.data_width, 0) + base = int(args.base, 0) + length = int(args.length, 0) + data_width = int(args.data_width, 0) -address = list(range(length)) -random.shuffle(address) -data = [random.randrange(0, 2**data_width) for _ in range(length)] + address = list(range(length)) + random.shuffle(address) + data = [random.randrange(0, 2**data_width) for _ in range(length)] -for a, d in zip(address, data): - print('0x{:08x},0x{:08x}'.format(a, d)) + for a, d in zip(address, data): + print('0x{:08x},0x{:08x}'.format(a, d)) + +if __name__ == "__main__": + main() diff --git a/test/gen_config.py b/test/gen_config.py index a0b9188..298e774 100755 --- a/test/gen_config.py +++ b/test/gen_config.py @@ -43,24 +43,28 @@ data_widths = [32] bist_lengths = [1, 1024, 8192] bist_randoms = [False] -parser = argparse.ArgumentParser(description='Generate configuration for all possible argument combinations.', - formatter_class=argparse.ArgumentDefaultsHelpFormatter) -parser.add_argument('--sdram-modules', nargs='+', default=modules, help='--sdram-module options') -parser.add_argument('--sdram-data-widths', nargs='+', default=data_widths, help='--sdram-data-width options') -parser.add_argument('--bist-lengths', nargs='+', default=bist_lengths, help='--bist-length options') -parser.add_argument('--bist-randoms', nargs='+', default=bist_randoms, help='--bist-random options') -parser.add_argument('--name-format', default='test_%d', help='Name format for i-th test') -args = parser.parse_args() +def main(): + parser = argparse.ArgumentParser(description='Generate configuration for all possible argument combinations.', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser.add_argument('--sdram-modules', nargs='+', default=modules, help='--sdram-module options') + parser.add_argument('--sdram-data-widths', nargs='+', default=data_widths, help='--sdram-data-width options') + parser.add_argument('--bist-lengths', nargs='+', default=bist_lengths, help='--bist-length options') + parser.add_argument('--bist-randoms', nargs='+', default=bist_randoms, help='--bist-random options') + 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) -configurations = {} -for i, (module, data_width, bist_length, bist_random) in enumerate(product): - configurations[args.name_format % i] = { - 'sdram_module': module, - 'sdram_data_width': data_width, - 'bist_length': bist_length, - 'bist_random': bist_random, - } + product = itertools.product(args.sdram_modules, args.sdram_data_widths, args.bist_lengths, args.bist_randoms) + configurations = {} + for i, (module, data_width, bist_length, bist_random) in enumerate(product): + configurations[args.name_format % i] = { + 'sdram_module': module, + 'sdram_data_width': data_width, + 'bist_length': bist_length, + 'bist_random': bist_random, + } -json_str = json.dumps(configurations, indent=4) -print(json_str) + json_str = json.dumps(configurations, indent=4) + print(json_str) + +if __name__ == "__main__": + main()