1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/borealis/borealis_hardware_checker.h"
#include "ash/constants/ash_features.h"
#include "base/system/sys_info.h"
#include "base/test/scoped_amount_of_physical_memory_override.h"
#include "base/test/scoped_chromeos_version_info.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_future.h"
#include "chromeos/ash/components/system/fake_statistics_provider.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace borealis {
namespace {
bool check(std::string board,
std::string model,
std::string cpu,
uint64_t mem_gib) {
// Fake out the values that will be checked
content::BrowserTaskEnvironment task_environment_;
base::test::ScopedChromeOSVersionInfo version(
"CHROMEOS_RELEASE_BOARD=" + board + "\n", base::Time());
ash::system::FakeStatisticsProvider fsp;
fsp.SetMachineStatistic(ash::system::kCustomizationIdKey, model);
ash::system::StatisticsProvider::SetTestProvider(&fsp);
SetCpuForTesting(&cpu);
// For some reason we're not allowed to pretend to have 0 memory.
base::test::ScopedAmountOfPhysicalMemoryOverride mem_override(
std::max(1024 * mem_gib, uint64_t(1)));
// Now do the actual check
base::test::TestFuture<bool> result_f;
HasSufficientHardware(result_f.GetCallback());
return result_f.Get();
}
} // namespace
TEST(BorealisHardwareCheckerTest, Hatch) {
// Valid case, we don't care about model.
EXPECT_TRUE(
check("hatch", "fake_model", "Intel(R) Core(TM) i3-10110U CPU", 8));
// Insufficient ram
EXPECT_FALSE(
check("hatch", "fake_model", "Intel(R) Core(TM) i3-10110U CPU", 6));
// Insufficient CPU
EXPECT_FALSE(
check("hatch", "fake_model", "Intel(R) Celeron(R) CPU 5205U", 8));
}
TEST(BorealisHardwareCheckerTest, Volteer) {
// Previous CPU name branding
EXPECT_TRUE(check("volteer", "lindar",
"11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz", 8));
EXPECT_TRUE(check("volteer-foo", "lindar",
"11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz", 8));
// New CPU name branding
// Note: These are not real Board/Model/CPU combinations.
EXPECT_TRUE(
check("volteer", "lindar", "11th Gen Intel(R) Core(TM) 5 NOT_A_CPU", 8));
// Insufficient ram/cpu - previous CPU name branding
EXPECT_FALSE(check("volteer", "lindar",
"11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz", 2));
EXPECT_FALSE(check("volteer", "lindar",
"11th Gen Intel(R) Core(TM) i1-1145G7 @ 2.60GHz", 8));
// Insufficient ram/cpu - new CPU name branding
// Note: These are not real Board/Model/CPU combinations.
EXPECT_FALSE(
check("volteer", "lindar", "11th Gen Intel(R) Core(TM) 1 NOT_A_CPU", 8));
EXPECT_FALSE(
check("volteer", "lindar", "11th Gen Intel(R) Core(TM) 5 NOT_A_CPU", 2));
// Any random model
EXPECT_TRUE(check("volteer", "not_a_real_model",
"11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz", 8));
}
TEST(BorealisHardwareCheckerTest, GuybrushMajolica) {
EXPECT_TRUE(
check("guybrush", "", "AMD Ryzen 5 5625C with Radeon Graphics", 8));
EXPECT_TRUE(
check("majolica", "", "AMD Ryzen 5 5625C with Radeon Graphics", 8));
EXPECT_TRUE(
check("guybrush-dash", "", "AMD Ryzen 5 5625C with Radeon Graphics", 8));
EXPECT_FALSE(
check("majolica", "", "AMD Ryzen 5 5625C with Radeon Graphics", 1));
}
TEST(BorealisHardwareCheckerTest, Aurora) {
EXPECT_TRUE(check("aurora", "", "", 0));
}
TEST(BorealisHardwareCheckerTest, Myst) {
EXPECT_TRUE(check("myst", "", "", 0));
}
TEST(BorealisHardwareCheckerTest, Nissa) {
auto check_nissa = []() {
return check("nissa", "", "Intel(R) Core(TM) i3-X105", 8);
};
// Nissa without FeatureManagement's flag are disallowed
EXPECT_FALSE(check_nissa());
// With FeatureManagement's flag, they are allowed
base::test::ScopedFeatureList features;
features.InitWithFeatureState(ash::features::kFeatureManagementBorealis,
/*enabled=*/true);
EXPECT_TRUE(check_nissa());
}
TEST(BorealisHardwareCheckerTest, Skyrim) {
auto check_skyrim = []() {
return check("skyrim", "", "AMD Ryzen 5 X303 with Radeon Graphics", 8);
};
EXPECT_FALSE(check_skyrim());
base::test::ScopedFeatureList features;
features.InitWithFeatureState(ash::features::kFeatureManagementBorealis,
/*enabled=*/true);
EXPECT_TRUE(check_skyrim());
}
TEST(BorealisHardwareCheckerTest, Rex) {
// TODO(307825451): Put the real CPU here.
EXPECT_TRUE(check("rex", "", "Fake Cpu", 8));
EXPECT_FALSE(check("rex", "", "Fake Cpu", 4));
}
} // namespace borealis
|