diff --git a/runtime/core/portable_type/test/CMakeLists.txt b/runtime/core/portable_type/test/CMakeLists.txt index 73d877d68b..f89381f512 100644 --- a/runtime/core/portable_type/test/CMakeLists.txt +++ b/runtime/core/portable_type/test/CMakeLists.txt @@ -23,7 +23,7 @@ set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) include(${EXECUTORCH_ROOT}/build/Test.cmake) -set(_test_srcs optional_test.cpp executor_tensor_test.cpp half_test.cpp +set(_test_srcs optional_test.cpp tensor_test.cpp half_test.cpp scalar_test.cpp tensor_impl_test.cpp ) diff --git a/runtime/core/portable_type/test/targets.bzl b/runtime/core/portable_type/test/targets.bzl index 15e002d451..af55f95e45 100644 --- a/runtime/core/portable_type/test/targets.bzl +++ b/runtime/core/portable_type/test/targets.bzl @@ -15,8 +15,8 @@ def define_common_targets(): ) runtime.cxx_test( - name = "executor_tensor_test", - srcs = ["executor_tensor_test.cpp"], + name = "tensor_test", + srcs = ["tensor_test.cpp"], deps = [ "//executorch/runtime/core/portable_type:portable_type", ], diff --git a/runtime/core/portable_type/test/executor_tensor_test.cpp b/runtime/core/portable_type/test/tensor_test.cpp similarity index 84% rename from runtime/core/portable_type/test/executor_tensor_test.cpp rename to runtime/core/portable_type/test/tensor_test.cpp index 944850ca8a..7a772cd076 100644 --- a/runtime/core/portable_type/test/executor_tensor_test.cpp +++ b/runtime/core/portable_type/test/tensor_test.cpp @@ -7,13 +7,25 @@ */ #include -#include + #include +#include +#include + namespace torch { namespace executor { -TEST(TensorTest, InvalidScalarType) { +class TensorTest : public ::testing::Test { + protected: + void SetUp() override { + // Since these tests cause ET_LOG to be called, the PAL must be initialized + // first. + runtime_init(); + } +}; + +TEST_F(TensorTest, InvalidScalarType) { TensorImpl::SizesType sizes[1] = {1}; // Undefined, which is sort of a special case since it's not part of the @@ -28,7 +40,7 @@ TEST(TensorTest, InvalidScalarType) { ET_EXPECT_DEATH({ TensorImpl y(static_cast(-1), 1, sizes); }, ""); } -TEST(TensorTest, SetData) { +TEST_F(TensorTest, SetData) { TensorImpl::SizesType sizes[1] = {5}; TensorImpl::DimOrderType dim_order[1] = {0}; int32_t data[5] = {0, 0, 1, 0, 0}; @@ -39,7 +51,7 @@ TEST(TensorTest, SetData) { EXPECT_EQ(a.const_data_ptr(), nullptr); } -TEST(TensorTest, Strides) { +TEST_F(TensorTest, Strides) { TensorImpl::SizesType sizes[2] = {2, 2}; TensorImpl::DimOrderType dim_order[2] = {0, 1}; int32_t data[4] = {0, 0, 1, 1}; @@ -53,7 +65,7 @@ TEST(TensorTest, Strides) { EXPECT_EQ(a.const_data_ptr()[0 + a.strides()[0]], 1); } -TEST(TensorTest, ModifyDataOfConstTensor) { +TEST_F(TensorTest, ModifyDataOfConstTensor) { TensorImpl::SizesType sizes[1] = {1}; TensorImpl::DimOrderType dim_order[2] = {0}; int32_t data[1] = {1}; diff --git a/test/utils/OSSTestConfig.json b/test/utils/OSSTestConfig.json index 38fa31cd6f..b7d7f1700b 100644 --- a/test/utils/OSSTestConfig.json +++ b/test/utils/OSSTestConfig.json @@ -77,7 +77,7 @@ "directory": "runtime/core/portable_type/test", "sources": [ "optional_test.cpp", - "executor_tensor_test.cpp", + "tensor_test.cpp", "half_test.cpp", "scalar_test.cpp", "tensor_impl_test.cpp"