/src/mozilla-central/tools/profiler/tests/gtest/ThreadProfileTest.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "gtest/gtest.h" |
8 | | |
9 | | #include "ProfileBufferEntry.h" |
10 | | #include "ThreadInfo.h" |
11 | | |
12 | | // Make sure we can record one entry and read it |
13 | 0 | TEST(ThreadProfile, InsertOneEntry) { |
14 | 0 | auto pb = MakeUnique<ProfileBuffer>(10); |
15 | 0 | pb->AddEntry(ProfileBufferEntry::Time(123.1)); |
16 | 0 | ASSERT_TRUE(pb->GetEntry(pb->mRangeStart).IsTime()); |
17 | 0 | ASSERT_TRUE(pb->GetEntry(pb->mRangeStart).u.mDouble == 123.1); |
18 | 0 | } |
19 | | |
20 | | // See if we can insert some entries |
21 | 0 | TEST(ThreadProfile, InsertEntriesNoWrap) { |
22 | 0 | auto pb = MakeUnique<ProfileBuffer>(100); |
23 | 0 | int test_size = 50; |
24 | 0 | for (int i = 0; i < test_size; i++) { |
25 | 0 | pb->AddEntry(ProfileBufferEntry::Time(i)); |
26 | 0 | } |
27 | 0 | uint64_t readPos = pb->mRangeStart; |
28 | 0 | while (readPos != pb->mRangeEnd) { |
29 | 0 | ASSERT_TRUE(pb->GetEntry(readPos).IsTime()); |
30 | 0 | ASSERT_TRUE(pb->GetEntry(readPos).u.mDouble == readPos); |
31 | 0 | readPos++; |
32 | 0 | } |
33 | 0 | } |
34 | | |
35 | | // See if evicting works as it should in the basic case |
36 | 0 | TEST(ThreadProfile, InsertEntriesWrap) { |
37 | 0 | int entries = 32; |
38 | 0 | auto pb = MakeUnique<ProfileBuffer>(entries); |
39 | 0 | ASSERT_TRUE(pb->mRangeStart == 0); |
40 | 0 | ASSERT_TRUE(pb->mRangeEnd == 0); |
41 | 0 | int test_size = 43; |
42 | 0 | for (int i = 0; i < test_size; i++) { |
43 | 0 | pb->AddEntry(ProfileBufferEntry::Time(i)); |
44 | 0 | } |
45 | 0 | // We inserted 11 more entries than fit in the buffer, so the first 11 entries |
46 | 0 | // should have been evicted, and the range start should have increased to 11. |
47 | 0 | ASSERT_TRUE(pb->mRangeStart == 11); |
48 | 0 | uint64_t readPos = pb->mRangeStart; |
49 | 0 | while (readPos != pb->mRangeEnd) { |
50 | 0 | ASSERT_TRUE(pb->GetEntry(readPos).IsTime()); |
51 | 0 | ASSERT_TRUE(pb->GetEntry(readPos).u.mDouble == readPos); |
52 | 0 | readPos++; |
53 | 0 | } |
54 | 0 | } |
55 | | |