1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cstdint>
6 #include <iostream>
7
8 #include "net/quic/platform/impl/quic_test_flags_utils.h"
9
10 #include "base/check_op.h"
11 #include "net/third_party/quiche/src/quiche/common/platform/api/quiche_flags.h"
12 #include "net/third_party/quiche/src/quiche/quic/platform/api/quic_flags.h"
13
QuicFlagSaverImpl()14 QuicFlagSaverImpl::QuicFlagSaverImpl() {
15 #define QUIC_FLAG(flag, value) saved_##flag##_ = FLAGS_##flag;
16 #include "net/third_party/quiche/src/quiche/quic/core/quic_flags_list.h"
17 #undef QUIC_FLAG
18 #define QUICHE_PROTOCOL_FLAG(type, flag, ...) saved_##flag##_ = FLAGS_##flag;
19 #include "net/third_party/quiche/src/quiche/common/quiche_protocol_flags_list.h"
20 #undef QUICHE_PROTOCOL_FLAG
21 }
22
~QuicFlagSaverImpl()23 QuicFlagSaverImpl::~QuicFlagSaverImpl() {
24 #define QUIC_FLAG(flag, value) FLAGS_##flag = saved_##flag##_;
25 #include "net/third_party/quiche/src/quiche/quic/core/quic_flags_list.h"
26 #undef QUIC_FLAG
27 #define QUICHE_PROTOCOL_FLAG(type, flag, ...) FLAGS_##flag = saved_##flag##_;
28 #include "net/third_party/quiche/src/quiche/common/quiche_protocol_flags_list.h"
29 #undef QUICHE_PROTOCOL_FLAG
30 }
31
QuicFlagChecker()32 QuicFlagChecker::QuicFlagChecker() {
33 #define QUIC_FLAG(flag, value) \
34 CHECK_EQ(value, FLAGS_##flag) \
35 << "Flag set to an unexpected value. A prior test is likely " \
36 << "setting a flag without using a QuicFlagSaver. Use QuicTest to " \
37 "avoid this issue.";
38 #include "net/third_party/quiche/src/quiche/quic/core/quic_flags_list.h"
39 #undef QUIC_FLAG
40
41 #define QUICHE_PROTOCOL_FLAG_CHECK(type, flag, value) \
42 CHECK_EQ((type)value, FLAGS_##flag) \
43 << "Flag set to an unexpected value. A prior test is likely " \
44 << "setting a flag without using a QuicFlagSaver. Use QuicTest to " \
45 "avoid this issue.";
46 #define DEFINE_QUICHE_PROTOCOL_FLAG_SINGLE_VALUE(type, flag, value, doc) \
47 QUICHE_PROTOCOL_FLAG_CHECK(type, flag, value);
48
49 #define DEFINE_QUICHE_PROTOCOL_FLAG_TWO_VALUES(type, flag, internal_value, \
50 external_value, doc) \
51 QUICHE_PROTOCOL_FLAG_CHECK(type, flag, external_value);
52 #define GET_6TH_ARG(arg1, arg2, arg3, arg4, arg5, arg6, ...) arg6
53 #define QUICHE_PROTOCOL_FLAG_MACRO_CHOOSER(...) \
54 GET_6TH_ARG(__VA_ARGS__, DEFINE_QUICHE_PROTOCOL_FLAG_TWO_VALUES, \
55 DEFINE_QUICHE_PROTOCOL_FLAG_SINGLE_VALUE)
56 #define QUICHE_PROTOCOL_FLAG(...) \
57 QUICHE_PROTOCOL_FLAG_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
58 #include "net/third_party/quiche/src/quiche/common/quiche_protocol_flags_list.h"
59 #undef QUICHE_PROTOCOL_FLAG
60 #undef QUICHE_PROTOCOL_FLAG_MACRO_CHOOSER
61 #undef GET_6TH_ARG
62 #undef DEFINE_QUICHE_PROTOCOL_FLAG_TWO_VALUES
63 #undef DEFINE_QUICHE_PROTOCOL_FLAG_SINGLE_VALUE
64 #undef QUICHE_PROTOCOL_FLAG_CHECK
65 }
66