mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-23 17:57:47 -03:00
0c9de67f34
0aef39d067
Silence "Test case [...] did not check any assertions" warnings when running "test_bitcoin --log_level=test_suite" (practicalswift)5fd73c8694
Avoid repeated log messages in tests by connecting to signal handlers (ThreadSafeMessageBox, etc.) only once (practicalswift)e502c3c515
tests: Reduce noise level in test_bitcoin output (practicalswift) Pull request description: Reduce noise level in `test_bitcoin` output. Context: When working on the non-determinism issues in the unit tests (see #15296) I got a bit tired of the amount of noise in the `test_bitcoin` output :-) Before: ``` $ src/test/test_bitcoin --log_level=test_suite 2>&1 | grep -vE '(Entering|Leaving)' | uniq -c 1 Running 341 test cases... 1 Test case blockencodings_tests/TransactionsRequestDeserializationOverflowTest did not check any assertions 1 CheckSplitTorReplyLine(PROTOCOLINFO PIVERSION) 1 CheckSplitTorReplyLine(AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE="/home/x/.tor/control_auth_cookie") 1 CheckSplitTorReplyLine(AUTH METHODS=NULL) 1 CheckSplitTorReplyLine(AUTH METHODS=HASHEDPASSWORD) 1 CheckSplitTorReplyLine(VERSION Tor="0.2.9.8 (git-a0df013ea241b026)") 1 CheckSplitTorReplyLine(AUTHCHALLENGE SERVERHASH=aaaa SERVERNONCE=bbbb) 1 CheckSplitTorReplyLine(COMMAND) 1 CheckSplitTorReplyLine(COMMAND SOME ARGS) 1 CheckSplitTorReplyLine(COMMAND ARGS) 1 CheckSplitTorReplyLine(COMMAND EVEN+more ARGS) 1 CheckParseTorReplyMapping(METHODS=COOKIE,SAFECOOKIE COOKIEFILE="/home/x/.tor/control_auth_cookie") 1 CheckParseTorReplyMapping(METHODS=NULL) 1 CheckParseTorReplyMapping(METHODS=HASHEDPASSWORD) 1 CheckParseTorReplyMapping(Tor="0.2.9.8 (git-a0df013ea241b026)") 1 CheckParseTorReplyMapping(SERVERHASH=aaaa SERVERNONCE=bbbb) 1 CheckParseTorReplyMapping(ServiceID=exampleonion1234) 1 CheckParseTorReplyMapping(PrivateKey=RSA1024:BLOB) 1 CheckParseTorReplyMapping(ClientAuth=bob:BLOB) 1 CheckParseTorReplyMapping(Foo=Bar=Baz Spam=Eggs) 1 CheckParseTorReplyMapping(Foo="Bar=Baz") 1 CheckParseTorReplyMapping(Foo="Bar Baz") 1 CheckParseTorReplyMapping(Foo="Bar\ Baz") 1 CheckParseTorReplyMapping(Foo="Bar\Baz") 1 CheckParseTorReplyMapping(Foo="Bar\@Baz") 1 CheckParseTorReplyMapping(Foo="Bar\"Baz" Spam="\"Eggs\"") 1 CheckParseTorReplyMapping(Foo="Bar\\Baz") 1 CheckParseTorReplyMapping(Foo="Bar\nBaz\t" Spam="\rEggs" Octals="\1a\11\17\18\81\377\378\400\2222" Final=Check) 1 CheckParseTorReplyMapping(Valid=Mapping Escaped="Escape\\") 1 CheckParseTorReplyMapping(Valid=Mapping Bare="Escape\") 1 CheckParseTorReplyMapping(OneOctal="OneEnd\1" TwoOctal="TwoEnd\11") 1 CheckParseTorReplyMapping(Null="\0") 1 CheckParseTorReplyMapping(SOME=args,here MORE optional=arguments here) 1 CheckParseTorReplyMapping(ARGS) 1 CheckParseTorReplyMapping(MORE ARGS) 1 CheckParseTorReplyMapping(MORE ARGS) 1 CheckParseTorReplyMapping(EVEN more=ARGS) 1 CheckParseTorReplyMapping(EVEN+more ARGS) 1 Test case util_tests/util_criticalsection did not check any assertions 1 Testing known outcomes 326 Error: Specified -walletdir "/tmp/test_bitcoin/1553850209_943311758/tempdir/path_does_not_exist" does not exist 327 Error: Specified -walletdir "/tmp/test_bitcoin/1553850209_643733972/tempdir/not_a_directory.dat" is not a directory 328 Error: Specified -walletdir "wallets" is a relative path 1 1 *** No errors detected ``` After: ``` $ src/test/test_bitcoin --log_level=test_suite 2>&1 | grep -vE '(Entering|Leaving)' | uniq -c 1 Running 341 test cases... 1 Error: Specified -walletdir "/tmp/test_bitcoin/1553850026_943311758/tempdir/path_does_not_exist" does not exist 1 Error: Specified -walletdir "/tmp/test_bitcoin/1553850026_643733972/tempdir/not_a_directory.dat" is not a directory 1 Error: Specified -walletdir "wallets" is a relative path 1 1 *** No errors detected ``` ACKs for commit 0aef39: MarcoFalke: utACK0aef39d067
Tree-SHA512: 9cc22f64aa5c875861bae6533d18675ad978c623f053754deef6a8e271ea70bda3f72fb4ec5c8fd19b841757f21380639051d5f5b44301b9d2464b57655e9c05
204 lines
7 KiB
C++
204 lines
7 KiB
C++
// Copyright (c) 2017 The Zcash developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
//
|
|
#include <test/setup_common.h>
|
|
#include <torcontrol.h>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
|
|
std::pair<std::string, std::string> SplitTorReplyLine(const std::string& s);
|
|
std::map<std::string, std::string> ParseTorReplyMapping(const std::string& s);
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(torcontrol_tests, BasicTestingSetup)
|
|
|
|
static void CheckSplitTorReplyLine(std::string input, std::string command, std::string args)
|
|
{
|
|
auto ret = SplitTorReplyLine(input);
|
|
BOOST_CHECK_EQUAL(ret.first, command);
|
|
BOOST_CHECK_EQUAL(ret.second, args);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(util_SplitTorReplyLine)
|
|
{
|
|
// Data we should receive during normal usage
|
|
CheckSplitTorReplyLine(
|
|
"PROTOCOLINFO PIVERSION",
|
|
"PROTOCOLINFO", "PIVERSION");
|
|
CheckSplitTorReplyLine(
|
|
"AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE=\"/home/x/.tor/control_auth_cookie\"",
|
|
"AUTH", "METHODS=COOKIE,SAFECOOKIE COOKIEFILE=\"/home/x/.tor/control_auth_cookie\"");
|
|
CheckSplitTorReplyLine(
|
|
"AUTH METHODS=NULL",
|
|
"AUTH", "METHODS=NULL");
|
|
CheckSplitTorReplyLine(
|
|
"AUTH METHODS=HASHEDPASSWORD",
|
|
"AUTH", "METHODS=HASHEDPASSWORD");
|
|
CheckSplitTorReplyLine(
|
|
"VERSION Tor=\"0.2.9.8 (git-a0df013ea241b026)\"",
|
|
"VERSION", "Tor=\"0.2.9.8 (git-a0df013ea241b026)\"");
|
|
CheckSplitTorReplyLine(
|
|
"AUTHCHALLENGE SERVERHASH=aaaa SERVERNONCE=bbbb",
|
|
"AUTHCHALLENGE", "SERVERHASH=aaaa SERVERNONCE=bbbb");
|
|
|
|
// Other valid inputs
|
|
CheckSplitTorReplyLine("COMMAND", "COMMAND", "");
|
|
CheckSplitTorReplyLine("COMMAND SOME ARGS", "COMMAND", "SOME ARGS");
|
|
|
|
// These inputs are valid because PROTOCOLINFO accepts an OtherLine that is
|
|
// just an OptArguments, which enables multiple spaces to be present
|
|
// between the command and arguments.
|
|
CheckSplitTorReplyLine("COMMAND ARGS", "COMMAND", " ARGS");
|
|
CheckSplitTorReplyLine("COMMAND EVEN+more ARGS", "COMMAND", " EVEN+more ARGS");
|
|
}
|
|
|
|
static void CheckParseTorReplyMapping(std::string input, std::map<std::string,std::string> expected)
|
|
{
|
|
auto ret = ParseTorReplyMapping(input);
|
|
BOOST_CHECK_EQUAL(ret.size(), expected.size());
|
|
auto r_it = ret.begin();
|
|
auto e_it = expected.begin();
|
|
while (r_it != ret.end() && e_it != expected.end()) {
|
|
BOOST_CHECK_EQUAL(r_it->first, e_it->first);
|
|
BOOST_CHECK_EQUAL(r_it->second, e_it->second);
|
|
r_it++;
|
|
e_it++;
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(util_ParseTorReplyMapping)
|
|
{
|
|
// Data we should receive during normal usage
|
|
CheckParseTorReplyMapping(
|
|
"METHODS=COOKIE,SAFECOOKIE COOKIEFILE=\"/home/x/.tor/control_auth_cookie\"", {
|
|
{"METHODS", "COOKIE,SAFECOOKIE"},
|
|
{"COOKIEFILE", "/home/x/.tor/control_auth_cookie"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"METHODS=NULL", {
|
|
{"METHODS", "NULL"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"METHODS=HASHEDPASSWORD", {
|
|
{"METHODS", "HASHEDPASSWORD"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Tor=\"0.2.9.8 (git-a0df013ea241b026)\"", {
|
|
{"Tor", "0.2.9.8 (git-a0df013ea241b026)"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"SERVERHASH=aaaa SERVERNONCE=bbbb", {
|
|
{"SERVERHASH", "aaaa"},
|
|
{"SERVERNONCE", "bbbb"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"ServiceID=exampleonion1234", {
|
|
{"ServiceID", "exampleonion1234"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"PrivateKey=RSA1024:BLOB", {
|
|
{"PrivateKey", "RSA1024:BLOB"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"ClientAuth=bob:BLOB", {
|
|
{"ClientAuth", "bob:BLOB"},
|
|
});
|
|
|
|
// Other valid inputs
|
|
CheckParseTorReplyMapping(
|
|
"Foo=Bar=Baz Spam=Eggs", {
|
|
{"Foo", "Bar=Baz"},
|
|
{"Spam", "Eggs"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar=Baz\"", {
|
|
{"Foo", "Bar=Baz"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar Baz\"", {
|
|
{"Foo", "Bar Baz"},
|
|
});
|
|
|
|
// Escapes
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar\\ Baz\"", {
|
|
{"Foo", "Bar Baz"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar\\Baz\"", {
|
|
{"Foo", "BarBaz"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar\\@Baz\"", {
|
|
{"Foo", "Bar@Baz"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar\\\"Baz\" Spam=\"\\\"Eggs\\\"\"", {
|
|
{"Foo", "Bar\"Baz"},
|
|
{"Spam", "\"Eggs\""},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar\\\\Baz\"", {
|
|
{"Foo", "Bar\\Baz"},
|
|
});
|
|
|
|
// C escapes
|
|
CheckParseTorReplyMapping(
|
|
"Foo=\"Bar\\nBaz\\t\" Spam=\"\\rEggs\" Octals=\"\\1a\\11\\17\\18\\81\\377\\378\\400\\2222\" Final=Check", {
|
|
{"Foo", "Bar\nBaz\t"},
|
|
{"Spam", "\rEggs"},
|
|
{"Octals", "\1a\11\17\1" "881\377\37" "8\40" "0\222" "2"},
|
|
{"Final", "Check"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Valid=Mapping Escaped=\"Escape\\\\\"", {
|
|
{"Valid", "Mapping"},
|
|
{"Escaped", "Escape\\"},
|
|
});
|
|
CheckParseTorReplyMapping(
|
|
"Valid=Mapping Bare=\"Escape\\\"", {});
|
|
CheckParseTorReplyMapping(
|
|
"OneOctal=\"OneEnd\\1\" TwoOctal=\"TwoEnd\\11\"", {
|
|
{"OneOctal", "OneEnd\1"},
|
|
{"TwoOctal", "TwoEnd\11"},
|
|
});
|
|
|
|
// Special handling for null case
|
|
// (needed because string comparison reads the null as end-of-string)
|
|
auto ret = ParseTorReplyMapping("Null=\"\\0\"");
|
|
BOOST_CHECK_EQUAL(ret.size(), 1U);
|
|
auto r_it = ret.begin();
|
|
BOOST_CHECK_EQUAL(r_it->first, "Null");
|
|
BOOST_CHECK_EQUAL(r_it->second.size(), 1U);
|
|
BOOST_CHECK_EQUAL(r_it->second[0], '\0');
|
|
|
|
// A more complex valid grammar. PROTOCOLINFO accepts a VersionLine that
|
|
// takes a key=value pair followed by an OptArguments, making this valid.
|
|
// Because an OptArguments contains no semantic data, there is no point in
|
|
// parsing it.
|
|
CheckParseTorReplyMapping(
|
|
"SOME=args,here MORE optional=arguments here", {
|
|
{"SOME", "args,here"},
|
|
});
|
|
|
|
// Inputs that are effectively invalid under the target grammar.
|
|
// PROTOCOLINFO accepts an OtherLine that is just an OptArguments, which
|
|
// would make these inputs valid. However,
|
|
// - This parser is never used in that situation, because the
|
|
// SplitTorReplyLine parser enables OtherLine to be skipped.
|
|
// - Even if these were valid, an OptArguments contains no semantic data,
|
|
// so there is no point in parsing it.
|
|
CheckParseTorReplyMapping("ARGS", {});
|
|
CheckParseTorReplyMapping("MORE ARGS", {});
|
|
CheckParseTorReplyMapping("MORE ARGS", {});
|
|
CheckParseTorReplyMapping("EVEN more=ARGS", {});
|
|
CheckParseTorReplyMapping("EVEN+more ARGS", {});
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|