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

Side by Side Diff: net/spdy/fuzzing/hpack_example_generator.cc

Issue 2801603003: Add SpdyString alias for std::string in net/spdy. (Closed)
Patch Set: Created 3 years, 8 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 | « net/spdy/buffered_spdy_framer_unittest.cc ('k') | net/spdy/fuzzing/hpack_fuzz_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/files/file.h" 7 #include "base/files/file.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "net/spdy/fuzzing/hpack_fuzz_util.h" 10 #include "net/spdy/fuzzing/hpack_fuzz_util.h"
11 #include "net/spdy/hpack/hpack_constants.h" 11 #include "net/spdy/hpack/hpack_constants.h"
12 #include "net/spdy/hpack/hpack_encoder.h" 12 #include "net/spdy/hpack/hpack_encoder.h"
13 #include "net/spdy/platform/api/spdy_string.h"
13 #include "net/spdy/spdy_protocol.h" 14 #include "net/spdy/spdy_protocol.h"
14 15
15 namespace { 16 namespace {
16 17
17 // Target file for generated HPACK header sets. 18 // Target file for generated HPACK header sets.
18 const char kFileToWrite[] = "file-to-write"; 19 const char kFileToWrite[] = "file-to-write";
19 20
20 // Number of header sets to generate. 21 // Number of header sets to generate.
21 const char kExampleCount[] = "example-count"; 22 const char kExampleCount[] = "example-count";
22 23
23 } // namespace 24 } // namespace
24 25
25 using net::HpackFuzzUtil; 26 using net::HpackFuzzUtil;
27 using net::SpdyString;
26 using std::map; 28 using std::map;
27 using std::string;
28 29
29 // Generates a configurable number of header sets (using HpackFuzzUtil), and 30 // Generates a configurable number of header sets (using HpackFuzzUtil), and
30 // sequentially encodes each header set with an HpackEncoder. Encoded header 31 // sequentially encodes each header set with an HpackEncoder. Encoded header
31 // sets are written to the output file in length-prefixed blocks. 32 // sets are written to the output file in length-prefixed blocks.
32 int main(int argc, char** argv) { 33 int main(int argc, char** argv) {
33 base::AtExitManager exit_manager; 34 base::AtExitManager exit_manager;
34 35
35 base::CommandLine::Init(argc, argv); 36 base::CommandLine::Init(argc, argv);
36 const base::CommandLine& command_line = 37 const base::CommandLine& command_line =
37 *base::CommandLine::ForCurrentProcess(); 38 *base::CommandLine::ForCurrentProcess();
38 39
39 if (!command_line.HasSwitch(kFileToWrite) || 40 if (!command_line.HasSwitch(kFileToWrite) ||
40 !command_line.HasSwitch(kExampleCount)) { 41 !command_line.HasSwitch(kExampleCount)) {
41 LOG(ERROR) << "Usage: " << argv[0] 42 LOG(ERROR) << "Usage: " << argv[0]
42 << " --" << kFileToWrite << "=/path/to/file.out" 43 << " --" << kFileToWrite << "=/path/to/file.out"
43 << " --" << kExampleCount << "=1000"; 44 << " --" << kExampleCount << "=1000";
44 return -1; 45 return -1;
45 } 46 }
46 string file_to_write = command_line.GetSwitchValueASCII(kFileToWrite); 47 SpdyString file_to_write = command_line.GetSwitchValueASCII(kFileToWrite);
47 48
48 int example_count = 0; 49 int example_count = 0;
49 base::StringToInt(command_line.GetSwitchValueASCII(kExampleCount), 50 base::StringToInt(command_line.GetSwitchValueASCII(kExampleCount),
50 &example_count); 51 &example_count);
51 52
52 DVLOG(1) << "Writing output to " << file_to_write; 53 DVLOG(1) << "Writing output to " << file_to_write;
53 base::File file_out(base::FilePath::FromUTF8Unsafe(file_to_write), 54 base::File file_out(base::FilePath::FromUTF8Unsafe(file_to_write),
54 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); 55 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
55 CHECK(file_out.IsValid()) << file_out.error_details(); 56 CHECK(file_out.IsValid()) << file_out.error_details();
56 57
57 HpackFuzzUtil::GeneratorContext context; 58 HpackFuzzUtil::GeneratorContext context;
58 HpackFuzzUtil::InitializeGeneratorContext(&context); 59 HpackFuzzUtil::InitializeGeneratorContext(&context);
59 net::HpackEncoder encoder(net::ObtainHpackHuffmanTable()); 60 net::HpackEncoder encoder(net::ObtainHpackHuffmanTable());
60 61
61 for (int i = 0; i != example_count; ++i) { 62 for (int i = 0; i != example_count; ++i) {
62 net::SpdyHeaderBlock headers = 63 net::SpdyHeaderBlock headers =
63 HpackFuzzUtil::NextGeneratedHeaderSet(&context); 64 HpackFuzzUtil::NextGeneratedHeaderSet(&context);
64 65
65 string buffer; 66 SpdyString buffer;
66 CHECK(encoder.EncodeHeaderSet(headers, &buffer)); 67 CHECK(encoder.EncodeHeaderSet(headers, &buffer));
67 68
68 string prefix = HpackFuzzUtil::HeaderBlockPrefix(buffer.size()); 69 SpdyString prefix = HpackFuzzUtil::HeaderBlockPrefix(buffer.size());
69 70
70 CHECK_LT(0, file_out.WriteAtCurrentPos(prefix.data(), prefix.size())); 71 CHECK_LT(0, file_out.WriteAtCurrentPos(prefix.data(), prefix.size()));
71 CHECK_LT(0, file_out.WriteAtCurrentPos(buffer.data(), buffer.size())); 72 CHECK_LT(0, file_out.WriteAtCurrentPos(buffer.data(), buffer.size()));
72 } 73 }
73 CHECK(file_out.Flush()); 74 CHECK(file_out.Flush());
74 DVLOG(1) << "Generated " << example_count << " blocks."; 75 DVLOG(1) << "Generated " << example_count << " blocks.";
75 return 0; 76 return 0;
76 } 77 }
OLDNEW
« no previous file with comments | « net/spdy/buffered_spdy_framer_unittest.cc ('k') | net/spdy/fuzzing/hpack_fuzz_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698