| OLD | NEW |
| (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 // This tests the performance of the C API. | |
| 6 | |
| 7 #include "mojo/public/system/core.h" | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/bind.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "mojo/public/tests/test_support.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class SystemPerftest : public testing::Test { | |
| 18 public: | |
| 19 SystemPerftest() {} | |
| 20 virtual ~SystemPerftest() {} | |
| 21 | |
| 22 void NoOp() { | |
| 23 } | |
| 24 | |
| 25 void MessagePipe_CreateAndClose() { | |
| 26 MojoResult result; | |
| 27 result = MojoCreateMessagePipe(&h_0_, &h_1_); | |
| 28 DCHECK_EQ(result, MOJO_RESULT_OK); | |
| 29 result = MojoClose(h_0_); | |
| 30 DCHECK_EQ(result, MOJO_RESULT_OK); | |
| 31 result = MojoClose(h_1_); | |
| 32 DCHECK_EQ(result, MOJO_RESULT_OK); | |
| 33 } | |
| 34 | |
| 35 void MessagePipe_WriteAndRead(void* buffer, uint32_t bytes) { | |
| 36 MojoResult result; | |
| 37 result = MojoWriteMessage(h_0_, | |
| 38 buffer, bytes, | |
| 39 NULL, 0, | |
| 40 MOJO_WRITE_MESSAGE_FLAG_NONE); | |
| 41 DCHECK_EQ(result, MOJO_RESULT_OK); | |
| 42 uint32_t read_bytes = bytes; | |
| 43 result = MojoReadMessage(h_1_, | |
| 44 buffer, &read_bytes, | |
| 45 NULL, NULL, | |
| 46 MOJO_READ_MESSAGE_FLAG_NONE); | |
| 47 DCHECK_EQ(result, MOJO_RESULT_OK); | |
| 48 } | |
| 49 | |
| 50 void MessagePipe_EmptyRead() { | |
| 51 MojoResult result; | |
| 52 result = MojoReadMessage(h_0_, | |
| 53 NULL, NULL, | |
| 54 NULL, NULL, | |
| 55 MOJO_READ_MESSAGE_FLAG_MAY_DISCARD); | |
| 56 DCHECK_EQ(result, MOJO_RESULT_SHOULD_WAIT); | |
| 57 } | |
| 58 | |
| 59 protected: | |
| 60 MojoHandle h_0_; | |
| 61 MojoHandle h_1_; | |
| 62 | |
| 63 private: | |
| 64 DISALLOW_COPY_AND_ASSIGN(SystemPerftest); | |
| 65 }; | |
| 66 | |
| 67 // A no-op test so we can compare performance. | |
| 68 TEST_F(SystemPerftest, NoOp) { | |
| 69 mojo::test::IterateAndReportPerf( | |
| 70 "NoOp", | |
| 71 base::Bind(&SystemPerftest::NoOp, | |
| 72 base::Unretained(this))); | |
| 73 } | |
| 74 | |
| 75 TEST_F(SystemPerftest, MessagePipe_CreateAndClose) { | |
| 76 mojo::test::IterateAndReportPerf( | |
| 77 "MessagePipe_CreateAndClose", | |
| 78 base::Bind(&SystemPerftest::MessagePipe_CreateAndClose, | |
| 79 base::Unretained(this))); | |
| 80 } | |
| 81 | |
| 82 TEST_F(SystemPerftest, MessagePipe_WriteAndRead) { | |
| 83 CHECK_EQ(MojoCreateMessagePipe(&h_0_, &h_1_), MOJO_RESULT_OK); | |
| 84 char buffer[10000] = { 0 }; | |
| 85 mojo::test::IterateAndReportPerf( | |
| 86 "MessagePipe_WriteAndRead_10bytes", | |
| 87 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead, | |
| 88 base::Unretained(this), | |
| 89 static_cast<void*>(buffer), static_cast<uint32_t>(10))); | |
| 90 mojo::test::IterateAndReportPerf( | |
| 91 "MessagePipe_WriteAndRead_100bytes", | |
| 92 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead, | |
| 93 base::Unretained(this), | |
| 94 static_cast<void*>(buffer), static_cast<uint32_t>(100))); | |
| 95 mojo::test::IterateAndReportPerf( | |
| 96 "MessagePipe_WriteAndRead_1000bytes", | |
| 97 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead, | |
| 98 base::Unretained(this), | |
| 99 static_cast<void*>(buffer), static_cast<uint32_t>(1000))); | |
| 100 mojo::test::IterateAndReportPerf( | |
| 101 "MessagePipe_WriteAndRead_10000bytes", | |
| 102 base::Bind(&SystemPerftest::MessagePipe_WriteAndRead, | |
| 103 base::Unretained(this), | |
| 104 static_cast<void*>(buffer), static_cast<uint32_t>(10000))); | |
| 105 CHECK_EQ(MojoClose(h_0_), MOJO_RESULT_OK); | |
| 106 CHECK_EQ(MojoClose(h_1_), MOJO_RESULT_OK); | |
| 107 } | |
| 108 | |
| 109 TEST_F(SystemPerftest, MessagePipe_EmptyRead) { | |
| 110 CHECK_EQ(MojoCreateMessagePipe(&h_0_, &h_1_), MOJO_RESULT_OK); | |
| 111 mojo::test::IterateAndReportPerf( | |
| 112 "MessagePipe_EmptyRead", | |
| 113 base::Bind(&SystemPerftest::MessagePipe_EmptyRead, | |
| 114 base::Unretained(this))); | |
| 115 CHECK_EQ(MojoClose(h_0_), MOJO_RESULT_OK); | |
| 116 CHECK_EQ(MojoClose(h_1_), MOJO_RESULT_OK); | |
| 117 } | |
| 118 | |
| 119 } // namespace | |
| OLD | NEW |