diff options
author | nlewycky <nicholas@mxc.ca> | 2019-07-17 15:51:33 -0700 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2019-07-17 15:51:33 -0700 |
commit | 00d1a725567e5879e5c6f131c0576ef16fc9f5c6 (patch) | |
tree | 0417ff160c1654683796deb307cce31f78183dd5 /src/test-literal.cc | |
parent | 3f2ba0f3bd2c829a57929a23c0cd08157b66cd61 (diff) | |
download | wabt-00d1a725567e5879e5c6f131c0576ef16fc9f5c6.tar.gz wabt-00d1a725567e5879e5c6f131c0576ef16fc9f5c6.tar.bz2 wabt-00d1a725567e5879e5c6f131c0576ef16fc9f5c6.zip |
Add spec test support for V128. (#1110)
* Add spec test support for V128.
* This algorithm, however simple, produces the digits in reverse order. Remember to reverse them again before printing.
* Correct order of the quads of the v128.
Given (v128.const i32x4 0x01020304 0x05060708 0x090a0b0c 0x0d0e0f00), the wabt v128 struct will contain 0x01020304 in v128_bits.v[0]. If a wasm program uses v128.store to store this constant then loads each byte with i32.load8_u, the wabt interpreter produces the order 04 03 02 01, 08 07 06 05, 0c 0b 0a 09, 00 0f 0e 0d.
* Add a parser for v128 and implement support in spectest-interp.
* Move WriteUint128 to literal.cc, add tests.
Rewrite so as to not use string streams. Roll repeated code into a loop.
Rename functions to comply with style guide, use anonymous namespace.
* Now that v128 has operator==, we can use it here.
* In a spectest with a binary module, use the same features for that module as for the outer spectest.
Diffstat (limited to 'src/test-literal.cc')
-rw-r--r-- | src/test-literal.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/test-literal.cc b/src/test-literal.cc index 9e38114b..6303bc90 100644 --- a/src/test-literal.cc +++ b/src/test-literal.cc @@ -14,6 +14,7 @@ * limitations under the License. */ +#include <cassert> #include <cstdio> #include <thread> #include <vector> @@ -86,6 +87,14 @@ void AssertInt64Equals(uint64_t expected, AssertIntEquals(expected, s, ParseInt64, parse_type); } +void AssertUint128Equals(v128 expected, + const char* s) { + const char* const end = s + strlen(s); + v128 actual; + ASSERT_EQ(Result::Ok, ParseUint128(s, end, &actual)) << s; + ASSERT_EQ(expected, actual); +} + void AssertInt8Fails(const char* s) { const char* const end = s + strlen(s); uint8_t actual; @@ -141,6 +150,11 @@ void AssertUint64Fails(const char* s) { ASSERT_EQ(Result::Error, ParseUint64(s, s + strlen(s), &actual_bits)) << s; } +void AssertUint128Fails(const char* s) { + v128 actual; + ASSERT_EQ(Result::Error, ParseUint128(s, s + strlen(s), &actual)) << s; +} + void AssertHexFloatEquals(uint32_t expected_bits, const char* s) { uint32_t actual_bits; ASSERT_EQ(Result::Ok, @@ -411,6 +425,23 @@ TEST(ParseUint64, Overflow) { AssertUint64Fails("10000000000000000000000000000000000000000"); } +TEST(ParseUint128, Basic) { + AssertUint128Equals({0, 0, 0, 0}, "0"); + AssertUint128Equals({1, 0, 0, 0}, "1"); + AssertUint128Equals({0x100f0e0d, 0x0c0b0a09, 0x08070605, 0x04030201}, + "5332529520247008778714484145835150861"); + AssertUint128Equals({0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}, + "340282366920938463463374607431768211455"); + AssertUint128Equals({0, 0, 1, 0}, "18446744073709551616"); +} + +TEST(ParseUint128, Invalid) { + AssertUint128Fails(""); + AssertUint128Fails("-1"); + AssertUint128Fails("340282366920938463463374607431768211456"); + AssertUint128Fails("123a456"); +} + TEST(ParseFloat, NonCanonical) { AssertHexFloatEquals(0x3f800000, "0x00000000000000000000001.0p0"); AssertHexFloatEquals(0x3f800000, "0x1.00000000000000000000000p0"); @@ -766,3 +797,43 @@ TEST(ParseDouble, RoundingSpec) { AssertHexDoubleEquals(test.output, test.input); } } + +void AssertWriteUint128Equals(const v128& value, const std::string& expected) { + assert(expected.length() < 128); + char buffer[128]; + WriteUint128(buffer, 128, value); + std::string actual(buffer, buffer + expected.length()); + ASSERT_EQ(expected, actual); + ASSERT_EQ(buffer[expected.length()], '\0'); +} + +TEST(WriteUint128, Basic) { + AssertWriteUint128Equals({0, 0, 0, 0}, "0"); + AssertWriteUint128Equals({1, 0, 0, 0}, "1"); + AssertWriteUint128Equals({0x100f0e0d, 0x0c0b0a09, 0x08070605, 0x04030201}, + "5332529520247008778714484145835150861"); + AssertWriteUint128Equals({0x00112233, 0x44556677, 0x8899aabb, 0xccddeeff}, + "272314856204801878456120017448021860915"); + AssertWriteUint128Equals({0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}, + "340282366920938463463374607431768211455"); + AssertWriteUint128Equals({0, 0, 1, 0}, "18446744073709551616"); +} + +TEST(WriteUint128, BufferTooSmall) { + { + char buffer[20]; + WriteUint128(buffer, 20, + {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}); + ASSERT_EQ(buffer[19], '\0'); + std::string actual(buffer, buffer + 19); + ASSERT_EQ("3402823669209384634", actual); + } + + { + char buffer[3]; + WriteUint128(buffer, 3, {123, 0, 0, 0}); + ASSERT_EQ(buffer[0], '1'); + ASSERT_EQ(buffer[1], '2'); + ASSERT_EQ(buffer[2], '\0'); + } +} |