Skip to content

Commit

Permalink
tests: Add InitializeFuzzingContext() for easy initialization of fuzz…
Browse files Browse the repository at this point in the history
…ing context without debug logging (avoids writing to disk)
  • Loading branch information
practicalswift committed Jun 8, 2020
1 parent 9a1c554 commit 5196ecb
Show file tree
Hide file tree
Showing 20 changed files with 38 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/test/fuzz/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <pubkey.h>
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <validation.h>
#include <version.h>

Expand All @@ -20,7 +20,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
1 change: 0 additions & 1 deletion src/test/fuzz/cuckoocache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>

#include <cstdint>
#include <string>
Expand Down
5 changes: 2 additions & 3 deletions src/test/fuzz/descriptor_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <pubkey.h>
#include <script/descriptor.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <util/memory.h>

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/deserialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <pubkey.h>
#include <script/keyorigin.h>
#include <streams.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <undo.h>
#include <version.h>

Expand All @@ -35,7 +35,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

namespace {
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/eval_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
#include <script/interpreter.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <util/memory.h>

#include <limits>

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
2 changes: 2 additions & 0 deletions src/test/fuzz/fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <test/util/setup_common.h>

#include <cstdint>
#include <functional>
#include <string>
#include <unistd.h>
#include <vector>

Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/hex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <pubkey.h>
#include <rpc/util.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <uint256.h>
#include <univalue.h>
#include <util/strencodings.h>
Expand All @@ -19,7 +19,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
3 changes: 1 addition & 2 deletions src/test/fuzz/integer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <uint256.h>
#include <util/check.h>
#include <util/moneystr.h>
Expand All @@ -43,7 +42,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
6 changes: 2 additions & 4 deletions src/test/fuzz/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <chainparamsbase.h>
#include <key.h>
#include <key_io.h>
#include <outputtype.h>
Expand All @@ -17,7 +15,7 @@
#include <script/standard.h>
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <util/memory.h>
#include <util/strencodings.h>

Expand All @@ -29,7 +27,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <script/signingprovider.h>
#include <script/standard.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>

#include <cassert>
#include <cstdint>
Expand All @@ -17,7 +17,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 1 addition & 3 deletions src/test/fuzz/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <key_io.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <util/message.h>
#include <util/strencodings.h>

Expand All @@ -19,7 +17,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/p2p_transport_deserializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <net.h>
#include <protocol.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>

#include <cassert>
#include <cstdint>
Expand All @@ -15,7 +15,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
6 changes: 2 additions & 4 deletions src/test/fuzz/parse_univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <core_io.h>
#include <rpc/client.h>
#include <rpc/util.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <util/memory.h>

#include <limits>
#include <string>

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
3 changes: 1 addition & 2 deletions src/test/fuzz/pow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>

#include <cstdint>
#include <optional>
Expand All @@ -18,7 +17,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/psbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <pubkey.h>
#include <script/script.h>
#include <streams.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <util/memory.h>
#include <version.h>

Expand All @@ -20,7 +20,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 1 addition & 3 deletions src/test/fuzz/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <compressor.h>
#include <core_io.h>
#include <core_memusage.h>
Expand All @@ -19,7 +18,6 @@
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <univalue.h>
#include <util/memory.h>

Expand All @@ -32,7 +30,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/script_flags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <pubkey.h>
#include <script/interpreter.h>
#include <streams.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <util/memory.h>
#include <version.h>

Expand All @@ -16,7 +16,7 @@ static bool IsValidFlagCombination(unsigned flags);

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
4 changes: 2 additions & 2 deletions src/test/fuzz/signature_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <script/interpreter.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <util/memory.h>

#include <cstdint>
Expand All @@ -16,7 +16,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup;
InitializeFuzzingContext(CBaseChainParams::MAIN);
}

namespace {
Expand Down
5 changes: 2 additions & 3 deletions src/test/fuzz/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <coins.h>
#include <consensus/tx_check.h>
#include <consensus/tx_verify.h>
Expand All @@ -14,7 +13,7 @@
#include <primitives/transaction.h>
#include <streams.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <test/fuzz/util.h>
#include <univalue.h>
#include <util/rbf.h>
#include <validation.h>
Expand All @@ -24,7 +23,7 @@

void initialize()
{
static const BasicTestingSetup basic_testing_setup{CBaseChainParams::REGTEST};
InitializeFuzzingContext();
}

void test_one_input(const std::vector<uint8_t>& buffer)
Expand Down
6 changes: 6 additions & 0 deletions src/test/fuzz/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <uint256.h>
#include <version.h>
Expand Down Expand Up @@ -214,4 +215,9 @@ NODISCARD inline bool ContainsSpentInput(const CTransaction& tx, const CCoinsVie
return false;
}

void InitializeFuzzingContext(const std::string& chain_name = CBaseChainParams::REGTEST)
{
static const BasicTestingSetup basic_testing_setup{chain_name, {"-nodebuglogfile"}};
}

#endif // BITCOIN_TEST_FUZZ_UTIL_H

0 comments on commit 5196ecb

Please sign in to comment.