Skip to content

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbencer committed Nov 26, 2024
1 parent 0539cb8 commit d698e5b
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/nnfw_api/src/GenModelTests/one_op_tests/ExpandDims.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ TEST_F(GenModelTest, OneOp_neg_ExpandDims_Axis)
SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_ExpandDims_NegAxis)
{
CircleGen cgen;

std::vector<int32_t> axis_data{-5};
uint32_t axis_buf = cgen.addBuffer(axis_data);
int in = cgen.addTensor({{1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
int axis = cgen.addTensor({{1}, circle::TensorType::TensorType_INT32, axis_buf});
int out = cgen.addTensor({{1, 1, 4, 1}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorExpandDims({{in, axis}, {out}});
cgen.setInputsAndOutputs({in}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->setBackends({"cpu"});
_context->expectFailCompile();

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_ExpandDims_AxisNegInput)
{
CircleGen cgen;
Expand Down
96 changes: 96 additions & 0 deletions tests/nnfw_api/src/GenModelTests/one_op_tests/Reshape.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,99 @@ TEST_F(GenModelTest, OneOp_neg_Reshape_invalid_target_dyn_type)

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_Reshape_invalid_target_shape_with_neg_dim)
{
CircleGen cgen;
const auto f32 = circle::TensorType::TensorType_FLOAT32;

const std::vector<int32_t> new_shape_data{5, -1};
const uint32_t new_shape_buf = cgen.addBuffer(new_shape_data);
const int new_shape = cgen.addTensor({{2}, f32, new_shape_buf});
const int input = cgen.addTensor({{4}, f32});
const int out = cgen.addTensor({{1, 5}, f32});

cgen.addOperatorReshape({{input, new_shape}, {out}}, &new_shape_data);
cgen.setInputsAndOutputs({input}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{1, 2, 3, 4}}));
_context->setBackends({"cpu", "gpu_cl"});

_context->expectFailCompile();

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_Reshape_invalid_target_dyn_shape_with_neg_dim)
{
CircleGen cgen;
const auto f32 = circle::TensorType::TensorType_FLOAT32;
const auto i32 = circle::TensorType::TensorType_INT32;

const std::vector<float> in_data{1.f, 2.f, 3.f, 4.f};
const uint32_t input_buf = cgen.addBuffer(in_data);
const int input = cgen.addTensor({{4}, f32, input_buf});
const int new_shape = cgen.addTensor({{2}, i32});
const int out = cgen.addTensor({{}, f32}); // unspecified shape

const CircleGen::Shape empty_new_shape;
cgen.addOperatorReshape({{input, new_shape}, {out}}, &empty_new_shape);
cgen.setInputsAndOutputs({new_shape}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(
TestCaseData{}.addInput(std::vector<int>{-1, 5}).addOutput(in_data).expectFailRun());
_context->output_sizes(0, sizeof(float) * in_data.size());
_context->setBackends({"cpu", "gpu_cl"});

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_Reshape_invalid_target_shape_with_zero_dim)
{
CircleGen cgen;
const auto f32 = circle::TensorType::TensorType_FLOAT32;

const std::vector<int32_t> new_shape_data{5, 0};
const uint32_t new_shape_buf = cgen.addBuffer(new_shape_data);
const int new_shape = cgen.addTensor({{2}, f32, new_shape_buf});
const int input = cgen.addTensor({{4}, f32});
const int out = cgen.addTensor({{1, 5}, f32});

cgen.addOperatorReshape({{input, new_shape}, {out}}, &new_shape_data);
cgen.setInputsAndOutputs({input}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{1, 2, 3, 4}}));
_context->setBackends({"cpu", "gpu_cl"});

_context->expectFailCompile();

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_Reshape_invalid_target_dyn_shape_with_zero_dim)
{
CircleGen cgen;
const auto f32 = circle::TensorType::TensorType_FLOAT32;
const auto i32 = circle::TensorType::TensorType_INT32;

const std::vector<float> in_data{1.f, 2.f, 3.f, 4.f};
const uint32_t input_buf = cgen.addBuffer(in_data);
const int input = cgen.addTensor({{4}, f32, input_buf});
const int new_shape = cgen.addTensor({{2}, i32});
const int out = cgen.addTensor({{}, f32}); // unspecified shape

const CircleGen::Shape empty_new_shape;
cgen.addOperatorReshape({{input, new_shape}, {out}}, &empty_new_shape);
cgen.setInputsAndOutputs({new_shape}, {out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(
TestCaseData{}.addInput(std::vector<int>{-1, 5}).addOutput(in_data).expectFailRun());
_context->output_sizes(0, sizeof(float) * in_data.size());
_context->setBackends({"cpu", "gpu_cl"});

SUCCEED();
}
38 changes: 38 additions & 0 deletions tests/nnfw_api/src/GenModelTests/one_op_tests/Squeeze.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,41 @@ TEST_F(GenModelTest, OneOp_neg_Squeeze_out_of_rank_dims)

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_Squeeze_neg_invalid_dims)
{
CircleGen cgen;
const std::vector<int32_t> squeeze_dims{0, -3}; // -3 dim here is incorrect
int input = cgen.addTensor({{1, 2, 1, 2}, circle::TensorType::TensorType_FLOAT32});
int squeeze_out = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});

cgen.addOperatorSqueeze({{input}, {squeeze_out}}, squeeze_dims);
cgen.setInputsAndOutputs({input}, {squeeze_out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{1, 2, 3, 4}}));
_context->setBackends({"cpu", "gpu_cl"});

_context->expectFailCompile();

SUCCEED();
}

TEST_F(GenModelTest, OneOp_neg_Squeeze_neg_out_of_rank_dims)
{
CircleGen cgen;
const std::vector<int32_t> squeeze_dims{0, -5}; // -5 dim here is incorrect
int input = cgen.addTensor({{1, 2, 1, 2}, circle::TensorType::TensorType_FLOAT32});
int squeeze_out = cgen.addTensor({{2, 2}, circle::TensorType::TensorType_FLOAT32});

cgen.addOperatorSqueeze({{input}, {squeeze_out}}, squeeze_dims);
cgen.setInputsAndOutputs({input}, {squeeze_out});

_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(uniformTCD<float>({{1, 2, 3, 4}}, {{1, 2, 3, 4}}));
_context->setBackends({"cpu", "gpu_cl"});

_context->expectFailCompile();

SUCCEED();
}

0 comments on commit d698e5b

Please sign in to comment.