Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctest jjobs framework #310

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
987ae5b
added ctest dir with cmake to create an experment
Dec 6, 2024
61fcf83
added CMakeLists for creating initial case EXPDIR usint ctest
Dec 6, 2024
f5f6595
ready to test getting the job names
Dec 6, 2024
cbe3bab
move all operations of creating EXPDIR cases into configure phase
Dec 6, 2024
6a50e14
got cmake configure to work for EXPDIR
Dec 6, 2024
bcebeca
can not do both file and variable save for execute_process
Dec 6, 2024
be7a890
working cmake config up to output of job names
Dec 6, 2024
2811629
Merge branch 'NOAA-EMC:develop' into ctest_jjobs_framework
TerrenceMcGuinness-NOAA Dec 9, 2024
70a8183
loop over jobnames and create an experment for each
Dec 9, 2024
72e5a9c
update JOB name update in loop
Dec 9, 2024
1f1fcd6
addded debug outputs
Dec 9, 2024
ee27b02
modifying plslot list to be only on a per case
Dec 9, 2024
bc76ddf
filter pslot list for only relevent cases
Dec 9, 2024
38838a6
refining get_job_names
Dec 9, 2024
d18ad01
modigied get_jobs_names to task and metatask names
Dec 9, 2024
ef0e066
got better jobname parcer working
Dec 9, 2024
519a919
Merge branch 'NOAA-EMC:develop' into ctest_jjobs_framework
TerrenceMcGuinness-NOAA Dec 9, 2024
f813a1b
replaced generate_workflows with create_experment
Dec 10, 2024
8238228
removed non-existing ENVIRONMENT setting to consolated COMMAND line
Dec 10, 2024
bf579ee
got cmake script to use creat_experiment
Dec 10, 2024
28ef1af
Merge branch 'NOAA-EMC:develop' into ctest_jjobs_framework
TerrenceMcGuinness-NOAA Dec 12, 2024
374927f
just getting started with addeding a ctest
Dec 12, 2024
8b4fc4f
add in test for configured project
Dec 12, 2024
ce37d86
added ctest and testing
Dec 12, 2024
d4e3266
Merge branch 'NOAA-EMC:develop' into ctest_jjobs_framework
TerrenceMcGuinness-NOAA Dec 13, 2024
bb12cda
moved ctests dir to top HOMEgfs/ci/ctests with its own scripts dir
Dec 13, 2024
f78181c
added all jobs for tests for each case
Dec 13, 2024
46cddb7
added data stagging dependances and started it as a stub script
Dec 14, 2024
d6c3a49
Merge branch 'NOAA-EMC:develop' into ctest_jjobs_framework
TerrenceMcGuinness-NOAA Dec 16, 2024
434f869
added driver for creating ctests from yaml files
Dec 18, 2024
99df88d
added a driver to create ctests from defintions in yaml files
Dec 18, 2024
e186173
added final step to loop over yaml files for creating functiona ctest…
Dec 18, 2024
c4a2780
Merge branch 'NOAA-EMC:develop' into ctest_jjobs_framework
TerrenceMcGuinness-NOAA Dec 19, 2024
0183667
added second yaml case file for testing python driver
Dec 19, 2024
3088bff
added a few comments for each section
Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ci/ctests/C48_ATM.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fcst_gfs:
staged_datapath: {{ STAGED_FUNCTIONAL_TEST_DIR }}/{{ testcase }}/fcst_gfs
input_files: use_jinja_template_fcst
output_files: use_jinja_template_fcst

gfs_atmos_pro:
staged_datapath: {{ STAGED_FUNCTIONAL_TEST_DIR }}/{{ testcase }}/gfs_atmos_prod
input_files: use_jinja_template_gfs_atmos_pro
output_files: use_jinja_template_gfs_atmos_pro
9 changes: 9 additions & 0 deletions ci/ctests/C48_S2SW.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fcst_gfs:
staged_datapath: {{ STAGED_FUNCTIONAL_TEST_DIR }}/{{ testcase }}/fcst_gfs
input_files: use_jinja_template_fcst
output_files: use_jinja_template_fcst

