Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/arc/process/arc_process.h" | |
| 6 | |
| 7 #include <list> | |
| 8 | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace arc { | |
|
Luis Héctor Chávez
2017/05/01 15:19:51
What was the final decision as to having the test
Yusuke Sato
2017/05/01 17:59:52
Good catch. The last conversation I remember was h
| |
| 12 | |
| 13 // Tests that ArcProcess objects can be sorted by their priority (higher to | |
| 14 // lower). This is critical for the OOM handler to work correctly. | |
| 15 TEST(ArcProcess, TestSorting) { | |
| 16 const int64_t kNow = 1234567890; | |
|
Luis Héctor Chávez
2017/05/01 15:19:51
nit: constexpr
Yusuke Sato
2017/05/01 17:59:52
Done.
| |
| 17 | |
| 18 std::list<ArcProcess> processes; | |
|
hidehiko
2017/05/01 05:24:48
IIUC, list is used to avoid copying ArcProcess on
Yusuke Sato
2017/05/01 17:59:52
No strong reason actually, used it just for emplac
hidehiko
2017/05/02 05:43:08
In future, if emplace_front is just a reason, prob
| |
| 19 processes.emplace_back(0, 0, "process 0", mojom::ProcessState::PERSISTENT, | |
| 20 false /* is_foreground */, kNow + 1); | |
| 21 processes.emplace_front(1, 1, "process 1", mojom::ProcessState::PERSISTENT, | |
| 22 false, kNow); | |
| 23 processes.emplace_back(2, 2, "process 2", mojom::ProcessState::LAST_ACTIVITY, | |
| 24 false, kNow); | |
| 25 processes.emplace_front(3, 3, "process 3", mojom::ProcessState::LAST_ACTIVITY, | |
| 26 false, kNow + 1); | |
| 27 processes.emplace_back(4, 4, "process 4", mojom::ProcessState::CACHED_EMPTY, | |
| 28 false, kNow + 1); | |
| 29 processes.emplace_front(5, 5, "process 5", mojom::ProcessState::CACHED_EMPTY, | |
| 30 false, kNow); | |
| 31 processes.sort(); | |
| 32 | |
| 33 ASSERT_LT(mojom::ProcessState::PERSISTENT, | |
|
Luis Héctor Chávez
2017/05/01 15:19:51
This can be done as a static assert (in arc_proces
Yusuke Sato
2017/05/01 17:59:52
Done.
| |
| 34 mojom::ProcessState::LAST_ACTIVITY); | |
| 35 ASSERT_LT(mojom::ProcessState::LAST_ACTIVITY, | |
| 36 mojom::ProcessState::CACHED_EMPTY); | |
| 37 | |
| 38 std::list<ArcProcess>::const_iterator it = processes.begin(); | |
| 39 // 0 should have higher priority since its last_activity_time is more recent. | |
| 40 EXPECT_EQ(0, it->pid()); | |
| 41 ++it; | |
| 42 EXPECT_EQ(1, it->pid()); | |
| 43 ++it; | |
| 44 // Same, 3 should have higher priority. | |
| 45 EXPECT_EQ(3, it->pid()); | |
| 46 ++it; | |
| 47 EXPECT_EQ(2, it->pid()); | |
| 48 ++it; | |
| 49 // Same, 4 should have higher priority. | |
| 50 EXPECT_EQ(4, it->pid()); | |
| 51 ++it; | |
| 52 EXPECT_EQ(5, it->pid()); | |
| 53 } | |
| 54 | |
| 55 } // namespace arc | |
| OLD | NEW |