Skip to content

Commit 303dd25

Browse files
committed
Add support for GitLab CI
There is a lingering issue with the *_host* tests. Their failure will not be reported correctly by the ci_print_failing.py script, since error messages are going to stderr and not to the output file.
1 parent d8adfbb commit 303dd25

13 files changed

Lines changed: 201 additions & 51 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*.app
2929

3030
# Build directories
31-
*build*
31+
*build*/
3232

3333
# Python stuff
3434
*.pyc

.gitlab-ci.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
before_script:
2-
- ls -la
3-
- apt-get update -y
4-
- apt-get install gcc g++ gfortran make cmake zlib1g-dev python-dateutil python-pyparsing python-numpy python-matplotlib python-pip python-setuptools python-dev -y
5-
gcc_debug:
6-
script:
7-
- "python setup.py --cxx=g++ --cc=gcc --fc=gfortran --type=debug"
8-
- cd build
9-
- make
10-
- ctest
11-
gcc_debug_nocxx11:
12-
script:
13-
- "python setup.py --cxx=g++ --cc=gcc --fc=gfortran --type=debug --cmake-options='-DENABLE_CXX11_SUPPORT=OFF'"
14-
- cd build
15-
- make
16-
- ctest
2+
- ls -la
3+
- apt-get update -y
4+
- apt-get install cmake zlib1g-dev libboost-all-dev python-dateutil python-pyparsing python-numpy python-matplotlib python-pip python-setuptools python-dev -y
5+
- python -V
6+
- cmake --version
7+
- g++ --version
8+
- gcc --version
9+
- gfortran --version
10+
11+
variables:
12+
CTEST_COMMAND: "ctest --parallel 2 --output-on-failure --verbose --dashboard Experimental --track GitLabCI"
13+
14+
gcc:
15+
image: gcc:5.4
16+
script:
17+
- python setup.py --cxx=g++ --cc=gcc --fc=gfortran --type=release
18+
- cd build
19+
- ../.scripts/ci_build.sh
20+
- python ../.scripts/ci_test.py ${CTEST_COMMAND}
21+
- python ../.scripts/ci_print_failing.py
22+
artifacts:
23+
paths:
24+
- build.log
25+
- full_ctest_output.dat

.scripts/ci_build.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
# The return code will capture an error from ANY of the functions in the pipe
4+
set -o pipefail
5+
cmake --build . -- --jobs=2 VERBOSE=1 | tee build.log | grep "Building"
6+
RESULT=$?
7+
8+
if [ $RESULT -eq 0 ]; then
9+
echo build succeeded
10+
else
11+
echo build failed
12+
cat build.log
13+
exit 1
14+
fi

.scripts/ci_print_failing.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
import re
3+
import sys
4+
5+
badtests = []
6+
testfail = re.compile(r'^\s*(?P<num>\d+) - (?P<name>\w+(?:-\w+)*) \(Failed\)\s*$')
7+
8+
with open('full_ctest_output.dat', 'r') as outfile:
9+
ctestout = outfile.readlines()
10+
11+
ctest_exit_status = int(ctestout[0])
12+
if len(ctestout[1:]) == 0:
13+
sys.stdout.write('\n <<< All test cases have passed! >>>\n\n')
14+
else:
15+
sys.stdout.write('\n <<< Failing outputs follow. >>>\n\n')
16+
17+
for line in ctestout[1:]:
18+
linematch = testfail.match(line)
19+
if linematch:
20+
bad = linematch.group('name')
21+
sys.stdout.write('\n\n {} failed. Here is the output:\n'.format(bad))
22+
23+
badoutfile = 'tests/' + bad + '.log'
24+
25+
with open(badoutfile, 'r') as ofile:
26+
sys.stdout.write(ofile.read())
27+
28+
# <<< return ctest error code >>>
29+
sys.exit(ctest_exit_status)

