Commit 499b4956 authored by Mark Brand's avatar Mark Brand Committed by Commit Bot

MojoLPM: Remove re-entrancy and use of RunUntilIdle.

The existing example fuzzer code used RunUntilIdle to avoid runloop
recursion issues caused by re-entrancy in the scheduling of fuzzer
tasks. This change removes the re-entrancy and refactors out the use
of RunUntilIdle, working towards refactoring out the common code
duplication between fuzzers that's currently necessary.

Bug: 1076336
Change-Id: I3729d20264638c00c14c3a8149395e3f22e90089
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2329531
Commit-Queue: Mark Brand <markbrand@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799545}
parent ed3fbbd4
...@@ -6,7 +6,7 @@ actions { ...@@ -6,7 +6,7 @@ actions {
} }
} }
actions { actions {
code_cache_host_call { code_cache_host_remote_action {
id: 1 id: 1
m_did_generate_cacheable_metadata { m_did_generate_cacheable_metadata {
m_cache_type: CodeCacheType_kJavascript m_cache_type: CodeCacheType_kJavascript
......
...@@ -6,7 +6,7 @@ actions { ...@@ -6,7 +6,7 @@ actions {
} }
} }
actions { actions {
code_cache_host_call { code_cache_host_remote_action {
id: 1 id: 1
m_did_generate_cacheable_metadata { m_did_generate_cacheable_metadata {
m_cache_type: CodeCacheType_kJavascript m_cache_type: CodeCacheType_kJavascript
......
// Copyright 2020 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.
// Message format for the MojoLPM fuzzer for the CodeCacheHost interface.
syntax = "proto2"; syntax = "proto2";
package content.fuzzing.code_cache_host.proto; package content.fuzzing.code_cache_host.proto;
import "third_party/blink/public/mojom/loader/code_cache.mojom.mojolpm.proto"; import "third_party/blink/public/mojom/loader/code_cache.mojom.mojolpm.proto";
message NewCodeCacheHost { // Bind a new CodeCacheHost remote
message NewCodeCacheHostAction {
enum OriginId { enum OriginId {
ORIGIN_A = 0; ORIGIN_A = 0;
ORIGIN_B = 1; ORIGIN_B = 1;
...@@ -17,7 +24,10 @@ message NewCodeCacheHost { ...@@ -17,7 +24,10 @@ message NewCodeCacheHost {
required OriginId origin_id = 3; required OriginId origin_id = 3;
} }
message RunUntilIdle { // Run the specific sequence for (an indeterminate) period. This is not
// intended to create a specific ordering, but to allow the fuzzer to delay a
// later task until previous tasks have completed.
message RunThreadAction {
enum ThreadId { enum ThreadId {
IO = 0; IO = 0;
UI = 1; UI = 1;
...@@ -26,18 +36,23 @@ message RunUntilIdle { ...@@ -26,18 +36,23 @@ message RunUntilIdle {
required ThreadId id = 1; required ThreadId id = 1;
} }
// Actions that can be performed by the fuzzer.
message Action { message Action {
oneof action { oneof action {
NewCodeCacheHost new_code_cache_host = 1; NewCodeCacheHostAction new_code_cache_host = 1;
RunUntilIdle run_until_idle = 2; RunThreadAction run_thread = 2;
mojolpm.blink.mojom.CodeCacheHost.RemoteCall code_cache_host_call = 3; mojolpm.blink.mojom.CodeCacheHost.RemoteAction
code_cache_host_remote_action = 3;
} }
} }
// Sequence provides a level of indirection which allows Testcase to compactly
// express repeated sequences of actions.
message Sequence { message Sequence {
repeated uint32 action_indexes = 1 [packed = true]; repeated uint32 action_indexes = 1 [packed = true];
} }
// Testcase is the top-level message type interpreted by the fuzzer.
message Testcase { message Testcase {
repeated Action actions = 1; repeated Action actions = 1;
repeated Sequence sequences = 2; repeated Sequence sequences = 2;
......
...@@ -93,7 +93,6 @@ class {{interface.name}}Impl : public {{mojom_type}} { ...@@ -93,7 +93,6 @@ class {{interface.name}}Impl : public {{mojom_type}} {
{%- if method.response_parameters != None %} {%- if method.response_parameters != None %}
mojolpm::GetContext()->AddInstance<{{mojom_type}}::{{method.name}}Callback>(std::move(callback)); mojolpm::GetContext()->AddInstance<{{mojom_type}}::{{method.name}}Callback>(std::move(callback));
{%- endif %} {%- endif %}
mojolpm::GetContext()->NextAction();
} }
{%- endfor %} {%- endfor %}
}; };
...@@ -251,16 +250,16 @@ bool ToProto(::mojo::PendingAssociatedReceiver<{{mojom_type}}>&& input, ...@@ -251,16 +250,16 @@ bool ToProto(::mojo::PendingAssociatedReceiver<{{mojom_type}}>&& input,
{%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %} {%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %} {%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%- if interface.methods %} {%- if interface.methods %}
bool HandleRemoteCall(const {{proto_type}}::RemoteCall& input) { bool HandleRemoteAction(const {{proto_type}}::RemoteAction& input) {
bool result = true; bool result = true;
switch (input.method_case()) { switch (input.method_case()) {
{%- for method in interface.methods %} {%- for method in interface.methods %}
case {{proto_type}}::RemoteCall::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: { case {{proto_type}}::RemoteAction::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: {
result = HandleRemoteCall(input.id(), input.{{("m" ~ method.name)|camel_to_under}}()); result = HandleRemoteCall(input.id(), input.{{("m" ~ method.name)|camel_to_under}}());
} break; } break;
{%- endfor %} {%- endfor %}
case {{proto_type}}::RemoteCall::kReset: { case {{proto_type}}::RemoteAction::kReset: {
mojolpm::GetContext()->GetAndRemoveInstance<::mojo::Remote<{{mojom_type}}>>(input.id()); mojolpm::GetContext()->GetAndRemoveInstance<::mojo::Remote<{{mojom_type}}>>(input.id());
} break; } break;
...@@ -272,16 +271,16 @@ bool HandleRemoteCall(const {{proto_type}}::RemoteCall& input) { ...@@ -272,16 +271,16 @@ bool HandleRemoteCall(const {{proto_type}}::RemoteCall& input) {
return result; return result;
} }
bool HandleAssociatedRemoteCall(const {{proto_type}}::AssociatedRemoteCall& input) { bool HandleAssociatedRemoteAction(const {{proto_type}}::AssociatedRemoteAction& input) {
bool result = true; bool result = true;
switch (input.method_case()) { switch (input.method_case()) {
{%- for method in interface.methods %} {%- for method in interface.methods %}
case {{proto_type}}::AssociatedRemoteCall::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: { case {{proto_type}}::AssociatedRemoteAction::k{{("m_" ~ method.name)|under_to_camel(digits_split=True)}}: {
result = HandleAssociatedRemoteCall(input.id(), input.{{("m" ~ method.name)|camel_to_under}}()); result = HandleAssociatedRemoteCall(input.id(), input.{{("m" ~ method.name)|camel_to_under}}());
} break; } break;
{%- endfor %} {%- endfor %}
case {{proto_type}}::AssociatedRemoteCall::kReset: { case {{proto_type}}::AssociatedRemoteAction::kReset: {
mojolpm::GetContext()->GetAndRemoveInstance<::mojo::AssociatedRemote<{{mojom_type}}>>(input.id()); mojolpm::GetContext()->GetAndRemoveInstance<::mojo::AssociatedRemote<{{mojom_type}}>>(input.id());
} break; } break;
...@@ -293,12 +292,12 @@ bool HandleAssociatedRemoteCall(const {{proto_type}}::AssociatedRemoteCall& inpu ...@@ -293,12 +292,12 @@ bool HandleAssociatedRemoteCall(const {{proto_type}}::AssociatedRemoteCall& inpu
return result; return result;
} }
bool HandleResponse( bool HandleReceiverAction(
const {{proto_type}}::ReceiverResponse& input) { const {{proto_type}}::ReceiverAction& input) {
bool result = true; bool result = true;
switch (input.response_case()) { switch (input.response_case()) {
{%- for method in interface.methods %} {%- for method in interface.methods %}
case {{proto_type}}::ReceiverResponse::k{{("m_" ~ method.name ~ "_response")|under_to_camel(digits_split=True)}}: { case {{proto_type}}::ReceiverAction::k{{("m_" ~ method.name ~ "_response")|under_to_camel(digits_split=True)}}: {
result = HandleResponse(input.id(), input.{{("m" ~ method.name ~ "_response")|camel_to_under}}()); result = HandleResponse(input.id(), input.{{("m" ~ method.name ~ "_response")|camel_to_under}}());
} break; } break;
{%- endfor %} {%- endfor %}
...@@ -326,7 +325,6 @@ static void {{interface.name}}_{{method.name}}Callback( ...@@ -326,7 +325,6 @@ static void {{interface.name}}_{{method.name}}Callback(
{{ util.add_instance(kind, 'param_' ~ name, False) }} {{ util.add_instance(kind, 'param_' ~ name, False) }}
{%- endfor %} {%- endfor %}
mojolpmdbg("{{interface.name}}.{{method.name}}Callback\n"); mojolpmdbg("{{interface.name}}.{{method.name}}Callback\n");
mojolpm::GetContext()->NextAction();
}{{"\n"-}} }{{"\n"-}}
{%- endif %} {%- endif %}
template <typename T> template <typename T>
......
...@@ -177,14 +177,14 @@ bool ToProto( ...@@ -177,14 +177,14 @@ bool ToProto(
{%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %} {%- set mojom_type = interface|get_qualified_name_for_kind(flatten_nested_kind=True) %}
{%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %} {%- set proto_type = "::mojolpm" ~ (interface|get_qualified_name_for_kind(flatten_nested_kind=True)) %}
{%- if interface.methods %} {%- if interface.methods %}
bool HandleRemoteCall( bool HandleRemoteAction(
const {{proto_type}}::RemoteCall& input); const {{proto_type}}::RemoteAction& input);
bool HandleAssociatedRemoteCall( bool HandleAssociatedRemoteAction(
const {{proto_type}}::AssociatedRemoteCall& input); const {{proto_type}}::AssociatedRemoteAction& input);
bool HandleResponse( bool HandleReceiverAction(
const {{proto_type}}::ReceiverResponse& response);{{"\n"-}} const {{proto_type}}::ReceiverAction& input);{{"\n"-}}
{%- for method in interface.methods %} {%- for method in interface.methods %}
bool HandleRemoteCall( bool HandleRemoteCall(
uint32_t instance_id, uint32_t instance_id,
......
...@@ -316,7 +316,7 @@ message {{interface.name}} { ...@@ -316,7 +316,7 @@ message {{interface.name}} {
{%- endfor%} {%- endfor%}
{%- if interface.methods|length %} {%- if interface.methods|length %}
message RemoteCall { message RemoteAction {
required uint32 id = 1; required uint32 id = 1;
oneof method { oneof method {
...@@ -327,7 +327,7 @@ message {{interface.name}} { ...@@ -327,7 +327,7 @@ message {{interface.name}} {
} }
} }
message AssociatedRemoteCall { message AssociatedRemoteAction {
required uint32 id = 1; required uint32 id = 1;
oneof method { oneof method {
...@@ -338,7 +338,7 @@ message {{interface.name}} { ...@@ -338,7 +338,7 @@ message {{interface.name}} {
} }
} }
message ReceiverResponse { message ReceiverAction {
required uint32 id = 1; required uint32 id = 1;
oneof response { oneof response {
......
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