Skip to content

Commit

Permalink
[test/nnfw_api] Update clang-format (Samsung#5300)
Browse files Browse the repository at this point in the history
Use clang-format-8 style for tests/nnfw_api

Signed-off-by: Hyeongseok Oh <[email protected]>
  • Loading branch information
hseok-oh authored Dec 7, 2020
1 parent 56713c8 commit 218e756
Show file tree
Hide file tree
Showing 38 changed files with 340 additions and 338 deletions.
1 change: 1 addition & 0 deletions tests/nnfw_api/.clang-format
30 changes: 15 additions & 15 deletions tests/nnfw_api/src/CircleGen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ CircleBuffer CircleGen::finish()
for (auto &ctx : _subgraph_contexts)
subgraphs.push_back(buildSubGraph(ctx));
auto model =
circle::CreateModelDirect(_fbb, 3, &_opcodes, &subgraphs, "CircleGen generated", &_buffers);
circle::CreateModelDirect(_fbb, 3, &_opcodes, &subgraphs, "CircleGen generated", &_buffers);
_fbb.Finish(model);
return CircleBuffer{std::move(_fbb)};
}
Expand Down Expand Up @@ -119,8 +119,8 @@ uint32_t CircleGen::addOperatorAveragePool2D(const OperatorParams &params, circl
circle::ActivationFunctionType actfn)
{
auto options =
circle::CreatePool2DOptions(_fbb, padding, stride_w, stride_h, filter_w, filter_h, actfn)
.Union();
circle::CreatePool2DOptions(_fbb, padding, stride_w, stride_h, filter_w, filter_h, actfn)
.Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_AVERAGE_POOL_2D,
circle::BuiltinOptions_Pool2DOptions, options);
}
Expand All @@ -147,8 +147,8 @@ uint32_t CircleGen::addOperatorConv2D(const OperatorParams &params, circle::Padd
int dilation_h)
{
auto options =
circle::CreateConv2DOptions(_fbb, padding, stride_w, stride_h, actfn, dilation_w, dilation_h)
.Union();
circle::CreateConv2DOptions(_fbb, padding, stride_w, stride_h, actfn, dilation_w, dilation_h)
.Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_CONV_2D,
circle::BuiltinOptions_Conv2DOptions, options);
}
Expand All @@ -174,9 +174,9 @@ uint32_t CircleGen::addOperatorDepthwiseConv2D(const OperatorParams &params,
int dilation_h)
{
auto options =
circle::CreateDepthwiseConv2DOptions(_fbb, padding, stride_w, stride_h, depth_multiplier,
actfn, dilation_w, dilation_h)
.Union();
circle::CreateDepthwiseConv2DOptions(_fbb, padding, stride_w, stride_h, depth_multiplier, actfn,
dilation_w, dilation_h)
.Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_DEPTHWISE_CONV_2D,
circle::BuiltinOptions_DepthwiseConv2DOptions, options);
}
Expand All @@ -199,8 +199,8 @@ CircleGen::addOperatorFullyConnected(const OperatorParams &params,
circle::FullyConnectedOptionsWeightsFormat weights_format)
{
auto options =
circle::CreateFullyConnectedOptions(_fbb, circle::ActivationFunctionType_NONE, weights_format)
.Union();
circle::CreateFullyConnectedOptions(_fbb, circle::ActivationFunctionType_NONE, weights_format)
.Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_FULLY_CONNECTED,
circle::BuiltinOptions_FullyConnectedOptions, options);
}
Expand Down Expand Up @@ -316,7 +316,7 @@ uint32_t CircleGen::addOperatorResizeBilinear(const OperatorParams &params, bool
bool half_pixel_centers)
{
auto options =
circle::CreateResizeBilinearOptions(_fbb, align_corners, half_pixel_centers).Union();
circle::CreateResizeBilinearOptions(_fbb, align_corners, half_pixel_centers).Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_RESIZE_BILINEAR,
circle::BuiltinOptions_ResizeBilinearOptions, options);
}
Expand Down Expand Up @@ -368,7 +368,7 @@ uint32_t CircleGen::addOperatorStridedSlice(const OperatorParams &params, int32_
{
auto options = circle::CreateStridedSliceOptions(_fbb, begin_mask, end_mask, ellipsis_mask,
new_axis_mask, shrink_axis_mask)
.Union();
.Union();
return addOperatorWithOptions(params, circle::BuiltinOperator_STRIDED_SLICE,
circle::BuiltinOptions_StridedSliceOptions, options);
}
Expand Down Expand Up @@ -495,7 +495,7 @@ CircleGen::buildSparsityParameters(const SparsityParams &sp)
flatbuffers::Offset<flatbuffers::Vector<int32_t>> traversal_order;
flatbuffers::Offset<flatbuffers::Vector<int32_t>> block_map;
flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<circle::DimensionMetadata>>>
dim_metadata;
dim_metadata;

traversal_order = _fbb.CreateVector(sp.traversal_order);
block_map = _fbb.CreateVector(sp.block_map);
Expand All @@ -506,8 +506,8 @@ CircleGen::buildSparsityParameters(const SparsityParams &sp)
auto fb_array_segments = circle::CreateUint16VectorDirect(_fbb, &it._array_segments.u16);
auto fb_array_indices = circle::CreateUint16VectorDirect(_fbb, &it._array_indices.u16);
auto dim_metadata = circle::CreateDimensionMetadata(
_fbb, it._format, it._dense_size, it._array_segments_type, fb_array_segments.Union(),
it._array_indices_type, fb_array_indices.Union());
_fbb, it._format, it._dense_size, it._array_segments_type, fb_array_segments.Union(),
it._array_indices_type, fb_array_indices.Union());
dim_metadata_vec.emplace_back(dim_metadata);
}
dim_metadata = _fbb.CreateVector(dim_metadata_vec);
Expand Down
10 changes: 5 additions & 5 deletions tests/nnfw_api/src/CircleGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ class CircleGen
DimMetaData() = delete;
DimMetaData(SparseDimensionType format, std::vector<uint16_t> array_segments,
std::vector<uint16_t> array_indices)
: _format{format},
_array_segments_type(SparseIndexVectorType::SparseIndexVector_Uint16Vector),
_array_indices_type(SparseIndexVectorType::SparseIndexVector_Uint16Vector)
: _format{format},
_array_segments_type(SparseIndexVectorType::SparseIndexVector_Uint16Vector),
_array_indices_type(SparseIndexVectorType::SparseIndexVector_Uint16Vector)
{
_array_segments.u16 = array_segments;
_array_indices.u16 = array_indices;
}
DimMetaData(SparseDimensionType format, int32_t dense_size)
: _format{format}, _dense_size{dense_size}
: _format{format}, _dense_size{dense_size}
{
}
SparseDimensionType _format{circle::DimensionType_DENSE};
Expand Down Expand Up @@ -163,7 +163,7 @@ class CircleGen
uint32_t addOperatorFloor(const OperatorParams &params);
uint32_t addOperatorFullyConnected(const OperatorParams &params,
circle::FullyConnectedOptionsWeightsFormat weights_format =
circle::FullyConnectedOptionsWeightsFormat_DEFAULT);
circle::FullyConnectedOptionsWeightsFormat_DEFAULT);
uint32_t addOperatorIf(const OperatorParams &params, uint32_t then_subg, uint32_t else_subg);
uint32_t addOperatorInstanceNorm(const OperatorParams &params, float epsilon,
circle::ActivationFunctionType actfn);
Expand Down
2 changes: 1 addition & 1 deletion tests/nnfw_api/src/GenModelTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class GenModelTest : public ::testing::Test
NNFW_ENSURE_SUCCESS(nnfw_create_session(&_so.session));
auto &cbuf = _context->cbuf();
auto model_load_result =
nnfw_load_circle_from_buffer(_so.session, cbuf.buffer(), cbuf.size());
nnfw_load_circle_from_buffer(_so.session, cbuf.buffer(), cbuf.size());
if (_context->expected_fail_model_load())
{
ASSERT_NE(model_load_result, NNFW_STATUS_NO_ERROR);
Expand Down
11 changes: 7 additions & 4 deletions tests/nnfw_api/src/NNPackages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@

// NOTE Must match `enum TestPackages`
const char *TEST_PACKAGE_NAMES[] = {
// for validation test
"add", "add_no_manifest", "add_invalid_manifest",
// for validation test
"add",
"add_no_manifest",
"add_invalid_manifest",

// for dynamic tensor test
"while_dynamic", "if_dynamic",
// for dynamic tensor test
"while_dynamic",
"if_dynamic",
};

NNPackages &NNPackages::get()
Expand Down
12 changes: 6 additions & 6 deletions tests/nnfw_api/src/RegressionTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ TEST_F(RegressionTest, github_11748)

uint8_t input_buf[new_dim * sizeof(float)];
NNFW_ENSURE_SUCCESS(
nnfw_set_input(session, 0, t_input.dtype, &input_buf, new_dim * sizeof(float)));
nnfw_set_input(session, 0, t_input.dtype, &input_buf, new_dim * sizeof(float)));

