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

Side by Side Diff: mojo/public/tests/buffer_unittest.cc

Issue 76943002: Have ScratchBuffer::Allocate prefer allocating on the stack even if a previous (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to other CL Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « mojo/public/bindings/lib/buffer.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/public/bindings/lib/bindings_serialization.h" 5 #include "mojo/public/bindings/lib/bindings_serialization.h"
6 #include "mojo/public/bindings/lib/buffer.h" 6 #include "mojo/public/bindings/lib/buffer.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace mojo { 9 namespace mojo {
10 namespace test { 10 namespace test {
(...skipping 14 matching lines...) Expand all
25 void* small = buf.Allocate(10); 25 void* small = buf.Allocate(10);
26 EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf))); 26 EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf)));
27 EXPECT_TRUE(IsZero(small, 10)); 27 EXPECT_TRUE(IsZero(small, 10));
28 28
29 // Large allocations won't be on the stack. 29 // Large allocations won't be on the stack.
30 void* large = buf.Allocate(100*1024); 30 void* large = buf.Allocate(100*1024);
31 EXPECT_TRUE(IsZero(large, 100*1024)); 31 EXPECT_TRUE(IsZero(large, 100*1024));
32 EXPECT_FALSE(large >= &buf && large < (&buf + sizeof(buf))); 32 EXPECT_FALSE(large >= &buf && large < (&buf + sizeof(buf)));
33 33
34 // But another small allocation should be back on the stack. 34 // But another small allocation should be back on the stack.
35 // TODO(mpcomplete): but it isn't. We can fix that easily enough.
36 small = buf.Allocate(10); 35 small = buf.Allocate(10);
37 EXPECT_TRUE(IsZero(small, 10)); 36 EXPECT_TRUE(IsZero(small, 10));
38 //EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf))); 37 EXPECT_TRUE(small >= &buf && small < (&buf + sizeof(buf)));
39 } 38 }
40 39
41 // Tests that FixedBuffer allocates memory aligned to 8 byte boundaries. 40 // Tests that FixedBuffer allocates memory aligned to 8 byte boundaries.
42 TEST(FixedBufferTest, Alignment) { 41 TEST(FixedBufferTest, Alignment) {
43 FixedBuffer buf(internal::Align(10) * 2); 42 FixedBuffer buf(internal::Align(10) * 2);
44 ASSERT_EQ(buf.size(), 16u * 2); 43 ASSERT_EQ(buf.size(), 16u * 2);
45 44
46 void* a = buf.Allocate(10); 45 void* a = buf.Allocate(10);
47 ASSERT_TRUE(a); 46 ASSERT_TRUE(a);
48 EXPECT_TRUE(IsZero(a, 10)); 47 EXPECT_TRUE(IsZero(a, 10));
(...skipping 29 matching lines...) Expand all
78 } 77 }
79 78
80 // Since we called Leak, ptr is still writable after FixedBuffer went out of 79 // Since we called Leak, ptr is still writable after FixedBuffer went out of
81 // scope. 80 // scope.
82 memset(ptr, 1, 8); 81 memset(ptr, 1, 8);
83 free(buf_ptr); 82 free(buf_ptr);
84 } 83 }
85 84
86 } // namespace test 85 } // namespace test
87 } // namespace mojo 86 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/bindings/lib/buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698