/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include "core/entity.h" #include "core/version_ctx.h" #include "ffrt_inner.h" #include "sched/task_state.h" #include "dfx/log/ffrt_log_api.h" #include "dfx/bbox/bbox.h" #include "tm/cpu_task.h" #include "../common.h" using namespace std; using namespace testing; #ifdef HWTEST_TESTING_EXT_ENABLE using namespace testing::ext; #endif using namespace ffrt; class CoreTest : public testing::Test { protected: static void SetUpTestCase() { } static void TearDownTestCase() { } virtual void SetUp() { } virtual void TearDown() { } }; HWTEST_F(CoreTest, core_test_success_01, TestSize.Level1) { sync_io(0); } HWTEST_F(CoreTest, task_ctx_success_01, TestSize.Level1) { auto func1 = ([]() {std::cout << std::endl << " push a task " << std::endl;}); SCPUEUTask *task1 = new SCPUEUTask(nullptr, nullptr, 0, QoS(static_cast(qos_user_interactive))); auto func2 = ([]() {std::cout << std::endl << " push a task " << std::endl;}); SCPUEUTask *task2 = new SCPUEUTask(nullptr, task1, 0, QoS()); QoS qos = QoS(static_cast(qos_inherit)); task2->SetQos(qos); EXPECT_EQ(task2->qos, static_cast(qos_user_interactive)); delete task1; delete task2; } HWTEST_F(CoreTest, ffrt_submit_wait_success_01, TestSize.Level1) { const uint32_t sleepTime = 3 * 200; int x = 0; ffrt_task_attr_t* attr = (ffrt_task_attr_t *) malloc(sizeof(ffrt_task_attr_t)); ffrt_task_attr_init(attr); std::function&& basicFunc = [&]() { EXPECT_EQ(x, 0); usleep(sleepTime); x = x + 1; }; ffrt_function_header_t* basicFunc_ht = ffrt::create_function_wrapper((basicFunc)); const std::vector in_deps = {}; ffrt_deps_t in{static_cast(in_deps.size()), in_deps.data()}; const std::vector ou_deps = {}; ffrt_deps_t ou{static_cast(ou_deps.size()), ou_deps.data()}; const std::vector wait_deps = {}; ffrt_deps_t wait{static_cast(wait_deps.size()), wait_deps.data()}; const ffrt_deps_t *wait_null = nullptr; ffrt_submit_base(basicFunc_ht, &in, &ou, attr); EXPECT_EQ(x, 0); ffrt_wait_deps(wait_null); EXPECT_EQ(x, 0); ffrt_wait_deps(&wait); EXPECT_EQ(x, 0); ffrt_wait(); EXPECT_EQ(x, 1); ffrt_task_attr_destroy(attr); free(attr); attr = nullptr; }