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