Skip to content

Commit 1aff915

Browse files
committed
Extract unittest scripts and add Buck mode
Fixes #8419 ghstack-source-id: 483f2bf ghstack-comment-id: 2658182008 Pull Request resolved: #8493
1 parent b5c0c61 commit 1aff915

File tree

7 files changed

+138
-46
lines changed

7 files changed

+138
-46
lines changed

.ci/scripts/unittest-buck2.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+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
set -eux
8+
9+
# TODO: expand this to //...
10+
buck2 query //runtime/...
11+
12+
# TODO: expand the covered scope of Buck targets.
13+
buck2 build //runtime/core/portable_type/...
14+
buck2 test //runtime/core/portable_type/...

.ci/scripts/unittest-linux-cmake.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
set -eux
8+
9+
# Run pytest with coverage
10+
pytest -n auto --cov=./ --cov-report=xml
11+
# Run gtest
12+
LLVM_PROFDATA=llvm-profdata-12 LLVM_COV=llvm-cov-12 \
13+
test/run_oss_cpp_tests.sh

.ci/scripts/unittest-linux.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
set -eux
8+
9+
BUILD_TOOL=$1
10+
if [[ $BUILD_TOOL =~ ^(cmake|buck2)$ ]]; then
11+
echo "Running unittests for ${BUILD_TOOL} ..."
12+
else
13+
echo "Missing build tool (require buck2 or cmake), exiting..."
14+
exit 1
15+
fi
16+
17+
# The generic Linux job chooses to use base env, not the one setup by the image
18+
eval "$(conda shell.bash hook)"
19+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
20+
conda activate "${CONDA_ENV}"
21+
22+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
23+
source .ci/scripts/setup-vulkan-linux-deps.sh
24+
25+
PYTHON_EXECUTABLE=python \
26+
EXECUTORCH_BUILD_PYBIND=ON \
27+
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
28+
.ci/scripts/setup-linux.sh "$BUILD_TOOL"
29+
30+
# Install llama3_2_vision dependencies.
31+
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
32+
33+
if [[ "$BUILD_TOOL" == "cmake" ]]; then
34+
.ci/scripts/unittest-linux-cmake.sh
35+
elif [[ "$BUILD_TOOL" == "buck2" ]]; then
36+
.ci/scripts/unittest-buck2.sh
37+
else
38+
echo "Unknown build tool $BUILD_TOOL"
39+
exit 1
40+
fi

.ci/scripts/unittest-macos-cmake.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
set -eux
8+
9+
# Run pytest with coverage
10+
${CONDA_RUN} pytest -n auto --cov=./ --cov-report=xml
11+
# Run gtest
12+
LLVM_PROFDATA="xcrun llvm-profdata" LLVM_COV="xcrun llvm-cov" \
13+
${CONDA_RUN} test/run_oss_cpp_tests.sh

.ci/scripts/unittest-macos.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
set -eux
8+
9+
BUILD_TOOL=$1
10+
if [[ $BUILD_TOOL =~ ^(cmake|buck2)$ ]]; then
11+
echo "Running unittests for ${BUILD_TOOL} ..."
12+
else
13+
echo "Missing build tool (require buck2 or cmake), exiting..."
14+
exit 1
15+
fi
16+
17+
bash .ci/scripts/setup-conda.sh
18+
eval "$(conda shell.bash hook)"
19+
20+
# Create temp directory for sccache shims
21+
export TMP_DIR=$(mktemp -d)
22+
export PATH="${TMP_DIR}:$PATH"
23+
trap 'rm -rfv ${TMP_DIR}' EXIT
24+
25+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
26+
PYTHON_EXECUTABLE=python \
27+
EXECUTORCH_BUILD_PYBIND=ON \
28+
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
29+
${CONDA_RUN} --no-capture-output \
30+
.ci/scripts/setup-macos.sh cmake
31+
32+
# Install llama3_2_vision dependencies.
33+
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
34+
35+
if [[ "$BUILD_TOOL" == "cmake" ]]; then
36+
.ci/scripts/unittest-macos-cmake.sh
37+
elif [[ "$BUILD_TOOL" == "buck2" ]]; then
38+
.ci/scripts/unittest-buck2.sh
39+
else
40+
echo "Unknown build tool $BUILD_TOOL"
41+
exit 1
42+
fi

.github/workflows/_unittest.yml

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
required: true
88
type: string
99
description: Name of the docker image to use.
10+
build-tool:
11+
required: true
12+
type: string
13+
description: Build tool to use, cmake or buck2.
1014
python-version:
1115
required: false
1216
type: string
@@ -26,28 +30,7 @@ jobs:
2630
timeout: 90
2731
script: |
2832
set -eux
29-
30-
# The generic Linux job chooses to use base env, not the one setup by the image
31-
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
32-
conda activate "${CONDA_ENV}"
33-
34-
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
35-
source .ci/scripts/setup-vulkan-linux-deps.sh
36-
37-
# Setup MacOS dependencies as there is no Docker support on MacOS atm
38-
PYTHON_EXECUTABLE=python \
39-
EXECUTORCH_BUILD_PYBIND=ON \
40-
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
41-
.ci/scripts/setup-linux.sh cmake
42-
43-
# Install llama3_2_vision dependencies.
44-
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
45-
46-
# Run pytest with coverage
47-
pytest -n auto --cov=./ --cov-report=xml
48-
# Run gtest
49-
LLVM_PROFDATA=llvm-profdata-12 LLVM_COV=llvm-cov-12 \
50-
test/run_oss_cpp_tests.sh
33+
.ci/scripts/unittest-linux.sh "${{ inputs.build-tool }}"
5134
5235
macos:
5336
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
@@ -58,27 +41,4 @@ jobs:
5841
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
5942
script: |
6043
set -eux
61-
62-
bash .ci/scripts/setup-conda.sh
63-
64-
# Create temp directory for sccache shims
65-
export TMP_DIR=$(mktemp -d)
66-
export PATH="${TMP_DIR}:$PATH"
67-
trap 'rm -rfv ${TMP_DIR}' EXIT
68-
69-
# Setup MacOS dependencies as there is no Docker support on MacOS atm
70-
PYTHON_EXECUTABLE=python \
71-
EXECUTORCH_BUILD_PYBIND=ON \
72-
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
73-
${CONDA_RUN} --no-capture-output \
74-
.ci/scripts/setup-macos.sh cmake
75-
76-
# Install llama3_2_vision dependencies.
77-
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
78-
./examples/models/llama3_2_vision/install_requirements.sh
79-
80-
# Run pytest with coverage
81-
${CONDA_RUN} pytest -n auto --cov=./ --cov-report=xml
82-
# Run gtest
83-
LLVM_PROFDATA="xcrun llvm-profdata" LLVM_COV="xcrun llvm-cov" \
84-
${CONDA_RUN} test/run_oss_cpp_tests.sh
44+
.ci/scripts/unittest-macos.sh "${{ inputs.build-tool }}"

.github/workflows/pull.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ jobs:
367367
id-token: write
368368
contents: read
369369
with:
370+
build-tool: cmake
371+
docker-image: executorch-ubuntu-22.04-clang12
372+
373+
unittest-buck:
374+
uses: ./.github/workflows/_unittest.yml
375+
permissions:
376+
id-token: write
377+
contents: read
378+
with:
379+
build-tool: buck2
370380
docker-image: executorch-ubuntu-22.04-clang12
371381

372382
unittest-arm:

0 commit comments

Comments
 (0)