Skip to content

Commit 6c540ff

Browse files
committed
Merge branch 'develop' into feature/libsundials
2 parents 873001e + 92045a9 commit 6c540ff

File tree

4 files changed

+119
-33
lines changed

4 files changed

+119
-33
lines changed

Jenkinsfile

+55-16
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ pipeline {
5757
OPENCL_PLATFORM_ID_CPU = 0
5858
OPENCL_PLATFORM_ID_GPU = 0
5959
PARALLEL = 4
60+
GIT_AUTHOR_NAME = 'Stan Jenkins'
61+
GIT_AUTHOR_EMAIL = '[email protected]'
62+
GIT_COMMITTER_NAME = 'Stan Jenkins'
63+
GIT_COMMITTER_EMAIL = '[email protected]'
6064
}
6165
stages {
6266

@@ -85,14 +89,12 @@ pipeline {
8589
usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD')]) {
8690
sh """#!/bin/bash
8791
set -x
88-
git config user.email "[email protected]"
89-
git config user.name "Stan Jenkins"
9092
git checkout -b ${branchName()}
9193
clang-format --version
9294
find stan test -name '*.hpp' -o -name '*.cpp' | xargs -n20 -P${PARALLEL} clang-format -i
9395
if [[ `git diff` != "" ]]; then
9496
git add stan test
95-
git commit --author='Stan BuildBot <[email protected]>' -m "[Jenkins] auto-formatting by `clang-format --version`"
97+
git commit -m "[Jenkins] auto-formatting by `clang-format --version`"
9698
git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/${fork()}/math.git ${branchName()}
9799
echo "Exiting build because clang-format found changes."
98100
echo "Those changes are now found on stan-dev/math under branch ${branchName()}"
@@ -177,25 +179,62 @@ pipeline {
177179
}
178180
}
179181

180-
stage('Headers check') {
181-
agent {
182-
docker {
183-
image 'stanorg/ci:gpu-cpp17'
184-
label 'linux'
185-
}
186-
}
182+
stage('Quick tests') {
187183
when {
188184
expression {
189185
!skipRemainingStages
190186
}
191187
}
192-
steps {
193-
unstash 'MathSetup'
194-
sh "echo CXX=${CLANG_CXX} -Werror > make/local"
195-
sh "echo O=0 >> make/local"
196-
sh "make -j${PARALLEL} test-headers"
188+
failFast true
189+
parallel {
190+
stage('Headers check') {
191+
when {
192+
expression {
193+
!skipRemainingStages
194+
}
195+
}
196+
agent {
197+
docker {
198+
image 'stanorg/ci:gpu-cpp17'
199+
label 'linux'
200+
}
201+
}
202+
203+
steps {
204+
unstash 'MathSetup'
205+
sh "echo CXX=${CLANG_CXX} -Werror > make/local"
206+
sh "make -j${PARALLEL} test-headers"
207+
}
208+
post { always { deleteDir() } }
209+
}
210+
stage('Run changed unit tests') {
211+
agent {
212+
docker {
213+
image 'stanorg/ci:gpu-cpp17'
214+
label 'linux'
215+
args '--cap-add SYS_PTRACE'
216+
}
217+
}
218+
when {
219+
allOf {
220+
expression {
221+
env.BRANCH_NAME ==~ /PR-\d+/
222+
}
223+
expression {
224+
!skipRemainingStages
225+
}
226+
}
227+
}
228+
steps {
229+
retry(3) { checkout scm }
230+
231+
sh "echo CXXFLAGS += -fsanitize=address >> make/local"
232+
sh "./runTests.py -j${PARALLEL} --changed --debug"
233+
234+
}
235+
post { always { retry(3) { deleteDir() } } }
236+
}
197237
}
198-
post { always { deleteDir() } }
199238
}
200239

201240
stage('Full Unit Tests') {

runTests.py

+63-16
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ def processCLIArgs():
8787
default=-1,
8888
help="number of files to split expressions tests in",
8989
)
90-
tests_help_msg = "The path(s) to the test case(s) to run.\n"
91-
tests_help_msg += "Example: 'test/unit', 'test/prob', and/or\n"
92-
tests_help_msg += " 'test/unit/math/prim/fun/abs_test.cpp'"
93-
parser.add_argument("tests", nargs="+", type=str, help=tests_help_msg)
9490
f_help_msg = "Only tests with file names matching these will be executed.\n"
9591
f_help_msg += "Example: '-f chol', '-f opencl', '-f prim'"
9692
parser.add_argument("-f", type=str, default=[], action="append", help=f_help_msg)
93+
changed_help = (
94+
"Use git to determine which tests may have changed, and run only those"
95+
)
96+
parser.add_argument("--changed", action="store_true", help=changed_help)
9797
parser.add_argument(
9898
"-d",
9999
"--debug",
@@ -127,6 +127,11 @@ def processCLIArgs():
127127
action="store_true",
128128
help="Build/run jumbo tests.",
129129
)
130+
131+
tests_help_msg = "The path(s) to the test case(s) to run.\n"
132+
tests_help_msg += "Example: 'test/unit', 'test/prob', and/or\n"
133+
tests_help_msg += " 'test/unit/math/prim/fun/abs_test.cpp'"
134+
parser.add_argument("tests", nargs="*", type=str, help=tests_help_msg)
130135
# And parse the command line against those rules
131136
return parser.parse_args()
132137

@@ -146,6 +151,8 @@ def isWin():
146151

147152
batchSize = 20 if isWin() else 200
148153
jumboSize = 5 if isWin() else 12
154+
maxChangedTests = 20
155+
149156

150157
def mungeName(name):
151158
"""Set up the makefile target name"""
@@ -306,6 +313,38 @@ def findTests(base_path, filter_names, do_jumbo=False):
306313
return tests
307314

308315

316+
def findChangedTests(debug):
317+
import subprocess
318+
319+
changed_files = subprocess.run(
320+
["git", "diff", "--name-only", "origin/develop...HEAD"], text=True, capture_output=True
321+
).stdout.splitlines()
322+
if debug:
323+
print("Changed files:", changed_files)
324+
325+
# changes in prim should also test other non-prim signatures
326+
test_deps = {"prim/": ["prim/", "rev/", "mix/", "fwd/"], "rev/": ["rev/", "mix/"], "fwd/": ["fwd/", "mix/"]}
327+
328+
changed_tests = set()
329+
for f in changed_files:
330+
if 'stan/' in f and f.endswith('.hpp') and 'opencl' not in f: # changed fn
331+
maybe_test = f.replace('stan/', 'test/unit/').replace('.hpp', testsfx)
332+
for (path, replacements) in test_deps.items():
333+
if path in maybe_test:
334+
for rep in replacements:
335+
maybe_test = maybe_test.replace(path, rep)
336+
if os.path.exists(maybe_test):
337+
changed_tests.add(maybe_test)
338+
339+
if f.endswith(testsfx) and 'opencl' not in f:
340+
changed_tests.add(f)
341+
342+
if len(changed_tests) > maxChangedTests:
343+
stopErr("Number of changed tests excluded maximum, not running priority tests", 0)
344+
345+
return list(map(mungeName, changed_tests))
346+
347+
309348
def batched(tests):
310349
return [tests[i : i + batchSize] for i in range(0, len(tests), batchSize)]
311350

@@ -357,30 +396,37 @@ def main():
357396
stan_mpi = "STAN_MPI" in f.read()
358397
except IOError:
359398
stan_mpi = False
360-
# pass 0: generate all auto-generated tests
361-
if any("test/prob" in arg for arg in inputs.tests):
362-
generateTests(inputs.j)
363-
tests = inputs.tests
364399

365400
jumboFiles = []
366-
if inputs.do_jumbo:
367-
jumboFiles = generateJumboTests(tests, debug=inputs.debug)
368-
try:
401+
402+
if inputs.changed:
403+
tests = findChangedTests(inputs.debug)
404+
else:
405+
# pass 0: generate all auto-generated tests
406+
if any("test/prob" in arg for arg in inputs.tests):
407+
generateTests(inputs.j)
408+
409+
if inputs.do_jumbo:
410+
jumboFiles = generateJumboTests(inputs.tests)
369411
if inputs.e == -1:
370412
if inputs.j == 1:
371413
num_expr_test_files = 1
372414
else:
373415
num_expr_test_files = inputs.j * 4
374416
else:
375417
num_expr_test_files = inputs.e
376-
handleExpressionTests(tests, inputs.only_functions, num_expr_test_files)
418+
handleExpressionTests(inputs.tests, inputs.only_functions, num_expr_test_files)
377419

378420
tests = findTests(inputs.tests, inputs.f, inputs.do_jumbo)
379421

380-
if not tests:
381-
stopErr("No matching tests found.", -1)
382-
if inputs.debug:
383-
print("Collected the following tests:\n", tests)
422+
if not tests:
423+
if inputs.changed:
424+
stopErr("No changed tests were found!", 0)
425+
stopErr(
426+
"No matching tests found. Check the path passed on the command line", -1
427+
)
428+
429+
try:
384430
# pass 1: make test executables
385431
for batch in batched(tests):
386432
if inputs.debug:
@@ -399,5 +445,6 @@ def main():
399445
cleanupJumboTests(jumboFiles)
400446
pass
401447

448+
402449
if __name__ == "__main__":
403450
main()

stan/math/prim/fun/asinh.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ inline std::complex<V> complex_asinh(const std::complex<V>& z) {
6565
return copysign(y, y_d);
6666
}
6767
} // namespace internal
68-
6968
} // namespace math
7069
} // namespace stan
7170

test/unit/math/mix/fun/abs_test.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TEST(mixFun, absBasics) {
1414
x << 1, 2, 3, 4, 5, 6;
1515
Eigen::Matrix<double, -1, -1> y = abs(x);
1616

17+
// test int -> int vectorization
1718
std::vector<int> u{1, 2, 3, 4};
1819
std::vector<int> v = abs(u);
1920
}

0 commit comments

Comments
 (0)