Skip to content

Commit

Permalink
Refactor C-I test scripts and update Dockerfile to avoid issues
Browse files Browse the repository at this point in the history
.ci-pipelines/ci-common-defs.sh
- Abstracted reusable code into this script, which is sourced
  by the other C-I test scripts.
- Renamed ALL_TESTS to GENERAL_TESTS
- Now put the X_minver test in the MINVERSION_TEST variable

.ci-pipelines/ci-cleanup-script.sh
.ci-pipelines/ci-testing-script.sh
- Now gets common variables & functions from ci-common-defs.sh
- Now execute the test for #MINVERSION separately
- Now uses #!/bin/bash instead of #!/bin/sh
- Now uses absolute paths instead of relative paths

./ci-manual-cleanup-script.sh
./ci-manual-testing-script.sh
- Removed

./ci-pipelines/Dockerfile
- Updated comments
- Add commands to make sure ci-common-defs.sh and ci-testing-script.sh
  are made executable

Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
  • Loading branch information
yantosca committed Jul 6, 2022
1 parent 7abbdd8 commit 398a78b
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 153 deletions.
16 changes: 9 additions & 7 deletions .ci-pipelines/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
# `docker build -f ./.ci-pipelines/Dockerfile --platform=amd64 -t kpp-build .` from top level of project
# To exec into the container run: `docker run -it --entrypoint /bin/bash kpp-build`

# Set platform/OS, a reference to maintainers, and the working directory.
# Set OS, a reference to maintainers, and the working directory.
#
# NOTE: The --platform=amd64 will make sure that the C-I tests will always
# run with AMD64 hardware. Otherwise, Docker will use the architecture
# of your current hardware, which might cause differences in library paths
# NOTE: Add --platform=amd64 (in .build-testing.yml and in your local
# aliases for 'docker build'. This will make sure that the C-I tests always
# run on AMD64 hardware. Otherwise, Docker will use the architecture of
# your current hardware, which might cause differences in library paths
# (e.g. /lib/aarch64-linux-gnu on Mac/M1 vs. /lib/x86_64-linux-gnu on Linux).
# -- Lucas Estrada & Bob Yantosca (06 Jul 2022)
FROM ubuntu:20.04
LABEL maintainer="GEOS-Chem Support Team <geos-chem-support@g.harvard.edu>"
WORKDIR /kpp

# Install KPP software dependencies
RUN apt-get update && apt-get install -y \
git gcc gfortran make flex bison
RUN apt-get update && apt-get install -y git gcc gfortran make flex bison

COPY . .

Expand All @@ -35,7 +35,9 @@ RUN sed -i 's/#define MAX_EQN .*/#define MAX_EQN 1023/g' /kpp/src/gdata.h \
RUN sed -i 's/FLEX_LIB_DIR = \/usr\/lib/FLEX_LIB_DIR = \/lib\/x86_64-linux-gnu/' /kpp/src/Makefile.defs

# Build KPP executable and ensure testing scripts are executable
RUN cd /kpp/src/ && make && chmod +x /kpp/.ci-pipelines/ci-*.sh
RUN cd /kpp/src/ && make
RUN chmod +x /kpp/.ci-pipelines/ci-common-defs.sh
RUN chmod +x /kpp/.ci-pipelines/ci-testing-script.sh

# Run C-I tests
RUN /kpp/.ci-pipelines/ci-testing-script.sh
Expand Down
26 changes: 26 additions & 0 deletions .ci-pipelines/ci-cleanup-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

########################################################################
### C-I test cleanup script for github.com/KineticPreProcessor/KPP ###
### ###
### Use this if you have run the C-I tests manually, and wish to ###
### remove compiled files (*.o, *.mod, *.exe) from C-I test folders. ###
########################################################################

# Load common variables and functions
. ${KPP_HOME}/.ci-pipelines/ci-common-defs.sh

# Current directory
cwd=$(pwd -P)

# Clean up files in each C-I test folder
for this_test in ${GENERAL_TESTS}; do
clean_ci_test_folder "${this_test}" "${cwd}"
done

# Remove any log files used to store C-I test results
cd $cwd
rm -fv *log*

# Return w/ success
exit 0
128 changes: 128 additions & 0 deletions .ci-pipelines/ci-common-defs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
########################################################################
### Common variables and functions for the C-I tests ###
########################################################################

#=======================================================================
# Lists of C-I tests
#=======================================================================

# Testing different mechanisms
GENERAL_TESTS="C_rk
C_rosadj
C_sd
C_sdadj
C_small_strato
F90_lsode
F90_radau
F90_rk
F90_rktlm
F90_ros
F90_rosadj
F90_ros_autoreduce
F90_rosenbrock
F90_ros_split
F90_rostlm
F90_ros_upcase
F90_saprc_2006
F90_sd
F90_sdadj
F90_seulex
F90_small_strato
"
# Testing if #MINVERSION works
MINVERSION_TEST="X_minver"

#=======================================================================
# Functions
#=======================================================================

