Mojo: clang-format mojo/public/c/... and add a presubmit check.

Note: clang-format misformats some C-style casts (in the C-compilable
parts of header files; e.g., it formats |(Foo)-5| as |(Foo) - 5|), but I
can live with that.

R=jamesr@chromium.org

Review URL: https://codereview.chromium.org/469393002

Cr-Commit-Position: refs/heads/master@{#289669}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289669 0039d316-1c4b-4281-b951-d872f2087c98
parent a124f7f2
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Presubmit script for mojo/public/c.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools.
"""
def CheckChangeOnUpload(input_api, output_api):
results = []
results += input_api.canned_checks.CheckChangeHasOnlyOneEol(input_api,
output_api)
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api)
return results
...@@ -19,11 +19,11 @@ const MojoLogLevel MOJO_LOG_LEVEL_WARNING = 1; ...@@ -19,11 +19,11 @@ const MojoLogLevel MOJO_LOG_LEVEL_WARNING = 1;
const MojoLogLevel MOJO_LOG_LEVEL_ERROR = 2; const MojoLogLevel MOJO_LOG_LEVEL_ERROR = 2;
const MojoLogLevel MOJO_LOG_LEVEL_FATAL = 3; const MojoLogLevel MOJO_LOG_LEVEL_FATAL = 3;
#else #else
#define MOJO_LOG_LEVEL_VERBOSE ((MojoLogLevel) -1) #define MOJO_LOG_LEVEL_VERBOSE ((MojoLogLevel) - 1)
#define MOJO_LOG_LEVEL_INFO ((MojoLogLevel) 0) #define MOJO_LOG_LEVEL_INFO ((MojoLogLevel)0)
#define MOJO_LOG_LEVEL_WARNING ((MojoLogLevel) 1) #define MOJO_LOG_LEVEL_WARNING ((MojoLogLevel)1)
#define MOJO_LOG_LEVEL_ERROR ((MojoLogLevel) 2) #define MOJO_LOG_LEVEL_ERROR ((MojoLogLevel)2)
#define MOJO_LOG_LEVEL_FATAL ((MojoLogLevel) 3) #define MOJO_LOG_LEVEL_FATAL ((MojoLogLevel)3)
#endif #endif
// Structure with basic logging functions (on top of which more friendly logging // Structure with basic logging functions (on top of which more friendly logging
......
...@@ -35,7 +35,7 @@ const MojoCreateSharedBufferOptionsFlags ...@@ -35,7 +35,7 @@ const MojoCreateSharedBufferOptionsFlags
MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE = 0; MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE = 0;
#else #else
#define MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE \ #define MOJO_CREATE_SHARED_BUFFER_OPTIONS_FLAG_NONE \
((MojoCreateSharedBufferOptionsFlags) 0) ((MojoCreateSharedBufferOptionsFlags)0)
#endif #endif
MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment);
...@@ -64,7 +64,7 @@ const MojoDuplicateBufferHandleOptionsFlags ...@@ -64,7 +64,7 @@ const MojoDuplicateBufferHandleOptionsFlags
MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE = 0; MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE = 0;
#else #else
#define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \ #define MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE \
((MojoDuplicateBufferHandleOptionsFlags) 0) ((MojoDuplicateBufferHandleOptionsFlags)0)
#endif #endif
struct MojoDuplicateBufferHandleOptions { struct MojoDuplicateBufferHandleOptions {
...@@ -82,7 +82,7 @@ typedef uint32_t MojoMapBufferFlags; ...@@ -82,7 +82,7 @@ typedef uint32_t MojoMapBufferFlags;
#ifdef __cplusplus #ifdef __cplusplus
const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0; const MojoMapBufferFlags MOJO_MAP_BUFFER_FLAG_NONE = 0;
#else #else
#define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags) 0) #define MOJO_MAP_BUFFER_FLAG_NONE ((MojoMapBufferFlags)0)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
...@@ -116,8 +116,8 @@ extern "C" { ...@@ -116,8 +116,8 @@ extern "C" {
// |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|.
MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer( MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer(
const struct MojoCreateSharedBufferOptions* options, // Optional. const struct MojoCreateSharedBufferOptions* options, // Optional.
uint64_t num_bytes, // In. uint64_t num_bytes, // In.
MojoHandle* shared_buffer_handle); // Out. MojoHandle* shared_buffer_handle); // Out.
// Duplicates the handle |buffer_handle| to a buffer. This creates another // Duplicates the handle |buffer_handle| to a buffer. This creates another
// handle (returned in |*new_buffer_handle| on success), which can then be sent // handle (returned in |*new_buffer_handle| on success), which can then be sent
...@@ -138,7 +138,7 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer( ...@@ -138,7 +138,7 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateSharedBuffer(
MOJO_SYSTEM_EXPORT MojoResult MojoDuplicateBufferHandle( MOJO_SYSTEM_EXPORT MojoResult MojoDuplicateBufferHandle(
MojoHandle buffer_handle, MojoHandle buffer_handle,
const struct MojoDuplicateBufferHandleOptions* options, // Optional. const struct MojoDuplicateBufferHandleOptions* options, // Optional.
MojoHandle* new_buffer_handle); // Out. MojoHandle* new_buffer_handle); // Out.
// Maps the part (at offset |offset| of length |num_bytes|) of the buffer given // Maps the part (at offset |offset| of length |num_bytes|) of the buffer given
// by |buffer_handle| into memory, with options specified by |flags|. |offset + // by |buffer_handle| into memory, with options specified by |flags|. |offset +
......
...@@ -35,15 +35,15 @@ ...@@ -35,15 +35,15 @@
typedef uint32_t MojoCreateDataPipeOptionsFlags; typedef uint32_t MojoCreateDataPipeOptionsFlags;
#ifdef __cplusplus #ifdef __cplusplus
const MojoCreateDataPipeOptionsFlags const MojoCreateDataPipeOptionsFlags MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE =
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE = 0; 0;
const MojoCreateDataPipeOptionsFlags const MojoCreateDataPipeOptionsFlags
MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD = 1 << 0; MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD = 1 << 0;
#else #else
#define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \ #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE \
((MojoCreateDataPipeOptionsFlags) 0) ((MojoCreateDataPipeOptionsFlags)0)
#define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD \ #define MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_MAY_DISCARD \
((MojoCreateDataPipeOptionsFlags) 1 << 0) ((MojoCreateDataPipeOptionsFlags)1 << 0)
#endif #endif
MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment);
...@@ -68,8 +68,8 @@ typedef uint32_t MojoWriteDataFlags; ...@@ -68,8 +68,8 @@ typedef uint32_t MojoWriteDataFlags;
const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0; const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_NONE = 0;
const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0; const MojoWriteDataFlags MOJO_WRITE_DATA_FLAG_ALL_OR_NONE = 1 << 0;
#else #else
#define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags) 0) #define MOJO_WRITE_DATA_FLAG_NONE ((MojoWriteDataFlags)0)
#define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags) 1 << 0) #define MOJO_WRITE_DATA_FLAG_ALL_OR_NONE ((MojoWriteDataFlags)1 << 0)
#endif #endif
// |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and // |MojoReadDataFlags|: Used to specify different modes to |MojoReadData()| and
...@@ -92,10 +92,10 @@ const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0; ...@@ -92,10 +92,10 @@ const MojoReadDataFlags MOJO_READ_DATA_FLAG_ALL_OR_NONE = 1 << 0;
const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1; const MojoReadDataFlags MOJO_READ_DATA_FLAG_DISCARD = 1 << 1;
const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2; const MojoReadDataFlags MOJO_READ_DATA_FLAG_QUERY = 1 << 2;
#else #else
#define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags) 0) #define MOJO_READ_DATA_FLAG_NONE ((MojoReadDataFlags)0)
#define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags) 1 << 0) #define MOJO_READ_DATA_FLAG_ALL_OR_NONE ((MojoReadDataFlags)1 << 0)
#define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags) 1 << 1) #define MOJO_READ_DATA_FLAG_DISCARD ((MojoReadDataFlags)1 << 1)
#define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags) 1 << 2) #define MOJO_READ_DATA_FLAG_QUERY ((MojoReadDataFlags)1 << 2)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
...@@ -129,8 +129,8 @@ extern "C" { ...@@ -129,8 +129,8 @@ extern "C" {
// |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|. // |MOJO_RESULT_UNIMPLEMENTED| if an unsupported flag was set in |*options|.
MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe(
const struct MojoCreateDataPipeOptions* options, // Optional. const struct MojoCreateDataPipeOptions* options, // Optional.
MojoHandle* data_pipe_producer_handle, // Out. MojoHandle* data_pipe_producer_handle, // Out.
MojoHandle* data_pipe_consumer_handle); // Out. MojoHandle* data_pipe_consumer_handle); // Out.
// Writes the given data to the data pipe producer given by // Writes the given data to the data pipe producer given by
// |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|; // |data_pipe_producer_handle|. |elements| points to data of size |*num_bytes|;
...@@ -168,11 +168,11 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe( ...@@ -168,11 +168,11 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateDataPipe(
// |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set. // |MOJO_WRITE_DATA_FLAG_ALL_OR_NONE| set.
// //
// TODO(vtl): Should there be a way of querying how much data can be written? // TODO(vtl): Should there be a way of querying how much data can be written?
MOJO_SYSTEM_EXPORT MojoResult MojoWriteData( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle data_pipe_producer_handle, MojoWriteData(MojoHandle data_pipe_producer_handle,
const void* elements, const void* elements,
uint32_t* num_bytes, // In/out. uint32_t* num_bytes, // In/out.
MojoWriteDataFlags flags); MojoWriteDataFlags flags);
// Begins a two-phase write to the data pipe producer given by // Begins a two-phase write to the data pipe producer given by
// |data_pipe_producer_handle|. On success, |*buffer| will be a pointer to which // |data_pipe_producer_handle|. On success, |*buffer| will be a pointer to which
...@@ -213,11 +213,11 @@ MOJO_SYSTEM_EXPORT MojoResult MojoWriteData( ...@@ -213,11 +213,11 @@ MOJO_SYSTEM_EXPORT MojoResult MojoWriteData(
// called, but not yet the matching |MojoEndWriteData()|). // called, but not yet the matching |MojoEndWriteData()|).
// |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be written (and the
// consumer is still open). // consumer is still open).
MOJO_SYSTEM_EXPORT MojoResult MojoBeginWriteData( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle data_pipe_producer_handle, MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
void** buffer, // Out. void** buffer, // Out.
uint32_t* buffer_num_bytes, // In/out. uint32_t* buffer_num_bytes, // In/out.
MojoWriteDataFlags flags); MojoWriteDataFlags flags);
// Ends a two-phase write to the data pipe producer given by // Ends a two-phase write to the data pipe producer given by
// |data_pipe_producer_handle| that was begun by a call to // |data_pipe_producer_handle| that was begun by a call to
...@@ -241,9 +241,9 @@ MOJO_SYSTEM_EXPORT MojoResult MojoBeginWriteData( ...@@ -241,9 +241,9 @@ MOJO_SYSTEM_EXPORT MojoResult MojoBeginWriteData(
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe producer is not in a
// two-phase write (e.g., |MojoBeginWriteData()| was not called or // two-phase write (e.g., |MojoBeginWriteData()| was not called or
// |MojoEndWriteData()| has already been called). // |MojoEndWriteData()| has already been called).
MOJO_SYSTEM_EXPORT MojoResult MojoEndWriteData( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle data_pipe_producer_handle, MojoEndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_written); uint32_t num_bytes_written);
// Reads data from the data pipe consumer given by |data_pipe_consumer_handle|. // Reads data from the data pipe consumer given by |data_pipe_consumer_handle|.
// May also be used to discard data or query the amount of data available. // May also be used to discard data or query the amount of data available.
...@@ -287,11 +287,10 @@ MOJO_SYSTEM_EXPORT MojoResult MojoEndWriteData( ...@@ -287,11 +287,10 @@ MOJO_SYSTEM_EXPORT MojoResult MojoEndWriteData(
// |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and // |MOJO_RESULT_SHOULD_WAIT| if there is no data to be read or discarded (and
// the producer is still open) and |flags| does *not* have // the producer is still open) and |flags| does *not* have
// |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set. // |MOJO_READ_DATA_FLAG_ALL_OR_NONE| set.
MOJO_SYSTEM_EXPORT MojoResult MojoReadData( MOJO_SYSTEM_EXPORT MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
MojoHandle data_pipe_consumer_handle, void* elements, // Out.
void* elements, // Out. uint32_t* num_bytes, // In/out.
uint32_t* num_bytes, // In/out. MojoReadDataFlags flags);
MojoReadDataFlags flags);
// Begins a two-phase read from the data pipe consumer given by // Begins a two-phase read from the data pipe consumer given by
// |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from // |data_pipe_consumer_handle|. On success, |*buffer| will be a pointer from
...@@ -329,11 +328,11 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadData( ...@@ -329,11 +328,11 @@ MOJO_SYSTEM_EXPORT MojoResult MojoReadData(
// called, but not yet the matching |MojoEndReadData()|). // called, but not yet the matching |MojoEndReadData()|).
// |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the // |MOJO_RESULT_SHOULD_WAIT| if no data can currently be read (and the
// producer is still open). // producer is still open).
MOJO_SYSTEM_EXPORT MojoResult MojoBeginReadData( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle data_pipe_consumer_handle, MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
const void** buffer, // Out. const void** buffer, // Out.
uint32_t* buffer_num_bytes, // In/out. uint32_t* buffer_num_bytes, // In/out.
MojoReadDataFlags flags); MojoReadDataFlags flags);
// Ends a two-phase read from the data pipe consumer given by // Ends a two-phase read from the data pipe consumer given by
// |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()| // |data_pipe_consumer_handle| that was begun by a call to |MojoBeginReadData()|
...@@ -354,9 +353,9 @@ MOJO_SYSTEM_EXPORT MojoResult MojoBeginReadData( ...@@ -354,9 +353,9 @@ MOJO_SYSTEM_EXPORT MojoResult MojoBeginReadData(
// |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a // |MOJO_RESULT_FAILED_PRECONDITION| if the data pipe consumer is not in a
// two-phase read (e.g., |MojoBeginReadData()| was not called or // two-phase read (e.g., |MojoBeginReadData()| was not called or
// |MojoEndReadData()| has already been called). // |MojoEndReadData()| has already been called).
MOJO_SYSTEM_EXPORT MojoResult MojoEndReadData( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle data_pipe_consumer_handle, MojoEndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_read); uint32_t num_bytes_read);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
// if (TakeOwnership(my_var.get()) == SUCCESS) // if (TakeOwnership(my_var.get()) == SUCCESS)
// mojo_ignore_result(my_var.release()); // mojo_ignore_result(my_var.release());
// //
template<typename T> template <typename T>
inline void mojo_ignore_result(const T&) { inline void mojo_ignore_result(const T&) {
} }
#endif #endif
...@@ -47,9 +47,12 @@ inline void mojo_ignore_result(const T&) { ...@@ -47,9 +47,12 @@ inline void mojo_ignore_result(const T&) {
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
#define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg) #define MOJO_COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
#elif defined(__cplusplus) #elif defined(__cplusplus)
namespace mojo { template <bool> struct CompileAssert {}; } namespace mojo {
template <bool>
struct CompileAssert {};
}
#define MOJO_COMPILE_ASSERT(expr, msg) \ #define MOJO_COMPILE_ASSERT(expr, msg) \
typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] typedef ::mojo::CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
#else #else
#define MOJO_COMPILE_ASSERT(expr, msg) #define MOJO_COMPILE_ASSERT(expr, msg)
#endif #endif
......
...@@ -28,7 +28,7 @@ const MojoCreateMessagePipeOptionsFlags ...@@ -28,7 +28,7 @@ const MojoCreateMessagePipeOptionsFlags
MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE = 0; MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE = 0;
#else #else
#define MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE \ #define MOJO_CREATE_MESSAGE_PIPE_OPTIONS_FLAG_NONE \
((MojoCreateMessagePipeOptionsFlags) 0) ((MojoCreateMessagePipeOptionsFlags)0)
#endif #endif
MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment); MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) == 8, int64_t_has_weird_alignment);
...@@ -48,7 +48,7 @@ typedef uint32_t MojoWriteMessageFlags; ...@@ -48,7 +48,7 @@ typedef uint32_t MojoWriteMessageFlags;
#ifdef __cplusplus #ifdef __cplusplus
const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE = 0; const MojoWriteMessageFlags MOJO_WRITE_MESSAGE_FLAG_NONE = 0;
#else #else
#define MOJO_WRITE_MESSAGE_FLAG_NONE ((MojoWriteMessageFlags) 0) #define MOJO_WRITE_MESSAGE_FLAG_NONE ((MojoWriteMessageFlags)0)
#endif #endif
// |MojoReadMessageFlags|: Used to specify different modes to // |MojoReadMessageFlags|: Used to specify different modes to
...@@ -64,8 +64,8 @@ typedef uint32_t MojoReadMessageFlags; ...@@ -64,8 +64,8 @@ typedef uint32_t MojoReadMessageFlags;
const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0; const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_NONE = 0;
const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0; const MojoReadMessageFlags MOJO_READ_MESSAGE_FLAG_MAY_DISCARD = 1 << 0;
#else #else
#define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags) 0) #define MOJO_READ_MESSAGE_FLAG_NONE ((MojoReadMessageFlags)0)
#define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags) 1 << 0) #define MOJO_READ_MESSAGE_FLAG_MAY_DISCARD ((MojoReadMessageFlags)1 << 0)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus
...@@ -94,8 +94,8 @@ extern "C" { ...@@ -94,8 +94,8 @@ extern "C" {
// TODO(vtl): Add an options struct pointer argument. // TODO(vtl): Add an options struct pointer argument.
MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe( MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe(
const struct MojoCreateMessagePipeOptions* options, // Optional. const struct MojoCreateMessagePipeOptions* options, // Optional.
MojoHandle* message_pipe_handle0, // Out. MojoHandle* message_pipe_handle0, // Out.
MojoHandle* message_pipe_handle1); // Out. MojoHandle* message_pipe_handle1); // Out.
// Writes a message to the message pipe endpoint given by |message_pipe_handle|, // Writes a message to the message pipe endpoint given by |message_pipe_handle|,
// with message data specified by |bytes| of size |num_bytes| and attached // with message data specified by |bytes| of size |num_bytes| and attached
...@@ -125,13 +125,13 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe( ...@@ -125,13 +125,13 @@ MOJO_SYSTEM_EXPORT MojoResult MojoCreateMessagePipe(
// //
// TODO(vtl): Add a notion of capacity for message pipes, and return // TODO(vtl): Add a notion of capacity for message pipes, and return
// |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full. // |MOJO_RESULT_SHOULD_WAIT| if the message pipe is full.
MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle message_pipe_handle, MojoWriteMessage(MojoHandle message_pipe_handle,
const void* bytes, // Optional. const void* bytes, // Optional.
uint32_t num_bytes, uint32_t num_bytes,
const MojoHandle* handles, // Optional. const MojoHandle* handles, // Optional.
uint32_t num_handles, uint32_t num_handles,
MojoWriteMessageFlags flags); MojoWriteMessageFlags flags);
// Reads a message from the message pipe endpoint given by // Reads a message from the message pipe endpoint given by
// |message_pipe_handle|; also usable to query the size of the next message or // |message_pipe_handle|; also usable to query the size of the next message or
...@@ -164,13 +164,13 @@ MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage( ...@@ -164,13 +164,13 @@ MOJO_SYSTEM_EXPORT MojoResult MojoWriteMessage(
// error code; should distinguish this from the hitting-system-limits // error code; should distinguish this from the hitting-system-limits
// case.) // case.)
// |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read. // |MOJO_RESULT_SHOULD_WAIT| if no message was available to be read.
MOJO_SYSTEM_EXPORT MojoResult MojoReadMessage( MOJO_SYSTEM_EXPORT MojoResult
MojoHandle message_pipe_handle, MojoReadMessage(MojoHandle message_pipe_handle,
void* bytes, // Optional out. void* bytes, // Optional out.
uint32_t* num_bytes, // Optional in/out. uint32_t* num_bytes, // Optional in/out.
MojoHandle* handles, // Optional out. MojoHandle* handles, // Optional out.
uint32_t* num_handles, // Optional in/out. uint32_t* num_handles, // Optional in/out.
MojoReadMessageFlags flags); MojoReadMessageFlags flags);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
...@@ -28,9 +28,7 @@ namespace { ...@@ -28,9 +28,7 @@ namespace {
class MessagePipeWriterThread : public mojo::Thread { class MessagePipeWriterThread : public mojo::Thread {
public: public:
MessagePipeWriterThread(MojoHandle handle, uint32_t num_bytes) MessagePipeWriterThread(MojoHandle handle, uint32_t num_bytes)
: handle_(handle), : handle_(handle), num_bytes_(num_bytes), num_writes_(0) {}
num_bytes_(num_bytes),
num_writes_(0) {}
virtual ~MessagePipeWriterThread() {} virtual ~MessagePipeWriterThread() {}
virtual void Run() MOJO_OVERRIDE { virtual void Run() MOJO_OVERRIDE {
...@@ -39,8 +37,8 @@ class MessagePipeWriterThread : public mojo::Thread { ...@@ -39,8 +37,8 @@ class MessagePipeWriterThread : public mojo::Thread {
// TODO(vtl): Should I throttle somehow? // TODO(vtl): Should I throttle somehow?
for (;;) { for (;;) {
MojoResult result = MojoWriteMessage(handle_, buffer, num_bytes_, NULL, 0, MojoResult result = MojoWriteMessage(
MOJO_WRITE_MESSAGE_FLAG_NONE); handle_, buffer, num_bytes_, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE);
if (result == MOJO_RESULT_OK) { if (result == MOJO_RESULT_OK) {
num_writes_++; num_writes_++;
continue; continue;
...@@ -68,9 +66,7 @@ class MessagePipeWriterThread : public mojo::Thread { ...@@ -68,9 +66,7 @@ class MessagePipeWriterThread : public mojo::Thread {
class MessagePipeReaderThread : public mojo::Thread { class MessagePipeReaderThread : public mojo::Thread {
public: public:
explicit MessagePipeReaderThread(MojoHandle handle) explicit MessagePipeReaderThread(MojoHandle handle)
: handle_(handle), : handle_(handle), num_reads_(0) {}
num_reads_(0) {
}
virtual ~MessagePipeReaderThread() {} virtual ~MessagePipeReaderThread() {}
virtual void Run() MOJO_OVERRIDE { virtual void Run() MOJO_OVERRIDE {
...@@ -78,16 +74,16 @@ class MessagePipeReaderThread : public mojo::Thread { ...@@ -78,16 +74,16 @@ class MessagePipeReaderThread : public mojo::Thread {
for (;;) { for (;;) {
uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer)); uint32_t num_bytes = static_cast<uint32_t>(sizeof(buffer));
MojoResult result = MojoReadMessage(handle_, buffer, &num_bytes, NULL, MojoResult result = MojoReadMessage(
NULL, MOJO_READ_MESSAGE_FLAG_NONE); handle_, buffer, &num_bytes, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE);
if (result == MOJO_RESULT_OK) { if (result == MOJO_RESULT_OK) {
num_reads_++; num_reads_++;
continue; continue;
} }
if (result == MOJO_RESULT_SHOULD_WAIT) { if (result == MOJO_RESULT_SHOULD_WAIT) {
result = MojoWait(handle_, MOJO_HANDLE_SIGNAL_READABLE, result = MojoWait(
MOJO_DEADLINE_INDEFINITE); handle_, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE);
if (result == MOJO_RESULT_OK) { if (result == MOJO_RESULT_OK) {
// Go to the top of the loop to read again. // Go to the top of the loop to read again.
continue; continue;
...@@ -118,8 +114,7 @@ class CorePerftest : public testing::Test { ...@@ -118,8 +114,7 @@ class CorePerftest : public testing::Test {
CorePerftest() : buffer_(NULL), num_bytes_(0) {} CorePerftest() : buffer_(NULL), num_bytes_(0) {}
virtual ~CorePerftest() {} virtual ~CorePerftest() {}
static void NoOp(void* /*closure*/) { static void NoOp(void* /*closure*/) {}
}
static void MessagePipe_CreateAndClose(void* closure) { static void MessagePipe_CreateAndClose(void* closure) {
CorePerftest* self = static_cast<CorePerftest*>(closure); CorePerftest* self = static_cast<CorePerftest*>(closure);
...@@ -136,14 +131,18 @@ class CorePerftest : public testing::Test { ...@@ -136,14 +131,18 @@ class CorePerftest : public testing::Test {
CorePerftest* self = static_cast<CorePerftest*>(closure); CorePerftest* self = static_cast<CorePerftest*>(closure);
MojoResult result MOJO_ALLOW_UNUSED; MojoResult result MOJO_ALLOW_UNUSED;
result = MojoWriteMessage(self->h0_, result = MojoWriteMessage(self->h0_,
self->buffer_, self->num_bytes_, self->buffer_,
NULL, 0, self->num_bytes_,
NULL,
0,
MOJO_WRITE_MESSAGE_FLAG_NONE); MOJO_WRITE_MESSAGE_FLAG_NONE);
assert(result == MOJO_RESULT_OK); assert(result == MOJO_RESULT_OK);
uint32_t read_bytes = self->num_bytes_; uint32_t read_bytes = self->num_bytes_;
result = MojoReadMessage(self->h1_, result = MojoReadMessage(self->h1_,
self->buffer_, &read_bytes, self->buffer_,
NULL, NULL, &read_bytes,
NULL,
NULL,
MOJO_READ_MESSAGE_FLAG_NONE); MOJO_READ_MESSAGE_FLAG_NONE);
assert(result == MOJO_RESULT_OK); assert(result == MOJO_RESULT_OK);
} }
...@@ -151,10 +150,8 @@ class CorePerftest : public testing::Test { ...@@ -151,10 +150,8 @@ class CorePerftest : public testing::Test {
static void MessagePipe_EmptyRead(void* closure) { static void MessagePipe_EmptyRead(void* closure) {
CorePerftest* self = static_cast<CorePerftest*>(closure); CorePerftest* self = static_cast<CorePerftest*>(closure);
MojoResult result MOJO_ALLOW_UNUSED; MojoResult result MOJO_ALLOW_UNUSED;
result = MojoReadMessage(self->h0_, result = MojoReadMessage(
NULL, NULL, self->h0_, NULL, NULL, NULL, NULL, MOJO_READ_MESSAGE_FLAG_MAY_DISCARD);
NULL, NULL,
MOJO_READ_MESSAGE_FLAG_MAY_DISCARD);
assert(result == MOJO_RESULT_SHOULD_WAIT); assert(result == MOJO_RESULT_SHOULD_WAIT);
} }
...@@ -223,18 +220,24 @@ class CorePerftest : public testing::Test { ...@@ -223,18 +220,24 @@ class CorePerftest : public testing::Test {
readers.clear(); readers.clear();
char test_name[200]; char test_name[200];
sprintf(test_name, "MessagePipe_Threaded_Writes_%uw_%ur_%ubytes", sprintf(test_name,
num_writers, num_readers, static_cast<unsigned>(num_bytes)); "MessagePipe_Threaded_Writes_%uw_%ur_%ubytes",
mojo::test::LogPerfResult(test_name, num_writers,
1000000.0 * static_cast<double>(num_writes) / num_readers,
(end_time - start_time), static_cast<unsigned>(num_bytes));
"writes/second"); mojo::test::LogPerfResult(
sprintf(test_name, "MessagePipe_Threaded_Reads_%uw_%ur_%ubytes", test_name,
num_writers, num_readers, static_cast<unsigned>(num_bytes)); 1000000.0 * static_cast<double>(num_writes) / (end_time - start_time),
mojo::test::LogPerfResult(test_name, "writes/second");
1000000.0 * static_cast<double>(num_reads) / sprintf(test_name,
(end_time - start_time), "MessagePipe_Threaded_Reads_%uw_%ur_%ubytes",
"reads/second"); num_writers,
num_readers,
static_cast<unsigned>(num_bytes));
mojo::test::LogPerfResult(
test_name,
1000000.0 * static_cast<double>(num_reads) / (end_time - start_time),
"reads/second");
} }
#endif // !defined(WIN32) #endif // !defined(WIN32)
...@@ -248,8 +251,8 @@ class CorePerftest : public testing::Test { ...@@ -248,8 +251,8 @@ class CorePerftest : public testing::Test {
#if !defined(WIN32) #if !defined(WIN32)
void Sleep(int64_t microseconds) { void Sleep(int64_t microseconds) {
struct timespec req = { struct timespec req = {
static_cast<time_t>(microseconds / 1000000), // Seconds. static_cast<time_t>(microseconds / 1000000), // Seconds.
static_cast<long>(microseconds % 1000000) * 1000L // Nanoseconds. static_cast<long>(microseconds % 1000000) * 1000L // Nanoseconds.
}; };
int rv MOJO_ALLOW_UNUSED; int rv MOJO_ALLOW_UNUSED;
rv = nanosleep(&req, NULL); rv = nanosleep(&req, NULL);
...@@ -275,7 +278,7 @@ TEST_F(CorePerftest, MessagePipe_WriteAndRead) { ...@@ -275,7 +278,7 @@ TEST_F(CorePerftest, MessagePipe_WriteAndRead) {
MojoResult result MOJO_ALLOW_UNUSED; MojoResult result MOJO_ALLOW_UNUSED;
result = MojoCreateMessagePipe(NULL, &h0_, &h1_); result = MojoCreateMessagePipe(NULL, &h0_, &h1_);
assert(result == MOJO_RESULT_OK); assert(result == MOJO_RESULT_OK);
char buffer[10000] = { 0 }; char buffer[10000] = {0};
buffer_ = buffer; buffer_ = buffer;
num_bytes_ = 10u; num_bytes_ = 10u;
mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10bytes", mojo::test::IterateAndReportPerf("MessagePipe_WriteAndRead_10bytes",
...@@ -303,9 +306,8 @@ TEST_F(CorePerftest, MessagePipe_EmptyRead) { ...@@ -303,9 +306,8 @@ TEST_F(CorePerftest, MessagePipe_EmptyRead) {
MojoResult result MOJO_ALLOW_UNUSED; MojoResult result MOJO_ALLOW_UNUSED;
result = MojoCreateMessagePipe(NULL, &h0_, &h1_); result = MojoCreateMessagePipe(NULL, &h0_, &h1_);
assert(result == MOJO_RESULT_OK); assert(result == MOJO_RESULT_OK);
mojo::test::IterateAndReportPerf("MessagePipe_EmptyRead", mojo::test::IterateAndReportPerf(
&CorePerftest::MessagePipe_EmptyRead, "MessagePipe_EmptyRead", &CorePerftest::MessagePipe_EmptyRead, this);
this);
result = MojoClose(h0_); result = MojoClose(h0_);
assert(result == MOJO_RESULT_OK); assert(result == MOJO_RESULT_OK);
result = MojoClose(h1_); result = MojoClose(h1_);
......
...@@ -24,7 +24,7 @@ TEST(CoreTest, GetTimeTicksNow) { ...@@ -24,7 +24,7 @@ TEST(CoreTest, GetTimeTicksNow) {
TEST(CoreTest, InvalidHandle) { TEST(CoreTest, InvalidHandle) {
MojoHandle h0, h1; MojoHandle h0, h1;
MojoHandleSignals sig; MojoHandleSignals sig;
char buffer[10] = { 0 }; char buffer[10] = {0};
uint32_t buffer_size; uint32_t buffer_size;
void* write_pointer; void* write_pointer;
const void* read_pointer; const void* read_pointer;
...@@ -41,13 +41,14 @@ TEST(CoreTest, InvalidHandle) { ...@@ -41,13 +41,14 @@ TEST(CoreTest, InvalidHandle) {
MojoWaitMany(&h0, &sig, 1, MOJO_DEADLINE_INDEFINITE)); MojoWaitMany(&h0, &sig, 1, MOJO_DEADLINE_INDEFINITE));
// Message pipe: // Message pipe:
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, EXPECT_EQ(
MojoWriteMessage(h0, buffer, 3, NULL, 0, MOJO_RESULT_INVALID_ARGUMENT,
MOJO_WRITE_MESSAGE_FLAG_NONE)); MojoWriteMessage(h0, buffer, 3, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
buffer_size = static_cast<uint32_t>(sizeof(buffer)); buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, EXPECT_EQ(
MojoReadMessage(h0, buffer, &buffer_size, NULL, NULL, MOJO_RESULT_INVALID_ARGUMENT,
MOJO_READ_MESSAGE_FLAG_NONE)); MojoReadMessage(
h0, buffer, &buffer_size, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE));
// Data pipe: // Data pipe:
buffer_size = static_cast<uint32_t>(sizeof(buffer)); buffer_size = static_cast<uint32_t>(sizeof(buffer));
...@@ -55,16 +56,16 @@ TEST(CoreTest, InvalidHandle) { ...@@ -55,16 +56,16 @@ TEST(CoreTest, InvalidHandle) {
MojoWriteData(h0, buffer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE)); MojoWriteData(h0, buffer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE));
write_pointer = NULL; write_pointer = NULL;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoBeginWriteData(h0, &write_pointer, &buffer_size, MojoBeginWriteData(
MOJO_WRITE_DATA_FLAG_NONE)); h0, &write_pointer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndWriteData(h0, 1)); EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndWriteData(h0, 1));
buffer_size = static_cast<uint32_t>(sizeof(buffer)); buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoReadData(h0, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE)); MojoReadData(h0, buffer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
read_pointer = NULL; read_pointer = NULL;
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
MojoBeginReadData(h0, &read_pointer, &buffer_size, MojoBeginReadData(
MOJO_READ_DATA_FLAG_NONE)); h0, &read_pointer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndReadData(h0, 1)); EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoEndReadData(h0, 1));
// Shared buffer: // Shared buffer:
...@@ -78,7 +79,7 @@ TEST(CoreTest, InvalidHandle) { ...@@ -78,7 +79,7 @@ TEST(CoreTest, InvalidHandle) {
TEST(CoreTest, BasicMessagePipe) { TEST(CoreTest, BasicMessagePipe) {
MojoHandle h0, h1; MojoHandle h0, h1;
MojoHandleSignals sig; MojoHandleSignals sig;
char buffer[10] = { 0 }; char buffer[10] = {0};
uint32_t buffer_size; uint32_t buffer_size;
h0 = MOJO_HANDLE_INVALID; h0 = MOJO_HANDLE_INVALID;
...@@ -96,16 +97,18 @@ TEST(CoreTest, BasicMessagePipe) { ...@@ -96,16 +97,18 @@ TEST(CoreTest, BasicMessagePipe) {
// Try to read. // Try to read.
buffer_size = static_cast<uint32_t>(sizeof(buffer)); buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, EXPECT_EQ(
MojoReadMessage(h0, buffer, &buffer_size, NULL, NULL, MOJO_RESULT_SHOULD_WAIT,
MOJO_READ_MESSAGE_FLAG_NONE)); MojoReadMessage(
h0, buffer, &buffer_size, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE));
// Write to |h1|. // Write to |h1|.
static const char kHello[] = "hello"; static const char kHello[] = "hello";
buffer_size = static_cast<uint32_t>(sizeof(kHello)); buffer_size = static_cast<uint32_t>(sizeof(kHello));
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(
MojoWriteMessage(h1, kHello, buffer_size, NULL, 0, MOJO_RESULT_OK,
MOJO_WRITE_MESSAGE_FLAG_NONE)); MojoWriteMessage(
h1, kHello, buffer_size, NULL, 0, MOJO_WRITE_MESSAGE_FLAG_NONE));
// |h0| should be readable. // |h0| should be readable.
sig = MOJO_HANDLE_SIGNAL_READABLE; sig = MOJO_HANDLE_SIGNAL_READABLE;
...@@ -114,9 +117,10 @@ TEST(CoreTest, BasicMessagePipe) { ...@@ -114,9 +117,10 @@ TEST(CoreTest, BasicMessagePipe) {
// Read from |h0|. // Read from |h0|.
buffer_size = static_cast<uint32_t>(sizeof(buffer)); buffer_size = static_cast<uint32_t>(sizeof(buffer));
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(
MojoReadMessage(h0, buffer, &buffer_size, NULL, NULL, MOJO_RESULT_OK,
MOJO_READ_MESSAGE_FLAG_NONE)); MojoReadMessage(
h0, buffer, &buffer_size, NULL, NULL, MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ(static_cast<uint32_t>(sizeof(kHello)), buffer_size); EXPECT_EQ(static_cast<uint32_t>(sizeof(kHello)), buffer_size);
EXPECT_STREQ(kHello, buffer); EXPECT_STREQ(kHello, buffer);
...@@ -128,10 +132,10 @@ TEST(CoreTest, BasicMessagePipe) { ...@@ -128,10 +132,10 @@ TEST(CoreTest, BasicMessagePipe) {
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0)); EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0));
// |h1| should no longer be readable or writable. // |h1| should no longer be readable or writable.
EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, EXPECT_EQ(
MojoWait(h1, MOJO_RESULT_FAILED_PRECONDITION,
MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, MojoWait(
1000)); h1, MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, 1000));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1)); EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1));
} }
...@@ -139,7 +143,7 @@ TEST(CoreTest, BasicMessagePipe) { ...@@ -139,7 +143,7 @@ TEST(CoreTest, BasicMessagePipe) {
TEST(CoreTest, BasicDataPipe) { TEST(CoreTest, BasicDataPipe) {
MojoHandle hp, hc; MojoHandle hp, hc;
MojoHandleSignals sig; MojoHandleSignals sig;
char buffer[20] = { 0 }; char buffer[20] = {0};
uint32_t buffer_size; uint32_t buffer_size;
void* write_pointer; void* write_pointer;
const void* read_pointer; const void* read_pointer;
...@@ -165,16 +169,16 @@ TEST(CoreTest, BasicDataPipe) { ...@@ -165,16 +169,16 @@ TEST(CoreTest, BasicDataPipe) {
// Try to begin a two-phase read from |hc|. // Try to begin a two-phase read from |hc|.
read_pointer = NULL; read_pointer = NULL;
EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT, EXPECT_EQ(MOJO_RESULT_SHOULD_WAIT,
MojoBeginReadData(hc, &read_pointer, &buffer_size, MojoBeginReadData(
MOJO_READ_DATA_FLAG_NONE)); hc, &read_pointer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
// Write to |hp|. // Write to |hp|.
static const char kHello[] = "hello "; static const char kHello[] = "hello ";
// Don't include terminating null. // Don't include terminating null.
buffer_size = static_cast<uint32_t>(strlen(kHello)); buffer_size = static_cast<uint32_t>(strlen(kHello));
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(
MojoWriteData(hp, kHello, &buffer_size, MOJO_RESULT_OK,
MOJO_WRITE_MESSAGE_FLAG_NONE)); MojoWriteData(hp, kHello, &buffer_size, MOJO_WRITE_MESSAGE_FLAG_NONE));
// |hc| should be(come) readable. // |hc| should be(come) readable.
sig = MOJO_HANDLE_SIGNAL_READABLE; sig = MOJO_HANDLE_SIGNAL_READABLE;
...@@ -183,8 +187,8 @@ TEST(CoreTest, BasicDataPipe) { ...@@ -183,8 +187,8 @@ TEST(CoreTest, BasicDataPipe) {
// Do a two-phase write to |hp|. // Do a two-phase write to |hp|.
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(MOJO_RESULT_OK,
MojoBeginWriteData(hp, &write_pointer, &buffer_size, MojoBeginWriteData(
MOJO_WRITE_DATA_FLAG_NONE)); hp, &write_pointer, &buffer_size, MOJO_WRITE_DATA_FLAG_NONE));
static const char kWorld[] = "world"; static const char kWorld[] = "world";
ASSERT_GE(buffer_size, sizeof(kWorld)); ASSERT_GE(buffer_size, sizeof(kWorld));
// Include the terminating null. // Include the terminating null.
...@@ -207,8 +211,8 @@ TEST(CoreTest, BasicDataPipe) { ...@@ -207,8 +211,8 @@ TEST(CoreTest, BasicDataPipe) {
// Do a two-phase read from |hc|. // Do a two-phase read from |hc|.
read_pointer = NULL; read_pointer = NULL;
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(MOJO_RESULT_OK,
MojoBeginReadData(hc, &read_pointer, &buffer_size, MojoBeginReadData(
MOJO_READ_DATA_FLAG_NONE)); hc, &read_pointer, &buffer_size, MOJO_READ_DATA_FLAG_NONE));
ASSERT_LE(buffer_size, sizeof(buffer) - 1); ASSERT_LE(buffer_size, sizeof(buffer) - 1);
memcpy(&buffer[1], read_pointer, buffer_size); memcpy(&buffer[1], read_pointer, buffer_size);
EXPECT_EQ(MOJO_RESULT_OK, MojoEndReadData(hc, buffer_size)); EXPECT_EQ(MOJO_RESULT_OK, MojoEndReadData(hc, buffer_size));
......
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
__FILE__ "(" STRINGIFY2(__LINE__) "): Failure: " message __FILE__ "(" STRINGIFY2(__LINE__) "): Failure: " message
// Poor man's gtest. // Poor man's gtest.
#define EXPECT_EQ(a, b) \ #define EXPECT_EQ(a, b) \
do { \ do { \
if ((a) != (b)) \ if ((a) != (b)) \
return FAILURE(STRINGIFY(a) " != " STRINGIFY(b) " (expected ==)"); \ return FAILURE(STRINGIFY(a) " != " STRINGIFY(b) " (expected ==)"); \
} while (0) } while (0)
#define EXPECT_NE(a, b) \ #define EXPECT_NE(a, b) \
do { \ do { \
if ((a) == (b)) \ if ((a) == (b)) \
return FAILURE(STRINGIFY(a) " == " STRINGIFY(b) " (expected !=)"); \ return FAILURE(STRINGIFY(a) " == " STRINGIFY(b) " (expected !=)"); \
} while (0) } while (0)
...@@ -44,7 +44,7 @@ const char* MinimalCTest(void) { ...@@ -44,7 +44,7 @@ const char* MinimalCTest(void) {
MojoHandle handle0, handle1; MojoHandle handle0, handle1;
MojoHandleSignals signals; MojoHandleSignals signals;
const char kHello[] = "hello"; const char kHello[] = "hello";
char buffer[200] = { 0 }; char buffer[200] = {0};
uint32_t num_bytes; uint32_t num_bytes;
ticks = MojoGetTimeTicksNow(); ticks = MojoGetTimeTicksNow();
...@@ -53,9 +53,9 @@ const char* MinimalCTest(void) { ...@@ -53,9 +53,9 @@ const char* MinimalCTest(void) {
handle0 = MOJO_HANDLE_INVALID; handle0 = MOJO_HANDLE_INVALID;
EXPECT_NE(MOJO_RESULT_OK, MojoClose(handle0)); EXPECT_NE(MOJO_RESULT_OK, MojoClose(handle0));
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, EXPECT_EQ(
MojoWait(handle0, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_RESULT_INVALID_ARGUMENT,
MOJO_DEADLINE_INDEFINITE)); MojoWait(handle0, ~MOJO_HANDLE_SIGNAL_NONE, MOJO_DEADLINE_INDEFINITE));
handle1 = MOJO_HANDLE_INVALID; handle1 = MOJO_HANDLE_INVALID;
EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &handle0, &handle1)); EXPECT_EQ(MOJO_RESULT_OK, MojoCreateMessagePipe(NULL, &handle0, &handle1));
...@@ -65,18 +65,26 @@ const char* MinimalCTest(void) { ...@@ -65,18 +65,26 @@ const char* MinimalCTest(void) {
MojoWaitMany(&handle0, &signals, 1, 1)); MojoWaitMany(&handle0, &signals, 1, 1));
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(MOJO_RESULT_OK,
MojoWriteMessage(handle0, kHello, (uint32_t) sizeof(kHello), NULL, MojoWriteMessage(handle0,
0u, MOJO_WRITE_DATA_FLAG_NONE)); kHello,
(uint32_t)sizeof(kHello),
EXPECT_EQ(MOJO_RESULT_OK, NULL,
MojoWait(handle1, MOJO_HANDLE_SIGNAL_READABLE, 0u,
MOJO_DEADLINE_INDEFINITE)); MOJO_WRITE_DATA_FLAG_NONE));
num_bytes = (uint32_t) sizeof(buffer); EXPECT_EQ(
MOJO_RESULT_OK,
MojoWait(handle1, MOJO_HANDLE_SIGNAL_READABLE, MOJO_DEADLINE_INDEFINITE));
num_bytes = (uint32_t)sizeof(buffer);
EXPECT_EQ(MOJO_RESULT_OK, EXPECT_EQ(MOJO_RESULT_OK,
MojoReadMessage(handle1, buffer, &num_bytes, NULL, NULL, MojoReadMessage(handle1,
buffer,
&num_bytes,
NULL,
NULL,
MOJO_READ_MESSAGE_FLAG_NONE)); MOJO_READ_MESSAGE_FLAG_NONE));
EXPECT_EQ((uint32_t) sizeof(kHello), num_bytes); EXPECT_EQ((uint32_t)sizeof(kHello), num_bytes);
EXPECT_EQ(0, memcmp(buffer, kHello, sizeof(kHello))); EXPECT_EQ(0, memcmp(buffer, kHello, sizeof(kHello)));
EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle0)); EXPECT_EQ(MOJO_RESULT_OK, MojoClose(handle0));
......
...@@ -58,11 +58,17 @@ TEST(MacrosTest, Alignof) { ...@@ -58,11 +58,17 @@ TEST(MacrosTest, Alignof) {
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(push) #pragma warning(push)
// Disable the warning "structure was padded due to __declspec(align())". // Disable the warning "structure was padded due to __declspec(align())".
#pragma warning(disable:4324) #pragma warning(disable : 4324)
#endif #endif
struct MOJO_ALIGNAS(1) StructAlignas1 { char x; }; struct MOJO_ALIGNAS(1) StructAlignas1 {
struct MOJO_ALIGNAS(4) StructAlignas4 { char x; }; char x;
struct MOJO_ALIGNAS(8) StructAlignas8 { char x; }; };
struct MOJO_ALIGNAS(4) StructAlignas4 {
char x;
};
struct MOJO_ALIGNAS(8) StructAlignas8 {
char x;
};
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
#endif #endif
......
...@@ -29,7 +29,7 @@ typedef uint32_t MojoHandle; ...@@ -29,7 +29,7 @@ typedef uint32_t MojoHandle;
#ifdef __cplusplus #ifdef __cplusplus
const MojoHandle MOJO_HANDLE_INVALID = 0; const MojoHandle MOJO_HANDLE_INVALID = 0;
#else #else
#define MOJO_HANDLE_INVALID ((MojoHandle) 0) #define MOJO_HANDLE_INVALID ((MojoHandle)0)
#endif #endif
// |MojoResult|: Result codes for Mojo operations. Non-negative values are // |MojoResult|: Result codes for Mojo operations. Non-negative values are
...@@ -110,24 +110,24 @@ const MojoResult MOJO_RESULT_DATA_LOSS = -15; ...@@ -110,24 +110,24 @@ const MojoResult MOJO_RESULT_DATA_LOSS = -15;
const MojoResult MOJO_RESULT_BUSY = -16; const MojoResult MOJO_RESULT_BUSY = -16;
const MojoResult MOJO_RESULT_SHOULD_WAIT = -17; const MojoResult MOJO_RESULT_SHOULD_WAIT = -17;
#else #else
#define MOJO_RESULT_OK ((MojoResult) 0) #define MOJO_RESULT_OK ((MojoResult)0)
#define MOJO_RESULT_CANCELLED ((MojoResult) -1) #define MOJO_RESULT_CANCELLED ((MojoResult) - 1)
#define MOJO_RESULT_UNKNOWN ((MojoResult) -2) #define MOJO_RESULT_UNKNOWN ((MojoResult) - 2)
#define MOJO_RESULT_INVALID_ARGUMENT ((MojoResult) -3) #define MOJO_RESULT_INVALID_ARGUMENT ((MojoResult) - 3)
#define MOJO_RESULT_DEADLINE_EXCEEDED ((MojoResult) -4) #define MOJO_RESULT_DEADLINE_EXCEEDED ((MojoResult) - 4)
#define MOJO_RESULT_NOT_FOUND ((MojoResult) -5) #define MOJO_RESULT_NOT_FOUND ((MojoResult) - 5)
#define MOJO_RESULT_ALREADY_EXISTS ((MojoResult) -6) #define MOJO_RESULT_ALREADY_EXISTS ((MojoResult) - 6)
#define MOJO_RESULT_PERMISSION_DENIED ((MojoResult) -7) #define MOJO_RESULT_PERMISSION_DENIED ((MojoResult) - 7)
#define MOJO_RESULT_RESOURCE_EXHAUSTED ((MojoResult) -8) #define MOJO_RESULT_RESOURCE_EXHAUSTED ((MojoResult) - 8)
#define MOJO_RESULT_FAILED_PRECONDITION ((MojoResult) -9) #define MOJO_RESULT_FAILED_PRECONDITION ((MojoResult) - 9)
#define MOJO_RESULT_ABORTED ((MojoResult) -10) #define MOJO_RESULT_ABORTED ((MojoResult) - 10)
#define MOJO_RESULT_OUT_OF_RANGE ((MojoResult) -11) #define MOJO_RESULT_OUT_OF_RANGE ((MojoResult) - 11)
#define MOJO_RESULT_UNIMPLEMENTED ((MojoResult) -12) #define MOJO_RESULT_UNIMPLEMENTED ((MojoResult) - 12)
#define MOJO_RESULT_INTERNAL ((MojoResult) -13) #define MOJO_RESULT_INTERNAL ((MojoResult) - 13)
#define MOJO_RESULT_UNAVAILABLE ((MojoResult) -14) #define MOJO_RESULT_UNAVAILABLE ((MojoResult) - 14)
#define MOJO_RESULT_DATA_LOSS ((MojoResult) -15) #define MOJO_RESULT_DATA_LOSS ((MojoResult) - 15)
#define MOJO_RESULT_BUSY ((MojoResult) -16) #define MOJO_RESULT_BUSY ((MojoResult) - 16)
#define MOJO_RESULT_SHOULD_WAIT ((MojoResult) -17) #define MOJO_RESULT_SHOULD_WAIT ((MojoResult) - 17)
#endif #endif
// |MojoDeadline|: Used to specify deadlines (timeouts), in microseconds (except // |MojoDeadline|: Used to specify deadlines (timeouts), in microseconds (except
...@@ -139,7 +139,7 @@ typedef uint64_t MojoDeadline; ...@@ -139,7 +139,7 @@ typedef uint64_t MojoDeadline;
#ifdef __cplusplus #ifdef __cplusplus
const MojoDeadline MOJO_DEADLINE_INDEFINITE = static_cast<MojoDeadline>(-1); const MojoDeadline MOJO_DEADLINE_INDEFINITE = static_cast<MojoDeadline>(-1);
#else #else
#define MOJO_DEADLINE_INDEFINITE ((MojoDeadline) -1) #define MOJO_DEADLINE_INDEFINITE ((MojoDeadline) - 1)
#endif #endif
// |MojoHandleSignals|: Used to specify signals that can be waited on for a // |MojoHandleSignals|: Used to specify signals that can be waited on for a
...@@ -157,9 +157,9 @@ const MojoHandleSignals MOJO_HANDLE_SIGNAL_NONE = 0; ...@@ -157,9 +157,9 @@ const MojoHandleSignals MOJO_HANDLE_SIGNAL_NONE = 0;
const MojoHandleSignals MOJO_HANDLE_SIGNAL_READABLE = 1 << 0; const MojoHandleSignals MOJO_HANDLE_SIGNAL_READABLE = 1 << 0;
const MojoHandleSignals MOJO_HANDLE_SIGNAL_WRITABLE = 1 << 1; const MojoHandleSignals MOJO_HANDLE_SIGNAL_WRITABLE = 1 << 1;
#else #else
#define MOJO_HANDLE_SIGNAL_NONE ((MojoHandleSignals) 0) #define MOJO_HANDLE_SIGNAL_NONE ((MojoHandleSignals)0)
#define MOJO_HANDLE_SIGNAL_READABLE ((MojoHandleSignals) 1 << 0) #define MOJO_HANDLE_SIGNAL_READABLE ((MojoHandleSignals)1 << 0)
#define MOJO_HANDLE_SIGNAL_WRITABLE ((MojoHandleSignals) 1 << 1) #define MOJO_HANDLE_SIGNAL_WRITABLE ((MojoHandleSignals)1 << 1)
#endif #endif
// TODO(vtl): Add out parameters with this to MojoWait/MojoWaitMany. // TODO(vtl): Add out parameters with this to MojoWait/MojoWaitMany.
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
"""Presubmit script for mojo/embedder. """Presubmit script for mojo/system.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into depot_tools. for more details about the presubmit API built into depot_tools.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment