-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathrun-tests.sh
More file actions
executable file
·189 lines (170 loc) · 6.48 KB
/
Copy pathrun-tests.sh
File metadata and controls
executable file
·189 lines (170 loc) · 6.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
# I use this script for building, testing and updating docs.
# Note: running Python scripts with locally built gemmi module requires setting
# PYTHONPATH. Locally, I'm using bash function "gpy" that starts python with
# gemmi imported ("gpy" for interactive mode, "gpy file.py" for script):
# echo "import gemmi" > $HOME/.import-gemmi.py
# gpy() { PYTHONPATH=$HOME/gemmi/gemmi/build/py PYTHONSTARTUP=$HOME/.import-gemmi.py python3 -q "$@"; }
# set up variables
set -eu
cd "$(dirname "$0")"
BUILD_DIR="$(pwd)"
[ -e build ] && BUILD_DIR="$(pwd)/build"
if [ -z "${PYTHON-}" ]; then
PYTHON=`grep '^_\?Python_EXECUTABLE:' $BUILD_DIR/CMakeCache.txt | cut -d= -f2`
fi
if [ -z "${PYTHON-}" ]; then
PYTHON=python3
fi
if [ -z "${CXX-}" ]; then
CXX=`grep '^CMAKE_CXX_COMPILER:' $BUILD_DIR/CMakeCache.txt | cut -d= -f2`
fi
if [ -z "${CXX-}" ]; then
CXX=c++
fi
if grep -q '^BUILD_SHARED_LIBS:BOOL=ON' $BUILD_DIR/CMakeCache.txt; then
GEMMI_CPP_LIB=$BUILD_DIR/libgemmi_cpp.so
GEMMI_CPP_RPATH="-Wl,-rpath=$BUILD_DIR"
else
GEMMI_CPP_LIB=$BUILD_DIR/libgemmi_cpp.a
GEMMI_CPP_RPATH=
fi
# Build all, except when we called with an option to avoid full compilation:
# G - only build the program,
# P - only build Python bindings,
# n - do not build, only run tests.
if [ $# = 1 ] && [ $1 = G ]; then
(cd $BUILD_DIR && make -j gemmi_prog)
exit
fi
if [ $# = 1 ] && [ $1 = P ]; then
(cd $BUILD_DIR && make -j gemmi_py)
exit
fi
if [ $# = 1 ] && [ $1 = doctest ]; then
(cd docs && PYTHONPATH=$BUILD_DIR/py $PYTHON -m sphinx -M doctest . _build -q -n)
exit
fi
if [ $# != 0 ] && [ $1 = n ]; then
shift
else
(cd $BUILD_DIR && make -j all check)
./tools/cmp-size.py build/gemmi $GEMMI_CPP_LIB build/py/gemmi/gemmi_ext*
./tools/docs-help.sh
fi
# Run tests and checks.
if [ $# = 0 ] || [ $1 != i ]; then
export PYTHONPATH=$BUILD_DIR/py
export PATH="$BUILD_DIR:$PATH"
fi
$PYTHON -m unittest discover -s tests
grep :: $BUILD_DIR/py/gemmi/*.pyi ||:
if [ -z "${NO_DOCTEST-}" ]; then
# 'make doctest' works only if sphinx-build was installed for python3.
#(cd docs && make doctest SPHINXOPTS="-q -n")
(cd docs && $PYTHON -m sphinx -M doctest . _build -q -n)
fi
echo "Building docs (in background)..."
./tools/header-list.py >docs/headers.rst
(cd docs && make -j html SPHINXOPTS="-q -n")&
# Usually, we stop here. Below are more extensive checks below that are run
# before making a release. They are run when this script is called with 'a'
# or with an option corresponding to the check.
[ $# = 0 ] && exit;
flake8 docs/ examples/ tests/ tools/
mypy --disable-error-code=override --disable-error-code=attr-defined $BUILD_DIR/py/gemmi
# this check is only for pip-installed packages
if [ $1 = i ]; then
echo 'Check if gemmi package is found by setuptools pkg_resources...'
$PYTHON -c '__requires__ = ["gemmi"]; import pkg_resources'
echo 'OK'
fi
# a few quick extra (x) checks
if [ $1 = x -o $1 = a ]; then
echo 'Run codespell'
codespell include src prog python fortran tests examples docs wasm tools ||:
echo 'Checking serialize.hpp...'
$PYTHON tools/check_serialize.py
fi
if [ $1 = m -o $1 = a ]; then
echo 'Creating, compiling and removing test_mmdb{1,2}.cpp'
mmdb_lto=`sed -n 's/^CXX_FLAGS = //p' $BUILD_DIR/CMakeFiles/gemmi_cpp.dir/flags.make |
tr ' ' '\n' | grep '^-flto' | tr '\n' ' ' ||:`
echo 'Example 1: gemmi -> mmdb'
cmd1="$CXX $mmdb_lto -O -Wall -Wextra -pedantic -Wshadow -Iinclude \
test_mmdb1.cpp -lmmdb2 $GEMMI_CPP_LIB -lz $GEMMI_CPP_RPATH -o test_mmdb1"
awk '/Example 1/,/^}/' include/gemmi/mmdb.hpp > test_mmdb1.cpp
${cmd1}
echo "Converting tests/1orc.pdb to /tmp/example1.pdb"
./test_mmdb1 tests/1orc.pdb /tmp/example1.pdb
echo 'Example 2: mmdb -> gemmi'
awk '/Example 2/,/^}/' include/gemmi/mmdb.hpp > test_mmdb2.cpp
echo "Converting tests/1orc.pdb to /tmp/example1.pdb"
./test_mmdb1 tests/1orc.pdb /tmp/example1.pdb
cmd2="$CXX $mmdb_lto -O -Wall -Wextra -pedantic -Wshadow -Iinclude \
test_mmdb2.cpp -lmmdb2 $GEMMI_CPP_LIB -lz $GEMMI_CPP_RPATH -o test_mmdb2"
${cmd2}
echo "Converting tests/1orc.pdb to /tmp/example2.pdb"
./test_mmdb2 tests/1orc.pdb /tmp/example2.pdb
rm -f test_mmdb1.cpp test_mmdb2.cpp test_mmdb1 test_mmdb2
fi
if [ $1 = h -o $1 = a ]; then
echo "check if each header can be compiled on its own"
# skip mmdb.hpp which requires also mmdb2 headers
for f in include/gemmi/*.hpp; do
if [ $f != include/gemmi/mmdb.hpp ]; then
echo -n .
gcc -c -fsyntax-only -Dsmall=.avoid/small $f
fi
done
echo
fi
if [ $1 = v -o $1 = a ]; then
echo "running tests under valgrind"
valgrind $BUILD_DIR/cpptest
PYTHONMALLOC=malloc valgrind $PYTHON -m unittest discover -s tests
(cd docs && PYTHONMALLOC=malloc valgrind --trace-children=yes \
$PYTHON $(which sphinx-build) -M doctest . _build -q -E)
fi
if [ $1 = p -o $1 = a ]; then
echo "check if pdb->cif conversion produces valid CIF files"
for i in $PDB_DIR/structures/divided/pdb/z[h-z]; do
echo $i
for j in $i/pdb*; do
#echo $j
gemmi convert $j /tmp/converted.cif
gemmi validate /tmp/converted.cif
done
#echo -n .
done
fi
if [ $1 = c -o $1 = a ]; then
echo "test with tools/compare_pdb.sh"
echo "=== part 1: cif -> pdb, pdb -> pdb ==="
for pdbid in 2aa2 3ee3 4ii4 5oo5 6yy6 5xx5 6dd6 7uu7 7ww7 8ff8; do
./tools/compare_pdb.sh $pdbid # cif -> pdb
FROM_PDB=1 ./tools/compare_pdb.sh $pdbid # pdb -> pdb
done
echo
echo "=== part 2: cif -> cif -> pdb, pdb -> cif -> pdb ==="
for pdbid in 2aa2 3ee3 4ii4 5oo5 6yy6 5xx5 6dd6 7ww7 8ff8; do
VIA_CIF=1 ./tools/compare_pdb.sh $pdbid # cif -> cif -> pdb
FROM_PDB=1 VIA_CIF=1 ./tools/compare_pdb.sh $pdbid # pdb -> cif -> pdb
done
fi
if [ $1 = w -o $1 = a ]; then
echo "check if wasm and project-gemmi/wasm can be built"
[ -z ${EMSDK+x} ] && . $HOME/local/emsdk/emsdk_env.sh
(cd wasm && make clean && make -j && npm run test)
fi
if [ $1 = M -o $1 = a ]; then
echo "check bulk solvent mask against cctbx"
for code in 1keb 1mru 5oo5 6dd6; do
echo Testing mask for $code ...
pdb="${PDB_DIR}/structures/divided/pdb/${code:1:2}/pdb${code}.ent.gz"
zcat $pdb > /tmp/file.pdb
$CCP4/libexec/python3 -m mmtbx.command_line.mask /tmp/file.pdb
$PYTHON examples/maskcheck.py mask.ccp4 /tmp/file.pdb
/bin/rm mask.ccp4
done
fi