Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / ValidationTestSingleSession.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 "NNPackages.h"
18 #include "fixtures.h"
19
20 TEST_F(ValidationTestSingleSession, create_001)
21 {
22   NNFW_ENSURE_SUCCESS(nnfw_create_session(&_session));
23   NNFW_ENSURE_SUCCESS(nnfw_close_session(_session));
24
25   SUCCEED();
26 }
27
28 TEST_F(ValidationTestSingleSession, query_info_u32)
29 {
30   uint32_t val = 0;
31   NNFW_ENSURE_SUCCESS(nnfw_query_info_u32(nullptr, NNFW_INFO_ID_VERSION, &val));
32
33   SUCCEED();
34 }
35
36 TEST_F(ValidationTestSingleSession, neg_create_001)
37 {
38   ASSERT_EQ(nnfw_create_session(nullptr), NNFW_STATUS_UNEXPECTED_NULL);
39 }
40
41 TEST_F(ValidationTestSingleSession, neg_run_001)
42 {
43   ASSERT_EQ(nnfw_run(nullptr), NNFW_STATUS_UNEXPECTED_NULL);
44 }
45
46 TEST_F(ValidationTestSingleSession, neg_set_input_001)
47 {
48   // Invalid session
49   ASSERT_EQ(nnfw_set_input(nullptr, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
50             NNFW_STATUS_UNEXPECTED_NULL);
51 }
52
53 TEST_F(ValidationTestSingleSession, neg_set_input_002)
54 {
55   char input[32];
56   ASSERT_EQ(nnfw_set_input(nullptr, 0, NNFW_TYPE_TENSOR_FLOAT32, input, sizeof(input)),
57             NNFW_STATUS_UNEXPECTED_NULL);
58 }
59
60 TEST_F(ValidationTestSingleSession, neg_set_output_001)
61 {
62   // Invalid session
63   ASSERT_EQ(nnfw_set_output(nullptr, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
64             NNFW_STATUS_UNEXPECTED_NULL);
65 }
66
67 TEST_F(ValidationTestSingleSession, neg_set_output_002)
68 {
69   char buffer[32];
70   ASSERT_EQ(nnfw_set_output(nullptr, 0, NNFW_TYPE_TENSOR_FLOAT32, buffer, sizeof(buffer)),
71             NNFW_STATUS_UNEXPECTED_NULL);
72 }
73
74 TEST_F(ValidationTestSingleSession, neg_get_input_size)
75 {
76   uint32_t size = 10000;
77   ASSERT_EQ(nnfw_input_size(nullptr, &size), NNFW_STATUS_UNEXPECTED_NULL);
78   ASSERT_EQ(size, 10000);
79 }
80
81 TEST_F(ValidationTestSingleSession, neg_get_output_size)
82 {
83   uint32_t size = 10000;
84   ASSERT_EQ(nnfw_output_size(nullptr, &size), NNFW_STATUS_UNEXPECTED_NULL);
85   ASSERT_EQ(size, 10000);
86 }
87
88 TEST_F(ValidationTestSingleSession, neg_load_model)
89 {
90   // Invalid state
91   ASSERT_EQ(nnfw_load_model_from_file(
92                 nullptr, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
93             NNFW_STATUS_UNEXPECTED_NULL);
94 }
95
96 TEST_F(ValidationTestSingleSession, neg_prepare_001)
97 {
98   ASSERT_EQ(nnfw_prepare(nullptr), NNFW_STATUS_UNEXPECTED_NULL);
99 }
100
101 TEST_F(ValidationTestSingleSession, neg_query_info_u32)
102 {
103   ASSERT_EQ(nnfw_query_info_u32(nullptr, NNFW_INFO_ID_VERSION, nullptr), NNFW_STATUS_ERROR);
104 }
105
106 TEST_F(ValidationTestSingleSession, neg_output_tensorinfo)
107 {
108   nnfw_tensorinfo tensor_info;
109   ASSERT_EQ(nnfw_output_tensorinfo(nullptr, 0, &tensor_info), NNFW_STATUS_UNEXPECTED_NULL);
110   ASSERT_EQ(nnfw_output_tensorinfo(nullptr, 0, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
111 }