Skip to content

Commit fabc57e

Browse files
author
MarcoFalke
committed
test: Log to debug.log in all tests
1 parent fa4a04a commit fabc57e

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

src/logging.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ bool BCLog::Logger::StartLogging()
7575
return true;
7676
}
7777

78+
void BCLog::Logger::DisconnectTestLogger()
79+
{
80+
std::lock_guard<std::mutex> scoped_lock(m_cs);
81+
m_buffering = true;
82+
if (m_fileout != nullptr) fclose(m_fileout);
83+
m_fileout = nullptr;
84+
}
85+
7886
void BCLog::Logger::EnableCategory(BCLog::LogFlags flag)
7987
{
8088
m_categories |= flag;

src/logging.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ namespace BCLog {
100100

101101
/** Start logging (and flush all buffered messages) */
102102
bool StartLogging();
103+
/** Only for testing */
104+
void DisconnectTestLogger();
103105

104106
void ShrinkDebugFile();
105107

src/qt/test/apptests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void AppTests::appTests()
6464
#endif
6565

6666
ECC_Stop(); // Already started by the common test setup, so stop it to avoid interference
67+
LogInstance().DisconnectTestLogger();
68+
6769
m_app.parameterSetup();
6870
m_app.createOptionsModel(true /* reset settings */);
6971
QScopedPointer<const NetworkStyle> style(

src/qt/test/rpcnestedtests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void RPCNestedTests::rpcNestedTests()
3535
tableRPC.appendCommand("rpcNestedTest", &vRPCCommands[0]);
3636
//mempool.setSanityCheck(1.0);
3737

38+
LogInstance().DisconnectTestLogger(); // Already started by the common test setup, so stop it to avoid interference
3839
TestingSetup test;
3940

4041
if (RPCIsInWarmup(nullptr)) SetRPCWarmupFinished();

src/test/setup_common.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <consensus/params.h>
1111
#include <consensus/validation.h>
1212
#include <crypto/sha256.h>
13+
#include <init.h>
1314
#include <miner.h>
1415
#include <net_processing.h>
1516
#include <noui.h>
@@ -37,14 +38,17 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
3738
fs::create_directories(m_path_root);
3839
gArgs.ForceSetArg("-datadir", m_path_root.string());
3940
ClearDatadirCache();
41+
SelectParams(chainName);
42+
gArgs.ForceSetArg("-printtoconsole", "0");
43+
InitLogging();
44+
LogInstance().StartLogging();
4045
SHA256AutoDetect();
4146
ECC_Start();
4247
SetupEnvironment();
4348
SetupNetworking();
4449
InitSignatureCache();
4550
InitScriptExecutionCache();
4651
fCheckBlockIndex = true;
47-
SelectParams(chainName);
4852
static bool noui_connected = false;
4953
if (!noui_connected) {
5054
noui_connect();
@@ -54,6 +58,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
5458

5559
BasicTestingSetup::~BasicTestingSetup()
5660
{
61+
LogInstance().DisconnectTestLogger();
5762
fs::remove_all(m_path_root);
5863
ECC_Stop();
5964
}

0 commit comments

Comments
 (0)