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

Side by Side Diff: mojo/public/tests/system/core_perftest.cc

Issue 140503005: Mojo: foo_[0-9] -> foo[0-9]. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
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 // This tests the performance of the C API. 5 // This tests the performance of the C API.
6 6
7 #include "mojo/public/system/core.h" 7 #include "mojo/public/system/core.h"
8 8
9 #include <assert.h> 9 #include <assert.h>
10 10
11 #include "mojo/public/system/macros.h" 11 #include "mojo/public/system/macros.h"
12 #include "mojo/public/tests/test_support.h" 12 #include "mojo/public/tests/test_support.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace { 15 namespace {
16 16
17 class CorePerftest : public testing::Test { 17 class CorePerftest : public testing::Test {
18 public: 18 public:
19 CorePerftest() : buffer_(NULL), num_bytes_(0) {} 19 CorePerftest() : buffer_(NULL), num_bytes_(0) {}
20 virtual ~CorePerftest() {} 20 virtual ~CorePerftest() {}
21 21
22 static void NoOp(void* /*closure*/) { 22 static void NoOp(void* /*closure*/) {
23 } 23 }
24 24
25 static void MessagePipe_CreateAndClose(void* closure) { 25 static void MessagePipe_CreateAndClose(void* closure) {
26 CorePerftest* self = static_cast<CorePerftest*>(closure); 26 CorePerftest* self = static_cast<CorePerftest*>(closure);
27 MojoResult result MOJO_ALLOW_UNUSED; 27 MojoResult result MOJO_ALLOW_UNUSED;
28 result = MojoCreateMessagePipe(&self->h_0_, &self->h_1_); 28 result = MojoCreateMessagePipe(&self->h0_, &self->h1_);
29 assert(result == MOJO_RESULT_OK); 29 assert(result == MOJO_RESULT_OK);
30 result = MojoClose(self->h_0_); 30 result = MojoClose(self->h0_);
31 assert(result == MOJO_RESULT_OK); 31 assert(result == MOJO_RESULT_OK);
32 result = MojoClose(self->h_1_); 32 result = MojoClose(self->h1_);
33 assert(result == MOJO_RESULT_OK); 33 assert(result == MOJO_RESULT_OK);
34 } 34 }
35 35
36 static void MessagePipe_WriteAndRead(void* closure) { 36 static void MessagePipe_WriteAndRead(void* closure) {
37 CorePerftest* self = static_cast<CorePerftest*>(closure); 37 CorePerftest* self = static_cast<CorePerftest*>(closure);
38 MojoResult result MOJO_ALLOW_UNUSED; 38 MojoResult result MOJO_ALLOW_UNUSED;
39 result = MojoWriteMessage(self->h_0_, 39 result = MojoWriteMessage(self->h0_,
40 self->buffer_, self->num_bytes_, 40 self->buffer_, self->num_bytes_,
41 NULL, 0, 41 NULL, 0,
42 MOJO_WRITE_MESSAGE_FLAG_NONE); 42 MOJO_WRITE_MESSAGE_FLAG_NONE);
43 assert(result == MOJO_RESULT_OK); 43 assert(result == MOJO_RESULT_OK);
44 uint32_t read_bytes = self->num_bytes_; 44 uint32_t read_bytes = self->num_bytes_;
45 result = MojoReadMessage(self->h_1_, 45 result = MojoReadMessage(self->h1_,
46 self->buffer_, &read_bytes, 46 self->buffer_, &read_bytes,
47 NULL, NULL, 47 NULL, NULL,
48 MOJO_READ_MESSAGE_FLAG_NONE); 48 MOJO_READ_MESSAGE_FLAG_NONE);
49 assert(result == MOJO_RESULT_OK); 49 assert(result == MOJO_RESULT_OK);
50 } 50 }
51 51
52 static void MessagePipe_EmptyRead(void* closure) { 52 static void MessagePipe_EmptyRead(void* closure) {
53 CorePerftest* self = static_cast<CorePerftest*>(closure); 53 CorePerftest* self = static_cast<CorePerftest*>(closure);
54 MojoResult result MOJO_ALLOW_UNUSED; 54 MojoResult result MOJO_ALLOW_UNUSED;
55 result = MojoReadMessage(self->h_0_, 55 result = MojoReadMessage(self->h0_,
56 NULL, NULL, 56 NULL, NULL,
57 NULL, NULL, 57 NULL, NULL,
58 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); 58 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD);
59 assert(result == MOJO_RESULT_SHOULD_WAIT); 59 assert(result == MOJO_RESULT_SHOULD_WAIT);
60 } 60 }
61 61
62 protected: 62 protected:
63 MojoHandle h_0_; 63 MojoHandle h0_;
64 MojoHandle h_1_; 64 MojoHandle h1_;
65 65
66 void* buffer_; 66 void* buffer_;
67 uint32_t num_bytes_; 67 uint32_t num_bytes_;
68 68
69 private: 69 private:
70 MOJO_DISALLOW_COPY_AND_ASSIGN(CorePerftest); 70 MOJO_DISALLOW_COPY_AND_ASSIGN(CorePerftest);
71 }; 71 };
72 72
73 // A no-op test so we can compare performance. 73 // A no-op test so we can compare performance.
74 TEST_F(CorePerftest, NoOp) { 74 TEST_F(CorePerftest, NoOp) {
75 mojo::test::IterateAndReportPerf("NoOp", &CorePerftest::NoOp, this); 75 mojo::test::IterateAndReportPerf("NoOp", &CorePerftest::NoOp, this);
76 } 76 }
77 77
78 TEST_F(CorePerftest, MessagePipe_CreateAndClose) { 78 TEST_F(CorePerftest, MessagePipe_CreateAndClose) {
79 mojo::test::IterateAndReportPerf("MessagePipe_CreateAndClose", 79 mojo::test::IterateAndReportPerf("MessagePipe_CreateAndClose",
80 &CorePerftest::MessagePipe_CreateAndClose, 80 &CorePerftest::MessagePipe_CreateAndClose,
81 this); 81 this);
82 } 82 }
83 83
84 TEST_F(CorePerftest, MessagePipe_WriteAndRead) { 84 TEST_F(CorePerftest, MessagePipe_WriteAndRead) {
85 MojoResult result MOJO_ALLOW_UNUSED; 85 MojoResult result MOJO_ALLOW_UNUSED;
86 result = MojoCreateMessagePipe(&h_0_, &h_1_); 86 result = MojoCreateMessagePipe(&h0_, &h1_);
87 assert(result == MOJO_RESULT_OK); 87 assert(result == MOJO_RESULT_OK);
88 char buffer[10000] = { 0 }; 88 char buffer[10000] = { 0 };
89 buffer_ = buffer; 89 buffer_ = buffer;
90 num_bytes_ = 10u; 90 num_bytes_ = 10u;
91 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10bytes", 91 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10bytes",
92 &CorePerftest::MessagePipe_WriteAndRead, 92 &CorePerftest::MessagePipe_WriteAndRead,
93 this); 93 this);
94 num_bytes_ = 100u; 94 num_bytes_ = 100u;
95 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_100bytes", 95 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_100bytes",
96 &CorePerftest::MessagePipe_WriteAndRead, 96 &CorePerftest::MessagePipe_WriteAndRead,
97 this); 97 this);
98 num_bytes_ = 1000u; 98 num_bytes_ = 1000u;
99 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_1000bytes", 99 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_1000bytes",
100 &CorePerftest::MessagePipe_WriteAndRead, 100 &CorePerftest::MessagePipe_WriteAndRead,
101 this); 101 this);
102 num_bytes_ = 10000u; 102 num_bytes_ = 10000u;
103 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10000bytes", 103 mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10000bytes",
104 &CorePerftest::MessagePipe_WriteAndRead, 104 &CorePerftest::MessagePipe_WriteAndRead,
105 this); 105 this);
106 result = MojoClose(h_0_); 106 result = MojoClose(h0_);
107 assert(result == MOJO_RESULT_OK); 107 assert(result == MOJO_RESULT_OK);
108 result = MojoClose(h_1_); 108 result = MojoClose(h1_);
109 assert(result == MOJO_RESULT_OK); 109 assert(result == MOJO_RESULT_OK);
110 } 110 }
111 111
112 TEST_F(CorePerftest, MessagePipe_EmptyRead) { 112 TEST_F(CorePerftest, MessagePipe_EmptyRead) {
113 MojoResult result MOJO_ALLOW_UNUSED; 113 MojoResult result MOJO_ALLOW_UNUSED;
114 result = MojoCreateMessagePipe(&h_0_, &h_1_); 114 result = MojoCreateMessagePipe(&h0_, &h1_);
115 assert(result == MOJO_RESULT_OK); 115 assert(result == MOJO_RESULT_OK);
116 mojo::test::IterateAndReportPerf("MessagePipe_EmptyRead", 116 mojo::test::IterateAndReportPerf("MessagePipe_EmptyRead",
117 &CorePerftest::MessagePipe_EmptyRead, 117 &CorePerftest::MessagePipe_EmptyRead,
118 this); 118 this);
119 result = MojoClose(h_0_); 119 result = MojoClose(h0_);
120 assert(result == MOJO_RESULT_OK); 120 assert(result == MOJO_RESULT_OK);
121 result = MojoClose(h_1_); 121 result = MojoClose(h1_);
122 assert(result == MOJO_RESULT_OK); 122 assert(result == MOJO_RESULT_OK);
123 } 123 }
124 124
125 } // namespace 125 } // namespace
OLDNEW
« no previous file with comments | « mojo/public/tests/system/core_cpp_unittest.cc ('k') | mojo/public/tests/system/core_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698