uint8_t output_buf[new_dim * sizeof(float)];
NNFW_ENSURE_SUCCESS(
nnfw_set_output(session, 0, t_output.dtype, &output_buf, new_dim * sizeof(float)));
nnfw_set_output(session, 0, t_output.dtype, &output_buf, new_dim * sizeof(float)));

NNFW_ENSURE_SUCCESS(nnfw_run(session));

Expand All @@ -134,9 +134,9 @@ TEST_F(RegressionTest, github_11748)
// seems weird calling but anyway nnstreamer people case calls this again.
// Anyways, runtime should work
NNFW_ENSURE_SUCCESS(
nnfw_set_input(session, 0, t_input.dtype, &input_buf, new_dim * sizeof(float)));
nnfw_set_input(session, 0, t_input.dtype, &input_buf, new_dim * sizeof(float)));
NNFW_ENSURE_SUCCESS(
nnfw_set_output(session, 0, t_output.dtype, &output_buf, new_dim * sizeof(float)));
nnfw_set_output(session, 0, t_output.dtype, &output_buf, new_dim * sizeof(float)));
NNFW_ENSURE_SUCCESS(nnfw_run(session));
}

Expand Down Expand Up @@ -166,9 +166,9 @@ TEST_F(RegressionTest, github_4585)
std::vector<float> out_buf{-1, -1};

