Skip to content

Commit

Permalink
Complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfouca committed Aug 7, 2016
1 parent ba69385 commit 622b7d0
Show file tree
Hide file tree
Showing 28 changed files with 190 additions and 548 deletions.
180 changes: 4 additions & 176 deletions scripts/Tools/bless_test_results
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ with versions of the files that you should not bless.

from standard_script_setup import *

import wait_for_tests, compare_namelists, simple_compare
from CIME.test_scheduler import NAMELIST_PHASE
from CIME.utils import run_cmd, run_cmd_no_fail, expect
from CIME.utils import expect
from CIME.XML.machines import Machines
from CIME.bless_test_results import bless_test_results

import argparse, sys, os, glob, doctest, time
import argparse, sys, os, doctest

_MACHINE = Machines()

Expand Down Expand Up @@ -94,177 +93,6 @@ formatter_class=argparse.ArgumentDefaultsHelpFormatter

return args.baseline_name, args.test_root, args.compiler, args.test_id, args.namelists_only, args.hist_only, args.report_only, args.force, args.bless_tests

###############################################################################
def bless_namelists(test_name, baseline_dir_for_test, testcase_dir_for_test, report_only, force):
###############################################################################
namelist_files = []

for root, _, files in os.walk(baseline_dir_for_test):
if (root == baseline_dir_for_test):
rel_root = ""
else:
rel_root = root.replace("%s/" % baseline_dir_for_test, "")

for file_ in files:
rel_file = os.path.join(rel_root, file_)

baseline_file = os.path.join(baseline_dir_for_test, rel_file)
testcase_file = os.path.join(testcase_dir_for_test, rel_file)

if (os.path.isfile(testcase_file) and (rel_root == "CaseDocs" or file_.startswith("user_nl"))):
if (compare_namelists.is_namelist_file(baseline_file)):
if (not compare_namelists.compare_namelist_files(baseline_file, testcase_file, test_name)):
print "Namelist files '%s' and '%s' did not match" % (baseline_file, testcase_file)
print
if (not report_only and
(force or raw_input("Update this file (y/n)? ").upper() in ["Y", "YES"])):
namelist_files.append((rel_file, rel_file))
else:
if (not simple_compare.compare_files(baseline_file, testcase_file, test_name)):
print "Simple files '%s' and '%s' did not match" % (baseline_file, testcase_file)
print
if (not report_only and
(force or raw_input("Update this file (y/n)? ").upper() in ["Y", "YES"])):
namelist_files.append((rel_file, rel_file))

# Update namelist files
if (namelist_files):
CIME.utils.safe_copy(testcase_dir_for_test, baseline_dir_for_test, namelist_files)

###############################################################################
def bless_history(test_name, baseline_tag, baseline_dir_for_test, testcase_dir_for_test, report_only, force):
###############################################################################
# Get user that test was run as (affects loc of hist files)
acme_root = run_cmd_no_fail("./xmlquery CESMSCRATCHROOT -value", from_dir=testcase_dir_for_test)

case = os.path.basename(testcase_dir_for_test)
cime_root = CIME.utils.get_cime_root()
compgen = os.path.join(cime_root, "scripts", "Tools", "component_compgen_baseline.sh")
machine_env = os.path.join(testcase_dir_for_test, ".env_mach_specific.sh")
run_dir = os.path.join(acme_root, case, "run")
cprnc_loc = _MACHINE.get_value("CCSM_CPRNC")
compgen_cmd = "source %s && %s -baseline_dir %s -testcase %s -testcase_base %s -test_dir %s -cprnc_exe %s -generate_tag %s" % \
(machine_env, compgen, baseline_dir_for_test, case, test_name, run_dir, cprnc_loc, baseline_tag)

check_compare = os.path.join(cime_root, "scripts", "Tools", "component_write_comparefail.pl")
stat, out, _ = run_cmd("%s %s 2>&1" % (check_compare, run_dir))

if (stat != 0):
# found diff, offer rebless
print out

if (not report_only and
(force or raw_input("Update this diff (y/n)? ").upper() in ["Y", "YES"])):
stat = run_cmd(compgen_cmd, verbose=True)[0]
if (stat != 0):
logging.warning("Hist file bless FAILED for test %s" % test_name)
return False, "Bless command failed"
else:
return True, None
else:
return True, None
else:
logging.warning("Test '%s' was marked as DIFF but cprnc did not find diff?" % test_name)
return False, "No diff found or missing baseline"

