Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 3 | // |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file or at |
| 6 | // https://developers.google.com/open-source/licenses/bsd |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 7 | |
| 8 | // This file defines a protocol for running the conformance test suite |
| 9 | // in-process. In other words, the suite itself will run in the same process as |
| 10 | // the code under test. |
| 11 | // |
| 12 | // For pros and cons of this approach, please see conformance.proto. |
| 13 | |
| 14 | #ifndef CONFORMANCE_CONFORMANCE_TEST_H |
| 15 | #define CONFORMANCE_CONFORMANCE_TEST_H |
| 16 | |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 17 | #include <cstddef> |
| 18 | #include <memory> |
Rafi Kamal | 4f02f05 | 2019-08-22 16:14:22 -0700 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <vector> |
| 21 | |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 22 | #include "google/protobuf/descriptor.pb.h" |
Mike Kruskal | 1595417 | 2022-09-09 10:42:19 -0700 | [diff] [blame] | 23 | #include "google/protobuf/util/type_resolver.h" |
Mike Kruskal | 2166cce | 2022-12-21 20:38:13 -0800 | [diff] [blame] | 24 | #include "absl/container/btree_set.h" |
| 25 | #include "absl/container/flat_hash_set.h" |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 26 | #include "absl/strings/string_view.h" |
Mike Kruskal | ca4b063 | 2022-08-11 20:55:01 -0700 | [diff] [blame] | 27 | #include "conformance/conformance.pb.h" |
Protobuf Team Bot | 0287cf4 | 2023-08-22 07:26:58 -0700 | [diff] [blame] | 28 | #include "google/protobuf/descriptor.h" |
Mike Kruskal | 60a84c3 | 2022-11-08 09:37:29 -0800 | [diff] [blame] | 29 | #include "google/protobuf/wire_format_lite.h" |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 30 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 31 | namespace conformance { |
| 32 | class ConformanceRequest; |
| 33 | class ConformanceResponse; |
| 34 | } // namespace conformance |
| 35 | |
Joshua Haberman | f1ce60e | 2016-12-03 11:51:25 -0500 | [diff] [blame] | 36 | namespace protobuf_test_messages { |
| 37 | namespace proto3 { |
Yilun Chong | 3adb054 | 2017-06-30 17:22:32 -0700 | [diff] [blame] | 38 | class TestAllTypesProto3; |
Joshua Haberman | f1ce60e | 2016-12-03 11:51:25 -0500 | [diff] [blame] | 39 | } // namespace proto3 |
| 40 | } // namespace protobuf_test_messages |
| 41 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 42 | namespace google { |
| 43 | namespace protobuf { |
| 44 | |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 45 | class ConformanceTestSuite; |
| 46 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 47 | class ConformanceTestRunner { |
| 48 | public: |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 49 | virtual ~ConformanceTestRunner() {} |
| 50 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 51 | // Call to run a single conformance test. |
| 52 | // |
| 53 | // "input" is a serialized conformance.ConformanceRequest. |
| 54 | // "output" should be set to a serialized conformance.ConformanceResponse. |
| 55 | // |
| 56 | // If there is any error in running the test itself, set "runtime_error" in |
| 57 | // the response. |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 58 | virtual void RunTest(const std::string& test_name, const std::string& input, |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 59 | std::string* output) = 0; |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 62 | // Test runner that spawns the process being tested and communicates with it |
| 63 | // over a pipe. |
| 64 | class ForkPipeRunner : public ConformanceTestRunner { |
| 65 | public: |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 66 | // Note: Run() doesn't take ownership of the pointers inside suites. |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 67 | static int Run(int argc, char* argv[], |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 68 | const std::vector<ConformanceTestSuite*>& suites); |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 69 | |
Rafi Kamal | 4f02f05 | 2019-08-22 16:14:22 -0700 | [diff] [blame] | 70 | ForkPipeRunner(const std::string& executable, |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 71 | const std::vector<std::string>& executable_args, |
| 72 | bool performance) |
Rafi Kamal | 4f02f05 | 2019-08-22 16:14:22 -0700 | [diff] [blame] | 73 | : child_pid_(-1), |
| 74 | executable_(executable), |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 75 | executable_args_(executable_args), |
| 76 | performance_(performance) {} |
Rafi Kamal | 4f02f05 | 2019-08-22 16:14:22 -0700 | [diff] [blame] | 77 | |
| 78 | explicit ForkPipeRunner(const std::string& executable) |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 79 | : child_pid_(-1), executable_(executable) {} |
| 80 | |
| 81 | virtual ~ForkPipeRunner() {} |
| 82 | |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 83 | void RunTest(const std::string& test_name, const std::string& request, |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 84 | std::string* response); |
| 85 | |
Paul Yang | cecba29 | 2018-12-14 16:05:03 -0800 | [diff] [blame] | 86 | private: |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 87 | void SpawnTestProgram(); |
| 88 | |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 89 | void CheckedWrite(int fd, const void* buf, size_t len); |
| 90 | bool TryRead(int fd, void* buf, size_t len); |
| 91 | void CheckedRead(int fd, void* buf, size_t len); |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 92 | |
| 93 | int write_fd_; |
| 94 | int read_fd_; |
| 95 | pid_t child_pid_; |
| 96 | std::string executable_; |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 97 | const std::vector<std::string> executable_args_; |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 98 | bool performance_; |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 99 | std::string current_test_name_; |
| 100 | }; |
| 101 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 102 | // Class representing the test suite itself. To run it, implement your own |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 103 | // class derived from ConformanceTestRunner, class derived from |
| 104 | // ConformanceTestSuite and then write code like: |
| 105 | // |
| 106 | // class MyConformanceTestSuite : public ConformanceTestSuite { |
| 107 | // public: |
| 108 | // void RunSuiteImpl() { |
Mike Kruskal | 701dd83 | 2022-08-20 14:22:08 -0700 | [diff] [blame] | 109 | // // INSERT ACTUAL TESTS. |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 110 | // } |
| 111 | // }; |
| 112 | // |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 113 | // class MyConformanceTestRunner : public ConformanceTestRunner { |
| 114 | // public: |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 115 | // static int Run(int argc, char *argv[], |
| 116 | // ConformanceTestSuite* suite); |
| 117 | // |
| 118 | // private: |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 119 | // virtual void RunTest(...) { |
| 120 | // // INSERT YOUR FRAMEWORK-SPECIFIC CODE HERE. |
| 121 | // } |
| 122 | // }; |
| 123 | // |
| 124 | // int main() { |
Paul Yang | 5aeee3d | 2018-09-06 15:02:04 -0700 | [diff] [blame] | 125 | // MyConformanceTestSuite suite; |
| 126 | // MyConformanceTestRunner::Run(argc, argv, &suite); |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 127 | // } |
| 128 | // |
| 129 | class ConformanceTestSuite { |
| 130 | public: |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 131 | ConformanceTestSuite() |
| 132 | : verbose_(false), |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 133 | performance_(false), |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 134 | enforce_recommended_(false), |
Mike Kruskal | a2ba8bc | 2023-10-18 13:12:07 -0700 | [diff] [blame] | 135 | maximum_edition_(Edition::EDITION_PROTO3), |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 136 | failure_list_flag_name_("--failure_list") {} |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 137 | virtual ~ConformanceTestSuite() {} |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 138 | |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 139 | void SetPerformance(bool performance) { performance_ = performance; } |
Josh Haberman | 181c7f2 | 2015-07-15 11:05:10 -0700 | [diff] [blame] | 140 | void SetVerbose(bool verbose) { verbose_ = verbose; } |
| 141 | |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 142 | // Whether to require the testee to pass RECOMMENDED tests. By default failing |
| 143 | // a RECOMMENDED test case will not fail the entire suite but will only |
| 144 | // generated a warning. If this flag is set to true, RECOMMENDED tests will |
| 145 | // be treated the same way as REQUIRED tests and failing a RECOMMENDED test |
| 146 | // case will cause the entire test suite to fail as well. An implementation |
| 147 | // can enable this if it wants to be strictly conforming to protobuf spec. |
| 148 | // See the comments about ConformanceLevel below to learn more about the |
| 149 | // difference between REQUIRED and RECOMMENDED test cases. |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 150 | void SetEnforceRecommended(bool value) { enforce_recommended_ = value; } |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 151 | |
Mike Kruskal | a2ba8bc | 2023-10-18 13:12:07 -0700 | [diff] [blame] | 152 | // Sets the maximum edition (inclusive) that should be tests for conformance. |
| 153 | void SetMaximumEdition(Edition edition) { maximum_edition_ = edition; } |
| 154 | |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 155 | // Gets the flag name to the failure list file. |
| 156 | // By default, this would return --failure_list |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 157 | std::string GetFailureListFlagName() { return failure_list_flag_name_; } |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 158 | |
| 159 | void SetFailureListFlagName(const std::string& failure_list_flag_name) { |
| 160 | failure_list_flag_name_ = failure_list_flag_name; |
| 161 | } |
| 162 | |
Joshua Haberman | dce403a | 2022-02-08 20:53:31 -0800 | [diff] [blame] | 163 | // Sets the path of the output directory. |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 164 | void SetOutputDir(const char* output_dir) { output_dir_ = output_dir; } |
Joshua Haberman | dce403a | 2022-02-08 20:53:31 -0800 | [diff] [blame] | 165 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 166 | // Run all the conformance tests against the given test runner. |
| 167 | // Test output will be stored in "output". |
Josh Haberman | d2b6738 | 2015-06-03 12:04:35 -0700 | [diff] [blame] | 168 | // |
| 169 | // Returns true if the set of failing tests was exactly the same as the |
Yilun Chong | 0adb74c | 2019-01-08 15:06:30 -0800 | [diff] [blame] | 170 | // failure list. |
| 171 | // The filename here is *only* used to create/format useful error messages for |
| 172 | // how to update the failure list. We do NOT read this file at all. |
| 173 | bool RunSuite(ConformanceTestRunner* runner, std::string* output, |
| 174 | const std::string& filename, |
| 175 | conformance::FailureSet* failure_list); |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 176 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 177 | protected: |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 178 | // Test cases are classified into a few categories: |
| 179 | // REQUIRED: the test case must be passed for an implementation to be |
| 180 | // interoperable with other implementations. For example, a |
Brian Wignall | a104dff | 2020-01-08 13:18:20 -0500 | [diff] [blame] | 181 | // parser implementation must accept both packed and unpacked |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 182 | // form of repeated primitive fields. |
| 183 | // RECOMMENDED: the test case is not required for the implementation to |
| 184 | // be interoperable with other implementations, but is |
| 185 | // recommended for best performance and compatibility. For |
| 186 | // example, a proto3 serializer should serialize repeated |
| 187 | // primitive fields in packed form, but an implementation |
| 188 | // failing to do so will still be able to communicate with |
| 189 | // other implementations. |
| 190 | enum ConformanceLevel { |
| 191 | REQUIRED = 0, |
| 192 | RECOMMENDED = 1, |
| 193 | }; |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 194 | |
| 195 | class ConformanceRequestSetting { |
| 196 | public: |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 197 | ConformanceRequestSetting(ConformanceLevel level, |
| 198 | conformance::WireFormat input_format, |
| 199 | conformance::WireFormat output_format, |
| 200 | conformance::TestCategory test_category, |
| 201 | const Message& prototype_message, |
| 202 | const std::string& test_name, |
| 203 | const std::string& input); |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 204 | virtual ~ConformanceRequestSetting() {} |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 205 | |
Rafi Kamal | 58d4420 | 2019-11-11 17:06:56 -0800 | [diff] [blame] | 206 | std::unique_ptr<Message> NewTestMessage() const; |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 207 | |
Mike Kruskal | 28e573e | 2023-10-17 17:26:08 -0700 | [diff] [blame] | 208 | std::string GetSyntaxIdentifier() const; |
| 209 | |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 210 | std::string GetTestName() const; |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 211 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 212 | const conformance::ConformanceRequest& GetRequest() const { |
| 213 | return request_; |
| 214 | } |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 215 | |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 216 | ConformanceLevel GetLevel() const { return level_; } |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 217 | |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 218 | std::string ConformanceLevelToString(ConformanceLevel level) const; |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 219 | |
Hao Nguyen | 2f864fd | 2019-03-20 11:45:01 -0700 | [diff] [blame] | 220 | void SetPrintUnknownFields(bool print_unknown_fields) { |
| 221 | request_.set_print_unknown_fields(true); |
| 222 | } |
| 223 | |
| 224 | void SetPrototypeMessageForCompare(const Message& message) { |
| 225 | prototype_message_for_compare_.reset(message.New()); |
| 226 | } |
| 227 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 228 | protected: |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 229 | virtual std::string InputFormatString(conformance::WireFormat format) const; |
| 230 | virtual std::string OutputFormatString( |
| 231 | conformance::WireFormat format) const; |
Paul Yang | cecba29 | 2018-12-14 16:05:03 -0800 | [diff] [blame] | 232 | conformance::ConformanceRequest request_; |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 233 | |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 234 | private: |
| 235 | ConformanceLevel level_; |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 236 | ::conformance::WireFormat input_format_; |
| 237 | ::conformance::WireFormat output_format_; |
| 238 | const Message& prototype_message_; |
Hao Nguyen | 2f864fd | 2019-03-20 11:45:01 -0700 | [diff] [blame] | 239 | std::unique_ptr<Message> prototype_message_for_compare_; |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 240 | std::string test_name_; |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 241 | }; |
| 242 | |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 243 | std::string WireFormatToString(conformance::WireFormat wire_format); |
Paul Yang | cecba29 | 2018-12-14 16:05:03 -0800 | [diff] [blame] | 244 | |
| 245 | // Parse payload in the response to the given message. Returns true on |
| 246 | // success. |
Joshua Haberman | 8a4bfd6 | 2023-09-08 19:26:10 -0700 | [diff] [blame] | 247 | virtual bool ParseResponse(const conformance::ConformanceResponse& response, |
| 248 | const ConformanceRequestSetting& setting, |
| 249 | Message* test_message) = 0; |
Paul Yang | cecba29 | 2018-12-14 16:05:03 -0800 | [diff] [blame] | 250 | |
Rafi Kamal | 4f02f05 | 2019-08-22 16:14:22 -0700 | [diff] [blame] | 251 | void VerifyResponse(const ConformanceRequestSetting& setting, |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 252 | const std::string& equivalent_wire_format, |
Rafi Kamal | 4f02f05 | 2019-08-22 16:14:22 -0700 | [diff] [blame] | 253 | const conformance::ConformanceResponse& response, |
| 254 | bool need_report_success, bool require_same_wire_format); |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 255 | |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 256 | void TruncateDebugPayload(std::string* payload); |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 257 | conformance::ConformanceRequest TruncateRequest( |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 258 | const conformance::ConformanceRequest& request); |
Mike Kruskal | 39752aa | 2023-10-17 16:58:29 -0700 | [diff] [blame] | 259 | conformance::ConformanceResponse TruncateResponse( |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 260 | const conformance::ConformanceResponse& response); |
| 261 | |
Josh Haberman | d2b6738 | 2015-06-03 12:04:35 -0700 | [diff] [blame] | 262 | void ReportSuccess(const std::string& test_name); |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 263 | void ReportFailure(const std::string& test_name, ConformanceLevel level, |
Josh Haberman | b0500b3 | 2015-07-10 16:36:59 -0700 | [diff] [blame] | 264 | const conformance::ConformanceRequest& request, |
| 265 | const conformance::ConformanceResponse& response, |
Mike Kruskal | e99b281 | 2022-09-23 14:27:46 -0700 | [diff] [blame] | 266 | absl::string_view message); |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 267 | void ReportSkip(const std::string& test_name, |
Josh Haberman | b0500b3 | 2015-07-10 16:36:59 -0700 | [diff] [blame] | 268 | const conformance::ConformanceRequest& request, |
| 269 | const conformance::ConformanceResponse& response); |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 270 | |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 271 | void RunValidInputTest(const ConformanceRequestSetting& setting, |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 272 | const std::string& equivalent_text_format); |
Paul Yang | 26eeec9 | 2018-07-09 14:29:23 -0700 | [diff] [blame] | 273 | void RunValidBinaryInputTest(const ConformanceRequestSetting& setting, |
Joshua Haberman | 32e5deb | 2020-04-28 08:40:38 -0700 | [diff] [blame] | 274 | const std::string& equivalent_wire_format, |
Paul Yang | a9bb656 | 2019-07-26 10:05:14 -0700 | [diff] [blame] | 275 | bool require_same_wire_format = false); |
Feng Xiao | e841bac | 2015-12-11 17:09:20 -0800 | [diff] [blame] | 276 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 277 | void RunTest(const std::string& test_name, |
| 278 | const conformance::ConformanceRequest& request, |
| 279 | conformance::ConformanceResponse* response); |
| 280 | |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 281 | void AddExpectedFailedTest(const std::string& test_name); |
| 282 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 283 | virtual void RunSuiteImpl() = 0; |
| 284 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 285 | ConformanceTestRunner* runner_; |
| 286 | int successes_; |
Josh Haberman | b0500b3 | 2015-07-10 16:36:59 -0700 | [diff] [blame] | 287 | int expected_failures_; |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 288 | bool verbose_; |
Mike Kruskal | 32bea52 | 2022-10-06 16:48:39 -0700 | [diff] [blame] | 289 | bool performance_; |
Bo Yang | cc8ca5b | 2016-09-19 13:45:07 -0700 | [diff] [blame] | 290 | bool enforce_recommended_; |
Mike Kruskal | a2ba8bc | 2023-10-18 13:12:07 -0700 | [diff] [blame] | 291 | Edition maximum_edition_; |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 292 | std::string output_; |
Joshua Haberman | dce403a | 2022-02-08 20:53:31 -0800 | [diff] [blame] | 293 | std::string output_dir_; |
Yilun Chong | d8c2501 | 2019-02-22 18:13:33 +0800 | [diff] [blame] | 294 | std::string failure_list_flag_name_; |
Josh Haberman | ef7894e | 2016-05-16 12:45:02 -0700 | [diff] [blame] | 295 | std::string failure_list_filename_; |
Josh Haberman | d2b6738 | 2015-06-03 12:04:35 -0700 | [diff] [blame] | 296 | |
| 297 | // The set of test names that are expected to fail in this run, but haven't |
| 298 | // failed yet. |
Mike Kruskal | 2166cce | 2022-12-21 20:38:13 -0800 | [diff] [blame] | 299 | absl::btree_set<std::string> expected_to_fail_; |
Josh Haberman | d2b6738 | 2015-06-03 12:04:35 -0700 | [diff] [blame] | 300 | |
| 301 | // The set of test names that have been run. Used to ensure that there are no |
| 302 | // duplicate names in the suite. |
Mike Kruskal | 2166cce | 2022-12-21 20:38:13 -0800 | [diff] [blame] | 303 | absl::flat_hash_set<std::string> test_names_; |
Josh Haberman | d2b6738 | 2015-06-03 12:04:35 -0700 | [diff] [blame] | 304 | |
| 305 | // The set of tests that failed, but weren't expected to. |
Mike Kruskal | 2166cce | 2022-12-21 20:38:13 -0800 | [diff] [blame] | 306 | absl::btree_set<std::string> unexpected_failing_tests_; |
Josh Haberman | d2b6738 | 2015-06-03 12:04:35 -0700 | [diff] [blame] | 307 | |
| 308 | // The set of tests that succeeded, but weren't expected to. |
Mike Kruskal | 2166cce | 2022-12-21 20:38:13 -0800 | [diff] [blame] | 309 | absl::btree_set<std::string> unexpected_succeeding_tests_; |
Josh Haberman | b0500b3 | 2015-07-10 16:36:59 -0700 | [diff] [blame] | 310 | |
| 311 | // The set of tests that the testee opted out of; |
Mike Kruskal | 2166cce | 2022-12-21 20:38:13 -0800 | [diff] [blame] | 312 | absl::btree_set<std::string> skipped_; |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 313 | }; |
| 314 | |
Josh Haberman | 4e63b52 | 2015-04-14 13:45:39 -0700 | [diff] [blame] | 315 | } // namespace protobuf |
| 316 | } // namespace google |
| 317 | |
| 318 | #endif // CONFORMANCE_CONFORMANCE_TEST_H |