Skip to content

Commit

Permalink
Fix test cases for big-endian systems
Browse files Browse the repository at this point in the history
A number of test cases were failing on big-endian systems simply due to
byte order assumptions in the tests themselves, and no underlying bug
in LLDB.

These two test cases:
  tools/lldb-server/lldbgdbserverutils.py
  python_api/process/TestProcessAPI.py
actually check for big-endian target byte order, but contain Python errors
in the corresponding code paths.

These test cases:
  functionalities/data-formatter/data-formatter-python-synth/TestDataFormatterPythonSynth.py
  functionalities/data-formatter/data-formatter-smart-array/TestDataFormatterSmartArray.py
  functionalities/data-formatter/synthcapping/TestSyntheticCapping.py
  lang/cpp/frame-var-anon-unions/TestFrameVariableAnonymousUnions.py
  python_api/sbdata/TestSBData.py  (first change)
could be fixed to check for big-endian target byte order and update the
expected result strings accordingly.  For the two synthetic tests, I've
also updated the source to make sure the fake_a value is always nonzero
on both big- and little-endian platforms.

These test case:
  python_api/sbdata/TestSBData.py  (second change)
  functionalities/memory/cache/TestMemoryCache.py
simply accessed memory with the wrong size, which wasn't noticed on LE
but fails on BE.

Differential Revision: http://reviews.llvm.org/D18985

llvm-svn: 266315
  • Loading branch information
uweigand committed Apr 14, 2016
1 parent 91a2ad1 commit 7e8de59
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 75 deletions.
Expand Up @@ -44,6 +44,8 @@ def data_formatter_commands(self):

self.runCmd("run", RUN_SUCCEEDED)

process = self.dbg.GetSelectedTarget().GetProcess()

# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
Expand All @@ -62,64 +64,86 @@ def cleanup():

# print the f00_1 variable without a synth
self.expect("frame variable f00_1",
substrs = ['a = 0',
'b = 1',
'r = 33']);
substrs = ['a = 1',
'b = 2',
'r = 34']);

# now set up the synth
self.runCmd("script from fooSynthProvider import *")
self.runCmd("type synth add -l fooSynthProvider foo")
self.expect("type synthetic list foo", substrs=['fooSynthProvider'])

# note that the value of fake_a depends on target byte order
if process.GetByteOrder() == lldb.eByteOrderLittle:
fake_a_val = 0x02000000
else:
fake_a_val = 0x00000100

# check that we get the two real vars and the fake_a variables
self.expect("frame variable f00_1",
substrs = ['r = 33',
'fake_a = 16777216',
'a = 0']);
substrs = ['r = 34',
'fake_a = %d' % fake_a_val,
'a = 1']);

# check that we do not get the extra vars
self.expect("frame variable f00_1", matching=False,
substrs = ['b = 1']);
substrs = ['b = 2']);

# check access to members by name
self.expect('frame variable f00_1.fake_a',
substrs = ['16777216'])
substrs = ['%d' % fake_a_val])

# check access to members by index
self.expect('frame variable f00_1[1]',
substrs = ['16777216'])
substrs = ['%d' % fake_a_val])

# put synthetic children in summary in several combinations
self.runCmd("type summary add --summary-string \"fake_a=${svar.fake_a}\" foo")
self.expect('frame variable f00_1',
substrs = ['fake_a=16777216'])
substrs = ['fake_a=%d' % fake_a_val])
self.runCmd("type summary add --summary-string \"fake_a=${svar[1]}\" foo")
self.expect('frame variable f00_1',
substrs = ['fake_a=16777216'])
substrs = ['fake_a=%d' % fake_a_val])

# clear the summary
self.runCmd("type summary delete foo")

# check that the caching does not span beyond the stopoint
self.runCmd("n")

if process.GetByteOrder() == lldb.eByteOrderLittle:
fake_a_val = 0x02000000
else:
fake_a_val = 0x00000200

