• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "hitrace_chain_utils.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace AbilityRuntime {
25 class AbilityHitraceChainTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp() override;
30     void TearDown() override;
31 };
32 
SetUpTestCase(void)33 void AbilityHitraceChainTest::SetUpTestCase(void) {}
34 
TearDownTestCase(void)35 void AbilityHitraceChainTest::TearDownTestCase(void) {}
36 
SetUp()37 void AbilityHitraceChainTest::SetUp() {}
38 
TearDown()39 void AbilityHitraceChainTest::TearDown() {}
40 
41 HWTEST_F(AbilityHitraceChainTest, AbilityHitraceChain_001, TestSize.Level1)
42 {
43     auto isValid = HiviewDFX::HiTraceChain::GetId().IsValid();
44     EXPECT_FALSE(isValid);
45     AAFwk::AbilityHitraceChain abilityHitraceChain("StartAbility", HITRACE_FLAG_INCLUDE_ASYNC);
46     isValid = HiviewDFX::HiTraceChain::GetId().IsValid();
47     EXPECT_TRUE(isValid);
48 }
49 
50 HWTEST_F(AbilityHitraceChainTest, AbilityHitraceChain_002, TestSize.Level1)
51 {
52     auto traceId = HiviewDFX::HiTraceChain::Begin("StartAbility", HITRACE_FLAG_INCLUDE_ASYNC);
53     AAFwk::AbilityHitraceChain abilityHitraceChain("StartAbility", HITRACE_FLAG_DEFAULT);
54     auto chainId = HiviewDFX::HiTraceChain::GetId().GetChainId();
55     EXPECT_EQ(chainId, traceId.GetChainId());
56     auto isFlagEnabled = HiviewDFX::HiTraceChain::GetId().IsFlagEnabled(HITRACE_FLAG_INCLUDE_ASYNC);
57     EXPECT_TRUE(isFlagEnabled);
58     HiviewDFX::HiTraceChain::End(traceId);
59 }
60 } // namespace AbilityRuntime
61 } // namespace OHOS