Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions kernels/test/ScalarOverflowTestMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

// Macro to generate scalar overflow test cases for a given test suite.
// The test suite must have a method called expect_bad_scalar_value_dies
// that takes a template parameter for ScalarType and a Scalar value.
#define GENERATE_SCALAR_OVERFLOW_TESTS(TEST_SUITE_NAME) \
TEST_F(TEST_SUITE_NAME, ByteTensorTooLargeScalarDies) { \
/* Cannot be represented by a uint8_t. */ \
expect_bad_scalar_value_dies<ScalarType::Byte>(256); \
} \
\
TEST_F(TEST_SUITE_NAME, CharTensorTooSmallScalarDies) { \
/* Cannot be represented by a int8_t. */ \
expect_bad_scalar_value_dies<ScalarType::Char>(-129); \
} \
\
TEST_F(TEST_SUITE_NAME, ShortTensorTooLargeScalarDies) { \
/* Cannot be represented by a int16_t. */ \
expect_bad_scalar_value_dies<ScalarType::Short>(32768); \
} \
\
TEST_F(TEST_SUITE_NAME, FloatTensorTooSmallScalarDies) { \
/* Cannot be represented by a float. */ \
expect_bad_scalar_value_dies<ScalarType::Float>(-3.41e+38); \
} \
\
TEST_F(TEST_SUITE_NAME, FloatTensorTooLargeScalarDies) { \
/* Cannot be represented by a float. */ \
expect_bad_scalar_value_dies<ScalarType::Float>(3.41e+38); \
}
26 changes: 2 additions & 24 deletions kernels/test/op_fill_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <executorch/kernels/test/FunctionHeaderWrapper.h> // Declares the operator
#include <executorch/kernels/test/ScalarOverflowTestMacros.h>
#include <executorch/kernels/test/TestUtil.h>
#include <executorch/kernels/test/supported_features.h>
#include <executorch/runtime/core/exec_aten/exec_aten.h>
Expand Down Expand Up @@ -167,27 +168,4 @@ TEST_F(OpFillTest, MismatchedOutputDtypeDies) {
ET_EXPECT_KERNEL_FAILURE(context_, op_fill_scalar_out(self, 0.0, out));
}

TEST_F(OpFillTest, ByteTensorTooLargeScalarDies) {
// Cannot be represented by a uint8_t.
expect_bad_scalar_value_dies<ScalarType::Byte>(256);
}

TEST_F(OpFillTest, CharTensorTooSmallScalarDies) {
// Cannot be represented by a int8_t.
expect_bad_scalar_value_dies<ScalarType::Char>(-129);
}

TEST_F(OpFillTest, ShortTensorTooLargeScalarDies) {
// Cannot be represented by a int16_t.
expect_bad_scalar_value_dies<ScalarType::Short>(32768);
}

TEST_F(OpFillTest, FloatTensorTooSmallScalarDies) {
// Cannot be represented by a float.
expect_bad_scalar_value_dies<ScalarType::Float>(-3.41e+38);
}

TEST_F(OpFillTest, FloatTensorTooLargeScalarDies) {
// Cannot be represented by a float.
expect_bad_scalar_value_dies<ScalarType::Float>(3.41e+38);
}
GENERATE_SCALAR_OVERFLOW_TESTS(OpFillTest)
1 change: 1 addition & 0 deletions kernels/test/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def define_common_targets():
],
exported_headers = [
"BinaryLogicalOpTest.h",
"ScalarOverflowTestMacros.h",
"UnaryUfuncRealHBBF16ToFloatHBF16Test.h",
],
visibility = [
Expand Down
Loading