Skip to content

Commit becec4d

Browse files
authored
Merge pull request #22 from PecanProject/event_handler_infrastructure
Event Handler Infrastructure
2 parents 08eb706 + 394c4ab commit becec4d

22 files changed

+1042
-69
lines changed

.github/workflows/ci.yml

+65-40
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,86 @@ on:
44
push:
55
branches:
66
- master
7-
87
pull_request:
98

109
jobs:
11-
12-
# try to build SIPNET on Ubuntu & MacOS
10+
# Build and Integration Test
1311
build:
1412
strategy:
1513
fail-fast: false
1614
matrix:
17-
OS:
15+
OS:
1816
- macos-latest
1917
- ubuntu-latest
2018
- ubuntu-20.04
21-
2219
runs-on: ${{ matrix.OS }}
2320

2421
steps:
25-
# checkout source code
26-
- uses: actions/checkout@v2
22+
# checkout source code
23+
- uses: actions/checkout@v2
2724

28-
# install doxygen
29-
- name: Install Doxygen
30-
run: |
31-
if [[ "$RUNNER_OS" == "Linux" ]]; then
32-
sudo apt-get install doxygen -y
33-
elif [[ "$RUNNER_OS" == "macOS" ]]; then
34-
brew install --formula doxygen
35-
fi
25+
# install doxygen
26+
- name: Install Doxygen
27+
run: |
28+
if [[ "$RUNNER_OS" == "Linux" ]]; then
29+
sudo apt-get install doxygen -y
30+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
31+
brew install --formula doxygen
32+
fi
3633
37-
# compile SIPNET
38-
- name: compile sipnet
39-
run: make
34+
# compile SIPNET
35+
- name: compile sipnet
36+
run: make
37+
38+
# remove existing test output file
39+
- name: Remove Niwout Output File
40+
run: rm Sites/Niwot/niwot.out
41+
42+
# run single sipnet run
43+
- name: Run SIPNET on Sites/Niwot/niwot
44+
run: ./sipnet
45+
46+
# check for correct output of Niwot run
47+
- name: Check if niwot.out is generated
48+
shell: bash
49+
run: |
50+
if [ ! -f Sites/Niwot/niwot.out ]; then
51+
echo "::error title={No Output}::Test run for Niwot site failed to produce output"
52+
exit 1
53+
fi
54+
55+
# Check if niwot.out has changed
56+
- name: Check whether niwot.out has changed
57+
shell: bash
58+
run: |
59+
if git diff --exit-code Sites/Niwot/niwot.out; then
60+
echo "Success: Niwot.out created and has not changed"
61+
else
62+
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."
63+
exit 1
64+
fi
65+
66+
# Run Unit Tests
67+
test:
68+
needs: build
69+
strategy:
70+
fail-fast: false
71+
matrix:
72+
OS:
73+
- macos-latest
74+
- ubuntu-latest
75+
- ubuntu-20.04
76+
runs-on: ${{ matrix.OS }}
77+
78+
steps:
79+
# checkout source code
80+
- uses: actions/checkout@v2
4081

41-
# remove existing test output file
42-
- name: Remove Niwout Output File
43-
run: rm Sites/Niwot/niwot.out
82+
# compile unit tests
83+
- name: compile tests
84+
run: make test
4485

45-
# run single sipnet run
46-
- name: sipnet on Sites/Niwot/niwot
47-
run: ./sipnet
86+
# run tests
87+
- name: Run Unit Tests
88+
run: make testrun
4889

49-
# check output of test
50-
- name: fail if no niwot output exists
51-
if: ${{ hashFiles('Sites/Niwot/niwot.out') == '' }}
52-
run: |
53-
echo "::error title={No Output}::Test run for Niwot site failed to produce output"
54-
exit 1
55-
# check whether niwot.out has changed
56-
- name: Check whether niwot.out has changed
57-
shell: bash
58-
run: |
59-
if git diff --exit-code Sites/Niwot/niwot.out; then
60-
echo "Success: Niwot.out created and has not changed"
61-
else
62-
echo "::error title={Output Changed}::The test file niwot.out has changed"
63-
exit 1
64-
fi

CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ make clean
1515
# list all make commands
1616
make help
1717
```
18+
## Testing
19+
20+
SIPNET also uses `make` to build and run its unit tests. This can be done with the following commands:
21+
```shell
22+
# Compile tests
23+
make test
24+
# Run tests
25+
make testrun
26+
# Clean after tests are run
27+
make testclean
28+
```

Makefile

+43-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
CC=gcc
22
LD=gcc
3+
AR=ar
34
CFLAGS=-Wall
45
LIBLINKS=-lm
56

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

9-
SENSTEST_CFILES=sipnet.c sensTest.c paramchange.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c
10+
SENSTEST_CFILES=sipnet.c sensTest.c paramchange.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c events.c
1011
SENSTEST_OFILES=$(SENSTEST_CFILES:.c=.o)
1112

12-
SIPNET_CFILES=sipnet.c frontend.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c
13+
SIPNET_CFILES=sipnet.c frontend.c runmean.c util.c spatialParams.c namelistInput.c outputItems.c events.c
1314
SIPNET_OFILES=$(SIPNET_CFILES:.c=.o)
1415

1516
TRANSPOSE_CFILES=transpose.c util.c
@@ -25,13 +26,9 @@ DOXYFILE = docs/Doxyfile
2526
DOXYGEN_HTML_DIR = docs/html
2627
DOXYGEN_LATEX_DIR = docs/latex
2728

28-
# .PHONY indicates target names that are not file names, preventing conflicts if these names are used for filenames
29-
.PHONY: all clean document estimate sipnet transpose subsetData doxygen
30-
3129
# all: estimate sensTest sipnet transpose subsetData
3230
all: estimate sipnet transpose subsetData document
3331

34-
3532
# Only update docs if source files or Doxyfile have changed
3633
document: .doxygen.stamp
3734

@@ -58,8 +55,45 @@ subsetData: $(SUBSET_DATA_OFILES)
5855
clean:
5956
rm -f $(ESTIMATE_OFILES) $(SIPNET_OFILES) $(TRANSPOSE_OFILES) $(SUBSET_DATA_OFILES) estimate sensTest sipnet transpose subsetData
6057
rm -rf $(DOXYGEN_HTML_DIR) $(DOXYGEN_LATEX_DIR)
61-
#clean:
62-
# rm -f $(ESTIMATE_OFILES) $(SENSTEST_OFILES) $(SIPNET_OFILES) $(TRANSPOSE_OFILES) $(SUBSET_DATA_OFILES) estimate sensTest sipnet transpose subsetData
58+
59+
# UNIT TESTS
60+
SIPNET_TEST_DIRS:=$(shell find tests/sipnet -type d -mindepth 1 -maxdepth 1)
61+
SIPNET_TEST_DIRS_RUN:= $(addsuffix .run, $(SIPNET_TEST_DIRS))
62+
SIPNET_TEST_DIRS_CLEAN:= $(addsuffix .clean, $(SIPNET_TEST_DIRS))
63+
SIPNET_LIB=libsipnet.a
64+
65+
$(SIPNET_LIB): $(SIPNET_LIB)($(SIPNET_OFILES))
66+
ranlib $(SIPNET_LIB)
67+
68+
test: pretest $(SIPNET_TEST_DIRS) posttest $(SIPNET_LIB)
69+
70+
pretest:
71+
cp modelStructures.h modelStructures.orig.h
72+
73+
# The dash in the build command tells make to continue if there are errors, allowing cleanup
74+
$(SIPNET_TEST_DIRS): pretest $(SIPNET_LIB)
75+
cp $@/modelStructures.h modelStructures.h
76+
-$(MAKE) -C $@
77+
78+
# This is far from infallible, as model_structures.h will be in a bad place if a test
79+
# build step fails in a non-catchable way
80+
posttest: $(SIPNET_TEST_DIRS)
81+
mv modelStructures.orig.h modelStructures.h
82+
83+
testrun: $(SIPNET_TEST_DIRS_RUN)
84+
85+
$(SIPNET_TEST_DIRS_RUN):
86+
$(MAKE) -C $(basename $@) run
87+
88+
testclean: $(SIPNET_TEST_DIRS_CLEAN)
89+
rm -f $(SIPNET_LIB)
90+
91+
$(SIPNET_TEST_DIRS_CLEAN):
92+
$(MAKE) -C $(basename $@) clean
93+
94+
.PHONY: all clean document estimate sipnet transpose subsetData doxygen
95+
test $(SIPNET_TEST_DIRS) pretest posttest $(SIPNET_LIB) testrun
96+
$(SIPNET_TEST_DIRS_RUN) testclean $(SIPNET_TEST_DIRS_CLEAN)
6397

6498
help:
6599
@echo "Available targets:"
@@ -80,4 +114,3 @@ depend::
80114

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

83-

0 commit comments

Comments
 (0)