.scripts/ci_test.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import time
4+
import subprocess
5+
6+
def run_ctest(command):
7+
"""
8+
Execute CTest command
9+
"""
10+
return subprocess.Popen(command,
11+
bufsize=0,
12+
stdout=subprocess.PIPE,
13+
universal_newlines=True)
14+
15+
ctest_command = sys.argv[1:]
16+
print("CTest command \"{}\"".format(' '.join(ctest_command)))
17+
retcode = run_ctest(ctest_command)
18+
print_all = False
19+
ctestout = ''
20+
while True:
21+
data = retcode.stdout.readline()
22+
# print(data.split())
23+
if not data:
24+
break
25+
26+
if '% tests passed,' in data:
27+
print_all = True
28+
29+
sdata = data.split()
30+
test_line = ('Test' in sdata) and ('sec' in sdata)
31+
start_line = ('Start' in sdata)
32+
if test_line or start_line or print_all:
33+
sys.stdout.write(data) # screen
34+
#print sys.stdout.write(data)
35+
ctestout += data # string
36+
37+
while True:
38+
retcode.poll()
39+
exstat = retcode.returncode
40+
if exstat is not None:
41+
ctest_exit_status = exstat
42+
break
43+
time.sleep(0.1)
44+
45+
# <<< identify failed tests and cat their output >>>
46+
sys.stdout.write("""\n <<< CTest complete with status %d. >>>\n\n""" %
47+
(ctest_exit_status))
48+
49+
ctestout = str(ctest_exit_status) + "\n" + ctestout
50+
51+
with open('full_ctest_output.dat', 'w') as outfile:
52+
outfile.write(ctestout)

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,10 @@ before_script:
349349
- ${Fortran_COMPILER} --version
350350
- python setup.py --cxx=${CXX_COMPILER} --cc=${C_COMPILER} --fc=${Fortran_COMPILER} --type=${BUILD_TYPE} --cmake-options='-Hprojects/CMake' ${STATIC} ${COVERAGE}
351351
- cd build
352+
- ../.scripts/ci_build.sh
352353
script:
353-
- ctest --parallel 2 --output-on-failure --verbose --dashboard Experimental --track TravisCI
354+
- python ../.scripts/ci_test.py ctest --parallel 2 --output-on-failure --verbose --dashboard Experimental --track TravisCI
355+
- python ../.scripts/ci_print_failing.py
354356
after_success:
355357
- |
356358
if [[ "${COVERAGE}" = true ]]; then

cmake/custom/test.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ macro(add_Catch_test _name _labels)
99
endforeach()
1010
unset(_labels)
1111

12-
# This is the unit tests runner
13-
set(RUNNER ${PROJECT_BINARY_DIR}/tests/unit_tests --success)
14-
15-
add_test(NAME ${_name} COMMAND ${RUNNER} [${_name}])
12+
add_test(NAME ${_name}
13+
COMMAND ${PROJECT_BINARY_DIR}/tests/unit_tests [${_name}] --success --out ${PROJECT_BINARY_DIR}/tests/${_name}.log --durations yes
14+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
1615

1716
if(labels)
1817
set_tests_properties(${_name} PROPERTIES LABELS "${labels}")

src/interface/Input.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct BIOperatorData;
3838
struct CavityData;
3939
struct GreenData;
4040
struct SolverData;
41-
struct TDSolverData;
4241
} // namespace pcm
4342

4443
#include "utils/Molecule.hpp"

src/utils/Atom.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct Atom {
8585
symbol(sym) {}
8686
};
8787

88-
typedef tuple<std::string, std::vector<Atom> > RadiiSet;
88+
typedef pcm::tuple<std::string, std::vector<Atom> > RadiiSet;
8989

