Skip to content

Commit af7fb73

Browse files
Optionally run specified rocoto task as part of the ctests (#1121)
Only tested with the coupled UFS and the marine DA tasks: ``` Test project /scratch1/NCEPDEV/stmp2/Guillaume.Vernieres/runs/prs/global-workflow/sorc/gdas.cd/build/gdas/test/gw-ci Test #1: C48mx500_3DVarAOWCDA Test #2: C96_atmaerosnowDA Test #3: C96C48_ufs_hybatmDA Test #4: C48mx500_3DVarAOWCDA_gdasfcst_202103241200 Test #5: C48mx500_3DVarAOWCDA_gdasprepoceanobs_202103241800 Test #6: C48mx500_3DVarAOWCDA_gdasocnanalprep_202103241800 Test #7: C48mx500_3DVarAOWCDA_gdasocnanalbmat_202103241800 Test #8: C48mx500_3DVarAOWCDA_gdasocnanalrun_202103241800 Test #9: C48mx500_3DVarAOWCDA_gdasocnanalchkpt_202103241800 Test #10: C48mx500_3DVarAOWCDA_gdasocnanalpost_202103241800 Total Tests: 10 ```
1 parent 52dfb5f commit af7fb73

File tree

4 files changed

+136
-7
lines changed

4 files changed

+136
-7
lines changed

test/gw-ci/CMakeLists.txt

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,60 @@ set(HOMEgfs ${CMAKE_SOURCE_DIR}/../../..)
33
set(RUNTESTS ${CMAKE_CURRENT_BINARY_DIR}/../../test/gw-ci)
44

55
# List of g-w ci test to create
6+
# -----------------------------
67
set(cycling_tests "C48mx500_3DVarAOWCDA" "C96_atmaerosnowDA" "C96C48_ufs_hybatmDA")
78

8-
# Prepare the cycling ctests
9+
# List of tasks to run for each test
10+
# ----------------------------------
11+
set(C48mx500_3DVarAOWCDA_tasks
12+
"gdasprepoceanobs"
13+
"gdasocnanalprep"
14+
"gdasocnanalbmat"
15+
"gdasocnanalrun"
16+
"gdasocnanalchkpt"
17+
"gdasocnanalpost")
18+
set(C96_atmaerosnowDA_tasks) # empty list for now
19+
set(C96C48_ufs_hybatmDA_tasks) # empty list for now
20+
21+
# Iterate through the list of cycling test
22+
# ----------------------------------------
923
foreach(pslot ${cycling_tests})
24+
message(STATUS "preparing ${pslot} ctest")
25+
# Prepare the COMROOT and EXPDIR for the cycling ctests
1026
set(YAML ${HOMEgfs}/ci/cases/pr/${pslot}.yaml)
1127
add_test(NAME ${pslot}
12-
COMMAND /bin/bash -c "${PROJECT_SOURCE_DIR}/test/gw-ci/create_exp.sh ${YAML} ${pslot} ${HOMEgfs} ${RUNTESTS}"
13-
WORKING_DIRECTORY ${RUNTESTS})
28+
COMMAND /bin/bash -c "${PROJECT_SOURCE_DIR}/test/gw-ci/create_exp.sh ${YAML} ${pslot} ${HOMEgfs} ${RUNTESTS}"
29+
WORKING_DIRECTORY ${RUNTESTS})
1430
set_tests_properties(${pslot} PROPERTIES LABELS "manual")
31+
32+
# Get the 1/2 cycle and full cycle's dates
33+
execute_process(
34+
COMMAND ${CMAKE_COMMAND} -E env python ${PROJECT_SOURCE_DIR}/test/gw-ci/get_cycles.py ${YAML}
35+
OUTPUT_VARIABLE SCRIPT_OUTPUT
36+
RESULT_VARIABLE SCRIPT_RESULT
37+
OUTPUT_STRIP_TRAILING_WHITESPACE
38+
)
39+
string(REPLACE "," ";" DATES_LIST ${SCRIPT_OUTPUT})
40+
list(GET DATES_LIST 0 HALF_CYCLE)
41+
list(GET DATES_LIST 1 FULL_CYCLE)
42+
43+
# 1/2 cycle gdasfcst
44+
message(STATUS "preparing 1/2 cycle gdasfcst for ${pslot} ctest")
45+
add_test(NAME ${pslot}_gdasfcst_${HALF_CYCLE}
46+
COMMAND /bin/bash -c "${PROJECT_SOURCE_DIR}/test/gw-ci/run_exp.sh ${pslot} gdasfcst ${HALF_CYCLE}"
47+
WORKING_DIRECTORY ${RUNTESTS})
48+
set_tests_properties(${pslot}_gdasfcst_${HALF_CYCLE} PROPERTIES LABELS "manual")
49+
50+
# Select the list of tasks to run for the full cycle
51+
set(TASK_LIST_NAME "${pslot}_tasks")
52+
set(TASK_LIST "${${TASK_LIST_NAME}}")
53+
message(STATUS "Tasks for ${EXPERIMENT}: ${TASK_LIST}")
54+
55+
foreach(task ${TASK_LIST})
56+
message(STATUS "preparing the full cycle ${task} for ${pslot} ctest")
57+
add_test(NAME ${pslot}_${task}_${FULL_CYCLE}
58+
COMMAND /bin/bash -c "${PROJECT_SOURCE_DIR}/test/gw-ci/run_exp.sh ${pslot} ${task} ${FULL_CYCLE}"
59+
WORKING_DIRECTORY ${RUNTESTS})
60+
set_tests_properties(${pslot}_${task}_${FULL_CYCLE} PROPERTIES LABELS "manual")
61+
endforeach()
1562
endforeach()

