Skip to content

Commit 869af13

Browse files
authored
Fix broken tests caused by runtime gtest skipping (#19658)
Differential Revision: D105634345 Pull Request resolved: #19658
1 parent 12bb0e7 commit 869af13

4 files changed

Lines changed: 83 additions & 13 deletions

File tree

kernels/test/op_clone_test.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <executorch/kernels/test/FunctionHeaderWrapper.h> // Declares the operator
1010
#include <executorch/kernels/test/TestUtil.h>
1111
#include <executorch/kernels/test/supported_features.h>
12+
#include <executorch/kernels/test/supported_features_skip.h>
1213
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1314
#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h>
1415
#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h>
@@ -73,9 +74,9 @@ class OpCloneTest : public OperatorTest {
7374

7475
// regular test for clone.out
7576
TEST_F(OpCloneTest, AllDtypesSupported) {
76-
if (torch::executor::testing::SupportedFeatures::get()->is_aten) {
77-
GTEST_SKIP() << "ATen kernel test fails";
78-
}
77+
ET_SKIP_IF(
78+
torch::executor::testing::SupportedFeatures::get()->is_aten,
79+
"ATen kernel test fails");
7980
#define TEST_ENTRY(ctype, dtype) test_dtype<ctype, ScalarType::dtype>();
8081
ET_FORALL_REAL_TYPES_AND(Bool, TEST_ENTRY);
8182
#undef TEST_ENTRY
@@ -88,9 +89,9 @@ TEST_F(OpCloneTest, EmptyInputSupported) {
8889
}
8990

9091
TEST_F(OpCloneTest, MismatchedSizesDie) {
91-
if (torch::executor::testing::SupportedFeatures::get()->is_aten) {
92-
GTEST_SKIP() << "ATen kernel can handle mismatched sizes";
93-
}
92+
ET_SKIP_IF(
93+
torch::executor::testing::SupportedFeatures::get()->is_aten,
94+
"ATen kernel can handle mismatched sizes");
9495
TensorFactory<ScalarType::Int> tf;
9596
Tensor input = tf.make(/*sizes=*/{3, 1, 1, 2}, /*data=*/{1, 2, 3, 4, 5, 6});
9697
Tensor out = tf.zeros({3, 2, 1, 1});
@@ -114,9 +115,9 @@ TEST_F(OpCloneTest, MismatchedTypesDie) {
114115
// MemoryFormat::Contiguous should not be allowed. The function is expected
115116
// depth if using the illegal memory format.
116117
TEST_F(OpCloneTest, MismatchedMemoryFormatDie) {
117-
if (torch::executor::testing::SupportedFeatures::get()->is_aten) {
118-
GTEST_SKIP() << "ATen kernel can handle non contiguous memory formats";
119-
}
118+
ET_SKIP_IF(
119+
torch::executor::testing::SupportedFeatures::get()->is_aten,
120+
"ATen kernel can handle non contiguous memory formats");
120121
TensorFactory<ScalarType::Float> tf_in;
121122
TensorFactory<ScalarType::Float> tf_out;
122123
Tensor input =

kernels/test/op_unbind_copy_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <executorch/kernels/test/FunctionHeaderWrapper.h> // Declares the operator
1010
#include <executorch/kernels/test/TestUtil.h>
1111
#include <executorch/kernels/test/supported_features.h>
12+
#include <executorch/kernels/test/supported_features_skip.h>
1213
#include <executorch/runtime/core/exec_aten/exec_aten.h>
1314
#include <executorch/runtime/core/exec_aten/testing_util/tensor_factory.h>
1415
#include <executorch/runtime/core/exec_aten/testing_util/tensor_util.h>
@@ -269,9 +270,9 @@ TEST_F(OpUnbindCopyIntOutTest, UnbindWorksWithZeroSizedTensors) {
269270
}
270271

271272
TEST_F(OpUnbindCopyIntOutTest, UnbindFailsWithWronglyAllocatedOutput) {
272-
if (torch::executor::testing::SupportedFeatures::get()->is_aten) {
273-
GTEST_SKIP() << "ATen kernel can handle mismatched output shape";
274-
}
273+
ET_SKIP_IF(
274+
torch::executor::testing::SupportedFeatures::get()->is_aten,
275+
"ATen kernel can handle mismatched output shape");
275276
TensorFactory<ScalarType::Int> tf;
276277
TensorListFactory<ScalarType::Int> tlf;
277278

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
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+
*/
8+
9+
#pragma once
10+
11+
// `ET_SKIP_IF(cond, reason)` -- skip a kernel test when `cond` is true.
12+
//
13+
// Replaces the older inline pattern:
14+
// if (SupportedFeatures::get()->is_aten) {
15+
// GTEST_SKIP() << "ATen handles X";
16+
// }
17+
// with:
18+
// ET_SKIP_IF(SupportedFeatures::get()->is_aten, "ATen handles X");
19+
//
20+
// OSS: expands to `if (cond) GTEST_SKIP() << reason;` (unchanged).
21+
// fbcode: expands to `if (cond) return;` so the test reports PASS, not SKIP.
22+
//
23+
// fbcode's TestX flags consistently-skipping tests as "broken" -- see
24+
// T208053850 and
25+
// https://fb.workplace.com/groups/testinfra.discuss/permalink/2044665472719153/.
26+
// Collapse back to the OSS form once that's resolved.
27+
//
28+
// `EXECUTORCH_INTERNAL` is set by BUCK gated on `runtime.is_oss` (see
29+
// `runtime/executor/targets.bzl` for the existing precedent).
30+
31+
#if defined(EXECUTORCH_INTERNAL) && EXECUTORCH_INTERNAL == 1
32+
33+
namespace executorch::testing::internal {
34+
// No-op sink so `<<` chains in the reason still parse and type-check.
35+
struct SkipReasonSink {
36+
template <typename T>
37+
const SkipReasonSink& operator<<(const T&) const {
38+
return *this;
39+
}
40+
};
41+
} // namespace executorch::testing::internal
42+
43+
// `if/else` form avoids dangling-else hazards and lets the reason still
44+
// participate in `<<` chains.
45+
#define ET_SKIP_IF(cond, reason) \
46+
if ((cond)) { \
47+
return; \
48+
} else \
49+
::executorch::testing::internal::SkipReasonSink{} << reason
50+
51+
#else // !EXECUTORCH_INTERNAL
52+
53+
#include <gtest/gtest.h>
54+
55+
#define ET_SKIP_IF(cond, reason) \
56+
if ((cond)) \
57+
GTEST_SKIP() << reason
58+
59+
#endif // EXECUTORCH_INTERNAL

kernels/test/targets.bzl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ def define_common_targets():
115115
runtime.cxx_library(
116116
name = "supported_features_header",
117117
srcs = [],
118-
exported_headers = {"supported_features.h": ":supported_feature_header_gen[supported_features.h]"},
118+
exported_headers = {
119+
"supported_features.h": ":supported_feature_header_gen[supported_features.h]",
120+
"supported_features_skip.h": "supported_features_skip.h",
121+
},
122+
# Set EXECUTORCH_INTERNAL=1 for fbcode-internal builds so the
123+
# ET_SKIP_IF helper in supported_features_skip.h compiles to an
124+
# early `return;` instead of GTEST_SKIP. This avoids TestX's
125+
# "ConsistentlySkipping" / broken-test signal. OSS builds keep
126+
# the canonical GTEST_SKIP behavior. See header for context.
127+
exported_preprocessor_flags = [] if runtime.is_oss else ["-DEXECUTORCH_INTERNAL=1"],
119128
visibility = [
120129
"//executorch/kernels/...",
121130
],

0 commit comments

Comments
 (0)