2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "NNPackages.h"
20 TEST_F(ValidationTestSessionCreated, load_session_001)
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);
28 TEST_F(ValidationTestSessionCreated, close_and_create_again)
30 NNFW_ENSURE_SUCCESS(nnfw_close_session(_session));
31 NNFW_ENSURE_SUCCESS(nnfw_create_session(&_session));
34 TEST_F(ValidationTestSessionCreated, neg_load_session_1)
36 ASSERT_EQ(nnfw_load_model_from_file(
37 _session, NNPackages::get().getModelAbsolutePath("nonexisting_directory").c_str()),
41 TEST_F(ValidationTestSessionCreated, neg_load_session_2)
43 ASSERT_EQ(nnfw_load_model_from_file(_session, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
46 TEST_F(ValidationTestSessionCreated, neg_load_session_3)
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()),
55 TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_1)
58 nnfw_load_model_from_file(
59 _session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD_NO_MANIFEST).c_str()),
61 ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
64 TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_2)
66 ASSERT_EQ(nnfw_load_model_from_file(
68 NNPackages::get().getModelAbsolutePath(NNPackages::ADD_INVALID_MANIFEST).c_str()),
70 ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
73 TEST_F(ValidationTestSessionCreated, neg_prepare_001)
75 // nnfw_load_model_from_file was not called
76 ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
79 TEST_F(ValidationTestSessionCreated, neg_run_001)
81 // nnfw_load_model_from_file and nnfw_prepare was not called
82 ASSERT_EQ(nnfw_run(_session), NNFW_STATUS_INVALID_STATE);
85 TEST_F(ValidationTestSessionCreated, neg_set_input_001)
87 ASSERT_EQ(nnfw_set_input(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
88 NNFW_STATUS_INVALID_STATE);
91 TEST_F(ValidationTestSessionCreated, neg_set_output_001)
93 ASSERT_EQ(nnfw_set_output(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
94 NNFW_STATUS_INVALID_STATE);
97 TEST_F(ValidationTestSessionCreated, neg_get_input_size)
99 uint32_t size = 10000;
100 ASSERT_EQ(nnfw_input_size(_session, &size), NNFW_STATUS_INVALID_STATE);
101 ASSERT_EQ(size, 10000); // Remain unchanged
104 TEST_F(ValidationTestSessionCreated, neg_get_output_size)
106 uint32_t size = 10000;
107 ASSERT_EQ(nnfw_output_size(_session, &size), NNFW_STATUS_INVALID_STATE);
108 ASSERT_EQ(size, 10000); // Remain unchanged
111 TEST_F(ValidationTestSessionCreated, neg_output_tensorinfo)
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);