Skip to content

Commit 687834d

Browse files
orionrfacebook-github-bot
authored andcommitted
Install cpp tests when built (pytorch#15000)
Summary: This is broken out of pytorch#13733 We want to install cpp tests so they can ultimately be runnable from that location for Caffe2 tests run from PyTorch builds. cc pjh5 yf225 anderspapitto Pull Request resolved: pytorch#15000 Reviewed By: pjh5 Differential Revision: D13416253 Pulled By: orionr fbshipit-source-id: 51280be0a22557a742f90c9f303c58c35cbd4a38
1 parent 5d3a347 commit 687834d

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ aten/build/
2323
aten/src/ATen/Config.h
2424
aten/src/ATen/cuda/CUDAConfig.h
2525
build/
26+
caffe2/cpp_test/
2627
dist/
2728
docs/src/**/*
2829
docs/cpp/build

.jenkins/caffe2/build.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ if [[ -z "$INTEGRATED" ]]; then
229229
exit 1
230230
fi
231231
232+
# This is to save test binaries for testing
233+
mv "$INSTALL_PREFIX/test/" "$INSTALL_PREFIX/cpp_test/"
234+
235+
ls $INSTALL_PREFIX
236+
232237
else
233238
234239
# sccache will be stuck if all cores are used for compiling
@@ -237,10 +242,12 @@ else
237242
export MAX_JOBS=`expr $(nproc) - 1`
238243
fi
239244
240-
USE_LEVELDB=1 USE_LMDB=1 USE_OPENCV=1 BUILD_BINARY=1 python setup.py install --user
245+
USE_LEVELDB=1 USE_LMDB=1 USE_OPENCV=1 BUILD_TEST=1 BUILD_BINARY=1 python setup.py install --user
241246
242247
# This is to save test binaries for testing
243248
cp -r torch/lib/tmp_install $INSTALL_PREFIX
249+
mkdir -p "$INSTALL_PREFIX/cpp_test/"
250+
cp -r caffe2/test/* "$INSTALL_PREFIX/cpp_test/"
244251
245252
ls $INSTALL_PREFIX
246253

.jenkins/caffe2/test.sh

+18-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ if [[ "${BUILD_ENVIRONMENT}" =~ py((2|3)\.?[0-9]?\.?[0-9]?) ]]; then
1212
PYTHON="python${BASH_REMATCH[1]}"
1313
fi
1414
15-
# The prefix must mirror the setting from build.sh
16-
INSTALL_PREFIX="/usr/local/caffe2"
17-
1815
# Add the site-packages in the caffe2 install prefix to the PYTHONPATH
1916
SITE_DIR=$($PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib(prefix=''))")
20-
INSTALL_SITE_DIR="${INSTALL_PREFIX}/${SITE_DIR}"
17+
18+
# Find where Caffe2 is installed. This will be the absolute path to the
19+
# site-packages of the active Python installation
20+
INSTALL_SITE_DIR=$($PYTHON -c "from distutils import sysconfig; print(sysconfig.get_python_lib())")
21+
INSTALL_PREFIX="$INSTALL_SITE_DIR/caffe2"
22+
if [ ! -d "$INSTALL_PREFIX/cpp_test" ]; then
23+
echo "Directory $INSTALL_PREFIX/cpp_test not found. Fallback to legacy location."
24+
INSTALL_PREFIX="/usr/local/caffe2"
25+
INSTALL_SITE_DIR="${INSTALL_PREFIX}/${SITE_DIR}"
26+
fi
2127
2228
# Skip tests in environments where they are not built/applicable
2329
if [[ "${BUILD_ENVIRONMENT}" == *-android* ]]; then
@@ -46,20 +52,20 @@ echo "Running C++ tests.."
4652
gtest_reports_dir="${TEST_DIR}/cpp"
4753
junit_reports_dir="${TEST_DIR}/junit_reports"
4854
mkdir -p "$gtest_reports_dir" "$junit_reports_dir"
49-
for test in $(find "${INSTALL_PREFIX}/test" -executable -type f); do
55+
for test in $(find "${INSTALL_PREFIX}/cpp_test" -executable -type f); do
5056
case "$test" in
5157
# skip tests we know are hanging or bad
5258
*/mkl_utils_test|*/aten/integer_divider_test)
5359
continue
5460
;;
5561
*/scalar_tensor_test|*/basic|*/native_test)
56-
if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
57-
continue
58-
else
59-
"$test"
60-
fi
61-
;;
62-
*)
62+
if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
63+
continue
64+
else
65+
"$test"
66+
fi
67+
;;
68+
*)
6369
# Currently, we use a mixture of gtest (caffe2) and Catch2 (ATen). While
6470
# planning to migrate to gtest as the common PyTorch c++ test suite, we
6571
# currently do NOT use the xml test reporter, because Catch doesn't

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ cmake_dependent_option(
7575
"NOT BUILD_SHARED_LIBS" OFF)
7676
option(BUILD_TEST "Build C++ test binaries (need gtest and gbenchmark)" OFF)
7777
cmake_dependent_option(
78-
INSTALL_TEST "Install test binaries if BUILD_TEST is on" OFF
78+
INSTALL_TEST "Install test binaries if BUILD_TEST is on" ON
7979
"BUILD_TEST" OFF)
8080
option(USE_ACL "Use ARM Compute Library" OFF)
8181
option(USE_ASAN "Use Address Sanitizer" OFF)

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ def make_relative_rpath(path):
10251025
'share/cmake/Torch/*.cmake',
10261026
],
10271027
'caffe2': [
1028-
rel_site_packages + '/caffe2/**/*.py'
1028+
'cpp_test/*',
10291029
]
10301030
},
10311031
)

tools/build_pytorch_libs.sh

+19
Original file line numberDiff line numberDiff line change
@@ -342,4 +342,23 @@ $SYNC_COMMAND -r "$INSTALL_DIR/include" .
342342
if [ -d "$INSTALL_DIR/bin/" ]; then
343343
$SYNC_COMMAND -r "$INSTALL_DIR/bin/"/* .
344344
fi
345+
346+
# Copy the test files to pytorch/caffe2 manually
347+
# They were built in pytorch/torch/lib/tmp_install/test
348+
# Why do we do this? So, setup.py has this section called 'package_data' which
349+
# you need to specify to include non-default files (usually .py files).
350+
# package_data takes a map from 'python package' to 'globs of files to
351+
# include'. By 'python package', it means a folder with an __init__.py file
352+
# that's not excluded in the find_packages call earlier in setup.py. So to
353+
# include our cpp_test into the site-packages folder in
354+
# site-packages/caffe2/cpp_test, we have to copy the cpp_test folder into the
355+
# root caffe2 folder and then tell setup.py to include them. Having another
356+
# folder like site-packages/caffe2_cpp_test would also be possible by adding a
357+
# caffe2_cpp_test folder to pytorch with an __init__.py in it.
358+
if [[ "$INSTALL_TEST" == "ON" ]]; then
359+
echo "Copying $INSTALL_DIR/test to $BASE_DIR/caffe2/cpp_test"
360+
mkdir -p "$BASE_DIR/caffe2/cpp_test/"
361+
$SYNC_COMMAND -r "$INSTALL_DIR/test/"/* "$BASE_DIR/caffe2/cpp_test/"
362+
fi
363+
345364
popd > /dev/null

0 commit comments

Comments
 (0)