From 9d2a685fd94abd352faf6c52af766c63ca8cb17e Mon Sep 17 00:00:00 2001 From: Benjamin Auer Date: Tue, 14 Jun 2022 13:32:59 -0400 Subject: [PATCH] get testing framework working --- Tests/CMakeLists.txt | 1 + .../ExtData_Testing_Framekwork/CMakeLists.txt | 25 +++ .../run_extdata1g.cmake | 25 +++ .../run_extdata2g.cmake | 27 +++ .../test_cases/case21/ExtData.rc | 5 +- .../test_script/run_case.py | 64 ------ .../test_script/run_extdatadriver_cases.py | 56 ----- .../test_script/utils.py | 191 ------------------ 8 files changed, 81 insertions(+), 313 deletions(-) create mode 100644 Tests/ExtData_Testing_Framekwork/CMakeLists.txt create mode 100644 Tests/ExtData_Testing_Framekwork/run_extdata1g.cmake create mode 100644 Tests/ExtData_Testing_Framekwork/run_extdata2g.cmake delete mode 100755 Tests/ExtData_Testing_Framekwork/test_script/run_case.py delete mode 100755 Tests/ExtData_Testing_Framekwork/test_script/run_extdatadriver_cases.py delete mode 100644 Tests/ExtData_Testing_Framekwork/test_script/utils.py diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index bba1dbb97aa7..aa469a39b433 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -32,3 +32,4 @@ endif () #install(PROGRAMS ExtDataDriver.x DESTINATION bin) #install(TARGETS ExtDataDriver.x DESTINATION bin) +add_subdirectory(ExtData_Testing_Framekwork EXCLUDE_FROM_ALL) diff --git a/Tests/ExtData_Testing_Framekwork/CMakeLists.txt b/Tests/ExtData_Testing_Framekwork/CMakeLists.txt new file mode 100644 index 000000000000..7e482e01eba6 --- /dev/null +++ b/Tests/ExtData_Testing_Framekwork/CMakeLists.txt @@ -0,0 +1,25 @@ +file(STRINGS "test_cases/cases.txt" TEST_CASES) + +foreach(TEST_CASE ${TEST_CASES}) +add_test( + NAME "ExtData1G_${TEST_CASE}" + COMMAND ${CMAKE_COMMAND} + -DTEST_CASE=${TEST_CASE} + -DMPIEXEC_EXECUTABLE=${MPIEXEC_EXECUTABLE} + -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} + -DMY_BINARY_DIR=${CMAKE_BINARY_DIR}/bin + -P ${CMAKE_CURRENT_SOURCE_DIR}/run_extdata1g.cmake + ) +endforeach() + +foreach(TEST_CASE ${TEST_CASES}) +add_test( + NAME "ExtData2G_${TEST_CASE}" + COMMAND ${CMAKE_COMMAND} + -DTEST_CASE=${TEST_CASE} + -DMPIEXEC_EXECUTABLE=${MPIEXEC_EXECUTABLE} + -DMPIEXEC_NUMPROC_FLAG=${MPIEXEC_NUMPROC_FLAG} + -DMY_BINARY_DIR=${CMAKE_BINARY_DIR}/bin + -P ${CMAKE_CURRENT_SOURCE_DIR}/run_extdata2g.cmake + ) +endforeach() diff --git a/Tests/ExtData_Testing_Framekwork/run_extdata1g.cmake b/Tests/ExtData_Testing_Framekwork/run_extdata1g.cmake new file mode 100644 index 000000000000..202d0aae191e --- /dev/null +++ b/Tests/ExtData_Testing_Framekwork/run_extdata1g.cmake @@ -0,0 +1,25 @@ +macro(run_case CASE) + string(RANDOM LENGTH 24 tempdir) + execute_process( + COMMAND ${CMAKE_COMMAND} -E make_directory ${tempdir} + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/test_cases/${CASE} ${tempdir} + ) + if (EXISTS "${tempdir}/nproc.rc") + file(READ "${tempdir}/nproc.rc" num_procs) + else() + set(num_procs "1") + endif() + execute_process( + COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${num_procs} ${MY_BINARY_DIR}/ExtDataDriver.x + RESULT_VARIABLE CMD_RESULT + WORKING_DIRECTORY ${tempdir} + #COMMAND_ECHO STDOUT + ) + execute_process( + COMMAND ${CMAKE_COMMAND} -E rm -rf ${tempdir} + ) + if(CMD_RESULT) + message(FATAL_ERROR "Error running ${CASE}") + endif() +endmacro() +run_case(${TEST_CASE}) diff --git a/Tests/ExtData_Testing_Framekwork/run_extdata2g.cmake b/Tests/ExtData_Testing_Framekwork/run_extdata2g.cmake new file mode 100644 index 000000000000..158ad09e1285 --- /dev/null +++ b/Tests/ExtData_Testing_Framekwork/run_extdata2g.cmake @@ -0,0 +1,27 @@ +macro(run_case CASE) + string(RANDOM LENGTH 24 tempdir) + execute_process( + COMMAND ${CMAKE_COMMAND} -E make_directory ${tempdir} + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_LIST_DIR}/test_cases/${CASE} ${tempdir} + ) + if (EXISTS "${tempdir}/nproc.rc") + file(READ "${tempdir}/nproc.rc" num_procs) + else() + set(num_procs "1") + endif() + file(APPEND "${tempdir}/CAP1.rc" "USE_EXTDATA2G: .true.") + file(APPEND "${tempdir}/CAP2.rc" "USE_EXTDATA2G: .true.") + execute_process( + COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${num_procs} ${MY_BINARY_DIR}/ExtDataDriver.x + RESULT_VARIABLE CMD_RESULT + WORKING_DIRECTORY ${tempdir} + #COMMAND_ECHO STDOUT + ) + execute_process( + COMMAND ${CMAKE_COMMAND} -E rm -rf ${tempdir} + ) + if(CMD_RESULT) + message(FATAL_ERROR "Error running ${CASE}") + endif() +endmacro() +run_case(${TEST_CASE}) diff --git a/Tests/ExtData_Testing_Framekwork/test_cases/case21/ExtData.rc b/Tests/ExtData_Testing_Framekwork/test_cases/case21/ExtData.rc index a45d1dd13f7f..57736ed30bef 100644 --- a/Tests/ExtData_Testing_Framekwork/test_cases/case21/ExtData.rc +++ b/Tests/ExtData_Testing_Framekwork/test_cases/case21/ExtData.rc @@ -4,10 +4,11 @@ Prefetch: .true. #DEBUG_LEVEL: 20 PrimaryExports%% -VAR2D NA N N 0 none none VAR2D case1.%y4.nc4 -VAR3D NA N N 0 none none VAR3D case1.%y4.nc4 +VAR1 NA N N 0 none none VAR1 case1.%y4.nc4 +VAR2 NA N N 0 none none VAR2 case1.%y4.nc4 %% DerivedExports%% +VAR2D VAR1+VAR2 0 %% diff --git a/Tests/ExtData_Testing_Framekwork/test_script/run_case.py b/Tests/ExtData_Testing_Framekwork/test_script/run_case.py deleted file mode 100755 index 129bc9a9bb61..000000000000 --- a/Tests/ExtData_Testing_Framekwork/test_script/run_case.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env python - -import argparse, sys, os -import subprocess as sp -import glob -import shutil -import utils - -class ExtDataCase(): - """ - """ - - def __init__(self, case_name, comm_line_args): - - self.build_dir = comm_line_args['build_dir'] - self.case_dir = comm_line_args['case_dir'] - self.case_name = case_name - self.case_path = self.case_dir+"/"+self.case_name.rstrip() - - def run(self,logfile): - - scrdir="ExtData_scratch" - orig_dir = os.getcwd() - if os.path.isdir(scrdir): - shutil.rmtree(scrdir) - os.mkdir(scrdir) - rc_files = glob.glob(self.case_path+"/*.rc") - for rc_file in rc_files: - shutil.copy(rc_file,scrdir) - yaml_files = glob.glob(self.case_path+"/*.yaml") - for yaml_file in yaml_files: - shutil.copy(yaml_file,scrdir) - os.chdir(scrdir) - - g5_mod_path = self.build_dir+"/g5_modules" - utils.source_g5_modules(g5_mod_path) - success = os.path.isfile('nproc.rc') - if success: - fproc = open('nproc.rc',"r") - nproc = fproc.readline() - nproc = nproc.rstrip() - fproc.close() - else: - nproc = "1" - - exec_path = "cat CAP1.rc " + self.case_dir+"/use_extdata2g.rc > temp.rc ;mv temp.rc CAP1.rc" - sp.call(exec_path,stdout=logfile,stderr=logfile,shell=True) - exec_path = "cat CAP2.rc " + self.case_dir+"/use_extdata2g.rc > temp.rc; mv temp.rc CAP2.rc" - sp.call(exec_path,stdout=logfile,stderr=logfile,shell=True) - - exec_path = "mpirun -np "+nproc+" "+self.build_dir+"/ExtDataDriver.x " - sp.call(exec_path,stdout=logfile,stderr=logfile,shell=True) - sp.call("~/bin/Killall ExtDataDriver.x",stdout=logfile,stderr=logfile,shell=True) - - print("finished exec of "+self.case_name.rstrip()) - success = os.path.isfile('egress') - os.chdir(orig_dir) - shutil.rmtree(scrdir) -# - if success: - return True - else: - return False - diff --git a/Tests/ExtData_Testing_Framekwork/test_script/run_extdatadriver_cases.py b/Tests/ExtData_Testing_Framekwork/test_script/run_extdatadriver_cases.py deleted file mode 100755 index 6e3fc6f4fb58..000000000000 --- a/Tests/ExtData_Testing_Framekwork/test_script/run_extdatadriver_cases.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python - -import argparse, sys, os -import subprocess as sp -from run_case import ExtDataCase - -def parse_comm_args(): - - p = argparse.ArgumentParser(description='Run ExtData tester script') - - # BAS_HOM_DIR, CUR_HOM_DIR, DIFF - # ------------------------------ - p.add_argument("--builddir", dest="build_dir",help='src directory for build') - p.add_argument("--casedir", dest="case_dir",help='where cases are located') - p.add_argument("--cases", dest="cases",help='list of cases') - p.add_argument("--savelog",dest="save_log",default="false",help='save the log files for all') - - - args = vars(p.parse_args()) # vars converts to dict - - # some checks on inputs - # --------------------- - if not os.path.isdir(args['build_dir']): - raise Exception('build_dir [%s] does not exist' % args['bas']) - if not os.path.isdir(args['case_dir']): - raise Exception('case_dir [%s] does not exist' % args['bas']) - - # return opts - # ----------- - return args - - -if __name__ == "__main__": - - comm_opts = parse_comm_args() - build_dir = comm_opts['build_dir'] - case_dir = comm_opts['case_dir'] - case_path = comm_opts['cases'] - case_file = open(case_path,'r') - lines =case_file.readlines() - case_file.close() - for case in lines: - if '#' not in case: - print("running "+case.rstrip()) - this_case = ExtDataCase(case,comm_opts) - logfile=case.rstrip()+".log" - log = open(logfile,'w') - success = this_case.run(log) - log.close() - if success: - print(case.rstrip()+" passed") - if comm_opts['save_log'].lower() == "false": - os.remove(logfile) - else: - print(case.rstrip()+" failed") - diff --git a/Tests/ExtData_Testing_Framekwork/test_script/utils.py b/Tests/ExtData_Testing_Framekwork/test_script/utils.py deleted file mode 100644 index f516aac1172e..000000000000 --- a/Tests/ExtData_Testing_Framekwork/test_script/utils.py +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/env python - -""" -# ------------------------------------------------------------------------------ -# collection of useful functions: -# -# writemsg -# get_hostname -# source_g5_modules -# ------------------------------------------------------------------------------ -""" - - -import os -import sys -import glob -import time -import shutil -import errno -import fnmatch -import subprocess as sp -import filecmp -import shlex -import distutils.spawn -import subprocess -import re - -def writemsg(str2write, fout=None, quiet=None): - """ - # -------------------------------------------------------------------------- - # write message to fout - # - # Inputs: - # str2write: (obvious) - # fout: handle of (open) output file, if None, set to sys.stdout - # -------------------------------------------------------------------------- - """ - if not fout: fout = sys.stdout - if not quiet: fout.write('%s' % str2write); fout.flush() - - - -def get_hostname(): - """ - # -------------------------------------------------------------------------- - # Return the hostname (DISCOVER, PLEIADES) - # -------------------------------------------------------------------------- - """ - - node = os.uname()[1] - if node[0:8]=='discover' or node[0:4]=='borg': - HOST = 'DISCOVER' - elif node[0:3]=='pfe' or node[0:4]=='maia' or (node[0]=='r' and node[4]=='i'): - HOST = 'PLEIADES' - elif node[-13:]=='gsfc.nasa.gov' or (node[:6]=='gs6101' - and (node[-12:]=='ndc.nasa.gov') or node[-5:]=='local'): - HOST = 'DESKTOP' - # MAT Note that the DESKTOP is a "failover" if it is gsfc - # we return DESKTOP if it matches nothing else - else: - HOST = 'DESKTOP' - #raise Exception('could not get host name from node [%s]' % node) - - return HOST - -def source_g5_modules(g5_modules, fout=None): - """ - #--------------------------------------------------------------------------- - # def source_g5_modules(g5_modules, fout): - # - # source_g5_modules is a wrapper for the csh script g5_modules. It - # queries the csh script for basedir, modules and modinit, adds basedir - # to os.environ and loads library modules - # - # Input: - # g5_modules: full path of g5_modules - # fout: handle of (open) log file, if None - set to sys.stdout - #--------------------------------------------------------------------------- - """ - - if not fout: fout = sys.stdout - - # check if g5_modules exists - # -------------------------- - if not os.path.isfile(g5_modules): - raise Exception('g5_modules does not exist') - - - # part of the command to run - # -------------------------- - cmd = ['/bin/csh', g5_modules] - - # query for basedir - # ----------------- - run = sp.Popen(cmd+['basedir'], stdout=sp.PIPE, stderr=sp.PIPE) - output = run.communicate() - rtrnCode = run.wait() - if rtrnCode != 0: - print('0:'); print(output[0]); print('1:'); print(output[1]) - raise Exception('cant query g5_modules for basedir') - #BASEDIR = output[0].strip() - BASEDIR = output[0].split('\n')[0].strip() - - - # query for modules to load - # ------------------------- - run = sp.Popen(cmd+['modules'], stdout=sp.PIPE, stderr=sp.PIPE) - output = run.communicate() - rtrnCode = run.wait() - if rtrnCode != 0: - print('0:'); print(output[0]); print('1:'); print(output[1]) - raise Exception('cant query g5_modules for modules') - #MODULES = output[0].strip().split() - MODULES = output[0].split('\n')[0].strip().split() - - #print("MATMAT MODULES: ", MODULES) - - - # query for modinit - # ----------------- - run = sp.Popen(cmd+['modinit'], stdout=sp.PIPE, stderr=sp.PIPE) - output = run.communicate() - rtrnCode = run.wait() - if rtrnCode != 0: - print('0:'); print(output[0]); print('1:'); print(output[1]) - raise Exception('cant query g5_modules for modinit') - # MODINIT = output[0].strip().replace('csh', 'python') - # For Matt, modinit query results in '/usr/share/modules/init/csh\n/usr/..' - tmpdir = output[0].split('\n')[0].strip() - newdir = tmpdir.split('/') - HOST = get_hostname() - # MAT On anvil, at least, the modules has python.py - if HOST=='PLEIADES' or HOST=='DESKTOP': - newdir[-1] = 'python.py' - else: - newdir[-1] = 'python' - MODINIT = '/'.join(newdir) - - # set BASEDIR - # ----------- - ARCH = os.uname()[0] - writemsg(' %s: Setting BASEDIR' % os.path.basename(g5_modules), fout) - os.environ['BASEDIR'] = BASEDIR # this only modifies the local environment - BASELIB = '%s/%s/lib' % (BASEDIR, ARCH) - if 'LD_LIBRARY_PATH' in os.environ: - os.environ['LD_LIBRARY_PATH'] += os.pathsep + BASELIB - else: - os.environ['LD_LIBRARY_PATH'] = BASELIB - - - # load library modules - # -------------------- - if (os.path.isfile(MODINIT)): - writemsg(' and modules.\n', fout) - - exec(open(MODINIT).read()) - module('purge') - for mod in MODULES: - module('load',mod) - - # At NAS something weird is happening with python - # if you force it to load this at the end, things work - #if HOST=='PLEIADES': - #module('load','python/2.7.15') - #module('list') - elif os.environ.get('LMOD_PKG') is not None: - writemsg(' and modules.\n', fout) - - sys.path.insert(0,os.path.join(os.environ['LMOD_PKG'], "init")) - from env_modules_python import module - - module('purge') - for mod in MODULES: - module('load',mod) - - else: - raise Exception('could not load required modules') - - # set ESMA_FC to gfortran, if needed - # ---------------------------------- - if BASEDIR.split(os.sep)[-1].split('_')[0]=='gfortran': - writemsg(' Setting ESMA_FC to gfortran\n', fout) - os.environ['ESMA_FC'] = 'gfortran' - - # set ESMA_FC to pgfortran, if needed - # ----------------------------------- - if BASEDIR.split(os.sep)[-1].split('_')[0]=='pgfortran': - writemsg(' Setting ESMA_FC to pgfortran\n', fout) - os.environ['ESMA_FC'] = 'pgfortran' - os.environ['PGI_LOCALRC'] = '/discover/swdev/mathomp4/PGILocalRC/linux86-64/17.10/bin/localrc.60300' - writemsg(' Setting PGI_LOCALRC to %s\n' % os.environ['PGI_LOCALRC'], fout)