self.expect("frame variable f00_1",
substrs = ['r = 33',
'fake_a = 16777216',
'a = 1']);
substrs = ['r = 34',
'fake_a = %d' % fake_a_val,
'a = 2']);

# check that altering the object also alters fake_a
self.runCmd("expr f00_1.a = 280")

if process.GetByteOrder() == lldb.eByteOrderLittle:
fake_a_val = 0x02000001
else:
fake_a_val = 0x00011800

self.expect("frame variable f00_1",
substrs = ['r = 33',
'fake_a = 16777217',
substrs = ['r = 34',
'fake_a = %d' % fake_a_val,
'a = 280']);

# check that expanding a pointer does the right thing
if process.GetByteOrder() == lldb.eByteOrderLittle:
fake_a_val = 0x0d000000
else:
fake_a_val = 0x00000c00

self.expect("frame variable --ptr-depth 1 f00_ptr",
substrs = ['r = 45',
'fake_a = 218103808',
'a = 12'])
substrs = ['r = 45',
'fake_a = %d' % fake_a_val,
'a = 12'])

# now add a filter.. it should fail
self.expect("type filter add foo --child b --child j", error=True,
Expand All @@ -131,19 +155,19 @@ def cleanup():
'j = 17'])
self.expect("frame variable --ptr-depth 1 f00_ptr",
substrs = ['r = 45',
'fake_a = 218103808',
'fake_a = %d' % fake_a_val,
'a = 12'])

# now delete the synth and add the filter
self.runCmd("type synth delete foo")
self.runCmd("type filter add foo --child b --child j")

self.expect('frame variable f00_1',
substrs = ['b = 1',
'j = 17'])
substrs = ['b = 2',
'j = 18'])
self.expect("frame variable --ptr-depth 1 f00_ptr", matching=False,
substrs = ['r = 45',
'fake_a = 218103808',
'fake_a = %d' % fake_a_val,
'a = 12'])

# now add the synth and it should fail
Expand All @@ -164,11 +188,11 @@ def cleanup():
self.runCmd("type synth add -l fooSynthProvider foo")

self.expect('frame variable f00_1', matching=False,
substrs = ['b = 1',
'j = 17'])
substrs = ['b = 2',
'j = 18'])
self.expect("frame variable --ptr-depth 1 f00_ptr",
substrs = ['r = 45',
'fake_a = 218103808',
'fake_a = %d' % fake_a_val,
'a = 12'])

# check the listing
Expand All @@ -185,8 +209,8 @@ def cleanup():

self.expect("frame variable f00_1",
substrs = ['a = 280',
'b = 1',
'j = 17']);
'b = 2',
'j = 18']);

self.expect("frame variable f00_1", matching=False,
substrs = ['fake_a = '])
Expand Down
Expand Up @@ -48,7 +48,7 @@ struct wrapint

int main()
{
foo f00_1(0);
foo f00_1(1);
foo *f00_ptr = new foo(12);

f00_1.a++; // Set break point at this line.
Expand Down
Expand Up @@ -36,6 +36,8 @@ def data_formatter_commands(self):

self.runCmd("run", RUN_SUCCEEDED)

process = self.dbg.GetSelectedTarget().GetProcess()

# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
Expand Down Expand Up @@ -311,39 +313,81 @@ def cleanup():
self.runCmd("type summary add --summary-string \"arr = ${var%y}\" \"float [7]\"")
self.runCmd("type summary add --summary-string \"arr = ${var%y}\" \"int [5]\"")

self.expect("frame variable flarr",
substrs = ['flarr = arr =',
'00 00 9d 42,00 80 9a 42,00 00 9c 42,00 40 98 42,00 80 99 42,00 c0 99 42,00 00 9a 42'])

self.expect("frame variable other.flarr",
substrs = ['flarr = arr =',
'00 00 cc 41,00 00 ca 41,00 00 c9 41,00 00 d6 41,00 00 db 41,00 00 dc 41,00 00 d1 41'])

self.expect("frame variable intarr",
substrs = ['intarr = arr =',
'01 00 00 00,01 00 00 00,02 00 00 00,03 00 00 00,05 00 00 00'])

self.expect("frame variable other.intarr",
substrs = ['intarr = arr = ',
'09 00 00 00,08 00 00 00,07 00 00 00,06 00 00 00,05 00 00 00'])
if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable flarr",
substrs = ['flarr = arr =',
'00 00 9d 42,00 80 9a 42,00 00 9c 42,00 40 98 42,00 80 99 42,00 c0 99 42,00 00 9a 42'])
else:
self.expect("frame variable flarr",
substrs = ['flarr = arr =',
'42 9d 00 00,42 9a 80 00,42 9c 00 00,42 98 40 00,42 99 80 00,42 99 c0 00,42 9a 00 00'])

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable other.flarr",
substrs = ['flarr = arr =',
'00 00 cc 41,00 00 ca 41,00 00 c9 41,00 00 d6 41,00 00 db 41,00 00 dc 41,00 00 d1 41'])
else:
self.expect("frame variable other.flarr",
substrs = ['flarr = arr =',
'41 cc 00 00,41 ca 00 00,41 c9 00 00,41 d6 00 00,41 db 00 00,41 dc 00 00,41 d1 00 00'])

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable intarr",
substrs = ['intarr = arr =',
'01 00 00 00,01 00 00 00,02 00 00 00,03 00 00 00,05 00 00 00'])
else:
self.expect("frame variable intarr",
substrs = ['intarr = arr =',
'00 00 00 01,00 00 00 01,00 00 00 02,00 00 00 03,00 00 00 05'])

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable other.intarr",
substrs = ['intarr = arr = ',
'09 00 00 00,08 00 00 00,07 00 00 00,06 00 00 00,05 00 00 00'])
else:
self.expect("frame variable other.intarr",
substrs = ['intarr = arr = ',
'00 00 00 09,00 00 00 08,00 00 00 07,00 00 00 06,00 00 00 05'])

self.runCmd("type summary add --summary-string \"arr = ${var%Y}\" \"float [7]\"")
self.runCmd("type summary add --summary-string \"arr = ${var%Y}\" \"int [5]\"")

self.expect("frame variable flarr",
substrs = ['flarr = arr =',
'00 00 9d 42 ...B,00 80 9a 42 ...B,00 00 9c 42 ...B,00 40 98 42 .@.B,00 80 99 42 ...B,00 c0 99 42 ...B,00 00 9a 42 ...B'])

self.expect("frame variable other.flarr",
substrs = ['flarr = arr =',
'00 00 cc 41 ...A,00 00 ca 41 ...A,00 00 c9 41 ...A,00 00 d6 41 ...A,00 00 db 41 ...A,00 00 dc 41 ...A,00 00 d1 41 ...A'])

self.expect("frame variable intarr",
substrs = ['intarr = arr =',
'....,01 00 00 00',
'....,05 00 00 00'])

self.expect("frame variable other.intarr",
substrs = ['intarr = arr = ',
'09 00 00 00',
'....,07 00 00 00'])
if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable flarr",
substrs = ['flarr = arr =',
'00 00 9d 42 ...B,00 80 9a 42 ...B,00 00 9c 42 ...B,00 40 98 42 .@.B,00 80 99 42 ...B,00 c0 99 42 ...B,00 00 9a 42 ...B'])
else:
self.expect("frame variable flarr",
substrs = ['flarr = arr =',
'42 9d 00 00 B...,42 9a 80 00 B...,42 9c 00 00 B...,42 98 40 00 B.@.,42 99 80 00 B...,42 99 c0 00 B...,42 9a 00 00 B...'])

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable other.flarr",
substrs = ['flarr = arr =',
'00 00 cc 41 ...A,00 00 ca 41 ...A,00 00 c9 41 ...A,00 00 d6 41 ...A,00 00 db 41 ...A,00 00 dc 41 ...A,00 00 d1 41 ...A'])
else:
self.expect("frame variable other.flarr",
substrs = ['flarr = arr =',
'41 cc 00 00 A...,41 ca 00 00 A...,41 c9 00 00 A...,41 d6 00 00 A...,41 db 00 00 A...,41 dc 00 00 A...,41 d1 00 00 A...'])

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable intarr",
substrs = ['intarr = arr =',
'....,01 00 00 00',
'....,05 00 00 00'])
else:
self.expect("frame variable intarr",
substrs = ['intarr = arr =',
'....,00 00 00 01',
'....,00 00 00 05'])

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect("frame variable other.intarr",
substrs = ['intarr = arr = ',
'09 00 00 00',
'....,07 00 00 00'])
else:
self.expect("frame variable other.intarr",
substrs = ['intarr = arr = ',
'00 00 00 09',
'....,00 00 00 07'])
Expand Up @@ -31,6 +31,8 @@ def test_with_run_command(self):

