Commit 9240b556 authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[cleanup] Templatize the EnableFlagScope

The EnableFlagScope is useful also for non-boolean flags. With the
template we can use if for example in the wasm fuzzers to reduce the
maximum memory size of a wasm module.

In addition I put the EnableFlagScope into the v8::internal namespace,
and I fixed a small typo.

BUG=v8:6474
R=clemensh@chromium.org

Change-Id: Iae5d5c058c334cd0f9e09d20adfd229fc2d6c585
Reviewed-on: https://chromium-review.googlesource.com/531005
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45862}
parent 2e592270
......@@ -5,20 +5,26 @@
#ifndef V8_TEST_COMMON_FLAG_UTILS_H
#define V8_TEST_COMMON_FLAG_UTILS_H
class EnableFlagScope {
namespace v8 {
namespace internal {
template <typename T>
class FlagScope {
public:
EnableFlagScope(bool* flag, bool new_value = true)
: flag_(flag), previous_value_(flag) {
FlagScope(T* flag, T new_value) : flag_(flag), previous_value_(*flag) {
*flag = new_value;
}
~EnableFlagScope() { *flag_ = previous_value_; }
~FlagScope() { *flag_ = previous_value_; }
private:
bool* flag_;
bool previous_value_;
T* flag_;
T previous_value_;
};
#define EXPERIMENTAL_FLAG_SCOPE(flag) \
EnableFlagScope __flag_scope_##__LINE__(&FLAG_experimental_wasm_##flag)
FlagScope<bool> __scope_##__LINE__(&FLAG_experimental_wasm_##flag, true)
} // namespace internal
} // namespace v8
#endif // V8_TEST_COMMON_FLAG_UTILS_H
......@@ -13,14 +13,15 @@
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/wasm/wasm-module.h"
#include "test/common/wasm/flag-utils.h"
#include "test/common/wasm/wasm-module-runner.h"
#include "test/fuzzer/fuzzer-support.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
unsigned int max_mem_flag_value = v8::internal::FLAG_wasm_max_mem_pages;
unsigned int max_table_flag_value = v8::internal::FLAG_wasm_max_table_size;
v8::internal::FLAG_wasm_max_mem_pages = 32;
v8::internal::FLAG_wasm_max_table_size = 100;
v8::internal::FlagScope<uint32_t> max_mem_flag_scope(
&v8::internal::FLAG_wasm_max_mem_pages, 32);
v8::internal::FlagScope<uint32_t> max_table_size_scope(
&v8::internal::FLAG_wasm_max_table_size, 100);
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
v8::Isolate* isolate = support->GetIsolate();
v8::internal::Isolate* i_isolate =
......@@ -38,7 +39,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
v8::internal::wasm::testing::CompileAndRunAsmWasmModule(i_isolate, data,
data + size);
v8::internal::FLAG_wasm_max_mem_pages = max_mem_flag_value;
v8::internal::FLAG_wasm_max_table_size = max_table_flag_value;
return 0;
}
......@@ -13,14 +13,15 @@
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/wasm/wasm-module.h"
#include "test/common/wasm/flag-utils.h"
#include "test/common/wasm/wasm-module-runner.h"
#include "test/fuzzer/fuzzer-support.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
unsigned int max_mem_flag_value = v8::internal::FLAG_wasm_max_mem_pages;
unsigned int max_table_flag_value = v8::internal::FLAG_wasm_max_table_size;
v8::internal::FLAG_wasm_max_mem_pages = 32;
v8::internal::FLAG_wasm_max_table_size = 100;
v8::internal::FlagScope<uint32_t> max_mem_flag_scope(
&v8::internal::FLAG_wasm_max_mem_pages, 32);
v8::internal::FlagScope<uint32_t> max_table_size_scope(
&v8::internal::FLAG_wasm_max_table_size, 100);
v8_fuzzer::FuzzerSupport* support = v8_fuzzer::FuzzerSupport::Get();
v8::Isolate* isolate = support->GetIsolate();
v8::internal::Isolate* i_isolate =
......@@ -38,7 +39,5 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::internal::wasm::testing::SetupIsolateForWasmModule(i_isolate);
v8::internal::wasm::testing::CompileAndRunWasmModule(i_isolate, data,
data + size);
v8::internal::FLAG_wasm_max_mem_pages = max_mem_flag_value;
v8::internal::FLAG_wasm_max_table_size = max_table_flag_value;
return 0;
}
......@@ -835,7 +835,7 @@ TEST_F(WasmSignatureDecodeTest, TooManyParams) {
TEST_F(WasmSignatureDecodeTest, TooManyReturns) {
for (int i = 0; i < 2; i++) {
EnableFlagScope flag_scope(&FLAG_experimental_wasm_mv, i != 0);
FlagScope<bool> flag_scope(&FLAG_experimental_wasm_mv, i != 0);
const int max_return_count = static_cast<int>(
FLAG_experimental_wasm_mv ? kV8MaxWasmFunctionMultiReturns
: kV8MaxWasmFunctionReturns);
......
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