9090
namespace detail {
9191
/*! \brief Returns a vector<Atom> containing Bondi van der Waals

tests/C_host/C_host.c

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void host_writer(const char * message) { fprintf(output, "%s\n", message); }
3939

4040
int main() {
4141

42-
output = fopen("C_host.log", "w+");
42+
output = fopen("C_host.out", "w+");
4343
if (!pcmsolver_is_compatible_library()) {
4444
fprintf(stderr, "%s\n", "PCMSolver library not compatible");
4545
exit(EXIT_FAILURE);
@@ -48,17 +48,36 @@ int main() {
4848
fprintf(output, "%s\n", "Starting a PCMSolver calculation");
4949
// Use C2H4 in D2h symmetry
5050
double charges[NR_NUCLEI] = {6.0, 1.0, 1.0, 6.0, 1.0, 1.0};
51-
double coordinates[3 * NR_NUCLEI] = {
52-
0.0, 0.000000, 1.257892, 0.0, 1.745462, 2.342716, 0.0, -1.745462, 2.342716,
53-
0.0, 0.000000, -1.257892, 0.0, 1.745462, -2.342716, 0.0, -1.745462, -2.342716};
51+
double coordinates[3 * NR_NUCLEI] = {0.0,
52+
0.000000,
53+
1.257892,
54+
0.0,
55+
1.745462,
56+
2.342716,
57+
0.0,
58+
-1.745462,
59+
2.342716,
60+
0.0,
61+
0.000000,
62+
-1.257892,
63+
0.0,
64+
1.745462,
65+
-2.342716,
66+
0.0,
67+
-1.745462,
68+
-2.342716};
5469
// This means the molecular point group has three generators:
5570
// the Oxy, Oxz and Oyz planes
5671
int symmetry_info[4] = {3, 4, 2, 1};
5772
struct PCMInput host_input = pcmsolver_input();
5873

59-
pcmsolver_context_t * pcm_context =
60-
pcmsolver_new(PCMSOLVER_READER_HOST, NR_NUCLEI, charges, coordinates,
61-
symmetry_info, &host_input, host_writer);
74+
pcmsolver_context_t * pcm_context = pcmsolver_new(PCMSOLVER_READER_HOST,
75+
NR_NUCLEI,
76+
charges,
77+
coordinates,
78+
symmetry_info,
79+
&host_input,
80+
host_writer);
6281

6382
pcmsolver_print(pcm_context);
6483

@@ -89,8 +108,8 @@ int main() {
89108
// This is the B3g irreducible representation
90109
irrep = 3;
91110
pcmsolver_compute_response_asc(pcm_context, mep_lbl, asc_neq_B3g_lbl, irrep);
92-
pcmsolver_get_surface_function(pcm_context, grid_size, asc_neq_B3g,
93-
asc_neq_B3g_lbl);
111+
pcmsolver_get_surface_function(
112+
pcm_context, grid_size, asc_neq_B3g, asc_neq_B3g_lbl);
94113

95114
// Equilibrium ASC in B3g symmetry.
96115
// This is an internal check: the relevant segment of the vector
@@ -104,33 +123,39 @@ int main() {
104123
// Cavity size
105124
const int ref_size = 576;
106125
if (grid_size != ref_size) {
107-
fprintf(stderr, "%s\n", "Error in the cavity size, please file an issue on: "
108-
"https://github.com/PCMSolver/pcmsolver");
126+
fprintf(stderr,
127+
"%s\n",
128+
"Error in the cavity size, please file an issue on: "
129+
"https://github.com/PCMSolver/pcmsolver");
109130
exit(EXIT_FAILURE);
110131
} else {
111132
fprintf(output, "%s\n", "Test on cavity size: PASSED");
112133
}
113134
// Irreducible cavity size
114135
const int ref_irr_size = 72;
115136
if (irr_grid_size != ref_irr_size) {
116-
fprintf(stderr, "%s\n", "Error in the irreducible cavity size, please file an "
117-
"issue on: https://github.com/PCMSolver/pcmsolver");
137+
fprintf(stderr,
138+
"%s\n",
139+
"Error in the irreducible cavity size, please file an "
140+
"issue on: https://github.com/PCMSolver/pcmsolver");
118141
exit(EXIT_FAILURE);
119142
} else {
120143
fprintf(output, "%s\n", "Test on irreducible cavity size: PASSED");
121144
}
122145
// Polarization energy
123146
const double ref_energy = -0.437960027982;
124147
if (!check_unsigned_error(energy, ref_energy, 1.0e-7)) {
125-
fprintf(stderr, "%s\n", "Error in the polarization energy, please file an issue "
126-
"on: https://github.com/PCMSolver/pcmsolver");
148+
fprintf(stderr,
149+
"%s\n",
150+
"Error in the polarization energy, please file an issue "
151+
"on: https://github.com/PCMSolver/pcmsolver");
127152
exit(EXIT_FAILURE);
128153
} else {
129154
fprintf(output, "%s\n", "Test on polarization energy: PASSED");
130155
}
131156
// Surface functions
132-
test_surface_functions(output, grid_size, mep, asc_Ag, asc_B3g, asc_neq_B3g,
133-
areas);
157+
test_surface_functions(
158+
output, grid_size, mep, asc_Ag, asc_B3g, asc_neq_B3g, areas);
134159

135160
pcmsolver_write_timings(pcm_context);
136161

0 commit comments

Comments
 (0)