• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "vsync_sampler.h"
17 
18 #include <gtest/gtest.h>
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 class VSyncPresentFenceTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28 
29     static inline sptr<VSyncSampler> vsyncSampler = nullptr;
30 };
31 
SetUpTestCase()32 void VSyncPresentFenceTest::SetUpTestCase()
33 {
34     vsyncSampler = CreateVSyncSampler();
35 }
36 
37 namespace {
38 /*
39 * Function: AddPresentFenceTimeErrorTest
40 * Type: Function
41 * Rank: Important(2)
42 * EnvConditions: N/A
43 * CaseDescription: 1. test AddPresentFenceTime error_ oversize
44  */
45 HWTEST_F(VSyncPresentFenceTest, AddPresentFenceTimeErrorTest, Function | MediumTest| Level3)
46 {
47     vsyncSampler->Reset();
48     vsyncSampler->BeginSample();
49     bool ret = true;
50     for (int i = 1; i <= 10; i++) { // add 10 samples
51         ret = vsyncSampler->AddSample(i * 16666667); // 16666667ns
52     }
53     ASSERT_EQ(ret, false);
54     vsyncSampler->SetVsyncEnabledScreenId(0);
55     for (int i = 1; i <= 10; i++) { // add 10 samples
56         ret = vsyncSampler->AddPresentFenceTime(0, i * 16666667); // 16666667ns
57     }
58     ASSERT_EQ(ret, false);
59     for (int i = 1; i <= 10; i++) { // add 10 samples
60         ret = vsyncSampler->AddPresentFenceTime(0, i * 16666667 + 1000000); // 16666667ns, 1000000ns
61     }
62     ASSERT_EQ(ret, true);
63     ret = vsyncSampler->AddPresentFenceTime(0, 1666666666); // 1666666666ns
64     ASSERT_EQ(ret, true);
65     ret = vsyncSampler->AddPresentFenceTime(0, 2666666666); // 2666666666ns
66     ASSERT_EQ(ret, true);
67     for (int i = 1; i <= 10; i++) { // add 10 samples
68         ret = vsyncSampler->AddPresentFenceTime(0, i * 16666667 + 1000000); // 16666667ns, 1000000ns
69     }
70     ASSERT_EQ(ret, true);
71 }
72 } // namespace
73 } // namespace Rosen
74 } // namespace OHOS