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

Unified Diff: test/cctest/wasm/test-wasm-function-name-table.cc

Issue 1916403002: [wasm] Add tests for function name encoding (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-offset-table-3
Patch Set: rebase Created 4 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-wasm-function-name-table.cc
diff --git a/test/cctest/wasm/test-wasm-function-name-table.cc b/test/cctest/wasm/test-wasm-function-name-table.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ce1b07ff20f50b6863b8f39d58d0a5b7ae2946e
--- /dev/null
+++ b/test/cctest/wasm/test-wasm-function-name-table.cc
@@ -0,0 +1,94 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/wasm/wasm-function-name-table.h"
+#include "src/wasm/wasm-module.h"
+#include "src/wasm/wasm-opcodes.h"
+
+#include "test/cctest/cctest.h"
+#include "test/cctest/compiler/value-helper.h"
+#include "test/cctest/wasm/test-signatures.h"
+#include "test/cctest/wasm/wasm-run-utils.h"
+
+using namespace v8::base;
+using namespace v8::internal;
+using namespace v8::internal::compiler;
+using namespace v8::internal::wasm;
+
+namespace {
+
+#define CHECK_STREQ(exp, found) \
+ do { \
+ Vector<const char> exp_ = (exp); \
+ Vector<const char> found_ = (found); \
+ if (V8_UNLIKELY(exp_.length() != found_.length() || \
+ memcmp(exp_.start(), found_.start(), exp_.length()))) { \
+ V8_Fatal(__FILE__, __LINE__, \
+ "Check failed: (%s) != (%s) ('%.*s' vs '%.*s').", #exp, #found, \
+ exp_.length(), exp_.start(), found_.length(), found_.start()); \
+ } \
+ } while (0)
+
+void testFunctionNameTable(Vector<Vector<const char>> names) {
+ TestSignatures sigs;
+ TestingModule module;
+
+ HandleAndZoneScope scope;
+ uint32_t func_index = 0;
+ for (Vector<const char> name : names) {
+ Vector<const char> real_name =
+ name.length() == 1 && name.first() == '?' ? Vector<const char>() : name;
+ WasmFunctionCompiler comp1(sigs.v_v(), &module, real_name);
+ BUILD(comp1, WASM_UNREACHABLE);
+ uint32_t wasm_index = comp1.CompileAndAdd();
+ CHECK_EQ(func_index, wasm_index);
+ ++func_index;
+ }
+
+ Handle<JSObject> wasm_obj = module.Instantiate();
titzer 2016/04/28 11:38:22 Ok, I see now. The implication of using Instantia
Clemens Hammacher 2016/04/28 14:34:56 Yep, you are right. It was very easy to refactor t
+ CHECK(!wasm_obj.is_null());
+
+ func_index = 0;
+ for (Vector<const char> name : names) {
+ Handle<Object> string_obj = wasm::GetWasmFunctionName(wasm_obj, func_index);
+ CHECK(!string_obj.is_null());
+ CHECK(string_obj->IsString());
+ Handle<String> string = Handle<String>::cast(string_obj);
+ CHECK(string->IsUtf8EqualTo(name));
+ ++func_index;
+ }
+}
+
+#define TEST_CSTR_FUNNAMES(...) \
titzer 2016/04/28 11:38:22 You could probably do this with a helper function,
Clemens Hammacher 2016/04/28 14:34:56 Done.
+ do { \
+ std::vector<Vector<const char>> names_vec; \
+ const char *names_cstr[] = {__VA_ARGS__}; \
+ for (const char **namep = names_cstr, \
+ **endp = namep + arraysize(names_cstr); \
+ namep != endp; ++namep) \
+ names_vec.push_back(CStrVector(*namep)); \
+ testFunctionNameTable(Vector<Vector<const char>>( \
+ names_vec.data(), static_cast<int>(names_vec.size()))); \
+ } while (0)
+
+} // namespace
+
+TEST(NoFunctions) { testFunctionNameTable(Vector<Vector<const char>>()); }
+TEST(OneFunctions) { TEST_CSTR_FUNNAMES("foo"); }
+TEST(ThreeFunctions) { TEST_CSTR_FUNNAMES("foo", "bar", "baz"); }
+TEST(OneUnnamedFunction) { TEST_CSTR_FUNNAMES(""); }
+TEST(UnnamedFirstFunction) { TEST_CSTR_FUNNAMES("", "bar", "baz"); }
+TEST(UnnamedLastFunction) { TEST_CSTR_FUNNAMES("bar", "baz", ""); }
+TEST(ThreeUnnamedFunctions) { TEST_CSTR_FUNNAMES("", "", ""); }
+TEST(UTF8Names) { TEST_CSTR_FUNNAMES("↱fun↰", "↺", "alpha:α beta:β"); }
+
+TEST(NonNullTerminatedNames) {
+ const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
+ Vector<const char> names[] = {
+ Vector<const char>(alphabet + 3, 6), // Four non-null-terminated names.
+ Vector<const char>(alphabet + 4, 2), // -
+ Vector<const char>(alphabet + 3, 0), // -
+ Vector<const char>(alphabet + 15, 5)};
+ testFunctionNameTable(ArrayVector(names));
+}
« no previous file with comments | « test/cctest/cctest.gyp ('k') | test/cctest/wasm/wasm-run-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698