gfs_atmos_pro:
staged_datapath: {{ STAGED_FUNCTIONAL_TEST_DIR }}/{{ testcase }}/gfs_atmos_prod
input_files: use_jinja_template_gfs_atmos_pro
output_files: use_jinja_template_gfs_atmos_pro
71 changes: 71 additions & 0 deletions ci/ctests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.10)

project(FunctionalTests)

enable_testing()

set(CMAKE_VERBOSE_MAKEFILE ON)

# Set environment variables and paths
set(ENV{RUNTESTS} "${CMAKE_BINARY_DIR}/RUNTESTS")
get_filename_component(HOMEgfs ${CMAKE_SOURCE_DIR}/../.. ABSOLUTE)
set(CASE_PATH ${HOMEgfs}/ci/cases/pr)
file(REMOVE_RECURSE ${CMAKE_BINARY_DIR}/RUNTESTS)

set(CREATE_EXPERIMENT_CMD "${HOMEgfs}/workflow/create_experiment.py --overwrite")

# Get the current git commit hash
message(STATUS "Executing: git rev-parse --short HEAD")
execute_process(
COMMAND git rev-parse --short HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Function to generate experiments for a given case
function(GenerateExperiments CASE)
# Read the job list file for this case
set(JOB_LIST_FILE "${CMAKE_BINARY_DIR}/${CASE}_jobs.txt")

if(EXISTS ${JOB_LIST_FILE})
file(STRINGS ${JOB_LIST_FILE} JOB_NAMES)
message(STATUS "Processing jobs from ${JOB_LIST_FILE}:\n${JOB_NAMES}")

foreach(JOB IN LISTS JOB_NAMES)
string(REGEX REPLACE "^${CASE}_" "" JOB_MODIFIED ${JOB})
message(STATUS "Executing: ${CREATE_EXPERIMENT_CMD} --yaml ${CASE_PATH}/${CASE}.yaml")
execute_process(
COMMAND bash -c "export pslot=${CASE}_${JOB_MODIFIED}_${GIT_HASH}; ${CREATE_EXPERIMENT_CMD} --yaml ${CASE_PATH}/${CASE}.yaml"
)
endforeach()
else()
message(WARNING "Job list file ${JOB_LIST_FILE} does not exist.")
endif()
endfunction()

# Function to add Rocoto boot test for a given case and job
function(AddRocotoBootTest CASE_NAME JOB_NAME)
add_test(NAME jjob_test_${CASE_NAME}_${JOB_NAME}_StageData
COMMAND bash -c "${HOMEgfs}/ci/ctests/scripts/stage_data.sh ${CASE_NAME} ${JOB_NAME} ${GIT_HASH}")
add_test(NAME jjob_test_${CASE_NAME}_${JOB_NAME}
COMMAND bash -c "rocotoboot -w RUNTESTS/EXPDIR/${CASE_NAME}_${GIT_HASH}/workflow.xml -d RUNTESTS/EXPDIR/${CASE_NAME}_${GIT_HASH}/workflow.db -t ${JOB_NAME}")
set_tests_properties(jjob_test_${CASE_NAME}_${JOB_NAME} PROPERTIES DEPENDS jjob_test_${CASE_NAME}_${JOB_NAME}_StageData)
endfunction()

# Add a test to build all components
add_test( NAME BuildAll
COMMAND bash -c "cd ${HOMEgfs}/sorc; ./build_all.sh"
)

# Split CASE_LIST into individual cases
string(REPLACE " " ";" CASE_LIST_SPLIT ${CASE_LIST})

# Loop over each case in CASE_LIST_SPLIT
foreach(CASE IN LISTS CASE_LIST_SPLIT)
GenerateExperiments(${CASE})
file(STRINGS ${CMAKE_BINARY_DIR}/${CASE}_jobs.txt JOB_NAMES)
foreach(JOB IN LISTS JOB_NAMES)
AddRocotoBootTest(${CASE} ${JOB})
endforeach()
endforeach()
79 changes: 79 additions & 0 deletions ci/ctests/create_functional_ctests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

import os, sys
import shutil
_here = os.path.dirname(__file__)
_top = os.path.abspath(os.path.join(os.path.abspath(_here), '../..'))
sys.path.insert(0, _top)

from argparse import ArgumentParser
from pathlib import Path
from wxflow import Configuration, AttrDict, parse_j2yaml, Logger, logit, which, CommandNotFoundError, ProcessError
from workflow.hosts import Host
from wxflow.fsutils import mkdir_p, chdir, cp

logger = Logger(level=os.environ.get("LOGGING_LEVEL", "DEBUG"), colored_log=False)

def parse_args():
"""
Parse command line arguments.

Returns
-------
argparse.Namespace
The parsed command line arguments.
"""
description = """Arguments for creating and updating error log files
"""
parser = ArgumentParser(description=description)

parser.add_argument('--yaml', help='paths to YAML files for creating functional tests per case', required=True, type=Path, nargs='+')
return parser.parse_args()

if __name__ == '__main__':
# Locate cmake executable
try:
cmake = which("cmake")
except CommandNotFoundError:
logger.exception("cmake not found in PATH")
raise CommandNotFoundError("cmake not found in PATH")

# Parse command line arguments
args = parse_args()
data = AttrDict(HOMEgfs=_top)
data.update(os.environ)

# Initialize host and configuration
host = Host()
cfg = Configuration(f'{data.HOMEgfs}/ci/platforms')

# Create directory for tests
test_dir = os.path.join(_here, 'TESTS')
mkdir_p(test_dir)

# Process each YAML file
case_names = ""
for yaml in args.yaml:
platform_config = cfg.parse_config(f'config.{host.machine.lower()}')
case_name = os.path.basename(yaml).split('.')[0]
platform_config['testcase'] = case_name
data.update(platform_config)
case_cfg = parse_j2yaml(path=yaml, data=data)
case_cfg.update(platform_config)

# Create job list file for the case
top_level_entries = [key for key in case_cfg.keys() if isinstance(case_cfg[key], dict)]
job_list_file = f"TESTS/{case_name}_jobs.txt"
with open(job_list_file, 'w') as f:
for entry in top_level_entries:
f.write(f"{case_name}_{entry}\n")

case_names += f"{case_name} "

platform_config.clear()
data.clear()
case_cfg.clear()

# Run cmake to create the functional tests
cmake.add_default_arg([f"-S {_here}", f"-B {test_dir}", f"-DCASE_LIST='{case_names[:-1]}'"])
cmake()
2 changes: 2 additions & 0 deletions ci/platforms/config.hera
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

export GFS_CI_ROOT=/scratch1/NCEPDEV/global/Terry.McGuinness/GFS_CI_ROOT
export ICSDIR_ROOT=/scratch1/NCEPDEV/global/glopara/data/ICSDIR

export STAGED_FUNCTIONAL_TEST_DIR=${GFS_CI_ROOT}/STAGED_FUNCTIONAL_TEST_DIR
export HPC_ACCOUNT=nems
export max_concurrent_cases=5
export max_concurrent_pr=4
Expand Down
1 change: 1 addition & 0 deletions ci/platforms/config.orion
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export GFS_CI_ROOT=/work2/noaa/stmp/GFS_CI_ROOT/ORION
export ICSDIR_ROOT=/work/noaa/global/glopara/data/ICSDIR
export HPC_ACCOUNT=nems
export STAGED_FUNCTIONAL_TEST_DIR=/work/noaa/stmp/GFS_CI_ROOT/ORION/STAGED_FUNCTIONAL_TEST_DIR
export max_concurrent_cases=5
export max_concurrent_pr=4

Expand Down
2 changes: 1 addition & 1 deletion workflow/generate_workflows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ echo "Running create_experiment.py for ${#_yaml_list[@]} cases"
for _case in "${_yaml_list[@]}"; do
[[ "${_verbose}" == false ]] && echo "${_case}"
_pslot="${_case}${_tag}"
_create_exp_cmd="./create_experiment.py -y ../ci/cases/pr/${_case}.yaml --overwrite"
_create_exp_cmd="${HOMEgfs}/workflow/create_experiment.py -y ${HOMEgfs}/ci/cases/pr/${_case}.yaml --overwrite"
if [[ "${_verbose}" == true ]]; then
pslot=${_pslot} RUNTESTS=${_runtests} ${_create_exp_cmd}
else
Expand Down
Loading