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 #include <cmath> 16 #include <cstdio> 17 #include <vector> 18 #include <thread> 19 20 #include "interfaces/kits/c/neural_network_runtime.h" 21 #include "nnrt_utils.h" 22 #include "model.h" 23 24 using namespace testing::ext; 25 using namespace OHOS::NeuralNetworkRuntime; 26 using namespace OHOS::NeuralNetworkRuntime::Test; 27 using namespace OHOS::HDI::Nnrt::V1_0; 28 29 class MultiThreadTest : public testing::Test { 30 public: SetUp()31 void SetUp() 32 { 33 } TearDown()34 void TearDown() 35 { 36 } 37 38 protected: 39 OHNNCompileParam compileParam; 40 AddModel addModel; 41 OHNNGraphArgs graphArgs = addModel.graphArgs; 42 }; 43 44 45 /** 46 * @tc.number : SUB_AI_NNR_Reliability_North_Stress_0100 47 * @tc.name : 模型编译并发长稳测试 48 * @tc.desc : [C- SOFTWARE -0200] 49 */ 50 HWTEST_F(MultiThreadTest, SUB_AI_NNR_Reliability_North_Stress_0100, Reliability | MediumTest | Level2) 51 { 52 for (int i = 0; i < STRESS_COUNT; i++) { 53 OH_NNModel *model1 = OH_NNModel_Construct(); 54 ASSERT_NE(nullptr, model1); 55 ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model1, graphArgs)); 56 57 OH_NNCompilation *compilation1 = OH_NNCompilation_Construct(model1); 58 ASSERT_NE(nullptr, compilation1); 59 ASSERT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation1, compileParam)); 60 61 Free(model1, compilation1); 62 if (i % PRINT_FREQ == 0) { 63 printf("[NnrtTest] SUB_AI_NNR_Reliability_North_Stress_0100 times: %d/%d\n", i, STRESS_COUNT); 64 } 65 } 66 } 67 68 /** 69 * @tc.number : SUB_AI_NNR_Reliability_North_Stress_0200 70 * @tc.name : 模型推理并发长稳测试 71 * @tc.desc : [C- SOFTWARE -0200] 72 */ 73 HWTEST_F(MultiThreadTest, SUB_AI_NNR_Reliability_North_Stress_0200, Reliability | MediumTest | Level2) 74 { 75 OH_NNModel *model1 = OH_NNModel_Construct(); 76 ASSERT_NE(nullptr, model1); 77 ASSERT_EQ(OH_NN_SUCCESS, BuildSingleOpGraph(model1, graphArgs)); 78 79 OH_NNCompilation *compilation1 = OH_NNCompilation_Construct(model1); 80 ASSERT_NE(nullptr, compilation1); 81 ASSERT_EQ(OH_NN_SUCCESS, CompileGraphMock(compilation1, compileParam)); 82 83 for (int i = 0; i < STRESS_COUNT; i++) { 84 OH_NNExecutor *executor1 = OH_NNExecutor_Construct(compilation1); 85 ASSERT_NE(nullptr, executor1); 86 ASSERT_EQ(OH_NN_SUCCESS, ExecuteGraphMock(executor1, graphArgs, nullptr)); 87 OH_NNExecutor_Destroy(&executor1); 88 ASSERT_EQ(nullptr, executor1); 89 if (i % PRINT_FREQ == 0) { 90 printf("[NnrtTest] SUB_AI_NNR_Reliability_North_Stress_0200 times: %d/%d\n", i, STRESS_COUNT); 91 } 92 } 93 Free(model1, compilation1); 94 } 95