Skip to content

Commit d9ae7c3

Browse files
authored
Rename tensor test and use gtest class fixture. (#4928)
1 parent 395d3f5 commit d9ae7c3

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

runtime/core/portable_type/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)
2323

2424
include(${EXECUTORCH_ROOT}/build/Test.cmake)
2525

26-
set(_test_srcs optional_test.cpp executor_tensor_test.cpp half_test.cpp
26+
set(_test_srcs optional_test.cpp tensor_test.cpp half_test.cpp
2727
scalar_test.cpp tensor_impl_test.cpp
2828
)
2929

runtime/core/portable_type/test/targets.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def define_common_targets():
1515
)
1616

1717
runtime.cxx_test(
18-
name = "executor_tensor_test",
19-
srcs = ["executor_tensor_test.cpp"],
18+
name = "tensor_test",
19+
srcs = ["tensor_test.cpp"],
2020
deps = [
2121
"//executorch/runtime/core/portable_type:portable_type",
2222
],

runtime/core/portable_type/test/executor_tensor_test.cpp renamed to runtime/core/portable_type/test/tensor_test.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,25 @@
77
*/
88

99
#include <executorch/runtime/core/portable_type/tensor.h>
10-
#include <executorch/test/utils/DeathTest.h>
10+
1111
#include <gtest/gtest.h>
1212

13+
#include <executorch/runtime/platform/runtime.h>
14+
#include <executorch/test/utils/DeathTest.h>
15+
1316
namespace torch {
1417
namespace executor {
1518

16-
TEST(TensorTest, InvalidScalarType) {
19+
class TensorTest : public ::testing::Test {
20+
protected:
21+
void SetUp() override {
22+
// Since these tests cause ET_LOG to be called, the PAL must be initialized
23+
// first.
24+
runtime_init();
25+
}
26+
};
27+
28+
TEST_F(TensorTest, InvalidScalarType) {
1729
TensorImpl::SizesType sizes[1] = {1};
1830

1931
// Undefined, which is sort of a special case since it's not part of the
@@ -28,7 +40,7 @@ TEST(TensorTest, InvalidScalarType) {
2840
ET_EXPECT_DEATH({ TensorImpl y(static_cast<ScalarType>(-1), 1, sizes); }, "");
2941
}
3042

31-
TEST(TensorTest, SetData) {
43+
TEST_F(TensorTest, SetData) {
3244
TensorImpl::SizesType sizes[1] = {5};
3345
TensorImpl::DimOrderType dim_order[1] = {0};
3446
int32_t data[5] = {0, 0, 1, 0, 0};
@@ -39,7 +51,7 @@ TEST(TensorTest, SetData) {
3951
EXPECT_EQ(a.const_data_ptr(), nullptr);
4052
}
4153

42-
TEST(TensorTest, Strides) {
54+
TEST_F(TensorTest, Strides) {
4355
TensorImpl::SizesType sizes[2] = {2, 2};
4456
TensorImpl::DimOrderType dim_order[2] = {0, 1};
4557
int32_t data[4] = {0, 0, 1, 1};
@@ -53,7 +65,7 @@ TEST(TensorTest, Strides) {
5365
EXPECT_EQ(a.const_data_ptr<int32_t>()[0 + a.strides()[0]], 1);
5466
}
5567

56-
TEST(TensorTest, ModifyDataOfConstTensor) {
68+
TEST_F(TensorTest, ModifyDataOfConstTensor) {
5769
TensorImpl::SizesType sizes[1] = {1};
5870
TensorImpl::DimOrderType dim_order[2] = {0};
5971
int32_t data[1] = {1};

test/utils/OSSTestConfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"directory": "runtime/core/portable_type/test",
7878
"sources": [
7979
"optional_test.cpp",
80-
"executor_tensor_test.cpp",
80+
"tensor_test.cpp",
8181
"half_test.cpp",
8282
"scalar_test.cpp",
8383
"tensor_impl_test.cpp"

0 commit comments

Comments
 (0)