Skip to content
Draft
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
61 changes: 38 additions & 23 deletions runtime/core/exec_aten/util/test/tensor_util_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ TEST_F(TensorUtilTest, SameShapesDifferentDtypes) {
ET_CHECK_SAME_SHAPE3(a, b, c);

// Not the same dtypes. Check both positions.
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE2(a, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE2(b, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(a, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(b, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE2(a, b), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE2(b, a), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(a, b), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(b, a), "Tensors do not match");

// Test with a mismatching tensor in all positions, where the other two agree.
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE3(a, b, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE3(b, a, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE3(b, b, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE3(a, b, b), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE3(b, a, b), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_DTYPE3(b, b, a), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE3(a, b, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE3(b, a, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE3(b, b, a), "");
Expand All @@ -88,13 +88,13 @@ TEST_F(TensorUtilTest, DifferentShapesSameDtypes) {
Tensor b2 = tf_int_.ones({2, 2});

// The different tensors are not the same shape. Check both positions.
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE2(a, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE2(b, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE2(a, b), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE2(b, a), "Tensors do not match");

// Test with the different tensor in all positions.
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE3(a, b, b2), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE3(b, a, b2), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE3(b, b2, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE3(a, b, b2), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE3(b, a, b2), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE3(b, b2, a), "Tensors do not match");

// They are the same dtypes.
ET_CHECK_SAME_DTYPE2(a, b);
Expand All @@ -104,11 +104,14 @@ TEST_F(TensorUtilTest, DifferentShapesSameDtypes) {
ET_CHECK_SAME_DTYPE3(b, b2, a);

// But not the same shape-and-dtype.
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(a, b), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(b, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE3(a, b, b2), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE3(b, a, b2), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE3(b, b2, a), "");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(a, b), "Tensors do not match");
ET_EXPECT_DEATH(ET_CHECK_SAME_SHAPE_AND_DTYPE2(b, a), "Tensors do not match");
ET_EXPECT_DEATH(
ET_CHECK_SAME_SHAPE_AND_DTYPE3(a, b, b2), "Tensors do not match");
ET_EXPECT_DEATH(
ET_CHECK_SAME_SHAPE_AND_DTYPE3(b, a, b2), "Tensors do not match");
ET_EXPECT_DEATH(
ET_CHECK_SAME_SHAPE_AND_DTYPE3(b, b2, a), "Tensors do not match");
}

TEST_F(TensorUtilTest, ZeroDimensionalTensor) {
Expand Down Expand Up @@ -163,9 +166,15 @@ TEST_F(TensorUtilTest, GetLeadingDimsInputOutOfBoundDies) {
Tensor t = tf_int_.ones({2, 3, 4});

// dim needs to be in the range [0, t.dim()]
ET_EXPECT_DEATH(executorch::ET_RUNTIME_NAMESPACE::getLeadingDims(t, -2), "");
ET_EXPECT_DEATH(executorch::ET_RUNTIME_NAMESPACE::getLeadingDims(t, -1), "");
ET_EXPECT_DEATH(executorch::ET_RUNTIME_NAMESPACE::getLeadingDims(t, 4), "");
ET_EXPECT_DEATH(
executorch::ET_RUNTIME_NAMESPACE::getLeadingDims(t, -2),
"Ending dimension.*should be in the range");
ET_EXPECT_DEATH(
executorch::ET_RUNTIME_NAMESPACE::getLeadingDims(t, -1),
"Ending dimension.*should be in the range");
ET_EXPECT_DEATH(
executorch::ET_RUNTIME_NAMESPACE::getLeadingDims(t, 4),
"Ending dimension.*should be in the range");
}

TEST_F(TensorUtilTest, GetTrailingDimsSmokeTest) {
Expand All @@ -187,9 +196,15 @@ TEST_F(TensorUtilTest, GetTrailingDimsInputOutOfBoundDies) {
Tensor t = tf_int_.ones({2, 3, 4});

// dim needs to be in the range [-1, t.dim() - 1)
ET_EXPECT_DEATH(executorch::ET_RUNTIME_NAMESPACE::getTrailingDims(t, -2), "");
ET_EXPECT_DEATH(executorch::ET_RUNTIME_NAMESPACE::getTrailingDims(t, 3), "");
ET_EXPECT_DEATH(executorch::ET_RUNTIME_NAMESPACE::getTrailingDims(t, 4), "");
ET_EXPECT_DEATH(
executorch::ET_RUNTIME_NAMESPACE::getTrailingDims(t, -2),
"Starting dimension.*should be in the range");
ET_EXPECT_DEATH(
executorch::ET_RUNTIME_NAMESPACE::getTrailingDims(t, 3),
"Starting dimension.*should be in the range");
ET_EXPECT_DEATH(
executorch::ET_RUNTIME_NAMESPACE::getTrailingDims(t, 4),
"Starting dimension.*should be in the range");
}

TEST_F(TensorUtilTest, ContiguousCheckSupported) {
Expand Down
45 changes: 27 additions & 18 deletions runtime/core/test/evalue_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST_F(EValueTest, TypeMismatchFatals) {
auto e = EValue(true);
e.toInt();
},
"");
"EValue is not an int");
}

TEST_F(EValueTest, NoneByDefault) {
Expand Down Expand Up @@ -279,38 +279,45 @@ TEST_F(EValueTest, ConstructFromTensorWrapper) {
TEST_F(EValueTest, ConstructFromNullPtrAborts) {
std::unique_ptr<executorch::aten::Tensor> null_ptr;

ET_EXPECT_DEATH({ EValue evalue(null_ptr); }, "");
ET_EXPECT_DEATH({ EValue evalue(null_ptr); }, "Pointer is null");
}

TEST_F(EValueTest, StringConstructorNullCheck) {
executorch::aten::ArrayRef<char>* null_string_ptr = nullptr;
ET_EXPECT_DEATH({ EValue evalue(null_string_ptr); }, "");
ET_EXPECT_DEATH(
{ EValue evalue(null_string_ptr); }, "pointer cannot be null");
}

TEST_F(EValueTest, BoolListConstructorNullCheck) {
executorch::aten::ArrayRef<bool>* null_bool_list_ptr = nullptr;
ET_EXPECT_DEATH({ EValue evalue(null_bool_list_ptr); }, "");
ET_EXPECT_DEATH(
{ EValue evalue(null_bool_list_ptr); }, "pointer cannot be null");
}

TEST_F(EValueTest, DoubleListConstructorNullCheck) {
executorch::aten::ArrayRef<double>* null_double_list_ptr = nullptr;
ET_EXPECT_DEATH({ EValue evalue(null_double_list_ptr); }, "");
ET_EXPECT_DEATH(
{ EValue evalue(null_double_list_ptr); }, "pointer cannot be null");
}

TEST_F(EValueTest, IntListConstructorNullCheck) {
BoxedEvalueList<int64_t>* null_int_list_ptr = nullptr;
ET_EXPECT_DEATH({ EValue evalue(null_int_list_ptr); }, "");
ET_EXPECT_DEATH(
{ EValue evalue(null_int_list_ptr); }, "pointer cannot be null");
}

TEST_F(EValueTest, TensorListConstructorNullCheck) {
BoxedEvalueList<executorch::aten::Tensor>* null_tensor_list_ptr = nullptr;
ET_EXPECT_DEATH({ EValue evalue(null_tensor_list_ptr); }, "");
ET_EXPECT_DEATH(
{ EValue evalue(null_tensor_list_ptr); }, "pointer cannot be null");
}

TEST_F(EValueTest, OptionalTensorListConstructorNullCheck) {
BoxedEvalueList<std::optional<executorch::aten::Tensor>>*
null_optional_tensor_list_ptr = nullptr;
ET_EXPECT_DEATH({ EValue evalue(null_optional_tensor_list_ptr); }, "");
ET_EXPECT_DEATH(
{ EValue evalue(null_optional_tensor_list_ptr); },
"pointer cannot be null");
}

TEST_F(EValueTest, BoxedEvalueListConstructorNullChecks) {
Expand All @@ -321,16 +328,18 @@ TEST_F(EValueTest, BoxedEvalueListConstructorNullChecks) {

// Test null wrapped_vals
ET_EXPECT_DEATH(
{ BoxedEvalueList<int64_t> list(nullptr, storage.data(), 3); }, "");
{ BoxedEvalueList<int64_t> list(nullptr, storage.data(), 3); },
"wrapped_vals cannot be null");

// Test null unwrapped_vals
ET_EXPECT_DEATH(
{ BoxedEvalueList<int64_t> list(values_p.data(), nullptr, 3); }, "");
{ BoxedEvalueList<int64_t> list(values_p.data(), nullptr, 3); },
"unwrapped_vals cannot be null");

// Test negative size
ET_EXPECT_DEATH(
{ BoxedEvalueList<int64_t> list(values_p.data(), storage.data(), -1); },
"");
"size cannot be negative");
}

TEST_F(EValueTest, toListOptionalTensorTypeCheck) {
Expand All @@ -340,7 +349,7 @@ TEST_F(EValueTest, toListOptionalTensorTypeCheck) {
EXPECT_FALSE(e.isListOptionalTensor());

// Should fail type check
ET_EXPECT_DEATH({ e.toListOptionalTensor(); }, "");
ET_EXPECT_DEATH({ e.toListOptionalTensor(); }, "EValue is not a");
}

TEST_F(EValueTest, toStringNullPointerCheck) {
Expand All @@ -351,7 +360,7 @@ TEST_F(EValueTest, toStringNullPointerCheck) {

// Should pass isString() check but fail null pointer check
EXPECT_TRUE(e.isString());
ET_EXPECT_DEATH({ e.toString(); }, "");
ET_EXPECT_DEATH({ e.toString(); }, "string pointer is null");
}

TEST_F(EValueTest, toIntListNullPointerCheck) {
Expand All @@ -362,7 +371,7 @@ TEST_F(EValueTest, toIntListNullPointerCheck) {

// Should pass isIntList() check but fail null pointer check
EXPECT_TRUE(e.isIntList());
ET_EXPECT_DEATH({ e.toIntList(); }, "");
ET_EXPECT_DEATH({ e.toIntList(); }, "int list pointer is null");
}

TEST_F(EValueTest, toBoolListNullPointerCheck) {
Expand All @@ -373,7 +382,7 @@ TEST_F(EValueTest, toBoolListNullPointerCheck) {

// Should pass isBoolList() check but fail null pointer check
EXPECT_TRUE(e.isBoolList());
ET_EXPECT_DEATH({ e.toBoolList(); }, "");
ET_EXPECT_DEATH({ e.toBoolList(); }, "bool list pointer is null");
}

TEST_F(EValueTest, toDoubleListNullPointerCheck) {
Expand All @@ -384,7 +393,7 @@ TEST_F(EValueTest, toDoubleListNullPointerCheck) {

// Should pass isDoubleList() check but fail null pointer check
EXPECT_TRUE(e.isDoubleList());
ET_EXPECT_DEATH({ e.toDoubleList(); }, "");
ET_EXPECT_DEATH({ e.toDoubleList(); }, "double list pointer is null");
}

TEST_F(EValueTest, toTensorListNullPointerCheck) {
Expand All @@ -395,7 +404,7 @@ TEST_F(EValueTest, toTensorListNullPointerCheck) {

// Should pass isTensorList() check but fail null pointer check
EXPECT_TRUE(e.isTensorList());
ET_EXPECT_DEATH({ e.toTensorList(); }, "");
ET_EXPECT_DEATH({ e.toTensorList(); }, "tensor list pointer is null");
}

TEST_F(EValueTest, toListOptionalTensorNullPointerCheck) {
Expand All @@ -406,5 +415,5 @@ TEST_F(EValueTest, toListOptionalTensorNullPointerCheck) {

// Should pass isListOptionalTensor() check but fail null pointer check
EXPECT_TRUE(e.isListOptionalTensor());
ET_EXPECT_DEATH({ e.toListOptionalTensor(); }, "");
ET_EXPECT_DEATH({ e.toListOptionalTensor(); }, "pointer is null");
}
Loading