NNFW_ENSURE_SUCCESS(
nnfw_set_input(session, 0, ti_new.dtype, in_buf.data(), in_buf.size() * sizeof(float)));
nnfw_set_input(session, 0, ti_new.dtype, in_buf.data(), in_buf.size() * sizeof(float)));
NNFW_ENSURE_SUCCESS(
nnfw_set_output(session, 0, ti_new.dtype, out_buf.data(), out_buf.size() * sizeof(float)));
nnfw_set_output(session, 0, ti_new.dtype, out_buf.data(), out_buf.size() * sizeof(float)));

NNFW_ENSURE_SUCCESS(nnfw_run(session));

Expand Down
2 changes: 1 addition & 1 deletion tests/nnfw_api/src/ValidationTestAddModelLoaded.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ TEST_F(ValidationTestAddModelLoaded, neg_load_model)
{
// load model twice
ASSERT_EQ(nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
NNFW_STATUS_INVALID_STATE);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/nnfw_api/src/ValidationTestAddSessionPrepared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ TEST_F(ValidationTestAddSessionPrepared, neg_load_model)
{
// Load model twice
ASSERT_EQ(nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
NNFW_STATUS_INVALID_STATE);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/nnfw_api/src/ValidationTestMultipleSessions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ TEST_F(ValidationTestTwoSessionsCreated, two_sessions_run_simple_model)
AveragePoolModel model(N, H, W, C);

NNFW_ENSURE_SUCCESS(
nnfw_load_circle_from_buffer(_session1, model.cbuf.buffer(), model.cbuf.size()));
nnfw_load_circle_from_buffer(_session1, model.cbuf.buffer(), model.cbuf.size()));
NNFW_ENSURE_SUCCESS(
nnfw_load_circle_from_buffer(_session2, model.cbuf.buffer(), model.cbuf.size()));
nnfw_load_circle_from_buffer(_session2, model.cbuf.buffer(), model.cbuf.size()));

NNFW_ENSURE_SUCCESS(nnfw_set_available_backends(_session1, "cpu"));
NNFW_ENSURE_SUCCESS(nnfw_set_available_backends(_session2, "cpu"));
Expand Down
20 changes: 10 additions & 10 deletions tests/nnfw_api/src/ValidationTestSessionCreated.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ TEST_F(ValidationTestSessionCreated, load_session_001)
{
// Existing model must
ASSERT_EQ(nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
NNFW_STATUS_NO_ERROR);
}

