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

Side by Side 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, 7 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project 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 #include "src/wasm/wasm-function-name-table.h"
6 #include "src/wasm/wasm-module.h"
7 #include "src/wasm/wasm-opcodes.h"
8
9 #include "test/cctest/cctest.h"
10 #include "test/cctest/compiler/value-helper.h"
11 #include "test/cctest/wasm/test-signatures.h"
12 #include "test/cctest/wasm/wasm-run-utils.h"
13
14 using namespace v8::base;
15 using namespace v8::internal;
16 using namespace v8::internal::compiler;
17 using namespace v8::internal::wasm;
18
19 namespace {
20
21 #define CHECK_STREQ(exp, found) \
22 do { \
23 Vector<const char> exp_ = (exp); \
24 Vector<const char> found_ = (found); \
25 if (V8_UNLIKELY(exp_.length() != found_.length() || \
26 memcmp(exp_.start(), found_.start(), exp_.length()))) { \
27 V8_Fatal(__FILE__, __LINE__, \
28 "Check failed: (%s) != (%s) ('%.*s' vs '%.*s').", #exp, #found, \
29 exp_.length(), exp_.start(), found_.length(), found_.start()); \
30 } \
31 } while (0)
32
33 void testFunctionNameTable(Vector<Vector<const char>> names) {
34 TestSignatures sigs;
35 TestingModule module;
36
37 HandleAndZoneScope scope;
38 uint32_t func_index = 0;
39 for (Vector<const char> name : names) {
40 Vector<const char> real_name =
41 name.length() == 1 && name.first() == '?' ? Vector<const char>() : name;
42 WasmFunctionCompiler comp1(sigs.v_v(), &module, real_name);
43 BUILD(comp1, WASM_UNREACHABLE);
44 uint32_t wasm_index = comp1.CompileAndAdd();
45 CHECK_EQ(func_index, wasm_index);
46 ++func_index;
47 }
48
49 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
50 CHECK(!wasm_obj.is_null());
51
52 func_index = 0;
53 for (Vector<const char> name : names) {
54 Handle<Object> string_obj = wasm::GetWasmFunctionName(wasm_obj, func_index);
55 CHECK(!string_obj.is_null());
56 CHECK(string_obj->IsString());
57 Handle<String> string = Handle<String>::cast(string_obj);
58 CHECK(string->IsUtf8EqualTo(name));
59 ++func_index;
60 }
61 }
62
63 #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.
64 do { \
65 std::vector<Vector<const char>> names_vec; \
66 const char *names_cstr[] = {__VA_ARGS__}; \
67 for (const char **namep = names_cstr, \
68 **endp = namep + arraysize(names_cstr); \
69 namep != endp; ++namep) \
70 names_vec.push_back(CStrVector(*namep)); \
71 testFunctionNameTable(Vector<Vector<const char>>( \
72 names_vec.data(), static_cast<int>(names_vec.size()))); \
73 } while (0)
74
75 } // namespace
76
77 TEST(NoFunctions) { testFunctionNameTable(Vector<Vector<const char>>()); }
78 TEST(OneFunctions) { TEST_CSTR_FUNNAMES("foo"); }
79 TEST(ThreeFunctions) { TEST_CSTR_FUNNAMES("foo", "bar", "baz"); }
80 TEST(OneUnnamedFunction) { TEST_CSTR_FUNNAMES(""); }
81 TEST(UnnamedFirstFunction) { TEST_CSTR_FUNNAMES("", "bar", "baz"); }
82 TEST(UnnamedLastFunction) { TEST_CSTR_FUNNAMES("bar", "baz", ""); }
83 TEST(ThreeUnnamedFunctions) { TEST_CSTR_FUNNAMES("", "", ""); }
84 TEST(UTF8Names) { TEST_CSTR_FUNNAMES("↱fun↰", "↺", "alpha:α beta:β"); }
85
86 TEST(NonNullTerminatedNames) {
87 const char *alphabet = "abcdefghijklmnopqrstuvwxyz";
88 Vector<const char> names[] = {
89 Vector<const char>(alphabet + 3, 6), // Four non-null-terminated names.
90 Vector<const char>(alphabet + 4, 2), // -
91 Vector<const char>(alphabet + 3, 0), // -
92 Vector<const char>(alphabet + 15, 5)};
93 testFunctionNameTable(ArrayVector(names));
94 }
OLDNEW
« 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