Skip to content

Commit

Permalink
[lldb][NFC] Add more test for builtin formats
Browse files Browse the repository at this point in the history
Reland 90c1af1 . This changes the char format
tests which were printing the pointer value of the C-string instead of its
contents, so this test failed on other machines. Now they just print the
bytes in a uint128_t.

Original commit description:

The previous tests apparently missed a few code branches in DumpDataExtractor
code. Also renames the 'test_instruction' which had the same name as another
test (and Python therefore ignored the test entirely).
  • Loading branch information
Teemperor committed Jun 22, 2020
1 parent de65b35 commit 7960837
Showing 1 changed file with 42 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def test(self):
self.assertIn("= 0\n", self.getFormatted("float", "0"))
self.assertIn("= 2\n", self.getFormatted("float", "0x40000000"))
self.assertIn("= NaN\n", self.getFormatted("float", "-1"))
# Checks the float16 code.
self.assertIn("= 2\n", self.getFormatted("float", "(__UINT16_TYPE__)0x4000"))
self.assertIn("= error: unsupported byte size (1) for float format\n", self.getFormatted("float", "'a'"))

# enumeration
self.assertIn("= 0\n", self.getFormatted("enumeration", "0"))
Expand All @@ -59,6 +62,13 @@ def test(self):

# octal
self.assertIn("= 04553207\n", self.getFormatted("octal", "1234567"))
self.assertIn("= 0221505317046536757\n", self.getFormatted("octal", "(__uint128_t)0x123456789ABDEFull"))

# complex float
self.assertIn("= error: unsupported byte size (1) for complex float format\n", self.getFormatted("complex float", "'a'"))

# complex integer
self.assertIn("= error: unsupported byte size (1) for complex integer format\n", self.getFormatted("complex integer", "'a'"))

# hex
self.assertIn("= 0x00abc123\n", self.getFormatted("hex", "0xABC123"))
Expand All @@ -79,28 +89,33 @@ def test(self):
self.assertIn(" = 0b10010001101000101011001111000\n", self.getFormatted("binary", "(__uint128_t)0x12345678ll"))

# Different character arrays.
# FIXME: Passing a 'const char *' will ignore any given format,
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("character array", "cstring"))
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("character", "cstring"))
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("c-string", "cstring"))
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("printable character", "cstring"))
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("OSType", "cstring"))
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("unicode8", "cstring"))

self.assertIn('= \\0\\0\\0\\0\\0\\0\\0\\0\n', self.getFormatted("character array", "(__UINT64_TYPE__)0"))
self.assertIn('= \\0\\0\\0\\0\\0\\0\\0\\0\n', self.getFormatted("character", "(__UINT64_TYPE__)0"))
self.assertIn('=\n', self.getFormatted("c-string", "(__UINT64_TYPE__)0"))
self.assertIn('= ........\n', self.getFormatted("printable character", "(__UINT64_TYPE__)0"))
self.assertIn('= \'\\0\\0\\0\\0\\0\\0\\0\\0\'\n', self.getFormatted("OSType", "(__UINT64_TYPE__)0"))
# FIXME: This seems wrong.
self.assertIn('= 0x0000000000000000\n', self.getFormatted("unicode8", "(__UINT64_TYPE__)0"))

self.assertIn('= xV4\\x12\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\n', self.getFormatted("character array", "(__uint128_t)0x12345678ll"))
self.assertIn('= xV4\\x12\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\n', self.getFormatted("character", "(__uint128_t)0x12345678ll"))
self.assertIn('=\n', self.getFormatted("c-string", "(__uint128_t)0x12345678ll"))
self.assertIn('= xV4.............\n', self.getFormatted("printable character", "(__uint128_t)0x12345678ll"))
self.assertIn('= 0x00000000000000000000000012345678\n', self.getFormatted("OSType", "(__uint128_t)0x12345678ll"))
# FIXME: This seems wrong.
self.assertIn('= 0x00000000000000000000000012345678\n', self.getFormatted("unicode8", "(__uint128_t)0x12345678ll"))

# Build a uint128_t that contains a series of characters in each byte.
# First 8 byte of the uint128_t.
cstring_chars1 = " \a\b\f\n\r\t\v"
# Last 8 byte of the uint128_t.
cstring_chars2 = "AZaz09\0\0"

# Build a uint128_t value with the hex encoded characters.
string_expr = "((__uint128_t)0x"
for c in cstring_chars1:
string_expr += format(ord(c), "x").zfill(2)
string_expr += "ull << 64) | (__uint128_t)0x"
for c in cstring_chars2:
string_expr += format(ord(c), "x").zfill(2)
string_expr += "ull"

# Try to print that uint128_t with the different char formatters.
self.assertIn('= \\0\\090zaZA\\v\\t\\r\\n\\f\\b\\a \n', self.getFormatted("character array", string_expr))
self.assertIn('= \\0\\090zaZA\\v\\t\\r\\n\\f\\b\\a \n', self.getFormatted("character", string_expr))
self.assertIn('= ..90zaZA....... \n', self.getFormatted("printable character", string_expr))
self.assertIn('= 0x2007080c0a0d090b415a617a30390000\n', self.getFormatted("OSType", string_expr))
# FIXME: This should probably print the characters in the uint128_t.
self.assertIn('= 0x2007080c0a0d090b415a617a30390000\n', self.getFormatted("unicode8", string_expr))

# bytes
self.assertIn('= " \\U0000001b\\a\\b\\f\\n\\r\\t\\vaA09"\n', self.getFormatted("bytes", "cstring"))
Expand Down Expand Up @@ -137,17 +152,24 @@ def test(self):
# There is not int128_t[] style, so this only tests uint128_t[].
self.assertIn("= {0x00000000000000000123456789abcdef}\n", self.getFormatted("uint128_t[]", "__uint128_t i = 0x123456789ABCDEF; i"))

# Different fixed-width float type arrays.
self.assertIn("{2 2}\n", self.getFormatted("float16[]", "0x40004000"))
self.assertIn("{2 2}\n", self.getFormatted("float32[]", "0x4000000040000000ll"))
self.assertIn("{2 0}\n", self.getFormatted("float64[]", "__uint128_t i = 0x4000000000000000ll; i"))

# Invalid format string
self.expect("expr --format invalid_format_string -- 1", error=True,
substrs=["error: Invalid format character or name 'invalid_format_string'. Valid values are:"])

# Extends to host target pointer width.
@skipIf(archs=no_match(['x86_64']))
@no_debug_info_test
def test_instruction(self):
def test_pointer(self):
# pointer
self.assertIn("= 0x000000000012d687\n", self.getFormatted("pointer", "1234567"))
self.assertIn("= 0x0000000000000000\n", self.getFormatted("pointer", "0"))
# FIXME: Just ignores the input value as it's not pointer sized.
self.assertIn("= 0x0000000000000000\n", self.getFormatted("pointer", "'a'"))

# Depends on the host target for decoding.
@skipIf(archs=no_match(['x86_64']))
Expand Down

0 comments on commit 7960837

Please sign in to comment.