test/gw-ci/create_exp.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#!/bin/bash
2-
expyaml="$1"
3-
export pslot="$2"
2+
expyaml_ctest="$1"
3+
pslot_ctest="$2"
44
HOMEgfs="$3"
5-
export RUNTESTS="$4"/${pslot}
6-
export SLURM_ACCOUNT="da-cpu"
5+
exp_path=$4
76

87
# Get ICSDIR_ROOT
98
source "${HOMEgfs}/ush/detect_machine.sh"
109
source "${HOMEgfs}/ci/platforms/config.${MACHINE_ID}"
1110

11+
# Arguments for the exp setup
12+
expyaml=${expyaml_ctest}
13+
export pslot=${pslot_ctest}
14+
export RUNTESTS=${exp_path}/${pslot}
15+
export SLURM_ACCOUNT="da-cpu"
16+
1217
# Source the gw environement
1318
source ${HOMEgfs}/workflow/gw_setup.sh
1419

test/gw-ci/get_cycles.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import re
2+
import argparse
3+
from datetime import datetime, timedelta
4+
5+
6+
def read_idate_from_yaml(file_path):
7+
idate_value = None
8+
with open(file_path, 'r') as file:
9+
for line in file:
10+
match = re.search(r'^\s*idate:\s*(.*)', line)
11+
12+
if match:
13+
idate_value = match.group(1).strip()
14+
break
15+
return idate_value
16+
17+
18+
def format_dates(idate_str):
19+
date_obj = datetime.strptime(idate_str, '%Y%m%d%H')
20+
half_cycle = date_obj.strftime('%Y%m%d%H%M')
21+
new_date_obj = date_obj + timedelta(hours=6)
22+
full_cycle = new_date_obj.strftime('%Y%m%d%H%M')
23+
24+
return half_cycle, full_cycle
25+
26+
27+
def main():
28+
parser = argparse.ArgumentParser(description="Extract and format idate.")
29+
parser.add_argument('yaml_file', help="Path to exp.yaml file")
30+
args = parser.parse_args()
31+
32+
idate_value = read_idate_from_yaml(args.yaml_file)
33+
half_cycle, full_cycle = format_dates(idate_value)
34+
print(f"{half_cycle},{full_cycle}")
35+
36+
37+
if __name__ == "__main__":
38+
main()

test/gw-ci/run_exp.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
pslot=$1
4+
TASK_NAME=$2
5+
CYCLE=$3
6+
7+
# Define the workflow XML and database files
8+
WORKFLOW_XML=${pslot}/EXPDIR/${pslot}/${pslot}.xml
9+
WORKFLOW_DB=${pslot}/EXPDIR/${pslot}/${pslot}.db
10+
11+
# Boot the task
12+
echo "booting $TASK_NAME for cycle $CYCLE"
13+
if [[ ! -e "$WORKFLOW_DB" ]]; then
14+
rocotorun -w "$WORKFLOW_XML" -d "$WORKFLOW_DB" -t "$TASK_NAME" -c "$CYCLE"
15+
fi
16+
rocotoboot -w "$WORKFLOW_XML" -d "$WORKFLOW_DB" -t "$TASK_NAME" -c "$CYCLE"
17+
18+
while true; do
19+
# Update the status of the task
20+
rocotorun -w "$WORKFLOW_XML" -d "$WORKFLOW_DB" -t "$TASK_NAME" -c "$CYCLE"
21+
22+
# Check the task status
23+
OUTPUT=$(rocotostat -w "$WORKFLOW_XML" -d "$WORKFLOW_DB" -t "$TASK_NAME" -c "$CYCLE")
24+
STATUS=$(echo "$OUTPUT" | awk '$2 == task {print $4}' task="$TASK_NAME")
25+
26+
if [[ "$STATUS" == "SUCCEEDED" ]]; then
27+
echo "The task succeeded."
28+
exit 0
29+
elif [[ "$STATUS" == "FAILED" ]]; then
30+
echo "The task failed."
31+
exit 1
32+
elif [[ "$STATUS" == "DEAD" ]]; then
33+
echo "The task is dead."
34+
exit 1
35+
else
36+
echo "The task is in state: $STATUS"
37+
fi
38+
sleep 10
39+
done

0 commit comments

Comments
 (0)