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

Side by Side Diff: sandbox/linux/bpf_dsl/codegen_unittest.cc

Issue 1124763003: Update from https://crrev.com/327068 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: update nacl, buildtools, fix display_change_notifier_unittest Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "sandbox/linux/bpf_dsl/codegen.h" 5 #include "sandbox/linux/bpf_dsl/codegen.h"
6 6
7 #include <linux/filter.h>
8
9 #include <map> 7 #include <map>
10 #include <utility> 8 #include <utility>
11 #include <vector> 9 #include <vector>
12 10
13 #include "base/macros.h" 11 #include "base/macros.h"
14 #include "base/md5.h" 12 #include "base/md5.h"
15 #include "base/strings/string_piece.h" 13 #include "base/strings/string_piece.h"
14 #include "sandbox/linux/system_headers/linux_filter.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 16
18 namespace sandbox { 17 namespace sandbox {
19 namespace { 18 namespace {
20 19
21 // Hash provides an abstraction for building "hash trees" from BPF 20 // Hash provides an abstraction for building "hash trees" from BPF
22 // control flow graphs, and efficiently identifying equivalent graphs. 21 // control flow graphs, and efficiently identifying equivalent graphs.
23 // 22 //
24 // For simplicity, we use MD5, because base happens to provide a 23 // For simplicity, we use MD5, because base happens to provide a
25 // convenient API for its use. However, any collision-resistant hash 24 // convenient API for its use. However, any collision-resistant hash
(...skipping 30 matching lines...) Expand all
56 55
57 private: 56 private:
58 template <typename T> 57 template <typename T>
59 void HashValue(base::MD5Context* ctx, const T& value) { 58 void HashValue(base::MD5Context* ctx, const T& value) {
60 base::MD5Update(ctx, 59 base::MD5Update(ctx,
61 base::StringPiece(reinterpret_cast<const char*>(&value), 60 base::StringPiece(reinterpret_cast<const char*>(&value),
62 sizeof(value))); 61 sizeof(value)));
63 } 62 }
64 63
65 std::string Base16() const { 64 std::string Base16() const {
66 return MD5DigestToBase16(digest_); 65 return base::MD5DigestToBase16(digest_);
67 } 66 }
68 67
69 base::MD5Digest digest_; 68 base::MD5Digest digest_;
70 }; 69 };
71 70
72 const Hash Hash::kZero; 71 const Hash Hash::kZero;
73 72
74 // Sanity check that equality and inequality work on Hash as required. 73 // Sanity check that equality and inequality work on Hash as required.
75 TEST(CodeGen, HashSanity) { 74 TEST(CodeGen, HashSanity) {
76 std::vector<Hash> hashes; 75 std::vector<Hash> hashes;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // Branching again to the same target nodes should require only one 393 // Branching again to the same target nodes should require only one
395 // new instruction, as we can reuse the previous branch's jumps. 394 // new instruction, as we can reuse the previous branch's jumps.
396 CodeGen::Node two = 395 CodeGen::Node two =
397 MakeInstruction(BPF_JMP + BPF_JEQ + BPF_K, 1, nodes[0], nodes[1]); 396 MakeInstruction(BPF_JMP + BPF_JEQ + BPF_K, 1, nodes[0], nodes[1]);
398 EXPECT_EQ(one + 1, two); // XXX: Implementation detail! 397 EXPECT_EQ(one + 1, two); // XXX: Implementation detail!
399 RunTest(two); 398 RunTest(two);
400 } 399 }
401 400
402 } // namespace 401 } // namespace
403 } // namespace sandbox 402 } // namespace sandbox
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698