Skip to content

Commit 8110020

Browse files
authored
Merge pull request #2244 from willend/main
Restore ability to "run version via config file" in mctest
2 parents f25d470 + 24809bb commit 8110020

1 file changed

Lines changed: 79 additions & 2 deletions

File tree

tools/Python/mctest/mctest.py

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,79 @@ def run_version_test(testdir, mccoderoot, limit, instrfilter, compfilter, versio
530530
logging.debug("Test results written to: %s" % reportfile)
531531

532532

533+
def run_config_test(testdir, mccoderoot, limit, configfilter, instrfilter, compfilter, suffix):
534+
'''
535+
Test a suite of configs, each a mccode_config_LABEL.py file, that is copied to the dist dir
536+
prior to starting the test. This action modifies the C-flags and the compiler used during
537+
the test. The original mccode_config.py file is restored after each test.
538+
'''
539+
540+
def activate_config(version, mccoderoot, configfile):
541+
''' activate a confige given by configfile, returns bckfile for use with deactivate_config '''
542+
libdir = join(mccoderoot, version, "tools", "Python", "mccodelib")
543+
os.rename(join(libdir, "mccode_config.py"), join(libdir, "mccode_config.py_BAK"))
544+
open(join(libdir, "mccode_config.py"), "w").write(open(configfile).read())
545+
return join(libdir, "mccode_config.py_BAK")
546+
547+
def deactivate_config(bckfile):
548+
''' use to restore changes made by activate_config '''
549+
restoreto = join(os.path.dirname(bckfile), "mccode_config.py")
550+
os.rename(bckfile, restoreto)
551+
552+
def extract_config_mccode_version(configfile):
553+
for l in open(configfile).read().splitlines():
554+
m = re.match(r"\s*\"MCCODE_VERSION\": (.+),", l)
555+
if m:
556+
return m.group(1).strip("\""), os.path.basename(os.path.dirname(configfile))
557+
558+
def get_config_files(configfltr):
559+
''' look in "__file__/../mccodelib/MCCODE-test" location or config files'''
560+
lookin = join(os.path.dirname(__file__), mccode_config.configuration["MCCODE"] + "-test")
561+
print("getting config files...")
562+
print(configfltr + " vs " + os.path.join(lookin,configfltr,'mccode_config.json'))
563+
if configfltr is not None and os.path.isfile(os.path.join(lookin,configfltr,'mccode_config.json')):
564+
print("returning " + os.path.join(lookin,configfltr,'mccode_config.json'))
565+
return [ os.path.join(lookin,configfltr,'mccode_config.json') ]
566+
for (_, _, files) in os.walk(lookin):
567+
print("Looking")
568+
if configfltr is not None:
569+
return [join(lookin, f) for f in files if re.search(r"^%s/mccode_config.json$" % configfltr, f)]
570+
else:
571+
return [join(lookin, f) for f in files if re.search(r"^mccode_config.json$", f)]
572+
573+
# get test directory datetime string
574+
datetime = utils.get_datetimestr()
575+
576+
# test labels loop
577+
for f in get_config_files(configfilter):
578+
[version,label] = extract_config_mccode_version(f)
579+
580+
oldpath = activate_mccode_version(version, mccoderoot)
581+
try:
582+
#bckfile = activate_config(version, mccoderoot, f)
583+
try:
584+
logging.info("")
585+
label0=label
586+
label=label+suffix+"_"+ncount
587+
logging.info("Testing label: %s" % label)
588+
589+
# craete the proper test dir
590+
labeldir = create_label_dir(testdir, label)
591+
results, failed = mccode_test(mccoderoot, labeldir, limit, instrfilter, compfilter, label0)
592+
593+
# write local test result
594+
reportfile = os.path.join(labeldir, "testresults_%s.json" % (os.path.basename(labeldir)))
595+
open(os.path.join(reportfile), "w").write(json.dumps(results, indent=2))
596+
597+
logging.debug("")
598+
logging.debug("Test results written to: %s" % reportfile)
599+
finally:
600+
pass
601+
finally:
602+
deactivate_mccode_version(oldpath)
603+
604+
605+
533606
ncount = None
534607
mpi = None
535608
openacc = None
@@ -542,6 +615,7 @@ def run_version_test(testdir, mccoderoot, limit, instrfilter, compfilter, versio
542615
def main(args):
543616
# mutually excusive main branches
544617
default = None # test system mccode version as-is
618+
configfilter = args.config # test only config matching this label
545619

546620
# modifying options
547621
verbose = args.verbose # display more info during runs
@@ -646,15 +720,18 @@ def main(args):
646720
permissive = True
647721
logging.info("Permissive mode, tool will not report failure on failed instruments")
648722

649-
run_default_test(testdir, mccoderoot, limit, instrfilter, compfilter, suffix)
650-
723+
if not configfilter:
724+
run_default_test(testdir, mccoderoot, limit, instrfilter, compfilter, suffix)
725+
else:
726+
run_config_test(testdir, mccoderoot, limit, configfilter, compfilter, instrfilter, suffix)
651727

652728
if __name__ == '__main__':
653729
parser = argparse.ArgumentParser(description=__doc__)
654730
parser.add_argument('--ncount', nargs=1, help='ncount sent to %s' % (mccode_config.configuration["MCRUN"]) )
655731
parser.add_argument('-n', nargs=1, help='ncount sent to %s' % (mccode_config.configuration["MCRUN"]) )
656732
parser.add_argument('--mpi', nargs=1, help='mpi nodecount sent to %s' % (mccode_config.configuration["MCRUN"]) )
657733
parser.add_argument('--openacc', action='store_true', help='openacc flag sent to %s' % (mccode_config.configuration["MCRUN"]))
734+
parser.add_argument('--config', nargs="?", help='test this specific config only - label name or absolute path')
658735
parser.add_argument('--instr', nargs="?", help='test only intruments matching this filter (py regex). Comma-separated list allowed for multiple filters.')
659736
parser.add_argument('--comp', nargs=1, help='test only intruments utilising COMP. Useful for testing the instrument suite after component changes.')
660737
parser.add_argument('--mccoderoot', nargs='?', help='manually select root search folder for mccode installations')

0 commit comments

Comments
 (0)