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));
36 TEST_F(ValidationTestSessionCreated, neg_load_session_1)
38 ASSERT_EQ(nnfw_load_model_from_file(
39 _session, NNPackages::get().getModelAbsolutePath("nonexisting_directory").c_str()),
43 TEST_F(ValidationTestSessionCreated, neg_load_session_2)
45 ASSERT_EQ(nnfw_load_model_from_file(_session, nullptr), NNFW_STATUS_UNEXPECTED_NULL);
48 TEST_F(ValidationTestSessionCreated, neg_load_session_3)
51 const std::string long_path(1024, 'x');
52 ASSERT_EQ(nnfw_load_model_from_file(
53 _session, NNPackages::get().getModelAbsolutePath(long_path.c_str()).c_str()),
57 TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_1)
60 nnfw_load_model_from_file(
61 _session, NNPackages::get().getModelAbsolutePath(NNPackages::ADD_NO_MANIFEST).c_str()),
63 ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
66 TEST_F(ValidationTestSessionCreated, neg_load_invalid_package_2)
68 ASSERT_EQ(nnfw_load_model_from_file(
70 NNPackages::get().getModelAbsolutePath(NNPackages::ADD_INVALID_MANIFEST).c_str()),
72 ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
75 TEST_F(ValidationTestSessionCreated, neg_prepare_001)
77 // nnfw_load_model_from_file was not called
78 ASSERT_EQ(nnfw_prepare(_session), NNFW_STATUS_INVALID_STATE);
81 TEST_F(ValidationTestSessionCreated, neg_run_001)
83 // nnfw_load_model_from_file and nnfw_prepare was not called
84 ASSERT_EQ(nnfw_run(_session), NNFW_STATUS_INVALID_STATE);
87 TEST_F(ValidationTestSessionCreated, neg_set_input_001)
89 ASSERT_EQ(nnfw_set_input(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
90 NNFW_STATUS_INVALID_STATE);
93 TEST_F(ValidationTestSessionCreated, neg_set_output_001)
95 ASSERT_EQ(nnfw_set_output(_session, 0, NNFW_TYPE_TENSOR_FLOAT32, nullptr, 0),
96 NNFW_STATUS_INVALID_STATE);
99 TEST_F(ValidationTestSessionCreated, neg_get_input_size)
101 uint32_t size = 10000;
102 ASSERT_EQ(nnfw_input_size(_session, &size), NNFW_STATUS_INVALID_STATE);
103 ASSERT_EQ(size, 10000); // Remain unchanged
106 TEST_F(ValidationTestSessionCreated, neg_get_output_size)
108 uint32_t size = 10000;
109 ASSERT_EQ(nnfw_output_size(_session, &size), NNFW_STATUS_INVALID_STATE);
110 ASSERT_EQ(size, 10000); // Remain unchanged
113 TEST_F(ValidationTestSessionCreated, neg_output_tensorinfo)
115 nnfw_tensorinfo tensor_info;
116 // model is not loaded
117 ASSERT_EQ(nnfw_output_tensorinfo(_session, 0, &tensor_info), NNFW_STATUS_INVALID_STATE);
118 // model is not loaded and tensor_info is null
119 ASSERT_EQ(nnfw_output_tensorinfo(_session, 0, nullptr), NNFW_STATUS_INVALID_STATE);
122 TEST_F(ValidationTestSessionCreated, neg_internal_set_config)
124 // All arguments are valid, but the session state is wrong
125 ASSERT_EQ(nnfw_set_config(_session, "TRACE_FILEPATH", ""), NNFW_STATUS_INVALID_STATE);
126 ASSERT_EQ(nnfw_set_config(_session, "GRAPH_DOT_DUMP", "0"), NNFW_STATUS_INVALID_STATE);