Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / tests / nnfw_api / src / ValidationTestSessionCreated.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(ValidationTestSessionCreated, load_session_001)
21 {
22   // Existing model must
23   ASSERT_EQ(nnfw_load_model_from_file(
24                 _session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD).c_str()),
25             NNFW_STATUS_NO_ERROR);
26 }
27
28 TEST_F(ValidationTestSessionCreated, close_and_create_again)
29 {
30   NNFW_ENSURE_SUCCESS(nnfw_close_session(_session));
31   NNFW_ENSURE_SUCCESS(nnfw_create_session(&_session));
32 }
33
34 TEST_F(ValidationTestSessionCreated, neg_load_session_1)
35 {
36   ASSERT_EQ(nnfw_load_model_from_file(
37                 _session, NNPackages::get().getModelAbsolutePath("nonexisting_directory").c_str()),
38             NNFW_STATUS_ERROR);
39 }
40
41 TEST_F(ValidationTestSessionCreated, neg_load_session_2)
42 {
43   ASSERT_EQ(nnfw_load_model_from_file(_session, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
44 }
45
46 TEST_F(ValidationTestSessionCreated, neg_load_session_3)
47 {
48   // Too long path
49   const std::string long_path(1024, 'x');
50   ASSERT_EQ(nnfw_load_model_from_file(
51                 _session, NNPackages::get().getModelAbsolutePath(long_path.c_str()).c_str()),
52             NNFW_STATUS_ERROR);
53 }
54
55 TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_1)
56 {
57   ASSERT_EQ(
58       nnfw_load_model_from_file(
59           _session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD_NO_MANIFEST).c_str()),
60       NNFW_STATUS_ERROR);
61   ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
62 }
63
64 TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_2)
65 {
66   ASSERT_EQ(nnfw_load_model_from_file(
67                 _session,
68                 NNPackages::get().getModelAbsolutePath(NNPackages::ADD_INVALID_MANIFEST).c_str()),
69             NNFW_STATUS_ERROR);
70   ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
71 }
72
73 TEST_F(ValidationTestSessionCreated, neg_prepare_001)
74 {
75   // nnfw_load_model_from_file was not called
76   ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
77 }
78
79 TEST_F(ValidationTestSessionCreated, neg_run_001)
80 {
81   // nnfw_load_model_from_file and nnfw_prepare was not called
82   ASSERT_EQ(nnfw_run(_session), NNFW_STATUS_INVALID_STATE);
83 }
84
85 TEST_F(ValidationTestSessionCreated, neg_set_input_001)
86 {
87   ASSERT_EQ(nnfw_set_input(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
88             NNFW_STATUS_INVALID_STATE);
89 }
90
91 TEST_F(ValidationTestSessionCreated, neg_set_output_001)
92 {
93   ASSERT_EQ(nnfw_set_output(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
94             NNFW_STATUS_INVALID_STATE);
95 }
96
97 TEST_F(ValidationTestSessionCreated, neg_get_input_size)
98 {
99   uint32_t size = 10000;
100   ASSERT_EQ(nnfw_input_size(_session, &size), NNFW_STATUS_INVALID_STATE);
101   ASSERT_EQ(size, 10000); // Remain unchanged
102 }
103
104 TEST_F(ValidationTestSessionCreated, neg_get_output_size)
105 {
106   uint32_t size = 10000;
107   ASSERT_EQ(nnfw_output_size(_session, &size), NNFW_STATUS_INVALID_STATE);
108   ASSERT_EQ(size, 10000); // Remain unchanged
109 }
110
111 TEST_F(ValidationTestSessionCreated, neg_output_tensorinfo)
112 {
113   nnfw_tensorinfo tensor_info;
114   // model is not loaded
115   ASSERT_EQ(nnfw_output_tensorinfo(_session, 0, &tensor_info), NNFW_STATUS_INVALID_STATE);
116   // model is not loaded and tensor_info is null
117   ASSERT_EQ(nnfw_output_tensorinfo(_session, 0, nullptr), NNFW_STATUS_INVALID_STATE);
118 }