Commit 29581348 authored by yusukes's avatar yusukes Committed by Commit bot

Add arc_process_unittest.cc

arc::ArcProcess has a relatively complex operator<() which should be
paired with a test. I'd add this before adding more changes for
crbug.com/706048.

BUG=None
TEST=try

Review-Url: https://codereview.chromium.org/2853633002
Cr-Commit-Position: refs/heads/master@{#468382}
parent e6af56f1
......@@ -1571,6 +1571,7 @@ source_set("unit_tests") {
"arc/notification/arc_provision_notification_service_unittest.cc",
"arc/optin/arc_terms_of_service_default_negotiator_unittest.cc",
"arc/policy/arc_policy_bridge_unittest.cc",
"arc/process/arc_process_unittest.cc",
"attestation/attestation_ca_client_unittest.cc",
"attestation/attestation_policy_observer_unittest.cc",
"attestation/fake_certificate.cc",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/arc/process/arc_process.h"
#include <assert.h>
#include <list>
#include "testing/gtest/include/gtest/gtest.h"
namespace arc {
namespace {
// Tests that ArcProcess objects can be sorted by their priority (higher to
// lower). This is critical for the OOM handler to work correctly.
TEST(ArcProcess, TestSorting) {
constexpr int64_t kNow = 1234567890;
std::list<ArcProcess> processes; // use list<> for emplace_front.
processes.emplace_back(0, 0, "process 0", mojom::ProcessState::PERSISTENT,
false /* is_foreground */, kNow + 1);
processes.emplace_front(1, 1, "process 1", mojom::ProcessState::PERSISTENT,
false, kNow);
processes.emplace_back(2, 2, "process 2", mojom::ProcessState::LAST_ACTIVITY,
false, kNow);
processes.emplace_front(3, 3, "process 3", mojom::ProcessState::LAST_ACTIVITY,
false, kNow + 1);
processes.emplace_back(4, 4, "process 4", mojom::ProcessState::CACHED_EMPTY,
false, kNow + 1);
processes.emplace_front(5, 5, "process 5", mojom::ProcessState::CACHED_EMPTY,
false, kNow);
processes.sort();
static_assert(
mojom::ProcessState::PERSISTENT < mojom::ProcessState::LAST_ACTIVITY,
"unexpected enum values");
static_assert(
mojom::ProcessState::LAST_ACTIVITY < mojom::ProcessState::CACHED_EMPTY,
"unexpected enum values");
std::list<ArcProcess>::const_iterator it = processes.begin();
// 0 should have higher priority since its last_activity_time is more recent.
EXPECT_EQ(0, it->pid());
++it;
EXPECT_EQ(1, it->pid());
++it;
// Same, 3 should have higher priority.
EXPECT_EQ(3, it->pid());
++it;
EXPECT_EQ(2, it->pid());
++it;
// Same, 4 should have higher priority.
EXPECT_EQ(4, it->pid());
++it;
EXPECT_EQ(5, it->pid());
}
} // namespace
} // namespace arc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment