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

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

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

Powered by Google App Engine
This is Rietveld 408576698