# Returns the path to a C-I test folder
function get_ci_test_path() {
echo "${KPP_HOME}/ci-tests/${1}"
return
}

# Run a C-I test
function run_ci_test() {

# Arguments
this_test=${1} # Name of test
return_dir=${2} # Directory where we will return upon test completion

# Navigate to C-I test folder (or exit if error)
test_path=$(get_ci_test_path "${this_test}")
cd $test_path
[[ $? -ne 0 ]] && exit 1

echo ""
echo ">>>>>>>> Generating ${this_test} mechanism with KPP <<<<<<<<"
echo ""
${KPP_HOME}/bin/kpp $this_test.kpp
[[ $? -ne 0 ]] && exit 1

echo ""
echo ">>>>>>>> Building the ${this_test} test executable <<<<<<<<<"
echo ""
make -j -f Makefile_$this_test COMPILER=GFORTRAN
[[ $? -ne 0 ]] && exit 1

echo ""
echo ">>>>>>>> Running the ${this_test} test <<<<<<<<"
echo ""
./$this_test.exe
[[ $? -ne 0 ]] && exit 1

echo ""
echo ">>>>>>>> ${this_test} test was successful! <<<<<<<<"
echo ""

# Navigate back to original path and return w/ success
cd $return_dir
}

# Test if the #MINVERSION command works
function run_minversion_ci_test() {

# Arguments
this_test=${1} # Name of test
return_dir=${2} # Directory where we will return upon test completion

# Navigate to test folder (or exit if error)
test_path=$(get_ci_test_path "${MINVERSION_TEST}")
cd ${test_path}
[[ $? -ne 0 ]] && exit 1

# Build the mechanism with KPP
echo ""
echo ">>>>>>>> Generating ${this_test} mechanism with KPP <<<<<<<<"
echo ""
${KPP_HOME}/bin/kpp ${MINVERSION_TEST}.kpp

# Navigate back to original path and return w/ success
cd $return_dir
}

# Removes compiled files in C-I test folders
function clean_ci_test_folder() {

# Arguments
this_test=${1} # Name of test
return_dir=${2} # Directory where we will return upon test completion

# Navigate to test folder (or exit if error)
test_path=$(get_ci_test_path "${this_test}")
cd ${test_path}
[[ $? -ne 0 ]] && exit 1

echo ""
echo ">>>>>>>> Making distclean for ${this_test} <<<<<<<<"
echo ""
make -f Makefile_${this_test} distclean

# Also remove other output files from the tests
rm -f *.m
rm -f Makefile.${this_test}

# Navigate back to original path and return w/ success
cd ${cwd}
}
39 changes: 0 additions & 39 deletions .ci-pipelines/ci-manual-cleanup-script.sh

This file was deleted.

48 changes: 0 additions & 48 deletions .ci-pipelines/ci-manual-testing-script.sh

This file was deleted.

27 changes: 0 additions & 27 deletions .ci-pipelines/ci-testing-list.sh

This file was deleted.

46 changes: 14 additions & 32 deletions .ci-pipelines/ci-testing-script.sh
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
#!/bin/sh
#!/bin/bash

########################################################################
### CI tests for github.com/KineticPreProcessor/KPP ###
### C-I test script for github.com/KineticPreProcessor/KPP ###
########################################################################

# Get the list of CI test folders in ALL_TESTS
source /kpp/.ci-pipelines/ci-testing-list.sh
# Load common variables and functions
. ${KPP_HOME}/.ci-pipelines/ci-common-defs.sh

# Run each test
# Check status of each individual operation and exit if any do not complete
for this_test in $ALL_TESTS; do

cd /kpp/ci-tests/$this_test
[ $? -ne 0 ] && exit 1

echo ""
echo ">>>>>>>> Generating $this_test mechanism with KPP <<<<<<<<"
echo ""
../../bin/kpp $this_test.kpp
[ $? -ne 0 ] && exit 1

echo ""
echo ">>>>>>>> Building the $this_test test executable <<<<<<<<<"
echo ""
make -j -f Makefile_$this_test COMPILER=GFORTRAN
[ $? -ne 0 ] && exit 1

echo ""
echo ">>>>>>>> Running the $this_test test <<<<<<<<"
echo ""
./$this_test.exe
[ $? -ne 0 ] && exit 1

echo ""
echo ">>>>>>>> $this_test test was successful! <<<<<<<<"
echo ""
# Current directory
cwd=$(pwd -P)

# Run C-I tests with various mechanism + integrator combinations
for this_test in ${GENERAL_TESTS}; do
run_ci_test "${this_test}" "${cwd}"
done

# Run a C-I test to see if the #MINVERSION command works as advertised
run_minversion_ci_test "${MINVERSION_TEST}" "${cwd}"

# Return w/ success
echo ""
echo ">>>>>>>> All tests finished succesfully! <<<<<<<<"
echo ""

# Return with success
exit 0

0 comments on commit 398a78b

Please sign in to comment.