1 /* 2 * Copyright (c) 2024 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 "native_engine/worker_manager.h" 19 20 #define NUM_80 80 21 #define NUM_64 64 22 #define NUM_16 16 23 #define NUM_8 8 24 25 class WorkerManagerTest : public testing::Test { 26 public: SetUpTestSuite()27 static void SetUpTestSuite() 28 { 29 } TearDownTestSuite()30 static void TearDownTestSuite() 31 { 32 } 33 }; 34 35 HWTEST_F(WorkerManagerTest, WorkerTest001, testing::ext::TestSize.Level0) 36 { 37 bool ret = false; 38 for (int k = 0; k < NUM_64; k++) { 39 ret = WorkerManager::IncrementArkRuntimeCount(); 40 ASSERT_TRUE(ret); 41 } 42 ret = WorkerManager::IncrementArkRuntimeCount(); 43 ASSERT_FALSE(ret); 44 45 WorkerManager::DecrementArkRuntimeCount(); 46 ret = WorkerManager::IncrementArkRuntimeCount(); 47 ASSERT_TRUE(ret); 48 49 for (int k = 0; k < NUM_64; k++) { 50 WorkerManager::DecrementArkRuntimeCount(); 51 } 52 } 53 54 HWTEST_F(WorkerManagerTest, WorkerTest002, testing::ext::TestSize.Level0) 55 { 56 bool ret = false; 57 for (int k = 0; k < NUM_8; k++) { 58 ret = WorkerManager::IncrementWorkerCount(WorkerType::OLD_WORKER); 59 ASSERT_TRUE(ret); 60 } 61 ret = WorkerManager::IncrementWorkerCount(WorkerType::OLD_WORKER); 62 ASSERT_FALSE(ret); 63 64 WorkerManager::DecrementWorkerCount(WorkerType::OLD_WORKER); 65 ret = WorkerManager::IncrementWorkerCount(WorkerType::OLD_WORKER); 66 ASSERT_TRUE(ret); 67 68 for (int k = 0; k < NUM_8; k++) { 69 WorkerManager::DecrementWorkerCount(WorkerType::OLD_WORKER); 70 } 71 } 72 73 HWTEST_F(WorkerManagerTest, WorkerTest003, testing::ext::TestSize.Level0) 74 { 75 bool ret = false; 76 for (int k = 0; k < NUM_16; k++) { 77 ret = WorkerManager::IncrementWorkerCount(WorkerType::LIMITED_WORKER); 78 ASSERT_TRUE(ret); 79 } 80 ret = WorkerManager::IncrementWorkerCount(WorkerType::LIMITED_WORKER); 81 ASSERT_FALSE(ret); 82 83 WorkerManager::DecrementWorkerCount(WorkerType::LIMITED_WORKER); 84 ret = WorkerManager::IncrementWorkerCount(WorkerType::LIMITED_WORKER); 85 ASSERT_TRUE(ret); 86 87 for (int k = 0; k < NUM_16; k++) { 88 WorkerManager::DecrementWorkerCount(WorkerType::LIMITED_WORKER); 89 } 90 } 91 92 HWTEST_F(WorkerManagerTest, WorkerTest004, testing::ext::TestSize.Level0) 93 { 94 bool ret = false; 95 for (int k = 0; k < NUM_64; k++) { 96 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 97 ASSERT_TRUE(ret); 98 } 99 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 100 ASSERT_FALSE(ret); 101 102 WorkerManager::DecrementWorkerCount(WorkerType::THREAD_WORKER); 103 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 104 ASSERT_TRUE(ret); 105 106 for (int k = 0; k < NUM_64; k++) { 107 WorkerManager::DecrementWorkerCount(WorkerType::THREAD_WORKER); 108 } 109 } 110 111 HWTEST_F(WorkerManagerTest, WorkerTest005, testing::ext::TestSize.Level0) 112 { 113 bool ret = false; 114 for (int k = 0; k < NUM_64; k++) { 115 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 116 ASSERT_TRUE(ret); 117 } 118 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 119 ASSERT_FALSE(ret); 120 121 for (int k = 0; k < NUM_16; k++) { 122 ret = WorkerManager::IncrementArkRuntimeCount(); 123 ASSERT_TRUE(ret); 124 } 125 126 ret = WorkerManager::IncrementArkRuntimeCount(); 127 ASSERT_FALSE(ret); 128 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 129 ASSERT_FALSE(ret); 130 ret = WorkerManager::IncrementWorkerCount(WorkerType::LIMITED_WORKER); 131 ASSERT_FALSE(ret); 132 ret = WorkerManager::IncrementWorkerCount(WorkerType::OLD_WORKER); 133 ASSERT_FALSE(ret); 134 135 for (int k = 0; k < NUM_64; k++) { 136 WorkerManager::DecrementWorkerCount(WorkerType::THREAD_WORKER); 137 } 138 for (int k = 0; k < NUM_16; k++) { 139 WorkerManager::DecrementArkRuntimeCount(); 140 } 141 } 142 143 HWTEST_F(WorkerManagerTest, WorkerTest006, testing::ext::TestSize.Level0) 144 { 145 bool ret = false; 146 for (int k = 0; k < NUM_64; k++) { 147 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 148 ASSERT_TRUE(ret); 149 } 150 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 151 ASSERT_FALSE(ret); 152 153 for (int k = 0; k < NUM_16; k++) { 154 ret = WorkerManager::IncrementWorkerCount(WorkerType::LIMITED_WORKER); 155 ASSERT_TRUE(ret); 156 } 157 158 ret = WorkerManager::IncrementArkRuntimeCount(); 159 ASSERT_FALSE(ret); 160 ret = WorkerManager::IncrementWorkerCount(WorkerType::THREAD_WORKER); 161 ASSERT_FALSE(ret); 162 ret = WorkerManager::IncrementWorkerCount(WorkerType::LIMITED_WORKER); 163 ASSERT_FALSE(ret); 164 ret = WorkerManager::IncrementWorkerCount(WorkerType::OLD_WORKER); 165 ASSERT_FALSE(ret); 166 }