File: histogram_shared_memory_config_unittest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (103 lines) | stat: -rw-r--r-- 3,696 bytes parent folder | download | duplicates (5)
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
// 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 "content/browser/metrics/histogram_shared_memory_config.h"

#include <string_view>

#include "base/metrics/histogram_shared_memory.h"
#include "base/test/scoped_feature_list.h"
#include "content/public/common/process_type.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

namespace {

using Config = base::HistogramSharedMemory::Config;
using base::HistogramSharedMemory;

struct ProcessTypeToOptionalConfig {
  int process_type;
  std::optional<Config> expected;

  ProcessTypeToOptionalConfig(int type, std::nullopt_t)
      : process_type(type), expected(std::nullopt) {}

  ProcessTypeToOptionalConfig(int type, std::string_view name, size_t size)
      : process_type(type), expected(Config{type, name, size}) {}
};

using HistogramSharedMemoryConfigTest =
    testing::TestWithParam<ProcessTypeToOptionalConfig>;

}  // namespace

TEST(HistogramSharedMemoryConfigTest, PassOnCommandLineIsDisabled) {
  base::test::ScopedFeatureList feature_list;
  feature_list.InitAndDisableFeature(base::kPassHistogramSharedMemoryOnLaunch);

  EXPECT_FALSE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_RENDERER));
  EXPECT_FALSE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_GPU));
  EXPECT_FALSE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_UTILITY));
}

TEST(HistogramSharedMemoryConfigTest, PassOnCommandLineIsEnabled) {
  base::test::ScopedFeatureList feature_list;
  feature_list.InitAndEnableFeature(base::kPassHistogramSharedMemoryOnLaunch);

  EXPECT_TRUE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_RENDERER));

#if BUILDFLAG(IS_CHROMEOS)
  EXPECT_FALSE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_GPU));
#else   // !BUILDFLAG(IS_CHROMEOS)
  EXPECT_TRUE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_GPU));
#endif  // !BUILDFLAG(IS_CHROMEOS)

#if BUILDFLAG(IS_ANDROID)
  EXPECT_FALSE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_UTILITY));
#else   // !BUILDFLAG(IS_ANDROID)
  EXPECT_TRUE(
      HistogramSharedMemory::PassOnCommandLineIsEnabled(PROCESS_TYPE_UTILITY));
#endif  // !BUILDFLAG(IS_ANDROID)
}

TEST_P(HistogramSharedMemoryConfigTest, GetHistogramSharedMemoryConfig) {
  const auto& process_type = GetParam().process_type;
  const auto& expected = GetParam().expected;

  const auto config = GetHistogramSharedMemoryConfig(process_type);
  ASSERT_EQ(config.has_value(), expected.has_value());
  if (config.has_value()) {
    EXPECT_EQ(config->process_type, process_type);
    EXPECT_EQ(config->allocator_name, expected->allocator_name);
    EXPECT_EQ(config->memory_size_bytes, expected->memory_size_bytes);
  }
}

INSTANTIATE_TEST_SUITE_P(
    All,
    HistogramSharedMemoryConfigTest,
    testing::ValuesIn(std::vector<ProcessTypeToOptionalConfig>({
        {PROCESS_TYPE_UNKNOWN, std::nullopt},
        {PROCESS_TYPE_BROWSER, std::nullopt},
        {PROCESS_TYPE_RENDERER, "RendererMetrics", 2 << 20},
        {PROCESS_TYPE_PLUGIN_DEPRECATED, std::nullopt},
        {PROCESS_TYPE_WORKER_DEPRECATED, std::nullopt},
        {PROCESS_TYPE_UTILITY, "UtilityMetrics", 512 << 10},
        {PROCESS_TYPE_ZYGOTE, "ZygoteMetrics", 64 << 10},
        {PROCESS_TYPE_SANDBOX_HELPER, "SandboxHelperMetrics", 64 << 10},
        {PROCESS_TYPE_GPU, "GpuMetrics", 256 << 10},
        {PROCESS_TYPE_PPAPI_PLUGIN, "PpapiPluginMetrics", 64 << 10},
        {PROCESS_TYPE_PPAPI_BROKER, "PpapiBrokerMetrics", 64 << 10},
    })));

}  // namespace content