Skip to content

Commit 65189b5

Browse files
huydhnfacebook-github-bot
authored andcommitted
Run more C++ tests on CI (#333)
Summary: This runs C++ tests on both Linux and MacOS CI. Also there are several fixes here to make the test works on Linux: * In aten mode with libtorch, gtest needs to be compiled with `-D_GLIBCXX_USE_CXX11_ABI=0`, same as libtorch to avoid linker error. * `libgomp-a34b3233.so.1` is missing in Linux, it's required by libtorch in the same mode above. * When compiling with pthread, gtest is crashing at teardown with the error `googletest/include/gtest/internal/gtest-port.h:1771:: pthread_key_delete(key_)failed with error 22`, so I turn this off for now. The test is pretty fast. * One of the platform test `platform_override_test` refuses to pass on Linux. I'm skipping it there for now to unblock this change. Here is the error P827107972 Pull Request resolved: #333 Test Plan: https://github.com/pytorch/executorch/actions/runs/6182116076/job/16781279705?pr=333 Reviewed By: guangy10 Differential Revision: D49264959 Pulled By: huydhn fbshipit-source-id: 772cd77142acb767089cb9e3cd7386f28dd3c1c0
1 parent 0574637 commit 65189b5

File tree

8 files changed

+217
-172
lines changed

8 files changed

+217
-172
lines changed

.github/workflows/_unittest.yml

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,16 @@ on:
77
required: true
88
type: string
99
description: Name of the docker image to use.
10-
runner:
11-
required: false
12-
type: string
13-
default: 'linux.2xlarge'
14-
description: The default runner for PyTorch infra.
1510
python-version:
1611
required: false
1712
type: string
1813
default: '3.10'
1914

2015
jobs:
21-
unittest:
22-
name: unittest
16+
linux:
2317
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
2418
with:
25-
runner: ${{ inputs.runner }}
19+
runner: linux.2xlarge
2620
docker-image: ${{ inputs.docker-image }}
2721
submodules: 'true'
2822
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -38,3 +32,32 @@ jobs:
3832
pip install .
3933
# Run pytest with coverage
4034
pytest -n auto --cov=./ --cov-report=xml
35+
36+
macos:
37+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
38+
strategy:
39+
matrix:
40+
include:
41+
- build-tool: buck2
42+
with:
43+
runner: macos-m1-12
44+
submodules: 'true'
45+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
46+
script: |
47+
set -eux
48+
49+
WORKSPACE=$(pwd)
50+
pushd "${WORKSPACE}/pytorch/executorch"
51+
52+
BUILD_TOOL=${{ matrix.build-tool }}
53+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
54+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
55+
56+
# Just need to install executorch, everything else has been setup
57+
pip install .
58+
# Run pytest with coverage
59+
pytest -n auto --cov=./ --cov-report=xml
60+
# Run gtest
61+
buck2 test runtime/core/... runtime/platform/...
62+
63+
popd

.github/workflows/pull.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,3 @@ jobs:
191191
uses: ./.github/workflows/_unittest.yml
192192
with:
193193
docker-image: executorch-ubuntu-22.04-clang12
194-
runner: linux.2xlarge

runtime/core/exec_aten/testing_util/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ def define_common_targets():
4343
"//executorch/runtime/core/exec_aten/util:tensor_util" + aten_suffix,
4444
],
4545
exported_external_deps = [
46-
"gmock",
46+
"gmock" + aten_suffix,
4747
] + (["libtorch"] if aten_mode else []),
4848
)

runtime/core/test/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def define_common_targets():
7878
srcs = ["tensor_shape_dynamism_test_aten.cpp"],
7979
deps = [
8080
"//executorch/runtime/core/exec_aten:lib_aten",
81+
"//executorch/runtime/core/exec_aten/testing_util:tensor_util_aten",
8182
],
8283
)
8384

