Skip to content

Commit cc00145

Browse files
committed
Pin the other direction of the moved overflow boundary
The vendored range check moved in both directions, and only the direction that starts refusing values had a test. Cover the quiet one: filling an int8 tensor with 127.5 used to be refused and now stores 127. Test Plan: Compiled the real header from before and after this change into the same probe and ran both. Before: 127.5 into int8 and 255.5 into uint8 both report overflow, and 2^63 into int64 is accepted. After: the first two are accepted and 2^63 overflows. So the boundary moved both ways, and the case added here fails against the previous header rather than passing either way. Placed in this file rather than the shared macro because the macro expands into eight suites, and several of them reach the scalar through a path that rejects a fractional value before any range check, where the case would not measure what it claims. Decide ATen mode before the wrapper consumes it on the test path too The library and binary paths were fixed to read the dependency list before the shared patch removes it. The test path has the same shape and was missed: it still called its own check afterwards, so a test naming an ATen dependency was pinned to C++17 and would fail on ATen's headers. Read it in the same place, and pass the answer down, so both paths agree. Test Plan: Ran the test path over the cases that matter, with the dependency list removed first to match what the wrapper really does. Before this a test naming libtorch, c10 or torch-core-cpp came away pinned to C++17; after, all three take C++20 from the toolchain. A test named for ATen is unchanged, and a plain test still gets C++17, which is what the embedded builds rely on. No open source test target has this shape today, so this closes the same defect on a path that is not yet exercised rather than repairing a red job.
1 parent 6ffbf76 commit cc00145

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎kernels/test/op_full_test.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ ET_FORALL_REALHBF16_TYPES(GENERATE_TEST)
8484

8585
GENERATE_SCALAR_OVERFLOW_TESTS(OpFullOutTest)
8686

87+
// The other half of the boundary change: 127.5 used to be refused for an int8
88+
// tensor and now truncates to 127.
89+
TEST_F(OpFullOutTest, CharTensorFractionalScalarTruncates) {
90+
TensorFactory<ScalarType::Char> tf;
91+
std::vector<int32_t> sizes = {2, 2};
92+
std::vector<int64_t> sizes_int64_t(sizes.begin(), sizes.end());
93+
auto aref = IntArrayRef(sizes_int64_t.data(), sizes_int64_t.size());
94+
Tensor out = tf.zeros(sizes);
95+
96+
op_full_out(aref, 127.5, out);
97+
EXPECT_TENSOR_EQ(out, tf.full(sizes, 127));
98+
}
99+
87100
TEST_F(OpFullOutTest, HalfSupport) {
88101
TensorFactory<ScalarType::Half> tf;
89102

‎shim_et/xplat/executorch/build/runtime_wrapper.bzl‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def _is_aten_target(kwargs):
157157
return True
158158
return False
159159

160-
def _patch_test_compiler_flags(kwargs):
160+
def _patch_test_compiler_flags(kwargs, aten_mode = False):
161161
if "compiler_flags" not in kwargs:
162162
kwargs["compiler_flags"] = []
163163

@@ -169,11 +169,11 @@ def _patch_test_compiler_flags(kwargs):
169169
xplat_deps = kwargs.get("xplat_deps", [])
170170
fbcode_deps = kwargs.get("fbcode_deps", [])
171171
is_aten_test = (
172+
aten_mode or
172173
"_aten" in name or
173174
"aten_" in name or
174175
"gtest_aten" in external_deps or
175176
"gmock_aten" in external_deps or
176-
_is_aten_target(kwargs) or
177177
_has_pytorch_dep(xplat_deps) or
178178
_has_pytorch_dep(fbcode_deps)
179179
)
@@ -340,10 +340,12 @@ def _cxx_test(*args, **kwargs):
340340
kwargs["deps"] = []
341341
kwargs["deps"].append("//executorch/test/utils:utils")
342342

343+
# Before _patch_kwargs_cxx, which consumes external_deps.
344+
aten_mode = _is_aten_target(kwargs)
343345
_patch_kwargs_cxx(kwargs)
344346
env.patch_headers(kwargs)
345347
_patch_build_mode_flags(kwargs)
346-
_patch_test_compiler_flags(kwargs)
348+
_patch_test_compiler_flags(kwargs, aten_mode)
347349

348350
env.patch_platform_build_mode_flags(kwargs)
349351
env.cxx_test(*args, **kwargs)

0 commit comments

Comments
 (0)