###############################################################################
def bless_test_results(baseline_name, test_root, compiler, test_id=None, namelists_only=False, hist_only=False, report_only=False, force=False, bless_tests=None):
###############################################################################
test_id_glob = "*%s*%s*" % (compiler, baseline_name) if test_id is None else "*%s" % test_id
test_status_files = glob.glob("%s/%s/TestStatus" % (test_root, test_id_glob))
expect(test_status_files, "No matching test cases found in for %s/%s/TestStatus" % (test_root, test_id_glob))

baseline_root = _MACHINE.get_value("CCSM_BASELINE")
baseline_tag = os.path.join(compiler, baseline_name)
baseline_area = os.path.join(baseline_root, baseline_tag)

# The env_mach_specific script may need these to be defined
compiler = _MACHINE.get_default_compiler() # this MUST match compiler that cprnc was built with
os.environ["COMPILER"] = compiler
os.environ["MPILIB"] = _MACHINE.get_default_MPIlib(attributes={"compiler":compiler})

broken_blesses = []
for test_status_file in test_status_files:
test_result, test_name = wait_for_tests.parse_test_status_file(test_status_file)
if (bless_tests in [[], None] or CIME.utils.match_any(test_name, bless_tests)):
overall_result = wait_for_tests.reduce_stati(test_result)

# Compute namelists status, False implies it diffed
if (not hist_only):
if (NAMELIST_PHASE in test_result):
nl_no_bless = test_result[NAMELIST_PHASE] == wait_for_tests.TEST_PASS_STATUS
else:
logging.warning("Test '%s' did not make it to namelist phase" % test_name)
broken_blesses.append((test_name, "no namelist phase"))
nl_no_bless = True
else:
nl_no_bless = True

# Compute hist status, False implies it diffed
if (not namelists_only):
if (wait_for_tests.RUN_PHASE not in test_result):
broken_blesses.append((test_name, "no run phase"))
logging.warning("Test '%s' did not make it to run phase" % test_name)
hist_no_bless = True
elif (test_result[wait_for_tests.RUN_PHASE] == wait_for_tests.TEST_PASS_STATUS):
if (wait_for_tests.HIST_COMPARE_PHASE not in test_result):
broken_blesses.append((test_name, "no history compare performed"))
logging.warning("Test '%s' had no history compare phase" % test_name)
hist_no_bless = True
else:
hist_no_bless = test_result[wait_for_tests.HIST_COMPARE_PHASE] == wait_for_tests.TEST_PASS_STATUS
else:
broken_blesses.append((test_name, "test did not pass"))
logging.warning("Test '%s' did not pass, not safe to bless" % test_name)
hist_no_bless = True
else:
hist_no_bless = True

# Now, do the bless
if ( (nl_no_bless and hist_no_bless) or (nl_no_bless and namelists_only) or (hist_no_bless and hist_only) ):
print "Nothing to bless for test:", test_name, " overall status:", overall_result
else:

print "###############################################################################"
print "Blessing results for test:", test_name, "most recent result:", overall_result
print "###############################################################################"
time.sleep(2)

# Get baseline dir for this test
baseline_dir_for_test = os.path.join(baseline_area, test_name)
if (not os.path.isdir(baseline_dir_for_test)):
logging.warning("Problem, baseline dir '%s' does not exist" % baseline_dir_for_test)
broken_blesses.append((test_name, "missing baseline dir"))
continue

# Get testcase dir for this test
if (test_id is None):
# The full name already contains the compiler, so we just need to glob for the branch name
globs = glob.glob("%s/%s*%s*" % (test_root, test_name, baseline_name))
else:
globs = glob.glob("%s/%s%s" % (test_root, test_name, test_id_glob))

if (len(globs) != 1):
logging.warning("Expected exactly one match for testcase area for test '%s', found '%s'" % (test_name, globs))
broken_blesses.append((test_name, "multiple matching testcase dirs"))
continue

testcase_dir_for_test = globs[0]

# Bless namelists
if (not nl_no_bless):
bless_namelists(test_name, baseline_dir_for_test, testcase_dir_for_test, report_only, force)

