|
| 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 | +// Macro to generate scalar overflow test cases for a given test suite. |
| 12 | +// The test suite must have a method called expect_bad_scalar_value_dies |
| 13 | +// that takes a template parameter for ScalarType and a Scalar value. |
| 14 | +#define GENERATE_SCALAR_OVERFLOW_TESTS(TEST_SUITE_NAME) \ |
| 15 | + TEST_F(TEST_SUITE_NAME, ByteTensorTooLargeScalarDies) { \ |
| 16 | + /* Cannot be represented by a uint8_t. */ \ |
| 17 | + expect_bad_scalar_value_dies<ScalarType::Byte>(256); \ |
| 18 | + } \ |
| 19 | + \ |
| 20 | + TEST_F(TEST_SUITE_NAME, CharTensorTooSmallScalarDies) { \ |
| 21 | + /* Cannot be represented by a int8_t. */ \ |
| 22 | + expect_bad_scalar_value_dies<ScalarType::Char>(-129); \ |
| 23 | + } \ |
| 24 | + \ |
| 25 | + TEST_F(TEST_SUITE_NAME, ShortTensorTooLargeScalarDies) { \ |
| 26 | + /* Cannot be represented by a int16_t. */ \ |
| 27 | + expect_bad_scalar_value_dies<ScalarType::Short>(32768); \ |
| 28 | + } \ |
| 29 | + \ |
| 30 | + TEST_F(TEST_SUITE_NAME, FloatTensorTooSmallScalarDies) { \ |
| 31 | + /* Cannot be represented by a float. */ \ |
| 32 | + expect_bad_scalar_value_dies<ScalarType::Float>(-3.41e+38); \ |
| 33 | + } \ |
| 34 | + \ |
| 35 | + TEST_F(TEST_SUITE_NAME, FloatTensorTooLargeScalarDies) { \ |
| 36 | + /* Cannot be represented by a float. */ \ |
| 37 | + expect_bad_scalar_value_dies<ScalarType::Float>(3.41e+38); \ |
| 38 | + } |
0 commit comments