1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "src/profiling/memory/sampler.h"
18
19 #include <thread>
20
21 #include "test/gtest_and_gmock.h"
22
23 namespace perfetto {
24 namespace profiling {
25 namespace {
26
TEST(SamplerTest,TestLarge)27 TEST(SamplerTest, TestLarge) {
28 GetGlobalRandomEngineLocked().seed(1);
29 Sampler sampler;
30 sampler.SetSamplingInterval(512);
31 EXPECT_EQ(sampler.SampleSize(1024), 1024u);
32 }
33
TEST(SamplerTest,TestSmall)34 TEST(SamplerTest, TestSmall) {
35 GetGlobalRandomEngineLocked().seed(1);
36 Sampler sampler;
37 sampler.SetSamplingInterval(512);
38 EXPECT_EQ(sampler.SampleSize(511), 512u);
39 }
40
TEST(SamplerTest,TestSequence)41 TEST(SamplerTest, TestSequence) {
42 GetGlobalRandomEngineLocked().seed(1);
43 Sampler sampler;
44 sampler.SetSamplingInterval(1);
45 EXPECT_EQ(sampler.SampleSize(3), 3u);
46 EXPECT_EQ(sampler.SampleSize(7), 7u);
47 EXPECT_EQ(sampler.SampleSize(5), 5u);
48 }
49
50 } // namespace
51 } // namespace profiling
52 } // namespace perfetto
53