shim/xplat/executorch/build/env_interface.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ _EXTERNAL_DEPS = {
3030
# Commandline flags library
3131
"gflags": "//third-party:gflags",
3232
"gmock": "//third-party:gmock",
33+
"gmock_aten": "//third-party:gmock_aten",
3334
"gtest": "//third-party:gtest",
35+
"gtest_aten": "//third-party:gtest_aten",
3436
"libtorch": "//third-party:libtorch",
3537
"prettytable": "//third-party:prettytable",
3638
"pybind11": [], # TODO(larryliu0820): Add support

test/utils/targets.bzl

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,38 @@ def define_common_targets():
77
TARGETS and BUCK files that call this function.
88
"""
99

10-
runtime.cxx_library(
11-
name = "utils",
12-
srcs = [
13-
"UnitTestMain.cpp",
14-
],
15-
exported_headers = [
16-
"alignment.h",
17-
"DeathTest.h",
18-
],
19-
visibility = [
20-
"//executorch/...",
21-
"@EXECUTORCH_CLIENTS",
22-
],
23-
deps = [
24-
"//executorch/runtime/platform:platform",
25-
"//executorch/runtime/core:core",
26-
],
27-
exported_external_deps = [
28-
"gtest",
29-
"gmock",
30-
],
31-
)
10+
for aten_mode in (True, False):
11+
aten_suffix = "_aten" if aten_mode else ""
3212

33-
runtime.cxx_test(
34-
name = "alignment_test",
35-
srcs = [
36-
"alignment_test.cpp",
37-
],
38-
deps = [
39-
":utils",
40-
],
41-
)
13+
runtime.cxx_library(
14+
name = "utils" + aten_suffix,
15+
srcs = [
16+
"UnitTestMain.cpp",
17+
],
18+
exported_headers = [
19+
"alignment.h",
20+
"DeathTest.h",
21+
],
22+
visibility = [
23+
"//executorch/...",
24+
"@EXECUTORCH_CLIENTS",
25+
],
26+
deps = [
27+
"//executorch/runtime/platform:platform",
28+
"//executorch/runtime/core:core",
29+
],
30+
exported_external_deps = [
31+
"gtest" + aten_suffix,
32+
"gmock" + aten_suffix,
33+
],
34+
)
35+
36+
runtime.cxx_test(
37+
name = "alignment_test" + aten_suffix,
38+
srcs = [
39+
"alignment_test.cpp",
40+
],
41+
deps = [
42+
":utils" + aten_suffix,
43+
],
44+
)

third-party/TARGETS

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,15 @@ runtime.genrule(
232232
"libtorch": ["libtorch.so"],
233233
"libc10": ["libc10.so"],
234234
"libtorch_cpu": ["libtorch_cpu.so"],
235+
"libgomp": ["libgomp-a34b3233.so.1"],
235236
"include": ["include"],
236237
},
237238
}),
238239
default_outs = ["."],
239240
srcs = ["link_torch.sh"],
240241
bash = select({
241242
"ovr_config//os:macos": "bash $SRCS -f torch/lib/libtorch.dylib,torch/lib/libtorch_cpu.dylib,torch/lib/libc10.dylib,torch/include -o ${OUT}",
242-
"DEFAULT": "bash $SRCS -f torch/lib/libtorch.so,torch/lib/libtorch_cpu.so,torch/lib/libc10.so,torch/include -o ${OUT}",
243+
"DEFAULT": "bash $SRCS -f torch/lib/libtorch.so,torch/lib/libtorch_cpu.so,torch/lib/libc10.so,torch/lib/libgomp-a34b3233.so.1,torch/include -o ${OUT}",
243244
}),
244245
)
245246

@@ -253,6 +254,11 @@ prebuilt_cxx_library(
253254
shared_lib = ":libtorch_gen[libtorch_cpu]",
254255
)
255256

257+
prebuilt_cxx_library(
258+
name = "libgomp",
259+
shared_lib = ":libtorch_gen[libgomp]",
260+
)
261+
256262
prebuilt_cxx_library(
257263
name = "libtorch",
258264
shared_lib = ":libtorch_gen[libtorch]",
@@ -266,9 +272,9 @@ prebuilt_cxx_library(
266272
"DEFAULT": ["-Wl,-rpath,$(location :libtorch_gen)"], # define rpath to locate shared library
267273
}),
268274
exported_headers = [":libtorch_gen[include]"],
269-
exported_deps = [
270-
":libc10",
271-
":libtorch_cpu",
272-
],
275+
exported_deps = select({
276+
"ovr_config//os:macos": [":libc10", ":libtorch_cpu"],
277+
"DEFAULT": [":libc10", ":libtorch_cpu", ":libgomp"],
278+
}),
273279
visibility = ["PUBLIC"],
274280
)

0 commit comments

Comments
 (0)