From 95e73d77b9a79f7d350a39d85f07d09cd58422cc Mon Sep 17 00:00:00 2001 From: Rob Hughes Date: Tue, 24 Sep 2019 09:34:53 +0100 Subject: NNXSW-1826 Move tests for Optimization classes to separate files This splits up the >1000 line OptimizerTests.cpp file. Each Optimization class now has its own test file, all of which are in a subfolder of tests called "optimizations". The original OptimizerTests.cpp now contains mostly (completely?) tests for validating output shapes, which perhaps should be moved to test files specific to the layer types they are testing. Change-Id: Icd1196cad8b720abcb156921aab1adbd4026756b Signed-off-by: Rob Hughes --- .../test/optimizations/PermuteAsReshapeTests.cpp | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/armnn/test/optimizations/PermuteAsReshapeTests.cpp (limited to 'src/armnn/test/optimizations/PermuteAsReshapeTests.cpp') diff --git a/src/armnn/test/optimizations/PermuteAsReshapeTests.cpp b/src/armnn/test/optimizations/PermuteAsReshapeTests.cpp new file mode 100644 index 0000000000..b44331c9fc --- /dev/null +++ b/src/armnn/test/optimizations/PermuteAsReshapeTests.cpp @@ -0,0 +1,60 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "../TestUtils.hpp" + +#include + +#include + +using namespace armnn; + +BOOST_AUTO_TEST_SUITE(Optimizer) +using namespace armnn::optimizations; + +BOOST_AUTO_TEST_CASE(PermuteAsReshapeTest) +{ + armnn::Graph graph; + + std::string permuteLayerName = "permute"; + + const armnn::TensorInfo infoIn({ 1, 2, 3, 1 }, armnn::DataType::Float32); + const armnn::TensorInfo infoOut({ 1, 1, 2, 3 }, armnn::DataType::Float32); + + auto output = graph.AddLayer(0, "output"); + + graph.InsertNewLayer(output->GetInputSlot(0), 0, "input") + ->GetOutputHandler() + .SetTensorInfo(infoIn); + + // Inserts permute. + graph + .InsertNewLayer(output->GetInputSlot(0), armnn::PermuteDescriptor({ 0, 2, 3, 1 }), + permuteLayerName.c_str()) + ->GetOutputHandler() + .SetTensorInfo(infoOut); + + BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType, + &IsLayerOfType, &IsLayerOfType)); + + armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(PermuteAsReshape())); + + // The permute is replaced by an equivalent reshape. + + auto checkReshape = [&infoOut](const armnn::Layer* const layer) -> bool { + const auto reshapeLayer = static_cast(layer); + return IsLayerOfType(layer) && + (reshapeLayer->GetParameters().m_TargetShape == infoOut.GetShape()) && + (reshapeLayer->GetOutputHandler().GetTensorInfo().GetShape() == infoOut.GetShape()); + }; + + BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType, checkReshape, + &IsLayerOfType)); + + std::list testRelatedLayers = { permuteLayerName }; + BOOST_TEST(CheckRelatedLayers(graph, testRelatedLayers)); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file -- cgit v1.2.1