Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / matchers / fill_with_data.hpp
1 /*
2  * INTEL CONFIDENTIAL
3  * Copyright (C) 2018-2019 Intel Corporation.
4  *
5  * The source code contained or described herein and all documents
6  * related to the source code ("Material") are owned by Intel Corporation
7  * or its suppliers or licensors. Title to the Material remains with
8  * Intel Corporation or its suppliers and licensors. The Material may
9  * contain trade secrets and proprietary and confidential information
10  * of Intel Corporation and its suppliers and licensors, and is protected
11  * by worldwide copyright and trade secret laws and treaty provisions.
12  * No part of the Material may be used, copied, reproduced, modified,
13  * published, uploaded, posted, transmitted, distributed, or disclosed
14  * in any way without Intel's prior express written permission.
15  *
16  * No license under any patent, copyright, trade secret or other
17  * intellectual property right is granted to or conferred upon you by
18  * disclosure or delivery of the Materials, either expressly, by implication,
19  * inducement, estoppel or otherwise. Any license under such intellectual
20  * property rights must be express and approved by Intel in writing.
21  *
22  * Include any supplier copyright notices as supplier requires Intel to use.
23  *
24  * Include supplier trademarks or logos as supplier requires Intel to use,
25  * preceded by an asterisk. An asterisked footnote can be added as follows:
26  * *Third Party trademarks are the property of their respective owners.
27  *
28  * Unless otherwise agreed by Intel in writing, you may not remove or alter
29  * this notice or any other notice embedded in Materials by Intel or Intel's
30  * suppliers or licensors in any way.
31  */
32
33  #pragma once
34
35
36 class OutputFiller : public ::testing::MatcherInterface<const intel_nnet_type_t*> {
37     mutable std::stringstream reason;
38     int32_t fill32BValue;
39     int16_t fill16BValue;
40
41  public:
42     OutputFiller(int32_t fill32BValue, int16_t fill16BValue) : fill32BValue(fill32BValue), fill16BValue(fill16BValue) {}
43
44
45     bool MatchAndExplain(const intel_nnet_type_t* foo, ::testing::MatchResultListener* listener) const override {
46         if (foo == nullptr)
47             return false;
48         reason.str("");
49         // checking pointers are set
50         for (int i=0; i < foo->nLayers; i++) {
51             if (nullptr == foo->pLayers[i].pInputs ||
52                 nullptr == foo->pLayers[i].pOutputs) {
53                 reason << "input/output pointers in pLayers[" << i << "] shouldn't be null NULL";
54                 return false;
55             }
56             auto nElements = foo->pLayers[i].nOutputColumns * foo->pLayers[i].nOutputRows;
57             if (foo->pLayers[i].nBytesPerOutput == 2) {
58                 std::fill_n((int16_t *) foo->pLayers[i].pOutputs, nElements, fill16BValue);
59             } else if (foo->pLayers[i].nBytesPerOutput == 4) {
60                 std::fill_n((int32_t *) foo->pLayers[i].pOutputs, nElements, fill32BValue);
61             } else {
62                 reason << "output bitness of layer [" << i << "] shouldn't be 16 or 32, but was " << foo->pLayers[i].nBytesPerOutput;
63                 return false;
64             }
65         }
66         return true;
67     }
68
69     void DescribeTo(::std::ostream *os) const override {
70         *os << "Not a Matcher but a fake, but error happened anyway: " << reason.str();
71     }
72
73 };
74