# Bless hist files
if (not hist_no_bless):
success, reason = bless_history(test_name, baseline_tag, baseline_dir_for_test, testcase_dir_for_test, report_only, force)
if (not success):
broken_blesses.append((test_name, reason))

# Make sure user knows that some tests were not blessed
for broken_bless, reason in broken_blesses:
logging.warning("FAILED TO BLESS TEST: %s, reason %s" % (broken_bless, reason))

###############################################################################
def _main_func(description):
###############################################################################
Expand All @@ -275,7 +103,7 @@ def _main_func(description):
baseline_name, test_root, compiler, test_id, namelists_only, hist_only, report_only, force, bless_tests = \
parse_command_line(sys.argv, description)

bless_test_results(baseline_name, test_root, compiler, test_id, namelists_only, hist_only, report_only, force, bless_tests)
CIME.bless_test_results.bless_test_results(baseline_name, test_root, compiler, test_id, namelists_only, hist_only, report_only, force, bless_tests)

###############################################################################

Expand Down
3 changes: 1 addition & 2 deletions scripts/Tools/case.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ def _main_func(description):

append_status("case.testbuild starting ",
caseroot=caseroot,sfile="CaseStatus")
with test:
test.build(sharedlib_only=sharedlib_only, model_only=model_only)
test.build(sharedlib_only=sharedlib_only, model_only=model_only)
append_status("case.testbuild complete",
caseroot=caseroot,sfile="CaseStatus")
else:
Expand Down
1 change: 0 additions & 1 deletion scripts/Tools/case.submit
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ OR

parser.add_argument("--resubmit", action="store_true",
help="Used with tests only, to continue rather than restart a test. ")


args = parser.parse_args(args[1:])

Expand Down
4 changes: 2 additions & 2 deletions scripts/Tools/code_checker
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def run_pylint(on_file):
cmd = "%s --disable I,C,R,logging-not-lazy,wildcard-import,unused-wildcard-import,fixme,broad-except,bare-except,eval-used,exec-used,global-statement %s" % (pylint, on_file)
stat, out, err = run_cmd(cmd)
if stat != 0:
sys.stdout.write("File %s has pylint problems, please fix\n Use command: %s\n%s\n %s\n %s\n" % (on_file, cmd, stat, out, err))
logging.info("File %s has pylint problems, please fix\n Use command: %s" % (on_file, cmd))
return False
else:
sys.stdout.write("File %s has no pylint problems\n" % on_file)
logging.info("File %s has no pylint problems" % on_file)
return True

###############################################################################
Expand Down
4 changes: 2 additions & 2 deletions scripts/Tools/compare_namelists
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ to not be sensitive to order or whitespace.
"""

from standard_script_setup import *
import compare_namelists
import CIME.compare_namelists
from CIME.utils import expect

import argparse, sys, os
Expand Down Expand Up @@ -65,7 +65,7 @@ def _main_func(description):
else:
logging.info("Using case: '%s'" % case)

expect(compare_namelists.compare_namelist_files(gold_file, compare_file, case),
expect(CIME.compare_namelists.compare_namelist_files(gold_file, compare_file, case),
"Namelist diff between files %s and %s" % (gold_file, compare_file))

print "Files %s and %s MATCH" % (gold_file, compare_file)
Expand Down
9 changes: 5 additions & 4 deletions scripts/Tools/cs_status
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ no errors occured (not based on test statuses).
"""

from standard_script_setup import *
import wait_for_tests
import argparse, sys, os, logging
from CIME.utils import expect
from CIME.test_status import *

###############################################################################
def parse_command_line(args, description):
Expand Down Expand Up @@ -43,10 +43,11 @@ formatter_class=argparse.ArgumentDefaultsHelpFormatter
def cs_status(test_paths, model):
###############################################################################
for test_path in test_paths:
statuses, test_name = wait_for_tests.parse_test_status_file(test_path)
summary = wait_for_tests.reduce_stati(statuses)
ts = TestStatus(test_dir=os.path.dirname(test_path))
test_name = ts.get_name()
summary = ts.get_overall_test_status()
print "%s (Overall: %s), details:" % (test_name, summary)
for phase, status in statuses.iteritems():
for phase, status in ts:
print " %s %s" % (status, phase)

###############################################################################
Expand Down
Loading

0 comments on commit 622b7d0

Please sign in to comment.