From 1ad960413dfa6ddda4d70c7c12861e2d1fd4cf5e Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 17 Aug 2017 10:32:55 +0930 Subject: [PATCH] test_lightningd: fix valgrind detection on children. I tracked down a bug, and couldn't figure out why valgrind wasn't finding it. From man valgrind: --log-file= Specifies that Valgrind should send all of its messages to the specified file. If the file name is empty, it causes an abort. There are three special format specifiers that can be used in the file name. %p is replaced with the current process ID. This is very useful for program that invoke multiple processes. WARNING: If you use --trace-children=yes and your program invokes multiple processes OR your program forks without calling exec afterwards, and you don't use this specifier (or the %q specifier below), the Valgrind output from all those processes will go into one file, possibly jumbled up, and possibly incomplete. "possibly incomplete" indeed! Signed-off-by: Rusty Russell --- tests/test_lightningd.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_lightningd.py b/tests/test_lightningd.py index fa3abb009..fd723825c 100644 --- a/tests/test_lightningd.py +++ b/tests/test_lightningd.py @@ -9,6 +9,7 @@ import json import logging import os import random +import re import sqlite3 import string import sys @@ -114,7 +115,7 @@ class NodeFactory(object): '--trace-children=yes', '--trace-children-skip=*bitcoin-cli*', '--error-exitcode=7', - '--log-file={}/valgrind-errors'.format(node.daemon.lightning_dir) + '--log-file={}/valgrind-errors.%p'.format(node.daemon.lightning_dir) ] + node.daemon.cmd_line node.daemon.start() @@ -135,10 +136,14 @@ class BaseLightningDTests(unittest.TestCase): self.node_factory = NodeFactory(self, self.executor) def getValgrindErrors(self, node): - error_file = '{}valgrind-errors'.format(node.daemon.lightning_dir) - with open(error_file, 'r') as f: - errors = f.read().strip() - return errors, error_file + for error_file in os.listdir(node.daemon.lightning_dir): + if not re.match("valgrind-errors.\d+", error_file): + continue; + with open(os.path.join(node.daemon.lightning_dir, error_file), 'r') as f: + errors = f.read().strip() + if errors: + return errors, error_file + return None, None def printValgrindErrors(self, node): errors, fname = self.getValgrindErrors(node)