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

Event Handler Infrastructure #22

Merged
merged 17 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
105 changes: 65 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,86 @@ on:
push:
branches:
- master

pull_request:

jobs:

# try to build SIPNET on Ubuntu & MacOS
# Build and Integration Test
build:
strategy:
fail-fast: false
matrix:
OS:
OS:
- macos-latest
- ubuntu-latest
- ubuntu-20.04

runs-on: ${{ matrix.OS }}

steps:
# checkout source code
- uses: actions/checkout@v2
# checkout source code
- uses: actions/checkout@v2

# install doxygen
- name: Install Doxygen
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
sudo apt-get install doxygen -y
elif [[ "$RUNNER_OS" == "macOS" ]]; then
brew install --formula doxygen
fi
# install doxygen
- name: Install Doxygen
run: |
if [[ "$RUNNER_OS" == "Linux" ]]; then
sudo apt-get install doxygen -y
elif [[ "$RUNNER_OS" == "macOS" ]]; then
brew install --formula doxygen
fi

# compile SIPNET
- name: compile sipnet
run: make
# compile SIPNET
- name: compile sipnet
run: make

# remove existing test output file
- name: Remove Niwout Output File
run: rm Sites/Niwot/niwot.out

# run single sipnet run
- name: Run SIPNET on Sites/Niwot/niwot
run: ./sipnet

# check for correct output of Niwot run
- name: Check if niwot.out is generated
shell: bash
run: |
if [ ! -f Sites/Niwot/niwot.out ]; then
echo "::error title={No Output}::Test run for Niwot site failed to produce output"
exit 1
fi

# Check if niwot.out has changed
- name: Check whether niwot.out has changed
shell: bash
run: |
if git diff --exit-code Sites/Niwot/niwot.out; then
echo "Success: Niwot.out created and has not changed"
else
echo "::error title={Output Changed}::The test file niwot.out has changed. This is expected to fail with some changes to SIPNET. When this happens, assess correctness and then update the reference niwot.out."
exit 1
fi

# Run Unit Tests
test:
needs: build
strategy:
fail-fast: false
matrix:
OS:
- macos-latest
- ubuntu-latest
- ubuntu-20.04
runs-on: ${{ matrix.OS }}

steps:
# checkout source code
- uses: actions/checkout@v2

# remove existing test output file
- name: Remove Niwout Output File
run: rm Sites/Niwot/niwot.out
# compile unit tests
- name: compile tests
run: make test

# run single sipnet run
- name: sipnet on Sites/Niwot/niwot
run: ./sipnet
# run tests
- name: Run Unit Tests
run: make testrun

# check output of test
- name: fail if no niwot output exists
if: ${{ hashFiles('Sites/Niwot/niwot.out') == '' }}
run: |
echo "::error title={No Output}::Test run for Niwot site failed to produce output"
exit 1
# check whether niwot.out has changed
- name: Check whether niwot.out has changed
shell: bash
run: |
if git diff --exit-code Sites/Niwot/niwot.out; then
echo "Success: Niwot.out created and has not changed"
else
echo "::error title={Output Changed}::The test file niwot.out has changed"
exit 1
fi
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ make clean
# list all make commands
make help
```
## Testing

SIPNET also uses `make` to build and run its unit tests. This can be done with the following commands:
```shell
# Compile tests
make test
# Run tests
make testrun
# Clean after tests are run
make testclean
```
53 changes: 43 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
CC=gcc
LD=gcc
AR=ar
CFLAGS=-Wall
LIBLINKS=-lm

ESTIMATE_CFILES=sipnet.c ml-metro5.c ml-metrorun.c paramchange.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c
ESTIMATE_CFILES=sipnet.c ml-metro5.c ml-metrorun.c paramchange.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c events.c
ESTIMATE_OFILES=$(ESTIMATE_CFILES:.c=.o)

SENSTEST_CFILES=sipnet.c sensTest.c paramchange.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c
SENSTEST_CFILES=sipnet.c sensTest.c paramchange.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c events.c
SENSTEST_OFILES=$(SENSTEST_CFILES:.c=.o)

SIPNET_CFILES=sipnet.c frontend.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c
SIPNET_CFILES=sipnet.c frontend.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c events.c
SIPNET_OFILES=$(SIPNET_CFILES:.c=.o)

TRANSPOSE_CFILES=transpose.c util.c
Expand All @@ -25,13 +26,9 @@ DOXYFILE = docs/Doxyfile
DOXYGEN_HTML_DIR = docs/html
DOXYGEN_LATEX_DIR = docs/latex

# .PHONY indicates target names that are not file names, preventing conflicts if these names are used for filenames
.PHONY: all clean document estimate sipnet transpose subsetData doxygen

# all: estimate sensTest sipnet transpose subsetData
all: estimate sipnet transpose subsetData document


# Only update docs if source files or Doxyfile have changed
document: .doxygen.stamp

Expand All @@ -58,8 +55,45 @@ subsetData: $(SUBSET_DATA_OFILES)
clean:
rm -f $(ESTIMATE_OFILES) $(SIPNET_OFILES) $(TRANSPOSE_OFILES) $(SUBSET_DATA_OFILES) estimate sensTest sipnet transpose subsetData
rm -rf $(DOXYGEN_HTML_DIR) $(DOXYGEN_LATEX_DIR)
#clean:
# rm -f $(ESTIMATE_OFILES) $(SENSTEST_OFILES) $(SIPNET_OFILES) $(TRANSPOSE_OFILES) $(SUBSET_DATA_OFILES) estimate sensTest sipnet transpose subsetData

# UNIT TESTS
SIPNET_TEST_DIRS:=$(shell find tests/sipnet -type d -mindepth 1 -maxdepth 1)
SIPNET_TEST_DIRS_RUN:= $(addsuffix .run, $(SIPNET_TEST_DIRS))
SIPNET_TEST_DIRS_CLEAN:= $(addsuffix .clean, $(SIPNET_TEST_DIRS))
SIPNET_LIB=libsipnet.a

$(SIPNET_LIB): $(SIPNET_LIB)($(SIPNET_OFILES))
ranlib $(SIPNET_LIB)

test: pretest $(SIPNET_TEST_DIRS) posttest $(SIPNET_LIB)

pretest:
cp modelStructures.h modelStructures.orig.h

# The dash in the build command tells make to continue if there are errors, allowing cleanup
$(SIPNET_TEST_DIRS): pretest $(SIPNET_LIB)
cp $@/modelStructures.h modelStructures.h
-$(MAKE) -C $@

# This is far from infallible, as model_structures.h will be in a bad place if a test
# build step fails in a non-catchable way
posttest: $(SIPNET_TEST_DIRS)
mv modelStructures.orig.h modelStructures.h

testrun: $(SIPNET_TEST_DIRS_RUN)

$(SIPNET_TEST_DIRS_RUN):
$(MAKE) -C $(basename $@) run

testclean: $(SIPNET_TEST_DIRS_CLEAN)
rm -f $(SIPNET_LIB)

$(SIPNET_TEST_DIRS_CLEAN):
$(MAKE) -C $(basename $@) clean

.PHONY: all clean document estimate sipnet transpose subsetData doxygen
test $(SIPNET_TEST_DIRS) pretest posttest $(SIPNET_LIB) testrun
$(SIPNET_TEST_DIRS_RUN) testclean $(SIPNET_TEST_DIRS_CLEAN)

help:
@echo "Available targets:"
Expand All @@ -80,4 +114,3 @@ depend::

# DO NOT DELETE THIS LINE -- make depend depends on it.


Loading
Loading