Skip to content

Commit

Permalink
load system test directories dynamically based on paths in config_fil…
Browse files Browse the repository at this point in the history
…es.xml
  • Loading branch information
jedwards4b committed Jul 28, 2016
1 parent b28ddff commit 503d5ad
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 125 deletions.
11 changes: 11 additions & 0 deletions cime_config/cesm/config_files.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
<desc>file containing specification of all pe-layouts for primary component (for documentation only - DO NOT EDIT)</desc>
</entry>

<entry id="SYSTEM_TESTS_DIR">
<type>char</type>
<values>
<value component="any">$CIMEROOT/utils/python/CIME/SystemTests</value>
<value component="clm">$SRCROOT/components/clm/cime_config/SystemTests</value>
</values>
<group>test</group>
<file>env_test.xml</file>
<desc>directories containing cime compatible system test modules</desc>
</entry>

<entry id="TESTS_SPEC_FILE">
<type>char</type>
<default_value>unset</default_value>
Expand Down
6 changes: 3 additions & 3 deletions cime_config/cesm/machines/config_machines.xml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@

<modules compiler="cray">
<command name="load">PrgEnv-cray</command>
<command name="switch">cce cce/8.5.0</command>
<command name="switch">cce cce/8.5.1</command>
</modules>
<modules compiler="gnu">
<command name="load">PrgEnv-gnu</command>
Expand Down Expand Up @@ -468,7 +468,7 @@
<COMPILERS>intel,gnu,cray</COMPILERS>
<NODENAME_REGEX>edison</NODENAME_REGEX>
<MPILIBS>mpt,mpi-serial</MPILIBS>
<CESMSCRATCHROOT>$ENV{SCRATCH}</CESMSCRATCHROOT>
<CESMSCRATCHROOT>$ENV{CSCRATCH}</CESMSCRATCHROOT>
<RUNDIR>$CESMSCRATCHROOT/$CASE/run</RUNDIR>
<EXEROOT>$CESMSCRATCHROOT/$CASE/bld</EXEROOT>
<DIN_LOC_ROOT>/project/projectdirs/ccsm1/inputdata</DIN_LOC_ROOT>
Expand Down Expand Up @@ -534,7 +534,7 @@
</modules>
<modules compiler="cray">
<command name="load">PrgEnv-cray</command>
<command name="switch">cce cce/8.4.3</command>
<command name="switch">cce cce/8.5.1</command>
</modules>
<modules compiler="gnu">
<command name="load">PrgEnv-gnu</command>
Expand Down
24 changes: 3 additions & 21 deletions scripts/Tools/case.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,10 @@ Script to build a case.
"""

from standard_script_setup import *
from CIME.SystemTests.eri import ERI
from CIME.SystemTests.erp import ERP
from CIME.SystemTests.err import ERR
from CIME.SystemTests.ers import ERS
from CIME.SystemTests.lii import LII
from CIME.SystemTests.nck import NCK
from CIME.SystemTests.ncr import NCR
from CIME.SystemTests.noc import NOC
from CIME.SystemTests.pea import PEA
from CIME.SystemTests.pem import PEM
from CIME.SystemTests.pet import PET
from CIME.SystemTests.pfs import PFS
from CIME.SystemTests.seq import SEQ
from CIME.SystemTests.sms import SMS
from CIME.SystemTests.ssp import SSP
from CIME.SystemTests.system_tests_common import *

import CIME.build as build
from CIME.case import Case
from CIME.utils import expect, append_status
from CIME.utils import expect, append_status, find_system_test
from CIME.XML.files import Files
from CIME.XML.component import Component

Expand Down Expand Up @@ -100,10 +84,8 @@ def _main_func(description):
elif(testname is not None):
logging.warn("Building test for %s in directory %s" %
(testname, caseroot))
try:
test = globals()[testname](case)
except KeyError:
expect(False, "Could not find a test called '%s'" % testname)
test = find_system_test(testname, case)(case)

append_status("case.testbuild starting ",
caseroot=caseroot,sfile="CaseStatus")
test.build(sharedlib_only=sharedlib_only, model_only=model_only)
Expand Down
82 changes: 0 additions & 82 deletions utils/python/CIME/SystemTests/lii.py

This file was deleted.

12 changes: 12 additions & 0 deletions utils/python/CIME/XML/env_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ def run_phase_get_clone_name(self, phase):
return node.attrib["clone"]
return None

def cleanupnode(self, node):
'''
keep the values component set
'''
fnode = node.find(".//file")
node.remove(fnode)
gnode = node.find(".//group")
node.remove(gnode)
dnode = node.find(".//default_value")
if dnode is not None:
node.remove(dnode)
return node
21 changes: 2 additions & 19 deletions utils/python/CIME/case_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,7 @@
Run a testcase.
"""

