1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 18 #include "validation.h" 19 #include "nn_tensor.h" 20 21 using namespace testing; 22 using namespace testing::ext; 23 using namespace OHOS::NeuralNetworkRuntime; 24 using namespace OHOS::NeuralNetworkRuntime::Validation; 25 26 namespace NNRT { 27 namespace UnitTest { 28 class NnValidationTest : public testing::Test { 29 }; 30 31 /** 32 * @tc.name: nn_validation_validate_tensor_datatype_001 33 * @tc.desc: Verify the success of the validate_tensor_datatype function 34 * @tc.type: FUNC 35 */ 36 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_datatype_001, TestSize.Level1) 37 { 38 int dataTypeTest = 12; 39 OH_NN_DataType dataType = (OH_NN_DataType)dataTypeTest; 40 EXPECT_EQ(true, ValidateTensorDataType(dataType)); 41 } 42 43 /** 44 * @tc.name: nn_validation_validate_tensor_datatype_002 45 * @tc.desc: Verify the gt bounds of the validate_tensor_datatype function 46 * @tc.type: FUNC 47 */ 48 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_datatype_002, TestSize.Level1) 49 { 50 int dataTypeTest = 13; 51 OH_NN_DataType dataType = (OH_NN_DataType)dataTypeTest; 52 EXPECT_EQ(false, ValidateTensorDataType(dataType)); 53 } 54 55 /** 56 * @tc.name: nn_validation_validate_tensor_datatype_003 57 * @tc.desc: Verify the lt bounds of the validate_tensor_datatype function 58 * @tc.type: FUNC 59 */ 60 HWTEST_F(NnValidationTest, nn_validation_validate_tensor_datatype_003, TestSize.Level1) 61 { 62 int dataTypeTest = -1; 63 OH_NN_DataType dataType = (OH_NN_DataType)dataTypeTest; 64 EXPECT_EQ(false, ValidateTensorDataType(dataType)); 65 } 66 67 /** 68 * @tc.name: nn_validation_validate_preformance_mode_001 69 * @tc.desc: Verify the success of the validate_preformance_mode function 70 * @tc.type: FUNC 71 */ 72 HWTEST_F(NnValidationTest, nn_validation_validate_preformance_mode_001, TestSize.Level1) 73 { 74 int performanceModeTest = 4; 75 OH_NN_PerformanceMode performanceMode = (OH_NN_PerformanceMode)performanceModeTest; 76 EXPECT_EQ(true, ValidatePerformanceMode(performanceMode)); 77 } 78 79 /** 80 * @tc.name: nn_validation_validate_preformance_mode_002 81 * @tc.desc: Verify the gt bounds of the validate_preformance_mode function 82 * @tc.type: FUNC 83 */ 84 HWTEST_F(NnValidationTest, nn_validation_validate_preformance_mode_002, TestSize.Level1) 85 { 86 int performanceModeTest = 5; 87 OH_NN_PerformanceMode performanceMode = (OH_NN_PerformanceMode)performanceModeTest; 88 EXPECT_EQ(false, ValidatePerformanceMode(performanceMode)); 89 } 90 91 /** 92 * @tc.name: nn_validation_validate_preformance_mode_003 93 * @tc.desc: Verify the lt bounds of the validate_preformance_mode function 94 * @tc.type: FUNC 95 */ 96 HWTEST_F(NnValidationTest, nn_validation_validate_preformance_mode_003, TestSize.Level1) 97 { 98 int performanceModeTest = -1; 99 OH_NN_PerformanceMode performanceMode = (OH_NN_PerformanceMode)performanceModeTest; 100 EXPECT_EQ(false, ValidatePerformanceMode(performanceMode)); 101 } 102 103 /** 104 * @tc.name: nn_validation_validate_priority_001 105 * @tc.desc: Verify the success of the validate_priority function 106 * @tc.type: FUNC 107 */ 108 HWTEST_F(NnValidationTest, nn_validation_validate_priority_001, TestSize.Level1) 109 { 110 int priorityTest = 2; 111 OH_NN_Priority priority = (OH_NN_Priority)priorityTest; 112 EXPECT_EQ(true, ValidatePriority(priority)); 113 } 114 115 /** 116 * @tc.name: nn_validation_validate_priority_002 117 * @tc.desc: Verify the gt bounds of the validate_priority function 118 * @tc.type: FUNC 119 */ 120 HWTEST_F(NnValidationTest, nn_validation_validate_priority_002, TestSize.Level1) 121 { 122 int priorityTest = 4; 123 OH_NN_Priority priority = (OH_NN_Priority)priorityTest; 124 EXPECT_EQ(false, ValidatePriority(priority)); 125 } 126 127 /** 128 * @tc.name: nn_validation_validate_priority_003 129 * @tc.desc: Verify the lt bounds of the validate_priority function 130 * @tc.type: FUNC 131 */ 132 HWTEST_F(NnValidationTest, nn_validation_validate_priority_003, TestSize.Level1) 133 { 134 int priorityTest = -1; 135 OH_NN_Priority priority = (OH_NN_Priority)priorityTest; 136 EXPECT_EQ(false, ValidatePriority(priority)); 137 } 138 139 /** 140 * @tc.name: nn_validation_fusetype_001 141 * @tc.desc: Verify the success of the validate_fusetype function 142 * @tc.type: FUNC 143 */ 144 HWTEST_F(NnValidationTest, nn_validation_fusetype_001, TestSize.Level1) 145 { 146 int fuseTypeTest = 2; 147 OH_NN_FuseType fuseType = (OH_NN_FuseType)fuseTypeTest; 148 EXPECT_EQ(true, ValidateFuseType(fuseType)); 149 } 150 151 /** 152 * @tc.name: nn_validation_fusetype_002 153 * @tc.desc: Verify the gt bounds of the validate_fusetype function 154 * @tc.type: FUNC 155 */ 156 HWTEST_F(NnValidationTest, nn_validation_fusetype_002, TestSize.Level1) 157 { 158 int fuseTypeTest = 3; 159 OH_NN_FuseType fuseType = (OH_NN_FuseType)fuseTypeTest; 160 EXPECT_EQ(false, ValidateFuseType(fuseType)); 161 } 162 163 /** 164 * @tc.name: nn_validation_fusetype_003 165 * @tc.desc: Verify the lt bounds of the validate_fusetype function 166 * @tc.type: FUNC 167 */ 168 HWTEST_F(NnValidationTest, nn_validation_fusetype_003, TestSize.Level1) 169 { 170 int fuseTypeTest = -1; 171 OH_NN_FuseType fuseType = (OH_NN_FuseType)fuseTypeTest; 172 EXPECT_EQ(false, ValidateFuseType(fuseType)); 173 } 174 } // namespace UnitTest 175 } // namespace NNRT 176