self.runCmd("run", RUN_SUCCEEDED)

process = self.dbg.GetSelectedTarget().GetProcess()

# The stop reason of the thread should be breakpoint.
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['stopped',
Expand All @@ -52,25 +54,31 @@ def cleanup():
self.runCmd("script from fooSynthProvider import *")
self.runCmd("type synth add -l fooSynthProvider foo")

# note that the value of fake_a depends on target byte order
if process.GetByteOrder() == lldb.eByteOrderLittle:
fake_a_val = 0x02000000
else:
fake_a_val = 0x00000100

# check that the synthetic children work, so we know we are doing the right thing
self.expect("frame variable f00_1",
substrs = ['r = 33',
'fake_a = 16777216',
'a = 0']);
substrs = ['r = 34',
'fake_a = %d' % fake_a_val,
'a = 1']);

# check that capping works
self.runCmd("settings set target.max-children-count 2", check=False)

self.expect("frame variable f00_1",
substrs = ['...',
'fake_a = 16777216',
'a = 0']);
'fake_a = %d' % fake_a_val,
'a = 1']);

self.expect("frame variable f00_1", matching=False,
substrs = ['r = 33']);
substrs = ['r = 34']);


self.runCmd("settings set target.max-children-count 256", check=False)

self.expect("frame variable f00_1", matching=True,
substrs = ['r = 33']);
substrs = ['r = 34']);
Expand Up @@ -48,7 +48,7 @@ struct wrapint

int main()
{
foo f00_1(0);
foo f00_1(1);
foo *f00_ptr = new foo(12);

f00_1.a++; // Set break point at this line.
Expand Down
Expand Up @@ -51,7 +51,7 @@ def test_memory_cache(self):
self.assertTrue(0x00000042 == int(line.split(':')[1], 0))

# Change the value of my_ints[0] in memory.
self.runCmd("memory write `&my_ints` AA")
self.runCmd("memory write -s 4 `&my_ints` AA")

# Re-read the chunk of memory. The cache line should have been
# flushed because of the 'memory write'.
Expand Down
Expand Up @@ -19,7 +19,13 @@ def test_with_run_command(self):

self.runCmd("process launch", RUN_SUCCEEDED)

self.expect('frame variable -f x i', substrs=['ffffff41'])
process = self.dbg.GetSelectedTarget().GetProcess()

if process.GetByteOrder() == lldb.eByteOrderLittle:
self.expect('frame variable -f x i', substrs=['ffffff41'])
else:
self.expect('frame variable -f x i', substrs=['41ffff00'])

self.expect('frame variable c', substrs=["'A"])

self.expect('frame variable x', matching=False, substrs=['3'])
Expand Down
Expand Up @@ -232,6 +232,7 @@ def test_access_my_int(self):

# The bytearray_to_int utility function expects a little endian bytearray.
if byteOrder == lldb.eByteOrderBig:
content = bytearray(content, 'ascii')
content.reverse()

new_value = bytearray_to_int(content, byteSize)
Expand Down

0 comments on commit 7e8de59

Please sign in to comment.