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

Side by Side Diff: tools/ipc_fuzzer/fuzzer/fuzzer.cc

Issue 2023243002: Remove base::Tuple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: lint fix Created 4 years, 6 months 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 | « media/gpu/video_encode_accelerator_unittest.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <iostream> 5 #include <iostream>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 #include <tuple>
8 #include <utility> 9 #include <utility>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/shared_memory_handle.h" 13 #include "base/memory/shared_memory_handle.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "build/build_config.h" 15 #include "build/build_config.h"
15 #include "ipc/ipc_message.h" 16 #include "ipc/ipc_message.h"
16 #include "ipc/ipc_message_utils.h" 17 #include "ipc/ipc_message_utils.h"
17 #include "ipc/ipc_switches.h" 18 #include "ipc/ipc_switches.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 template <> 206 template <>
206 struct FuzzTraits<base::string16> { 207 struct FuzzTraits<base::string16> {
207 static bool Fuzz(base::string16* p, Fuzzer* fuzzer) { 208 static bool Fuzz(base::string16* p, Fuzzer* fuzzer) {
208 fuzzer->FuzzString16(p); 209 fuzzer->FuzzString16(p);
209 return true; 210 return true;
210 } 211 }
211 }; 212 };
212 213
213 // Specializations for tuples. 214 // Specializations for tuples.
214 template <> 215 template <>
215 struct FuzzTraits<base::Tuple<>> { 216 struct FuzzTraits<std::tuple<>> {
216 static bool Fuzz(base::Tuple<>* p, Fuzzer* fuzzer) { 217 static bool Fuzz(std::tuple<>* p, Fuzzer* fuzzer) { return true; }
217 return true;
218 }
219 }; 218 };
220 219
221 template <class A> 220 template <class A>
222 struct FuzzTraits<base::Tuple<A>> { 221 struct FuzzTraits<std::tuple<A>> {
223 static bool Fuzz(base::Tuple<A>* p, Fuzzer* fuzzer) { 222 static bool Fuzz(std::tuple<A>* p, Fuzzer* fuzzer) {
224 return FuzzParam(&base::get<0>(*p), fuzzer); 223 return FuzzParam(&std::get<0>(*p), fuzzer);
225 } 224 }
226 }; 225 };
227 226
228 template <class A, class B> 227 template <class A, class B>
229 struct FuzzTraits<base::Tuple<A, B>> { 228 struct FuzzTraits<std::tuple<A, B>> {
230 static bool Fuzz(base::Tuple<A, B>* p, Fuzzer* fuzzer) { 229 static bool Fuzz(std::tuple<A, B>* p, Fuzzer* fuzzer) {
231 return 230 return FuzzParam(&std::get<0>(*p), fuzzer) &&
232 FuzzParam(&base::get<0>(*p), fuzzer) && 231 FuzzParam(&std::get<1>(*p), fuzzer);
233 FuzzParam(&base::get<1>(*p), fuzzer);
234 } 232 }
235 }; 233 };
236 234
237 template <class A, class B, class C> 235 template <class A, class B, class C>
238 struct FuzzTraits<base::Tuple<A, B, C>> { 236 struct FuzzTraits<std::tuple<A, B, C>> {
239 static bool Fuzz(base::Tuple<A, B, C>* p, Fuzzer* fuzzer) { 237 static bool Fuzz(std::tuple<A, B, C>* p, Fuzzer* fuzzer) {
240 return 238 return FuzzParam(&std::get<0>(*p), fuzzer) &&
241 FuzzParam(&base::get<0>(*p), fuzzer) && 239 FuzzParam(&std::get<1>(*p), fuzzer) &&
242 FuzzParam(&base::get<1>(*p), fuzzer) && 240 FuzzParam(&std::get<2>(*p), fuzzer);
243 FuzzParam(&base::get<2>(*p), fuzzer);
244 } 241 }
245 }; 242 };
246 243
247 template <class A, class B, class C, class D> 244 template <class A, class B, class C, class D>
248 struct FuzzTraits<base::Tuple<A, B, C, D>> { 245 struct FuzzTraits<std::tuple<A, B, C, D>> {
249 static bool Fuzz(base::Tuple<A, B, C, D>* p, Fuzzer* fuzzer) { 246 static bool Fuzz(std::tuple<A, B, C, D>* p, Fuzzer* fuzzer) {
250 return 247 return FuzzParam(&std::get<0>(*p), fuzzer) &&
251 FuzzParam(&base::get<0>(*p), fuzzer) && 248 FuzzParam(&std::get<1>(*p), fuzzer) &&
252 FuzzParam(&base::get<1>(*p), fuzzer) && 249 FuzzParam(&std::get<2>(*p), fuzzer) &&
253 FuzzParam(&base::get<2>(*p), fuzzer) && 250 FuzzParam(&std::get<3>(*p), fuzzer);
254 FuzzParam(&base::get<3>(*p), fuzzer);
255 } 251 }
256 }; 252 };
257 253
258 template <class A, class B, class C, class D, class E> 254 template <class A, class B, class C, class D, class E>
259 struct FuzzTraits<base::Tuple<A, B, C, D, E>> { 255 struct FuzzTraits<std::tuple<A, B, C, D, E>> {
260 static bool Fuzz(base::Tuple<A, B, C, D, E>* p, Fuzzer* fuzzer) { 256 static bool Fuzz(std::tuple<A, B, C, D, E>* p, Fuzzer* fuzzer) {
261 return 257 return FuzzParam(&std::get<0>(*p), fuzzer) &&
262 FuzzParam(&base::get<0>(*p), fuzzer) && 258 FuzzParam(&std::get<1>(*p), fuzzer) &&
263 FuzzParam(&base::get<1>(*p), fuzzer) && 259 FuzzParam(&std::get<2>(*p), fuzzer) &&
264 FuzzParam(&base::get<2>(*p), fuzzer) && 260 FuzzParam(&std::get<3>(*p), fuzzer) &&
265 FuzzParam(&base::get<3>(*p), fuzzer) && 261 FuzzParam(&std::get<4>(*p), fuzzer);
266 FuzzParam(&base::get<4>(*p), fuzzer);
267 } 262 }
268 }; 263 };
269 264
270 // Specializations for containers. 265 // Specializations for containers.
271 template <class A> 266 template <class A>
272 struct FuzzTraits<std::vector<A> > { 267 struct FuzzTraits<std::vector<A> > {
273 static bool Fuzz(std::vector<A>* p, Fuzzer* fuzzer) { 268 static bool Fuzz(std::vector<A>* p, Fuzzer* fuzzer) {
274 ++g_depth; 269 ++g_depth;
275 size_t count = p->size(); 270 size_t count = p->size();
276 if (fuzzer->ShouldGenerate()) { 271 if (fuzzer->ShouldGenerate()) {
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 template <typename... Args> 1957 template <typename... Args>
1963 static Message* New(const Args&... args) { 1958 static Message* New(const Args&... args) {
1964 return new Message(RandInRange(MAX_FAKE_ROUTING_ID), args...); 1959 return new Message(RandInRange(MAX_FAKE_ROUTING_ID), args...);
1965 } 1960 }
1966 }; 1961 };
1967 1962
1968 template <typename Message> 1963 template <typename Message>
1969 class FuzzerHelper; 1964 class FuzzerHelper;
1970 1965
1971 template <typename Meta, typename... Ins> 1966 template <typename Meta, typename... Ins>
1972 class FuzzerHelper<IPC::MessageT<Meta, base::Tuple<Ins...>, void>> { 1967 class FuzzerHelper<IPC::MessageT<Meta, std::tuple<Ins...>, void>> {
1973 public: 1968 public:
1974 using Message = IPC::MessageT<Meta, base::Tuple<Ins...>, void>; 1969 using Message = IPC::MessageT<Meta, std::tuple<Ins...>, void>;
1975 1970
1976 static IPC::Message* Fuzz(IPC::Message* msg, Fuzzer* fuzzer) { 1971 static IPC::Message* Fuzz(IPC::Message* msg, Fuzzer* fuzzer) {
1977 return FuzzImpl(msg, fuzzer, base::MakeIndexSequence<sizeof...(Ins)>()); 1972 return FuzzImpl(msg, fuzzer, base::MakeIndexSequence<sizeof...(Ins)>());
1978 } 1973 }
1979 1974
1980 private: 1975 private:
1981 template <size_t... Ns> 1976 template <size_t... Ns>
1982 static IPC::Message* FuzzImpl(IPC::Message* msg, 1977 static IPC::Message* FuzzImpl(IPC::Message* msg,
1983 Fuzzer* fuzzer, 1978 Fuzzer* fuzzer,
1984 base::IndexSequence<Ns...>) { 1979 base::IndexSequence<Ns...>) {
1985 typename Message::Param p; 1980 typename Message::Param p;
1986 if (msg) { 1981 if (msg) {
1987 Message::Read(static_cast<Message*>(msg), &p); 1982 Message::Read(static_cast<Message*>(msg), &p);
1988 } 1983 }
1989 if (FuzzParam(&p, fuzzer)) { 1984 if (FuzzParam(&p, fuzzer)) {
1990 return MessageFactory<Message, Meta::kKind>::New(base::get<Ns>(p)...); 1985 return MessageFactory<Message, Meta::kKind>::New(std::get<Ns>(p)...);
1991 } 1986 }
1992 std::cerr << "Don't know how to handle " << Meta::kName << "\n"; 1987 std::cerr << "Don't know how to handle " << Meta::kName << "\n";
1993 return nullptr; 1988 return nullptr;
1994 } 1989 }
1995 }; 1990 };
1996 1991
1997 template <typename Meta, typename... Ins, typename... Outs> 1992 template <typename Meta, typename... Ins, typename... Outs>
1998 class FuzzerHelper< 1993 class FuzzerHelper<
1999 IPC::MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>>> { 1994 IPC::MessageT<Meta, std::tuple<Ins...>, std::tuple<Outs...>>> {
2000 public: 1995 public:
2001 using Message = 1996 using Message = IPC::MessageT<Meta, std::tuple<Ins...>, std::tuple<Outs...>>;
2002 IPC::MessageT<Meta, base::Tuple<Ins...>, base::Tuple<Outs...>>;
2003 1997
2004 static IPC::Message* Fuzz(IPC::Message* msg, Fuzzer* fuzzer) { 1998 static IPC::Message* Fuzz(IPC::Message* msg, Fuzzer* fuzzer) {
2005 return FuzzImpl(msg, fuzzer, base::MakeIndexSequence<sizeof...(Ins)>()); 1999 return FuzzImpl(msg, fuzzer, base::MakeIndexSequence<sizeof...(Ins)>());
2006 } 2000 }
2007 2001
2008 private: 2002 private:
2009 template <size_t... Ns> 2003 template <size_t... Ns>
2010 static IPC::Message* FuzzImpl(IPC::Message* msg, 2004 static IPC::Message* FuzzImpl(IPC::Message* msg,
2011 Fuzzer* fuzzer, 2005 Fuzzer* fuzzer,
2012 base::IndexSequence<Ns...>) { 2006 base::IndexSequence<Ns...>) {
2013 typename Message::SendParam p; 2007 typename Message::SendParam p;
2014 Message* real_msg = static_cast<Message*>(msg); 2008 Message* real_msg = static_cast<Message*>(msg);
2015 Message* new_msg = nullptr; 2009 Message* new_msg = nullptr;
2016 if (real_msg) { 2010 if (real_msg) {
2017 Message::ReadSendParam(real_msg, &p); 2011 Message::ReadSendParam(real_msg, &p);
2018 } 2012 }
2019 if (FuzzParam(&p, fuzzer)) { 2013 if (FuzzParam(&p, fuzzer)) {
2020 new_msg = MessageFactory<Message, Meta::kKind>::New( 2014 new_msg = MessageFactory<Message, Meta::kKind>::New(
2021 base::get<Ns>(p)..., static_cast<Outs*>(nullptr)...); 2015 std::get<Ns>(p)..., static_cast<Outs*>(nullptr)...);
2022 } 2016 }
2023 if (real_msg && new_msg) { 2017 if (real_msg && new_msg) {
2024 MessageCracker::CopyMessageID(new_msg, real_msg); 2018 MessageCracker::CopyMessageID(new_msg, real_msg);
2025 } else if (!new_msg) { 2019 } else if (!new_msg) {
2026 std::cerr << "Don't know how to handle " << Meta::kName << "\n"; 2020 std::cerr << "Don't know how to handle " << Meta::kName << "\n";
2027 } 2021 }
2028 return new_msg; 2022 return new_msg;
2029 } 2023 }
2030 }; 2024 };
2031 2025
(...skipping 11 matching lines...) Expand all
2043 #include "tools/ipc_fuzzer/message_lib/all_message_null_macros.h" 2037 #include "tools/ipc_fuzzer/message_lib/all_message_null_macros.h"
2044 #undef IPC_MESSAGE_DECL 2038 #undef IPC_MESSAGE_DECL
2045 #define IPC_MESSAGE_DECL(name, ...) \ 2039 #define IPC_MESSAGE_DECL(name, ...) \
2046 (*map)[static_cast<uint32_t>(name::ID)] = FuzzerHelper<name>::Fuzz; 2040 (*map)[static_cast<uint32_t>(name::ID)] = FuzzerHelper<name>::Fuzz;
2047 2041
2048 void PopulateFuzzerFunctionMap(FuzzerFunctionMap* map) { 2042 void PopulateFuzzerFunctionMap(FuzzerFunctionMap* map) {
2049 #include "tools/ipc_fuzzer/message_lib/all_messages.h" 2043 #include "tools/ipc_fuzzer/message_lib/all_messages.h"
2050 } 2044 }
2051 2045
2052 } // namespace ipc_fuzzer 2046 } // namespace ipc_fuzzer
OLDNEW
« no previous file with comments | « media/gpu/video_encode_accelerator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698