Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: base/metrics/field_trial_unittest.cc

Issue 2530573002: Share field trial allocator on zygote-using Linuxes (Closed)
Patch Set: revert to excluding nacl in ifdef Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/metrics/field_trial.h" 5 #include "base/metrics/field_trial.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/build_time.h" 10 #include "base/build_time.h"
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 // Trying to instantiate a one-time randomized field trial before the 1129 // Trying to instantiate a one-time randomized field trial before the
1130 // FieldTrialList is created should crash. 1130 // FieldTrialList is created should crash.
1131 EXPECT_DEATH_IF_SUPPORTED( 1131 EXPECT_DEATH_IF_SUPPORTED(
1132 FieldTrialList::FactoryGetFieldTrial( 1132 FieldTrialList::FactoryGetFieldTrial(
1133 "OneTimeRandomizedTrialWithoutFieldTrialList", 100, kDefaultGroupName, 1133 "OneTimeRandomizedTrialWithoutFieldTrialList", 100, kDefaultGroupName,
1134 base::FieldTrialList::kNoExpirationYear, 1, 1, 1134 base::FieldTrialList::kNoExpirationYear, 1, 1,
1135 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL), 1135 base::FieldTrial::ONE_TIME_RANDOMIZED, NULL),
1136 ""); 1136 "");
1137 } 1137 }
1138 1138
1139 TEST(FieldTrialListTest, TestCopyFieldTrialStateToFlags) {
1140 base::FieldTrialList field_trial_list(
1141 base::MakeUnique<base::MockEntropyProvider>());
1142 base::FieldTrialList::CreateFieldTrial("Trial1", "Group1");
1143 base::FilePath test_file_path = base::FilePath(FILE_PATH_LITERAL("Program"));
1144 base::CommandLine cmd_line = base::CommandLine(test_file_path);
1145 const char field_trial_handle[] = "test-field-trial-handle";
1146
1147 base::FieldTrialList::CopyFieldTrialStateToFlags(field_trial_handle,
1148 &cmd_line);
1149 #if defined(OS_WIN)
1150 EXPECT_TRUE(cmd_line.HasSwitch(field_trial_handle) ||
1151 cmd_line.HasSwitch(switches::kForceFieldTrials));
1152 #else
1153 EXPECT_TRUE(cmd_line.HasSwitch(switches::kForceFieldTrials));
1154 #endif
1155 }
1156
1157 TEST(FieldTrialListTest, InstantiateAllocator) { 1139 TEST(FieldTrialListTest, InstantiateAllocator) {
1158 FieldTrialList field_trial_list(nullptr); 1140 FieldTrialList field_trial_list(nullptr);
1159 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); 1141 FieldTrialList::CreateFieldTrial("Trial1", "Group1");
1160 1142
1161 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); 1143 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1162 void* memory = field_trial_list.field_trial_allocator_->shared_memory(); 1144 void* memory = field_trial_list.field_trial_allocator_->shared_memory();
1163 size_t used = field_trial_list.field_trial_allocator_->used(); 1145 size_t used = field_trial_list.field_trial_allocator_->used();
1164 1146
1165 // Ensure that the function is idempotent. 1147 // Ensure that the function is idempotent.
1166 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); 1148 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); 1206 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
1225 // 4 KiB is enough to hold the trials only created for this test. 1207 // 4 KiB is enough to hold the trials only created for this test.
1226 shm.get()->Map(4 << 10); 1208 shm.get()->Map(4 << 10);
1227 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); 1209 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1228 std::string check_string; 1210 std::string check_string;
1229 FieldTrialList::AllStatesToString(&check_string); 1211 FieldTrialList::AllStatesToString(&check_string);
1230 ASSERT_EQ(check_string.find("Simulated"), std::string::npos); 1212 ASSERT_EQ(check_string.find("Simulated"), std::string::npos);
1231 } 1213 }
1232 1214
1233 } // namespace base 1215 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698