| OLD | NEW |
| 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 string file_to_write = command_line.GetSwitchValueASCII(kFileToWrite); | 46 string file_to_write = command_line.GetSwitchValueASCII(kFileToWrite); |
| 47 | 47 |
| 48 int example_count = 0; | 48 int example_count = 0; |
| 49 base::StringToInt(command_line.GetSwitchValueASCII(kExampleCount), | 49 base::StringToInt(command_line.GetSwitchValueASCII(kExampleCount), |
| 50 &example_count); | 50 &example_count); |
| 51 | 51 |
| 52 DVLOG(1) << "Writing output to " << file_to_write; | 52 DVLOG(1) << "Writing output to " << file_to_write; |
| 53 base::File file_out(base::FilePath::FromUTF8Unsafe(file_to_write), | 53 base::File file_out(base::FilePath::FromUTF8Unsafe(file_to_write), |
| 54 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); | 54 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
| 55 CHECK(file_out.IsValid()) << file_out.error_details(); | 55 CHECK(file_out.IsValid()); |
| 56 | 56 |
| 57 HpackFuzzUtil::GeneratorContext context; | 57 HpackFuzzUtil::GeneratorContext context; |
| 58 HpackFuzzUtil::InitializeGeneratorContext(&context); | 58 HpackFuzzUtil::InitializeGeneratorContext(&context); |
| 59 net::HpackEncoder encoder(net::ObtainHpackHuffmanTable()); | 59 net::HpackEncoder encoder(net::ObtainHpackHuffmanTable()); |
| 60 | 60 |
| 61 for (int i = 0; i != example_count; ++i) { | 61 for (int i = 0; i != example_count; ++i) { |
| 62 net::SpdyHeaderBlock headers = | 62 net::SpdyHeaderBlock headers = |
| 63 HpackFuzzUtil::NextGeneratedHeaderSet(&context); | 63 HpackFuzzUtil::NextGeneratedHeaderSet(&context); |
| 64 | 64 |
| 65 string buffer; | 65 string buffer; |
| 66 CHECK(encoder.EncodeHeaderSet(headers, &buffer)); | 66 CHECK(encoder.EncodeHeaderSet(headers, &buffer)); |
| 67 | 67 |
| 68 string prefix = HpackFuzzUtil::HeaderBlockPrefix(buffer.size()); | 68 string prefix = HpackFuzzUtil::HeaderBlockPrefix(buffer.size()); |
| 69 | 69 |
| 70 CHECK_LT(0, file_out.WriteAtCurrentPos(prefix.data(), prefix.size())); | 70 CHECK_LT(0, file_out.WriteAtCurrentPos(prefix.data(), prefix.size())); |
| 71 CHECK_LT(0, file_out.WriteAtCurrentPos(buffer.data(), buffer.size())); | 71 CHECK_LT(0, file_out.WriteAtCurrentPos(buffer.data(), buffer.size())); |
| 72 } | 72 } |
| 73 CHECK(file_out.Flush()); | 73 CHECK(file_out.Flush()); |
| 74 DVLOG(1) << "Generated " << example_count << " blocks."; | 74 DVLOG(1) << "Generated " << example_count << " blocks."; |
| 75 return 0; | 75 return 0; |
| 76 } | 76 } |
| OLD | NEW |