Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / ValidationTestAddModelLoaded.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "fixtures.h"
18 #include "NNPackages.h"
19
20 using ValidationTestAddModelLoaded = ValidationTestModelLoaded<NNPackages::ADD>;
21
22 TEST_F(ValidationTestAddModelLoaded, prepare_001) { NNFW_ENSURE_SUCCESS(nnfw_prepare(_session)); }
23
24 TEST_F(ValidationTestAddModelLoaded, set_available_backends_001)
25 {
26   NNFW_ENSURE_SUCCESS(nnfw_set_available_backends(_session, "cpu"));
27 }
28
29 TEST_F(ValidationTestAddModelLoaded, get_input_size)
30 {
31   uint32_t size = 0;
32   NNFW_ENSURE_SUCCESS(nnfw_input_size(_session, &size));
33   ASSERT_EQ(size, 1);
34 }
35
36 TEST_F(ValidationTestAddModelLoaded, get_output_size)
37 {
38   uint32_t size = 0;
39   NNFW_ENSURE_SUCCESS(nnfw_output_size(_session, &size));
40   ASSERT_EQ(size, 1);
41 }
42
43 TEST_F(ValidationTestAddModelLoaded, output_tensorinfo)
44 {
45   nnfw_tensorinfo tensor_info;
46   NNFW_ENSURE_SUCCESS(nnfw_output_tensorinfo(_session, 0, &tensor_info));
47   ASSERT_EQ(tensor_info.rank, 1);
48   ASSERT_EQ(tensor_info.dims[0], 1);
49 }
50
51 TEST_F(ValidationTestAddModelLoaded, neg_run)
52 {
53   // nnfw_prepare is not called
54   ASSERT_EQ(nnfw_run(_session), NNFW_STATUS_INVALID_STATE);
55 }
56
57 TEST_F(ValidationTestAddModelLoaded, neg_set_input)
58 {
59   // nnfw_prepare is not called
60   ASSERT_EQ(nnfw_set_input(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
61             NNFW_STATUS_INVALID_STATE);
62 }
63
64 TEST_F(ValidationTestAddModelLoaded, neg_set_output)
65 {
66   // nnfw_prepare is not called
67   ASSERT_EQ(nnfw_set_output(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
68             NNFW_STATUS_INVALID_STATE);
69 }
70
71 TEST_F(ValidationTestAddModelLoaded, neg_get_input_size)
72 {
73   ASSERT_EQ(nnfw_input_size(_session, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
74 }
75
76 TEST_F(ValidationTestAddModelLoaded, neg_get_output_size)
77 {
78   ASSERT_EQ(nnfw_output_size(_session, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
79 }
80
81 TEST_F(ValidationTestAddModelLoaded, neg_load_model)
82 {
83   // load model twice
84   ASSERT_EQ(nnfw_load_model_from_file(
85                 _session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
86             NNFW_STATUS_INVALID_STATE);
87 }
88
89 TEST_F(ValidationTestAddModelLoaded, neg_output_tensorinfo)
90 {
91   // tensor_info is null
92   ASSERT_EQ(nnfw_output_tensorinfo(_session, 0, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
93 }