Expand All @@ -36,7 +36,7 @@ TEST_F(ValidationTestSessionCreated, close_and_create_again)
TEST_F(ValidationTestSessionCreated, neg_load_session_1)
{
ASSERT_EQ(nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath("nonexisting_directory").c_str()),
_session, NNPackages::get().getModelAbsolutePath("nonexisting_directory").c_str()),
NNFW_STATUS_ERROR);
}

Expand All @@ -50,25 +50,25 @@ TEST_F(ValidationTestSessionCreated, neg_load_session_3)
// Too long path
const std::string long_path(1024, 'x');
ASSERT_EQ(nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(long_path.c_str()).c_str()),
_session, NNPackages::get().getModelAbsolutePath(long_path.c_str()).c_str()),
NNFW_STATUS_ERROR);
}

TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_1)
{
ASSERT_EQ(
nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD_NO_MANIFEST).c_str()),
NNFW_STATUS_ERROR);
nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD_NO_MANIFEST).c_str()),
NNFW_STATUS_ERROR);
ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
}

TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_2)
{
ASSERT_EQ(nnfw_load_model_from_file(
_session,
NNPackages::get().getModelAbsolutePath(NNPackages::ADD_INVALID_MANIFEST).c_str()),
NNFW_STATUS_ERROR);
ASSERT_EQ(
nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD_INVALID_MANIFEST).c_str()),
NNFW_STATUS_ERROR);
ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/nnfw_api/src/ValidationTestSingleSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST_F(ValidationTestSingleSession, neg_load_model)
{
// Invalid state
ASSERT_EQ(nnfw_load_model_from_file(
nullptr, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
nullptr, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
NNFW_STATUS_UNEXPECTED_NULL);
}

Expand Down
16 changes: 8 additions & 8 deletions tests/nnfw_api/src/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ template <int PackageNo> class ValidationTestModelLoaded : public ValidationTest
{
// TODO Eventually, downloaded model tests are removed.
NNFW_ENSURE_SUCCESS(nnfw_load_model_from_file(
_session, NNPackages::get().getModelAbsolutePath(PackageNo).c_str()));
_session, NNPackages::get().getModelAbsolutePath(PackageNo).c_str()));
}
}

Expand Down Expand Up @@ -136,8 +136,8 @@ class ValidationTestSessionPrepared : public ValidationTestModelLoaded<PackageNo
EXPECT_EQ(input_elements, 1);
_input.resize(input_elements);
ASSERT_EQ(
nnfw_set_input(_session, 0, ti_input.dtype, _input.data(), sizeof(float) * input_elements),
NNFW_STATUS_NO_ERROR);
nnfw_set_input(_session, 0, ti_input.dtype, _input.data(), sizeof(float) * input_elements),
NNFW_STATUS_NO_ERROR);

nnfw_tensorinfo ti_output;
ASSERT_EQ(nnfw_output_tensorinfo(_session, 0, &ti_output), NNFW_STATUS_NO_ERROR);
Expand All @@ -155,13 +155,13 @@ class ValidationTestSessionPrepared : public ValidationTestModelLoaded<PackageNo
uint64_t input_elements = num_elems(ti_input);
_input.resize(input_elements);
ASSERT_EQ(
nnfw_set_input(_session, 0, ti_input->dtype, _input.data(), sizeof(float) * input_elements),
NNFW_STATUS_NO_ERROR);
nnfw_set_input(_session, 0, ti_input->dtype, _input.data(), sizeof(float) * input_elements),
NNFW_STATUS_NO_ERROR);

_output.resize(40000); // Give sufficient size for the output
ASSERT_EQ(nnfw_set_output(_session, 0, ti_input->dtype, _output.data(),
sizeof(float) * _output.size()),
NNFW_STATUS_NO_ERROR);
ASSERT_EQ(
nnfw_set_output(_session, 0, ti_input->dtype, _output.data(), sizeof(float) * _output.size()),
NNFW_STATUS_NO_ERROR);
}

protected:
Expand Down
Loading

0 comments on commit 218e756

Please sign in to comment.