from CIME.utils import expect

from CIME.SystemTests.eri import ERI # pylint: disable=unused-import
from CIME.SystemTests.err import ERR # pylint: disable=unused-import
from CIME.SystemTests.erp import ERP # pylint: disable=unused-import
from CIME.SystemTests.ers import ERS # pylint: disable=unused-import
from CIME.SystemTests.ert import ERT # pylint: disable=unused-import
from CIME.SystemTests.lii import LII # pylint: disable=unused-import
from CIME.SystemTests.nck import NCK # pylint: disable=unused-import
from CIME.SystemTests.pea import PEA # pylint: disable=unused-import
from CIME.SystemTests.pem import PEM # pylint: disable=unused-import
from CIME.SystemTests.pet import PET # pylint: disable=unused-import
from CIME.SystemTests.pfs import PFS # pylint: disable=unused-import
from CIME.SystemTests.sms import SMS # pylint: disable=unused-import
from CIME.SystemTests.seq import SEQ # pylint: disable=unused-import
from CIME.SystemTests.ssp import SSP # pylint: disable=unused-import

from CIME.utils import expect, find_system_test
from CIME.SystemTests.system_tests_common import *

def case_test(case, testname=None):
Expand All @@ -29,8 +13,7 @@ def case_test(case, testname=None):
logging.warn("Running test for %s" % testname)

try:
test = globals()[testname](case)

test = find_system_test(testname, case)(case)
success = test.run()

test.report()
Expand Down
1 change: 1 addition & 0 deletions utils/python/CIME/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ def _xml_phase(self, test):
files = Files()
drv_config_file = files.get_value("CONFIG_DRV_FILE")
drv_comp = Component(drv_config_file)
envtest.add_elements_by_group(files, {}, "env_test.xml")
envtest.add_elements_by_group(drv_comp, {}, "env_test.xml")
envtest.set_value("TESTCASE", test_case)
envtest.set_value("TEST_TESTID", self._test_id)
Expand Down
47 changes: 47 additions & 0 deletions utils/python/CIME/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Warning: you cannot use CIME Classes in this module as it causes circular dependencies
"""
import logging, gzip, sys, os, time, re, shutil
from importlib import import_module

# Return this error code if the scripts worked but tests failed
TESTS_FAILED_ERR_CODE = 100
Expand Down Expand Up @@ -872,3 +873,49 @@ def touch(fname):
os.utime(fname, None)
else:
open(fname, 'a').close()

def find_system_test(testname, case):
'''
Find and import the test matching testname
Look through the paths set in config_files.xml variable SYSTEM_TESTS_DIR
for components used in this case to find a test matching testname. Add the
path to that directory to sys.path if its not there and return the test object
Fail if the test is not found in any of the paths.
'''
system_test_path = None
if testname in ("TESTRUNPASS", "TESTRUNDIFF", "TESTRUNFAIL", "TESTBUILDFAIL",
"TESTRUNSLOWPASS", "TESTMEMLEAKFAIL", "TESTMEMLEAKPASS"):
system_test_path = "CIME.SystemTests.system_tests_common.%s"%(testname)
else:
components = ["any"]
components.extend( case.get_compset_components())
env_test = case.get_env("test")
for component in components:
tdir = env_test.get_value("SYSTEM_TESTS_DIR",
attribute={"component":component})

if tdir is not None:
tdir = os.path.abspath(tdir)
system_test_file = os.path.join(tdir ,"%s.py"%testname.lower())
if os.path.isfile(system_test_file):
logger.debug( "found "+system_test_file)
if component == "any":
system_test_path = "CIME.SystemTests.%s.%s"%(testname.lower(),testname)
else:
system_test_dir = os.path.dirname(system_test_file)
if system_test_dir not in sys.path:
sys.path.append(system_test_dir)
system_test_path = "%s.%s"%(testname.lower(),testname)
break

expect(system_test_path is not None, "No test %s found"%testname)

path, m = system_test_path.rsplit('.',1)
mod = import_module(path)
return getattr(mod, m)






0 comments on commit 503d5ad

Please sign in to comment.