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

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

Issue 23621056: Initial in-process implementation of some Mojo primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: build fix Created 7 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/public/system/core.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/logging.h"
10 #include "mojo/public/tests/test_support.h"
11
12 namespace mojo {
13 namespace {
14
15 class SystemPerftest : public test::TestBase {
16 public:
17 SystemPerftest() {}
18 virtual ~SystemPerftest() {}
19
20 void NoOp() {
21 }
22
23 void MessagePipe_CreateAndClose() {
24 MojoResult result;
25 result = CreateMessagePipe(&h_0_, &h_1_);
26 DCHECK_EQ(result, MOJO_RESULT_OK);
27 result = Close(h_0_);
28 DCHECK_EQ(result, MOJO_RESULT_OK);
29 result = Close(h_1_);
30 DCHECK_EQ(result, MOJO_RESULT_OK);
31 }
32
33 void MessagePipe_WriteAndRead(void* buffer, uint32_t bytes) {
34 MojoResult result;
35 result = WriteMessage(h_0_,
36 buffer, bytes,
37 NULL, 0,
38 MOJO_WRITE_MESSAGE_FLAG_NONE);
39 DCHECK_EQ(result, MOJO_RESULT_OK);
40 uint32_t read_bytes = bytes;
41 result = ReadMessage(h_1_,
42 buffer, &read_bytes,
43 NULL, NULL,
44 MOJO_READ_MESSAGE_FLAG_NONE);
45 DCHECK_EQ(result, MOJO_RESULT_OK);
46 }
47
48 protected:
49 Handle h_0_;
50 Handle h_1_;
51
52 private:
53 DISALLOW_COPY_AND_ASSIGN(SystemPerftest);
54 };
55
56 // A no-op test so we can compare performance.
57 TEST_F(SystemPerftest, NoOp) {
58 test::IterateAndReportPerf(
59 "NoOp",
60 base::Bind(&SystemPerftest::NoOp,
61 base::Unretained(this)));
62 }
63
64 TEST_F(SystemPerftest, MessagePipe_CreateAndClose) {
65 test::IterateAndReportPerf(
66 "MessagePipe_CreateAndClose",
67 base::Bind(&SystemPerftest::MessagePipe_CreateAndClose,
68 base::Unretained(this)));
69 }
70
71 TEST_F(SystemPerftest, MessagePipe_WriteAndRead) {
72 CHECK_EQ(CreateMessagePipe(&h_0_, &h_1_), MOJO_RESULT_OK);
73 char buffer[10000] = { 0 };
74 test::IterateAndReportPerf(
75 "MessagePipe_WriteAndRead_10bytes",
76 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead,
77 base::Unretained(this),
78 static_cast<void*>(buffer), static_cast<uint32_t>(10)));
79 test::IterateAndReportPerf(
80 "MessagePipe_WriteAndRead_100bytes",
81 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead,
82 base::Unretained(this),
83 static_cast<void*>(buffer), static_cast<uint32_t>(100)));
84 test::IterateAndReportPerf(
85 "MessagePipe_WriteAndRead_1000bytes",
86 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead,
87 base::Unretained(this),
88 static_cast<void*>(buffer), static_cast<uint32_t>(1000)));
89 test::IterateAndReportPerf(
90 "MessagePipe_WriteAndRead_10000bytes",
91 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead,
92 base::Unretained(this),
93 static_cast<void*>(buffer), static_cast<uint32_t>(10000)));
94 CHECK_EQ(Close(h_0_), MOJO_RESULT_OK);
95 CHECK_EQ(Close(h_1_), MOJO_RESULT_OK);
96 }
97
98 } // namespace
99 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698