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

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

Issue 2517193003: Fix adding duplicate trials to allocator (finally) (Closed)
Patch Set: 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 shm.get()->Map(64 << 10); // Hardcoded, equal to kFieldTrialAllocationSize.
Alexei Svitkine (slow) 2016/11/21 18:28:45 This seems suboptimal. I think you shouldn't make
lawrencewu 2016/11/21 19:11:48 Done.
1191 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm)); 1191 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1192 std::string check_string; 1192 std::string check_string;
1193 FieldTrialList::AllStatesToString(&check_string); 1193 FieldTrialList::AllStatesToString(&check_string);
1194 EXPECT_EQ(save_string, check_string); 1194 EXPECT_EQ(save_string, check_string);
1195 } 1195 }
1196 1196
1197 TEST(FieldTrialListTest, DoNotAddSimulatedFieldTrialsToAllocator) {
1198 constexpr char kTrialName[] = "trial";
1199 base::SharedMemoryHandle handle;
1200 {
1201 // Create a simulated trial and a real trial and call group() on them, which
1202 // should only add the real trial to the field trial allocator.
1203 FieldTrialList field_trial_list(nullptr);
1204 FieldTrialList::InstantiateFieldTrialAllocatorIfNeeded();
1205
1206 // This shouldn't add to the allocator.
1207 FieldTrial* simulated_trial = FieldTrial::CreateSimulatedFieldTrial(
1208 kTrialName, 100, "Simulated", 0.95);
1209 simulated_trial->group();
1210
1211 // This should add to the allocator.
1212 FieldTrial* real_trial =
1213 FieldTrialList::CreateFieldTrial(kTrialName, "Real");
1214 real_trial->group();
1215
1216 handle = base::SharedMemory::DuplicateHandle(
1217 field_trial_list.field_trial_allocator_->shared_memory()->handle());
1218 }
1219
1220 // Check that there's only one entry in the allocator.
1221 FieldTrialList field_trial_list2(nullptr);
1222 std::unique_ptr<base::SharedMemory> shm(new SharedMemory(handle, true));
1223 shm.get()->Map(64 << 10); // Hardcoded, equal to kFieldTrialAllocationSize.
1224 FieldTrialList::CreateTrialsFromSharedMemory(std::move(shm));
1225 std::string check_string;
1226 FieldTrialList::AllStatesToString(&check_string);
1227 ASSERT_TRUE(check_string.find("Simulated") == std::string::npos);
Alexei Svitkine (slow) 2016/11/21 18:28:45 EXPECT_NE?
lawrencewu 2016/11/21 19:11:48 Done.
1228 }
1229
1197 } // namespace base 1230 } // 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