pytest: make valgrind a per-node option.

Next patch will turn it off for slow-marked tests.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2020-08-07 12:44:59 +09:30 committed by Christian Decker
parent 79278b880f
commit 51aae9cce7
2 changed files with 9 additions and 7 deletions

View File

@ -550,9 +550,10 @@ class LightningD(TailableProc):
class LightningNode(object): class LightningNode(object):
def __init__(self, node_id, lightning_dir, bitcoind, executor, may_fail=False, def __init__(self, node_id, lightning_dir, bitcoind, executor, valgrind, may_fail=False,
may_reconnect=False, allow_broken_log=False, may_reconnect=False, allow_broken_log=False,
allow_bad_gossip=False, db=None, port=None, disconnect=None, random_hsm=None, options=None, **kwargs): allow_bad_gossip=False, db=None, port=None, disconnect=None, random_hsm=None, options=None,
**kwargs):
self.bitcoin = bitcoind self.bitcoin = bitcoind
self.executor = executor self.executor = executor
self.may_fail = may_fail self.may_fail = may_fail
@ -585,7 +586,7 @@ class LightningNode(object):
self.daemon.env["LIGHTNINGD_DEV_MEMLEAK"] = "1" self.daemon.env["LIGHTNINGD_DEV_MEMLEAK"] = "1"
if os.getenv("DEBUG_SUBD"): if os.getenv("DEBUG_SUBD"):
self.daemon.opts["dev-debugger"] = os.getenv("DEBUG_SUBD") self.daemon.opts["dev-debugger"] = os.getenv("DEBUG_SUBD")
if VALGRIND: if valgrind:
self.daemon.env["LIGHTNINGD_DEV_NO_BACKTRACE"] = "1" self.daemon.env["LIGHTNINGD_DEV_NO_BACKTRACE"] = "1"
if not may_reconnect: if not may_reconnect:
self.daemon.opts["dev-no-reconnect"] = None self.daemon.opts["dev-no-reconnect"] = None
@ -595,7 +596,7 @@ class LightningNode(object):
dsn = db.get_dsn() dsn = db.get_dsn()
if dsn is not None: if dsn is not None:
self.daemon.opts['wallet'] = dsn self.daemon.opts['wallet'] = dsn
if VALGRIND: if valgrind:
self.daemon.cmd_prefix = [ self.daemon.cmd_prefix = [
'valgrind', 'valgrind',
'-q', '-q',
@ -968,6 +969,7 @@ class NodeFactory(object):
self.lock = threading.Lock() self.lock = threading.Lock()
self.db_provider = db_provider self.db_provider = db_provider
self.node_cls = node_cls self.node_cls = node_cls
self.valgrind = VALGRIND
def split_options(self, opts): def split_options(self, opts):
"""Split node options from cli options """Split node options from cli options
@ -1042,7 +1044,7 @@ class NodeFactory(object):
# node. # node.
db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id) db = self.db_provider.get_db(os.path.join(lightning_dir, TEST_NETWORK), self.testname, node_id)
node = self.node_cls( node = self.node_cls(
node_id, lightning_dir, self.bitcoind, self.executor, db=db, node_id, lightning_dir, self.bitcoind, self.executor, self.valgrind, db=db,
port=port, options=options, may_fail=may_fail or expect_fail, port=port, options=options, may_fail=may_fail or expect_fail,
**kwargs **kwargs
) )
@ -1165,7 +1167,7 @@ class NodeFactory(object):
leaks = None leaks = None
# leak detection upsets VALGRIND by reading uninitialized mem. # leak detection upsets VALGRIND by reading uninitialized mem.
# If it's dead, we'll catch it below. # If it's dead, we'll catch it below.
if not VALGRIND and DEVELOPER: if not self.valgrind and DEVELOPER:
try: try:
# This also puts leaks in log. # This also puts leaks in log.
leaks = self.nodes[i].rpc.dev_memleak()['leaks'] leaks = self.nodes[i].rpc.dev_memleak()['leaks']

View File

@ -2174,7 +2174,7 @@ def test_unix_socket_path_length(node_factory, bitcoind, directory, executor, db
os.makedirs(lightning_dir) os.makedirs(lightning_dir)
db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1) db = db_provider.get_db(lightning_dir, "test_unix_socket_path_length", 1)
l1 = LightningNode(1, lightning_dir, bitcoind, executor, db=db, port=node_factory.get_next_port()) l1 = LightningNode(1, lightning_dir, bitcoind, executor, VALGRIND, db=db, port=node_factory.get_next_port())
# `LightningNode.start()` internally calls `LightningRpc.getinfo()` which # `LightningNode.start()` internally calls `LightningRpc.getinfo()` which
# exercises the socket logic, and raises an issue if it fails. # exercises the socket logic, and raises an issue if it fails.