aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test/TestLayerVisitor.cpp
blob: ec405119d1aac7f34eb1be80d1cb00c4db197d78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "TestLayerVisitor.hpp"

#include <doctest/doctest.h>

namespace armnn
{

void TestLayerVisitor::CheckLayerName(const char* name)
{
    if (name == nullptr)
    {
        CHECK(m_LayerName == nullptr);
    }
    else if (m_LayerName == nullptr)
    {
        CHECK(name == nullptr);
    }
    else
    {
        CHECK_EQ(std::string(m_LayerName), std::string(name));
    }
}

void TestLayerVisitor::CheckLayerPointer(const IConnectableLayer* layer)
{
    CHECK(layer != nullptr);
}

void TestLayerVisitor::CheckConstTensors(const ConstTensor& expected, const ConstTensor& actual)
{
    CHECK(expected.GetInfo() == actual.GetInfo());
    CHECK(expected.GetNumDimensions() == actual.GetNumDimensions());
    CHECK(expected.GetNumElements() == actual.GetNumElements());
    CHECK(expected.GetNumBytes() == actual.GetNumBytes());
    if (expected.GetNumBytes() == actual.GetNumBytes())
    {
        //check data is the same byte by byte
        const unsigned char* expectedPtr = static_cast<const unsigned char*>(expected.GetMemoryArea());
        const unsigned char* actualPtr = static_cast<const unsigned char*>(actual.GetMemoryArea());
        for (unsigned int i = 0; i < expected.GetNumBytes(); i++)
        {
            CHECK(*(expectedPtr + i) == *(actualPtr + i));
        }
    }
}

void TestLayerVisitor::CheckOptionalConstTensors(const Optional<ConstTensor>& expected,
                                                 const Optional<ConstTensor>& actual)
{
    CHECK(expected.has_value() == actual.has_value());
    if (expected.has_value() && actual.has_value())
    {
        CheckConstTensors(expected.value(), actual.value());
    }
}

} //namespace armnn