webrtc/test/field_trial.h
Jonas Olsson 5b2eda4895 Sanity-check field trial string at initialization.
It's easy to make small errors when building field trial strings, and
those errors can cause all sorts of weird problems. This CL checks if
the FT string has an odd number of delimiters, duplicate
names or any trailing chars.

If so we'll log a error message. On debug builds we'll also crash.

Bug: webrtc:10729
Change-Id: Iebf7155d9b117a02d1e9cfe7f64408e11df2aec5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/140866
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#28234}
2019-06-11 14:11:06 +00:00

39 lines
1.2 KiB
C++

/*
* Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef TEST_FIELD_TRIAL_H_
#define TEST_FIELD_TRIAL_H_
#include <map>
#include <string>
namespace webrtc {
namespace test {
// TODO(jonasolsson): remove once all internal usages are gone.
void ValidateFieldTrialsStringOrDie(const std::string&);
// This class is used to override field-trial configs within specific tests.
// After this class goes out of scope previous field trials will be restored.
class ScopedFieldTrials {
public:
explicit ScopedFieldTrials(const std::string& config);
ScopedFieldTrials(const ScopedFieldTrials&) = delete;
ScopedFieldTrials& operator=(const ScopedFieldTrials&) = delete;
~ScopedFieldTrials();
private:
std::string current_field_trials_;
const char* previous_field_trials_;
};
} // namespace test
} // namespace webrtc
#endif // TEST_FIELD_TRIAL_H_