-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
162 lines (145 loc) · 5.45 KB
/
test.sh
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
#!/bin/bash
# Whether the next argument is the user. This is primarily to make testing more
# ergonomic on macOS.
# Example: "philipturner" in "/Users/philipturner/miniforge3/lib"
next_argument_user=false
# Whether the user has been specified.
user_specified=false
# The name of the user.
user_name=""
# Whether the next argument is the path.
next_argument_path=false
# Whether the path has been specified.
path_specified=false
# The name of the path.
path_name=""
# Whether to build the tests in release mode.
build_release=false
# Check whether the arguments parse correctly.
if [[ $# -gt 5 ]]; then
echo "Too many arguments."
invalid_input=true
elif [[ $# != 0 ]]; then
invalid_input=false
if [[ $invalid_input == false ]]; then
for param in "$@"; do
if [[ $param == "--user" ]]; then
if [[ $next_argument_user == true ]]; then
echo "Duplicate argument '--user'."
invalid_input=true
elif [[ $user_specified == true ]]; then
echo "Duplicate argument '--user'."
invalid_input=true
elif [[ $next_argument_path == true ]]; then
echo "Invalid use of '--path'."
invalid_input=true
else
next_argument_user=true
fi
elif [[ $param == "--path" ]]; then
if [[ $next_argument_path == true ]]; then
echo "Duplicate argument '--path'."
invalid_input=true
elif [[ $path_specified == true ]]; then
echo "Duplicate argument '--path'."
invalid_input=true
elif [[ $next_argument_user == true ]]; then
echo "Invalid use of '--user'."
invalid_input=true
else
next_argument_path=true
fi
elif [[ $param == "--release" ]]; then
if [[ $build_release == true ]]; then
echo "Duplicate argument '--release'."
invalid_input=true
elif [[ $next_argument_user == true ]]; then
echo "Invalid use of '--user'."
invalid_input=true
elif [[ $next_argument_path == true ]]; then
echo "Invalid use of '--path'."
invalid_input=true
else
build_release=true
fi
elif [[ $next_argument_user == true ]]; then
next_argument_user=false
user_specified=true
user_name="${param}"
elif [[ $next_argument_path == true ]]; then
next_argument_path=false
path_specified=true
path_name="${param}"
else
echo "Unrecognized argument '${param}'."
invalid_input=true
fi
done
fi
else
echo "No arguments found."
invalid_input=true
fi
# If the arguments parse correctly, check whether the path is correct.
if [[ $invalid_input == false ]]; then
if [[ $user_specified == true ]]; then
if [[ $path_specified == true ]]; then
echo "Choose either user or path."
invalid_input=true
else
# Automatically detect the OpenMM library path. This is only tested on
# Linux and arm64 macOS. Source: https://stackoverflow.com/a/8597411
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
export OPENMM_LIBRARY_PATH="/home/${user_name}/miniconda3/lib"
elif [[ "$OSTYPE" == "darwin"* ]]; then
export OPENMM_LIBRARY_PATH="/Users/${user_name}/miniforge3/lib"
else
echo "Unrecognized OS for argument '--user'."
exit -1
fi
fi
elif [[ $path_specified == true ]]; then
export OPENMM_LIBRARY_PATH="${path_name}"
else
echo "No user or path specified."
invalid_input=true
fi
fi
# Return early if the arguments are incorrect.
if [[ $invalid_input == true ]]; then
echo "Usage: test.sh [--user USER] [--path OPENMM_LIBRARY_PATH] [--release]"
exit -1
fi
# Add OpenMM to the dynamic linker path, if possible.
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
export LD_LIBRARY_PATH="$OPENMM_LIBRARY_PATH:$LD_LIBRARY_PATH"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# The tests shouldn't actually run, and no error should
# appear, because the command is broken.
:
fi
# Compile the executable.
if [[ $build_release == true ]]; then
swift test -Xswiftc -Ounchecked -Xswiftc -DRELEASE
export XCTEST_FILE="$(pwd)/.build/debug/MM4PackageTests.xctest"
# Alternative commands to activate when benchmarking performance.
# swift test -c release -Xswiftc -DRELEASE
# export XCTEST_FILE="$(pwd)/.build/release/MM4PackageTests.xctest"
else
swift test
export XCTEST_FILE="$(pwd)/.build/debug/MM4PackageTests.xctest"
fi
# Workaround for the tests not running on macOS.
if [[ "$OSTYPE" == "darwin"* ]]; then
export XCTEST_EXEC="$XCTEST_FILE/Contents/MacOS/MM4PackageTests"
# Link libc++ and every plausible OpenMM version for the next 5 years.
install_name_tool -change @rpath/libOpenMM.8.0.dylib "$OPENMM_LIBRARY_PATH/libOpenMM.8.0.dylib" $XCTEST_EXEC
install_name_tool -change @rpath/libOpenMM.8.1.dylib "$OPENMM_LIBRARY_PATH/libOpenMM.8.1.dylib" $XCTEST_EXEC
install_name_tool -change @rpath/libOpenMM.8.2.dylib "$OPENMM_LIBRARY_PATH/libOpenMM.8.2.dylib" $XCTEST_EXEC
install_name_tool -change @rpath/libOpenMM.8.3.dylib "$OPENMM_LIBRARY_PATH/libOpenMM.8.3.dylib" $XCTEST_EXEC
install_name_tool -change @rpath/libOpenMM.8.4.dylib "$OPENMM_LIBRARY_PATH/libOpenMM.8.4.dylib" $XCTEST_EXEC
install_name_tool -change @rpath/libOpenMM.8.5.dylib "$OPENMM_LIBRARY_PATH/libOpenMM.8.5.dylib" $XCTEST_EXEC
install_name_tool -change @rpath/libc++.1.dylib "$OPENMM_LIBRARY_PATH/libc++.1.dylib" $XCTEST_EXEC
# Actually run the Swift package tests.
swift test --skip-build
fi