JDevlieghere created this revision.
JDevlieghere added reviewers: labath, teemperor, aprantl.
Herald added a subscriber: abidh.
While debugging replay failures I noticed that a lot of tests have print
statements, sometimes commented out, which half of the time don't show up in
the terminal anyway because dotest swallows the output.
We already have a good mechanism for these kind of things: the `-t` flag to
enable tracing. I've added a `trace` method to replace these print statements.
In this patch I've only updated the ones that are commented out, but I feel all
the print statements in the API tests should be replaced by this.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D80448
Files:
lldb/packages/Python/lldbsuite/test/lldbtest.py
lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
Index: lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
+++ lldb/test/API/tools/lldb-server/TestLldbGdbServer.py
@@ -10,9 +10,6 @@
the initial set of tests implemented.
"""
-from __future__ import division, print_function
-
-
import unittest2
import gdbremote_testcase
import lldbgdbserverutils
@@ -1442,7 +1439,7 @@
# Write flipped bit pattern of existing value to each register.
(successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value(
gpr_reg_infos, endian)
- # print("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
+ self.trace("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
self.assertTrue(successful_writes > 0)
# Note: as of this moment, a hefty number of the GPR writes are failing with E32 (everything except rax-rdx, rdi, rsi, rbp).
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteRegisterState.py
@@ -1,6 +1,3 @@
-from __future__ import print_function
-
-
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -50,7 +47,7 @@
self.assertIsNotNone(threads)
thread_id = threads[0]
self.assertIsNotNone(thread_id)
- # print("Running on thread: 0x{:x}".format(thread_id))
+ self.trace("Running on thread: 0x{:x}".format(thread_id))
else:
thread_id = None
@@ -64,22 +61,22 @@
(success, state_id) = self.parse_QSaveRegisterState_response(context)
self.assertTrue(success)
self.assertIsNotNone(state_id)
- # print("saved register state id: {}".format(state_id))
+ self.trace("saved register state id: {}".format(state_id))
# Remember initial register values.
initial_reg_values = self.read_register_values(
gpr_reg_infos, endian, thread_id=thread_id)
- # print("initial_reg_values: {}".format(initial_reg_values))
+ self.trace("initial_reg_values: {}".format(initial_reg_values))
# Flip gpr register values.
(successful_writes, failed_writes) = self.flip_all_bits_in_each_register_value(
gpr_reg_infos, endian, thread_id=thread_id)
- # print("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
+ self.trace("successful writes: {}, failed writes: {}".format(successful_writes, failed_writes))
self.assertTrue(successful_writes > 0)
flipped_reg_values = self.read_register_values(
gpr_reg_infos, endian, thread_id=thread_id)
- # print("flipped_reg_values: {}".format(flipped_reg_values))
+ self.trace("flipped_reg_values: {}".format(flipped_reg_values))
# Restore register values.
self.reset_test_sequence()
@@ -91,7 +88,7 @@
# Verify registers match initial register values.
final_reg_values = self.read_register_values(
gpr_reg_infos, endian, thread_id=thread_id)
- # print("final_reg_values: {}".format(final_reg_values))
+ self.trace("final_reg_values: {}".format(final_reg_values))
self.assertIsNotNone(final_reg_values)
self.assertEqual(final_reg_values, initial_reg_values)
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteExpeditedRegisters.py
@@ -1,6 +1,3 @@
-from __future__ import print_function
-
-
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -59,7 +56,7 @@
# Ensure the expedited registers contained it.
self.assertTrue(reg_info["lldb_register_index"] in expedited_registers)
- # print("{} reg_info:{}".format(generic_register_name, reg_info))
+ self.trace("{} reg_info:{}".format(generic_register_name, reg_info))
def stop_notification_contains_any_registers(self):
# Generate a stop reply, parse out expedited registers from stop
Index: lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
+++ lldb/test/API/tools/lldb-server/TestGdbRemoteAuxvSupport.py
@@ -1,6 +1,3 @@
-from __future__ import print_function
-
-
import gdbremote_testcase
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
@@ -119,7 +116,7 @@
# Ensure auxv data is a multiple of 2*word_size (there should be two
# unsigned long fields per auxv entry).
self.assertEqual(len(auxv_data) % (2 * word_size), 0)
- # print("auxv contains {} entries".format(len(auxv_data) / (2*word_size)))
+ self.trace("auxv contains {} entries".format(len(auxv_data) / (2*word_size)))
@debugserver_test
def test_auxv_data_is_correct_size_debugserver(self):
@@ -159,7 +156,7 @@
for auxv_key in auxv_dict:
self.assertTrue(auxv_key >= 1)
self.assertTrue(auxv_key <= 1000)
- # print("auxv dict: {}".format(auxv_dict))
+ self.trace("auxv dict: {}".format(auxv_dict))
@debugserver_test
def test_auxv_keys_look_valid_debugserver(self):
Index: lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
===================================================================
--- lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
+++ lldb/test/API/lang/objc/blocks/TestObjCIvarsInBlocks.py
@@ -125,7 +125,7 @@
expr, "Successfully got a local variable in a block in a class method.")
ret_value_signed = expr.GetValueAsSigned(error)
- # print('ret_value_signed = %i' % (ret_value_signed))
+ self.trace('ret_value_signed = %i' % (ret_value_signed))
self.assertTrue(
ret_value_signed == 5,
"The local variable in the block was what we expected.")
Index: lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
===================================================================
--- lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
+++ lldb/test/API/lang/c/register_variables/TestRegisterVariables.py
@@ -1,7 +1,5 @@
"""Check that compiler-generated register values work correctly"""
-from __future__ import print_function
-
import re
import lldb
from lldbsuite.test.decorators import *
@@ -19,20 +17,20 @@
def is_variable_in_register(frame, var_name):
# Ensure we can lookup the variable.
var = frame.FindVariable(var_name)
- # print("\nchecking {}...".format(var_name))
+ self.trace("\nchecking {}...".format(var_name))
if var is None or not var.IsValid():
- # print("{} cannot be found".format(var_name))
+ self.trace("{} cannot be found".format(var_name))
return False
# Check that we can get its value. If not, this
# may be a variable that is just out of scope at this point.
value = var.GetValue()
- # print("checking value...")
+ self.trace("checking value...")
if value is None:
- # print("value is invalid")
+ self.trace("value is invalid")
return False
# else:
- # print("value is {}".format(value))
+ self.trace("value is {}".format(value))
# We have a variable and we can get its value. The variable is in
# a register if we cannot get an address for it, assuming it is
@@ -41,15 +39,15 @@
# multiple registers, but what we're verifying here is much more
# than it was doing before).
var_addr = var.GetAddress()
- # print("checking address...")
+ self.trace("checking address...")
if var_addr.IsValid():
# We have an address, it must not be in a register.
- # print("var {} is not in a register: has a valid address {}".format(var_name, var_addr))
+ self.trace("var {} is not in a register: has a valid address {}".format(var_name, var_addr))
return False
else:
# We don't have an address but we can read the value.
# It is likely stored in a register.
- # print("var {} is in a register (we don't have an address for it)".format(var_name))
+ self.trace("var {} is in a register (we don't have an address for it)".format(var_name))
return True
@@ -60,13 +58,13 @@
print("\nchecking {}...".format(var_name))
if var is None or not var.IsValid():
- # print("{} cannot be found".format(var_name))
+ self.trace("{} cannot be found".format(var_name))
return False
# Check that we can get its value. If not, this
# may be a variable that is just out of scope at this point.
value = var.GetValue()
- # print("checking value...")
+ self.trace("checking value...")
if value is None:
if trace:
print("value is invalid")
@@ -80,10 +78,10 @@
print("checking location: {}".format(var_loc))
if var_loc is None or var_loc.startswith("0x"):
# The frame var is not in a register but rather a memory location.
- # print("frame var {} is not in a register".format(var_name))
+ self.trace("frame var {} is not in a register".format(var_name))
return False
else:
- # print("frame var {} is in a register".format(var_name))
+ self.trace("frame var {} is in a register".format(var_name))
return True
@@ -199,6 +197,6 @@
self.assertTrue(
register_variables_count > 0,
"expected to verify at least one variable in a register")
- # print("executed {} expressions with values in registers".format(register_variables_count))
+ self.trace("executed {} expressions with values in registers".format(register_variables_count))
self.runCmd("kill")
Index: lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
===================================================================
--- lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
+++ lldb/test/API/functionalities/breakpoint/serialize/TestBreakpointSerialization.py
@@ -118,7 +118,7 @@
copy_text = copy_desc.GetData()
# These two should be identical.
- # print ("Source text for %d is %s."%(i, source_text))
+ self.trace("Source text for %d is %s."%(i, source_text))
self.assertTrue (source_text == copy_text, "Source and dest breakpoints are not identical: \nsource: %s\ndest: %s"%(source_text, copy_text))
def do_check_resolvers(self):
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -505,6 +505,10 @@
"""Returns True if we are in trace mode (tracing detailed test execution)."""
return traceAlways
+ def trace(self, *args,**kwargs):
+ with recording(self, self.TraceOn()) as sbuf:
+ print(args, kwargs, file=sbuf)
+
@classmethod
def setUpClass(cls):
"""
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits