Index: test/unittests/wasm/module-decoder-unittest.cc |
diff --git a/test/unittests/wasm/module-decoder-unittest.cc b/test/unittests/wasm/module-decoder-unittest.cc |
index f4ae74b6245008af7412bcf125962cf70391d8f0..10e23300e5c7ca1b4f587f16d46ddcbe75e17c07 100644 |
--- a/test/unittests/wasm/module-decoder-unittest.cc |
+++ b/test/unittests/wasm/module-decoder-unittest.cc |
@@ -39,6 +39,38 @@ namespace wasm { |
#define EMPTY_FUNCTION_BODIES_SECTION SECTION(FUNCTION_BODIES, 1), 0 |
#define EMPTY_NAMES_SECTION SECTION(NAMES, 1), 0 |
+#define X1(...) __VA_ARGS__ |
+#define X2(...) __VA_ARGS__, __VA_ARGS__ |
+#define X3(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ |
+#define X4(...) __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ |
+ |
+#define ONE_EMPTY_FUNCTION WASM_SECTION_FUNCTION_SIGNATURES, 1 + 1 * 1, 1, X1(0) |
+ |
+#define TWO_EMPTY_FUNCTIONS \ |
+ WASM_SECTION_FUNCTION_SIGNATURES, 1 + 2 * 1, 2, X2(0) |
+ |
+#define THREE_EMPTY_FUNCTIONS \ |
+ WASM_SECTION_FUNCTION_SIGNATURES, 1 + 3 * 1, 3, X3(0) |
+ |
+#define FOUR_EMPTY_FUNCTIONS \ |
+ WASM_SECTION_FUNCTION_SIGNATURES, 1 + 4 * 1, 4, X4(0) |
+ |
+#define ONE_EMPTY_BODY \ |
+ WASM_SECTION_FUNCTION_BODIES, 1 + 1 * (1 + SIZEOF_EMPTY_BODY), 1, \ |
+ X1(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+ |
+#define TWO_EMPTY_BODIES \ |
+ WASM_SECTION_FUNCTION_BODIES, 1 + 2 * (1 + SIZEOF_EMPTY_BODY), 2, \ |
+ X2(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+ |
+#define THREE_EMPTY_BODIES \ |
+ WASM_SECTION_FUNCTION_BODIES, 1 + 3 * (1 + SIZEOF_EMPTY_BODY), 3, \ |
+ X3(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+ |
+#define FOUR_EMPTY_BODIES \ |
+ WASM_SECTION_FUNCTION_BODIES, 1 + 4 * (1 + SIZEOF_EMPTY_BODY), 4, \ |
+ X4(SIZEOF_EMPTY_BODY, EMPTY_BODY) |
+ |
#define SIGNATURES_SECTION_VOID_VOID \ |
SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v), 1, SIG_ENTRY_v_v |
@@ -321,163 +353,6 @@ TEST_F(WasmModuleVerifyTest, MultipleSignatures) { |
EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); |
} |
-TEST_F(WasmModuleVerifyTest, FunctionWithoutSig) { |
bradnelson
2016/05/25 14:51:23
Why drop these, as they're brittle?
|
- static const byte data[] = { |
- SECTION(OLD_FUNCTIONS, 25), 1, |
- // func#0 ------------------------------------------------------ |
- SIG_INDEX(0), // signature index |
- NO_NAME, // name length |
- U32_LE(0), // code start offset |
- U32_LE(0), // code end offset |
- U16_LE(899), // local int32 count |
- U16_LE(799), // local int64 count |
- U16_LE(699), // local float32 count |
- U16_LE(599), // local float64 count |
- 0, // exported |
- 0 // external |
- }; |
- |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
- EXPECT_FALSE(result.ok()); |
- if (result.val) delete result.val; |
-} |
- |
-TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { |
- const int kCodeStartOffset = 41; |
- const int kCodeEndOffset = kCodeStartOffset + 1; |
- |
- static const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- // func#0 ------------------------------------------------------ |
- SECTION(OLD_FUNCTIONS, 10), 1, kDeclFunctionExport | kDeclFunctionName, |
- SIG_INDEX(0), // signature index |
- NAME_LENGTH(2), 'h', 'i', // name |
- 1, 0, // size |
- kExprNop, |
- }; |
- |
- { |
- // Should decode to exactly one function. |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
- EXPECT_OK(result); |
- EXPECT_EQ(0, result.val->globals.size()); |
- EXPECT_EQ(1, result.val->signatures.size()); |
- EXPECT_EQ(1, result.val->functions.size()); |
- EXPECT_EQ(0, result.val->data_segments.size()); |
- EXPECT_EQ(0, result.val->function_table.size()); |
- |
- const WasmFunction* function = &result.val->functions.back(); |
- |
- EXPECT_EQ(37, function->name_offset); |
- EXPECT_EQ(2, function->name_length); |
- EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
- EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
- |
- EXPECT_TRUE(function->exported); |
- |
- if (result.val) delete result.val; |
- } |
- |
- EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); |
-} |
- |
-TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { |
- static const byte kCodeStartOffset = 38; |
- static const byte kCodeEndOffset = kCodeStartOffset + 1; |
- |
- static const byte data[] = { |
- SIGNATURES_SECTION_VOID_VOID, // -- |
- SECTION(OLD_FUNCTIONS, 7), 1, |
- // func#0 ------------------------------------------------------ |
- 0, // no name, no locals |
- 0, 0, // signature index |
- 1, 0, // body size |
- kExprNop // body |
- }; |
- |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
- EXPECT_OK(result); |
- EXPECT_EQ(1, result.val->functions.size()); |
- const WasmFunction* function = &result.val->functions.back(); |
- |
- EXPECT_EQ(0, function->name_length); |
- EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
- EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
- |
- EXPECT_FALSE(function->exported); |
- |
- if (result.val) delete result.val; |
-} |
- |
-TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { |
- static const byte kNameOffset = 49; |
- static const byte kCodeStartOffset = 53; |
- static const byte kCodeEndOffset = kCodeStartOffset + 3; |
- static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22; |
- |
- static const byte data[] = { |
- // global#0 -------------------------------------------------- |
- SECTION(GLOBALS, 4), 1, |
- 0, // name length |
- kMemU8, // memory type |
- 0, // exported |
- // sig#0 ----------------------------------------------------- |
- SIGNATURES_SECTION_VOID_VOID, |
- // func#0 ---------------------------------------------------- |
- SECTION(OLD_FUNCTIONS, 12), 1, |
- kDeclFunctionName, // -- |
- SIG_INDEX(0), // signature index |
- 2, 'h', 'i', // name |
- 3, 0, // body size |
- kExprNop, // func#0 body |
- kExprNop, // func#0 body |
- kExprNop, // func#0 body |
- // memory section -------------------------------------------- |
- SECTION(MEMORY, 3), 28, 28, 1, |
- // segment#0 ------------------------------------------------- |
- SECTION(DATA_SEGMENTS, 10), 1, |
- U32V_3(0x8b3ae), // dest addr |
- U32V_1(5), // source size |
- 0, 1, 2, 3, 4, // data bytes |
- // rest ------------------------------------------------------ |
- SECTION(END, 0), |
- }; |
- |
- { |
- ModuleResult result = DecodeModule(data, data + arraysize(data)); |
- EXPECT_OK(result); |
- EXPECT_EQ(1, result.val->globals.size()); |
- EXPECT_EQ(1, result.val->functions.size()); |
- EXPECT_EQ(1, result.val->data_segments.size()); |
- |
- const WasmGlobal* global = &result.val->globals.back(); |
- |
- EXPECT_EQ(0, global->name_length); |
- EXPECT_EQ(MachineType::Uint8(), global->type); |
- EXPECT_EQ(0, global->offset); |
- EXPECT_FALSE(global->exported); |
- |
- const WasmFunction* function = &result.val->functions.back(); |
- |
- EXPECT_EQ(kNameOffset, function->name_offset); |
- EXPECT_EQ(2, function->name_length); |
- EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
- EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
- |
- EXPECT_FALSE(function->exported); |
- |
- const WasmDataSegment* segment = &result.val->data_segments.back(); |
- |
- EXPECT_EQ(0x8b3ae, segment->dest_addr); |
- EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); |
- EXPECT_EQ(5, segment->source_size); |
- EXPECT_TRUE(segment->init); |
- |
- if (result.val) delete result.val; |
- } |
-} |
- |
TEST_F(WasmModuleVerifyTest, OneDataSegment) { |
const byte kDataSegmentSourceOffset = 30; |
const byte data[] = { |
@@ -605,9 +480,8 @@ TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { |
static const byte data[] = { |
// sig#0 ------------------------------------------------------- |
SIGNATURES_SECTION_VOID_VOID, |
- // func#0 ------------------------------------------------------ |
- SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), 1, // -- |
- EMPTY_FUNCTION(0), |
+ // funcs ------------------------------------------------------ |
+ ONE_EMPTY_FUNCTION, |
// indirect table ---------------------------------------------- |
SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)}; |
@@ -629,12 +503,8 @@ TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
2, // -- |
SIG_ENTRY_v_v, // void -> void |
SIG_ENTRY_v_x(kLocalI32), // void -> i32 |
- // func#0 ------------------------------------------------------ |
- SECTION(OLD_FUNCTIONS, 1 + 4 * SIZEOF_EMPTY_FUNCTION), 4, // -- |
- EMPTY_FUNCTION(0), // -- |
- EMPTY_FUNCTION(1), // -- |
- EMPTY_FUNCTION(0), // -- |
- EMPTY_FUNCTION(1), // -- |
+ // funcs ------------------------------------------------------ |
+ FOUR_EMPTY_FUNCTIONS, |
// indirect table ---------------------------------------------- |
SECTION(FUNCTION_TABLE, 9), 8, |
U32V_1(0), // -- |
@@ -645,7 +515,7 @@ TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
U32V_1(1), // -- |
U32V_1(2), // -- |
U32V_1(3), // -- |
- }; |
+ FOUR_EMPTY_BODIES}; |
ModuleResult result = DecodeModule(data, data + arraysize(data)); |
EXPECT_OK(result); |
@@ -676,8 +546,7 @@ TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) { |
// sig#0 ------------------------------------------------------- |
SIGNATURES_SECTION_VOID_VOID, |
// functions --------------------------------------------------- |
- SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), 1, // -- |
- EMPTY_FUNCTION(0), |
+ ONE_EMPTY_FUNCTION, |
// indirect table ---------------------------------------------- |
SECTION(FUNCTION_TABLE, 3), 1, 1, 0, |
}; |
@@ -839,7 +708,6 @@ TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { |
EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); |
EXPECT_EQ(arraysize(data), function->code_end_offset); |
// TODO(titzer): verify encoding of local declarations |
- EXPECT_FALSE(function->exported); |
} |
if (result.val) delete result.val; |
@@ -1071,22 +939,24 @@ TEST_F(WasmModuleVerifyTest, ImportTable_off_end) { |
} |
TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { |
- static const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
- 1, |
- EMPTY_FUNCTION(0), |
- SECTION(EXPORT_TABLE, 1), |
- 0 // -- |
- }; |
- EXPECT_VERIFIES(data); |
+ static const byte data[] = {// signatures |
+ SIGNATURES_SECTION_VOID_VOID, ONE_EMPTY_FUNCTION, |
+ SECTION(EXPORT_TABLE, 1), |
+ 0, // -- |
+ ONE_EMPTY_BODY}; |
+ |
+ ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ EXPECT_OK(result); |
+ |
+ EXPECT_EQ(1, result.val->functions.size()); |
+ EXPECT_EQ(0, result.val->export_table.size()); |
+ |
+ if (result.val) delete result.val; |
} |
TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { |
static const byte data[] = { |
- SECTION(SIGNATURES, 1), 0, SECTION(OLD_FUNCTIONS, 1), 0, |
- SECTION(EXPORT_TABLE, 1), 0 // -- |
+ SECTION(SIGNATURES, 1), 0, SECTION(EXPORT_TABLE, 1), 0 // -- |
}; |
// TODO(titzer): current behavior treats empty functions section as missing. |
EXPECT_FAILURE(data); |
@@ -1105,85 +975,88 @@ TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { |
} |
TEST_F(WasmModuleVerifyTest, ExportTableOne) { |
- static const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
- 1, // functions |
- EMPTY_FUNCTION(0), // -- |
- SECTION(EXPORT_TABLE, 3), |
- 1, // exports |
- FUNC_INDEX(0), // -- |
- NO_NAME // -- |
- }; |
- EXPECT_VERIFIES(data); |
+ static const byte data[] = {// signatures |
+ SIGNATURES_SECTION_VOID_VOID, |
+ ONE_EMPTY_FUNCTION, |
+ SECTION(EXPORT_TABLE, 3), |
+ 1, // exports |
+ FUNC_INDEX(0), // -- |
+ NO_NAME, // -- |
+ ONE_EMPTY_BODY}; |
+ ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ EXPECT_OK(result); |
+ |
+ EXPECT_EQ(1, result.val->functions.size()); |
+ EXPECT_EQ(1, result.val->export_table.size()); |
+ |
+ if (result.val) delete result.val; |
} |
TEST_F(WasmModuleVerifyTest, ExportTableTwo) { |
- static const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
- 1, // functions |
- EMPTY_FUNCTION(0), // -- |
- SECTION(EXPORT_TABLE, 12), |
- 2, // exports |
- FUNC_INDEX(0), // -- |
- NAME_LENGTH(4), |
- 'n', |
- 'a', |
- 'm', |
- 'e', // -- |
- FUNC_INDEX(0), // -- |
- NAME_LENGTH(3), |
- 'n', |
- 'o', |
- 'm' // -- |
- }; |
- EXPECT_VERIFIES(data); |
+ static const byte data[] = {// signatures |
+ SIGNATURES_SECTION_VOID_VOID, |
+ ONE_EMPTY_FUNCTION, |
+ SECTION(EXPORT_TABLE, 12), |
+ 2, // exports |
+ FUNC_INDEX(0), // -- |
+ NAME_LENGTH(4), |
+ 'n', |
+ 'a', |
+ 'm', |
+ 'e', // -- |
+ FUNC_INDEX(0), // -- |
+ NAME_LENGTH(3), |
+ 'n', |
+ 'o', |
+ 'm', // -- |
+ ONE_EMPTY_BODY}; |
+ |
+ ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ EXPECT_OK(result); |
+ |
+ EXPECT_EQ(1, result.val->functions.size()); |
+ EXPECT_EQ(2, result.val->export_table.size()); |
+ |
+ if (result.val) delete result.val; |
} |
TEST_F(WasmModuleVerifyTest, ExportTableThree) { |
- static const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- SECTION(OLD_FUNCTIONS, 1 + 3 * SIZEOF_EMPTY_FUNCTION), |
- 3, // functions |
- EMPTY_FUNCTION(0), // -- |
- EMPTY_FUNCTION(0), // -- |
- EMPTY_FUNCTION(0), // -- |
- SECTION(EXPORT_TABLE, 10), |
- 3, // exports |
- FUNC_INDEX(0), // -- |
- NAME_LENGTH(1), |
- 'a', // -- |
- FUNC_INDEX(1), // -- |
- NAME_LENGTH(1), |
- 'b', // -- |
- FUNC_INDEX(2), // -- |
- NAME_LENGTH(1), |
- 'c' // -- |
- }; |
- EXPECT_VERIFIES(data); |
+ static const byte data[] = {// signatures |
+ SIGNATURES_SECTION_VOID_VOID, |
+ THREE_EMPTY_FUNCTIONS, |
+ SECTION(EXPORT_TABLE, 10), |
+ 3, // exports |
+ FUNC_INDEX(0), // -- |
+ NAME_LENGTH(1), |
+ 'a', // -- |
+ FUNC_INDEX(1), // -- |
+ NAME_LENGTH(1), |
+ 'b', // -- |
+ FUNC_INDEX(2), // -- |
+ NAME_LENGTH(1), |
+ 'c', // -- |
+ THREE_EMPTY_BODIES}; |
+ ModuleResult result = DecodeModule(data, data + arraysize(data)); |
+ EXPECT_OK(result); |
+ |
+ EXPECT_EQ(3, result.val->functions.size()); |
+ EXPECT_EQ(3, result.val->export_table.size()); |
+ |
+ if (result.val) delete result.val; |
} |
TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { |
for (int i = 0; i < 6; i++) { |
- const byte data[] = { |
- // signatures |
- SIGNATURES_SECTION_VOID_VOID, |
- SECTION(OLD_FUNCTIONS, 1 + 3 * SIZEOF_EMPTY_FUNCTION), |
- 3, // functions |
- EMPTY_FUNCTION(0), // -- |
- EMPTY_FUNCTION(0), // -- |
- EMPTY_FUNCTION(0), // -- |
- SECTION(EXPORT_TABLE, 5), |
- 1, // exports |
- FUNC_INDEX(i), // -- |
- NAME_LENGTH(2), |
- 'e', |
- 'x', // -- |
- }; |
+ const byte data[] = {// signatures |
+ SIGNATURES_SECTION_VOID_VOID, |
+ THREE_EMPTY_FUNCTIONS, |
+ SECTION(EXPORT_TABLE, 5), |
+ 1, // exports |
+ FUNC_INDEX(i), // -- |
+ NAME_LENGTH(2), |
+ 'e', |
+ 'x', // -- |
+ THREE_EMPTY_BODIES}; |
if (i < 3) { |
EXPECT_VERIFIES(data); |
@@ -1197,9 +1070,7 @@ TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { |
static const byte data[] = { |
// signatures |
SIGNATURES_SECTION_VOID_VOID, |
- SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
- 1, // functions |
- EMPTY_FUNCTION(0), // -- |
+ ONE_EMPTY_FUNCTION, |
SECTION(EXPORT_TABLE, 1 + 6), |
1, // exports |
FUNC_INDEX(0), // -- |