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

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

Issue 2517193003: Fix adding duplicate trials to allocator (finally) (Closed)
Patch Set: git rebase-update Created 4 years, 1 month 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
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 FieldTrialList field_trial_list(nullptr); 1180 FieldTrialList field_trial_list(nullptr);
1181 FieldTrialList::CreateFieldTrial("Trial1", "Group1"); 1181 FieldTrialList::CreateFieldTrial("Trial1", "Group1");
1182 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded(); 1182 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1183 FieldTrialList::AllStatesToString(&save_string); 1183 FieldTrialList::AllStatesToString(&save_string);
1184 handle = base::SharedMemory::DuplicateHandle( 1184 handle = base::SharedMemory::DuplicateHandle(
1185 field_trial_list.field_trial_allocator_->shared_memory()->handle()); 1185 field_trial_list.field_trial_allocator_->shared_memory()->handle());
1186 } 1186 }
1187 1187
1188 FieldTrialList field_trial_list2(nullptr); 1188 FieldTrialList field_trial_list2(nullptr);
1189 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true)); 1189 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
1190 shm.get()->Map(4 << 10); // Hardcoded, equal to kFieldTrialAllocationSize. 1190 // 4 KiB is enough to hold the trials only created for this test.
1191 shm.get()->Map(4 << 10);
1191 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); 1192 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1192 std::string check_string; 1193 std::string check_string;
1193 FieldTrialList::AllStatesToString(&check_string); 1194 FieldTrialList::AllStatesToString(&check_string);
1194 EXPECT_EQ(save_string, check_string); 1195 EXPECT_EQ(save_string, check_string);
1195 } 1196 }
1196 1197
1198 TEST(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) {
1199 constexpr char kTrialName[] = "trial";
1200 base::SharedMemoryHandle handle;
1201 {
1202 // Create a simulated trial and a real trial and call group() on them, which
1203 // should only add the real trial to the field trial allocator.
1204 FieldTrialList field_trial_list(nullptr);
1205 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1206
1207 // This shouldn't add to the allocator.
1208 scoped_refptr<FieldTrial> simulated_trial =
1209 FieldTrial::CreateSimulatedFieldTrial(kTrialName, 100, "Simulated",
1210 0.95);
1211 simulated_trial->group();
1212
1213 // This should add to the allocator.
1214 FieldTrial* real_trial =
1215 FieldTrialList::CreateFieldTrial(kTrialName, "Real");
1216 real_trial->group();
1217
1218 handle = base::SharedMemory::DuplicateHandle(
1219 field_trial_list.field_trial_allocator_->shared_memory()->handle());
1220 }
1221
1222 // Check that there's only one entry in the allocator.
1223 FieldTrialList field_trial_list2(nullptr);
1224 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
1225 // 4 KiB is enough to hold the trials only created for this test.
1226 shm.get()->Map(4 << 10);
1227 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1228 std::string check_string;
1229 FieldTrialList::AllStatesToString(&check_string);
1230 ASSERT_EQ(check_string.find("Simulated"), std::string::npos);
1231 }
1232
1197 } // namespace base 1233 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698