test/gen_config: review/cleanup.
This commit is contained in:
parent
2bb8f8fd22
commit
265e79f2aa
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
@ -9,96 +9,97 @@ import itertools
|
||||||
|
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
'--sdram-module': [
|
"--sdram-module": [
|
||||||
'IS42S16160',
|
"IS42S16160",
|
||||||
'IS42S16320',
|
"IS42S16320",
|
||||||
'MT48LC4M16',
|
"MT48LC4M16",
|
||||||
'MT48LC16M16',
|
"MT48LC16M16",
|
||||||
'AS4C16M16',
|
"AS4C16M16",
|
||||||
'AS4C32M16',
|
"AS4C32M16",
|
||||||
'AS4C32M8',
|
"AS4C32M8",
|
||||||
'M12L64322A',
|
"M12L64322A",
|
||||||
'M12L16161A',
|
"M12L16161A",
|
||||||
'MT46V32M16',
|
"MT46V32M16",
|
||||||
'MT46H32M16',
|
"MT46H32M16",
|
||||||
'MT46H32M32',
|
"MT46H32M32",
|
||||||
'MT47H128M8',
|
"MT47H128M8",
|
||||||
'MT47H32M16',
|
"MT47H32M16",
|
||||||
'MT47H64M16',
|
"MT47H64M16",
|
||||||
'P3R1GE4JGF',
|
"P3R1GE4JGF",
|
||||||
'MT41K64M16',
|
"MT41K64M16",
|
||||||
'MT41J128M16',
|
"MT41J128M16",
|
||||||
'MT41K128M16',
|
"MT41K128M16",
|
||||||
'MT41J256M16',
|
"MT41J256M16",
|
||||||
'MT41K256M16',
|
"MT41K256M16",
|
||||||
'K4B1G0446F',
|
"K4B1G0446F",
|
||||||
'K4B2G1646F',
|
"K4B2G1646F",
|
||||||
'H5TC4G63CFR',
|
"H5TC4G63CFR",
|
||||||
'IS43TR16128B',
|
"IS43TR16128B",
|
||||||
'MT8JTF12864',
|
"MT8JTF12864",
|
||||||
'MT8KTF51264',
|
"MT8KTF51264",
|
||||||
# 'MT18KSF1G72HZ',
|
#"MT18KSF1G72HZ",
|
||||||
# 'AS4C256M16D3A',
|
#"AS4C256M16D3A",
|
||||||
# 'MT16KTF1G64HZ',
|
#"MT16KTF1G64HZ",
|
||||||
# 'EDY4016A',
|
#"EDY4016A",
|
||||||
# 'MT40A1G8',
|
#"MT40A1G8",
|
||||||
# 'MT40A512M16',
|
#"MT40A512M16",
|
||||||
],
|
],
|
||||||
'--sdram-data-width': [32],
|
"--sdram-data-width": [32],
|
||||||
'--bist-alternating': [True, False],
|
"--bist-alternating": [True, False],
|
||||||
'--bist-length': [1, 4096],
|
"--bist-length": [1, 4096],
|
||||||
'--bist-random': [True, False],
|
"--bist-random": [True, False],
|
||||||
'--num-generators': [1],
|
"--num-generators": [1],
|
||||||
'--num-checkers': [1],
|
"--num-checkers": [1],
|
||||||
'--access-pattern': ['access_pattern.csv']
|
"--access-pattern": ["access_pattern.csv"]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def convert_string_arg(args, arg, type):
|
def convert_string_arg(args, arg, type):
|
||||||
map_func = {
|
map_func = {
|
||||||
bool: lambda s: {'false': False, 'true': True}[s.lower()],
|
bool: lambda s: {"false": False, "true": True}[s.lower()],
|
||||||
int: lambda s: int(s, 0),
|
int: lambda s: int(s, 0),
|
||||||
}
|
}
|
||||||
setattr(args, arg, [map_func[type](val) if not isinstance(val, type) else val for val in getattr(args, arg)])
|
setattr(args, arg, [map_func[type](val) if not isinstance(val, type) else val for val in getattr(args, arg)])
|
||||||
|
|
||||||
|
|
||||||
def generate_header(args):
|
def generate_header(args):
|
||||||
header = 'Auto-generated on {} by {}'.format(
|
header = "Auto-generated on {} by {}".format(
|
||||||
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
sys.argv[0],
|
sys.argv[0],
|
||||||
)
|
)
|
||||||
args_str = pprint.pformat(vars(args), sort_dicts=False)
|
#args_str = pprint.pformat(vars(args), sort_dicts=False) # FIXME: python3.7 specific?
|
||||||
arg_lines = args_str.split('\n')
|
args_str = pprint.pformat(vars(args))
|
||||||
lines = [60*'=', header, 60*'-', *arg_lines, 60*'=']
|
arg_lines = args_str.split("\n")
|
||||||
return '\n'.join('# ' + line for line in lines)
|
lines = [60*"=", header, 60*"-", *arg_lines, 60*"="]
|
||||||
|
return "\n".join("# " + line for line in lines)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description='Generate configuration for all possible argument combinations.',
|
parser = argparse.ArgumentParser(description="Generate configuration for all possible argument combinations.",
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
parser.add_argument('--name-format', default='test_%d', help='Name format for i-th test')
|
parser.add_argument("--name-format", default="test_%d", help="Name format for i-th test")
|
||||||
for name, default in defaults.items():
|
for name, default in defaults.items():
|
||||||
parser.add_argument(name, nargs='+', default=default, help='%s options' % name)
|
parser.add_argument(name, nargs="+", default=default, help="%s options" % name)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# make sure not to write those as strings
|
# Make sure not to write those as strings
|
||||||
convert_string_arg(args, 'sdram_data_width', int)
|
convert_string_arg(args, "sdram_data_width", int)
|
||||||
convert_string_arg(args, 'bist_alternating', bool)
|
convert_string_arg(args, "bist_alternating", bool)
|
||||||
convert_string_arg(args, 'bist_length', int)
|
convert_string_arg(args, "bist_length", int)
|
||||||
convert_string_arg(args, 'bist_random', bool)
|
convert_string_arg(args, "bist_random", bool)
|
||||||
convert_string_arg(args, 'num_generators', int)
|
convert_string_arg(args, "num_generators", int)
|
||||||
convert_string_arg(args, 'num_checkers', int)
|
convert_string_arg(args, "num_checkers", int)
|
||||||
|
|
||||||
common_args = ('sdram_module', 'sdram_data_width', 'bist_alternating', 'num_generators', 'num_checkers')
|
common_args = ("sdram_module", "sdram_data_width", "bist_alternating", "num_generators", "num_checkers")
|
||||||
generated_pattern_args = ('bist_length', 'bist_random')
|
generated_pattern_args = ("bist_length", "bist_random")
|
||||||
custom_pattern_args = ('access_pattern', )
|
custom_pattern_args = ("access_pattern", )
|
||||||
|
|
||||||
def generated_pattern_configuration(values):
|
def generated_pattern_configuration(values):
|
||||||
config = dict(zip(common_args + generated_pattern_args, values))
|
config = dict(zip(common_args + generated_pattern_args, values))
|
||||||
# move access pattern parameters deeper
|
# Move access pattern parameters deeper
|
||||||
config['access_pattern'] = {
|
config["access_pattern"] = {
|
||||||
'bist_length': config.pop('bist_length'),
|
"bist_length": config.pop("bist_length"),
|
||||||
'bist_random': config.pop('bist_random'),
|
"bist_random": config.pop("bist_random"),
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -106,12 +107,12 @@ def main():
|
||||||
config = dict(zip(common_args + custom_pattern_args, values))
|
config = dict(zip(common_args + custom_pattern_args, values))
|
||||||
# "rename" --access-pattern to access_pattern.pattern_file due to name difference between
|
# "rename" --access-pattern to access_pattern.pattern_file due to name difference between
|
||||||
# command line args and run_benchmarks.py configuration format
|
# command line args and run_benchmarks.py configuration format
|
||||||
config['access_pattern'] = {
|
config["access_pattern"] = {
|
||||||
'pattern_file': config.pop('access_pattern'),
|
"pattern_file": config.pop("access_pattern"),
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
|
|
||||||
# iterator over the product of given command line arguments
|
# Iterator over the product of given command line arguments
|
||||||
def args_product(names):
|
def args_product(names):
|
||||||
return itertools.product(*(getattr(args, name) for name in names))
|
return itertools.product(*(getattr(args, name) for name in names))
|
||||||
|
|
||||||
|
@ -122,8 +123,8 @@ def main():
|
||||||
configurations = {}
|
configurations = {}
|
||||||
for config_generator, values in itertools.chain(generated_pattern_iter, custom_pattern_iter):
|
for config_generator, values in itertools.chain(generated_pattern_iter, custom_pattern_iter):
|
||||||
config = config_generator(values)
|
config = config_generator(values)
|
||||||
# ignore unsupported case: bist_random=True and bist_alternating=False
|
# Ignore unsupported case: bist_random=True and bist_alternating=False
|
||||||
if config['access_pattern'].get('bist_random', False) and not config['bist_alternating']:
|
if config["access_pattern"].get("bist_random", False) and not config["bist_alternating"]:
|
||||||
continue
|
continue
|
||||||
configurations[args.name_format % i] = config
|
configurations[args.name_format % i] = config
|
||||||
i += 1
|
i += 1
|
||||||
|
|
Loading…
Reference in New Issue