Merge pull request 'upstream' (#357) from wowario/wownero:upstream into master
Reviewed-on: https://git.wownero.com/wownero/wownero/pulls/357
This commit is contained in:
commit
d886300416
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
||||||
Copyright (c) 2014-2020, The Monero Project
|
Copyright (c) 2014-2021, The Monero Project
|
||||||
|
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <boost/thread/lock_guard.hpp>
|
#include <boost/thread/lock_guard.hpp>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
|
static bool same_as_last_line(const std::string&);
|
||||||
static void install_line_handler();
|
static void install_line_handler();
|
||||||
static void remove_line_handler();
|
static void remove_line_handler();
|
||||||
|
|
||||||
|
@ -175,8 +176,11 @@ static void handle_line(char* line)
|
||||||
boost::trim_right(test_line);
|
boost::trim_right(test_line);
|
||||||
if(!test_line.empty())
|
if(!test_line.empty())
|
||||||
{
|
{
|
||||||
add_history(test_line.c_str());
|
if (!same_as_last_line(test_line))
|
||||||
history_set_pos(history_length);
|
{
|
||||||
|
add_history(test_line.c_str());
|
||||||
|
history_set_pos(history_length);
|
||||||
|
}
|
||||||
if (test_line == "exit" || test_line == "q")
|
if (test_line == "exit" || test_line == "q")
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
|
@ -192,6 +196,16 @@ static void handle_line(char* line)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// same_as_last_line returns true, if the last line in the history is
|
||||||
|
// equal to test_line.
|
||||||
|
static bool same_as_last_line(const std::string& test_line)
|
||||||
|
{
|
||||||
|
// Note that state->offset == state->length, when a new line was entered.
|
||||||
|
HISTORY_STATE* state = history_get_history_state();
|
||||||
|
return state->length > 0
|
||||||
|
&& test_line.compare(state->entries[state->length-1]->line) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static char* completion_matches(const char* text, int state)
|
static char* completion_matches(const char* text, int state)
|
||||||
{
|
{
|
||||||
static size_t list_index;
|
static size_t list_index;
|
||||||
|
|
|
@ -14,8 +14,8 @@ then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
case "$type" in
|
case "$type" in
|
||||||
block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof) ;;
|
block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|utf8) ;;
|
||||||
*) echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof"; exit 1 ;;
|
*) echo "usage: $0 block|transaction|signature|cold-outputs|cold-transaction|load-from-binary|load-from-json|base58|parse-url|http-client|levin|bulletproof|utf8"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if test -d "fuzz-out/$type"
|
if test -d "fuzz-out/$type"
|
||||||
|
|
|
@ -549,6 +549,7 @@ namespace cryptonote
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<tx_blob_entry> have_tx;
|
std::vector<tx_blob_entry> have_tx;
|
||||||
|
have_tx.reserve(new_block.tx_hashes.size());
|
||||||
|
|
||||||
// Instead of requesting missing transactions by hash like BTC,
|
// Instead of requesting missing transactions by hash like BTC,
|
||||||
// we do it by index (thanks to a suggestion from moneromooo) because
|
// we do it by index (thanks to a suggestion from moneromooo) because
|
||||||
|
@ -557,6 +558,7 @@ namespace cryptonote
|
||||||
// Also, remember to pepper some whitespace changes around to bother
|
// Also, remember to pepper some whitespace changes around to bother
|
||||||
// moneromooo ... only because I <3 him.
|
// moneromooo ... only because I <3 him.
|
||||||
std::vector<uint64_t> need_tx_indices;
|
std::vector<uint64_t> need_tx_indices;
|
||||||
|
need_tx_indices.reserve(new_block.tx_hashes.size());
|
||||||
|
|
||||||
transaction tx;
|
transaction tx;
|
||||||
crypto::hash tx_hash;
|
crypto::hash tx_hash;
|
||||||
|
@ -829,6 +831,7 @@ namespace cryptonote
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<crypto::hash> txids;
|
std::vector<crypto::hash> txids;
|
||||||
|
txids.reserve(b.tx_hashes.size());
|
||||||
NOTIFY_NEW_FLUFFY_BLOCK::request fluffy_response;
|
NOTIFY_NEW_FLUFFY_BLOCK::request fluffy_response;
|
||||||
fluffy_response.b.block = t_serializable_object_to_blob(b);
|
fluffy_response.b.block = t_serializable_object_to_blob(b);
|
||||||
fluffy_response.current_blockchain_height = arg.current_blockchain_height;
|
fluffy_response.current_blockchain_height = arg.current_blockchain_height;
|
||||||
|
@ -2189,6 +2192,7 @@ skip:
|
||||||
if (span.second > 0)
|
if (span.second > 0)
|
||||||
{
|
{
|
||||||
is_next = true;
|
is_next = true;
|
||||||
|
req.blocks.reserve(hashes.size());
|
||||||
for (const auto &hash: hashes)
|
for (const auto &hash: hashes)
|
||||||
{
|
{
|
||||||
req.blocks.push_back(hash);
|
req.blocks.push_back(hash);
|
||||||
|
@ -2247,6 +2251,7 @@ skip:
|
||||||
if (span.second > 0)
|
if (span.second > 0)
|
||||||
{
|
{
|
||||||
is_next = true;
|
is_next = true;
|
||||||
|
req.blocks.reserve(hashes.size());
|
||||||
for (const auto &hash: hashes)
|
for (const auto &hash: hashes)
|
||||||
{
|
{
|
||||||
req.blocks.push_back(hash);
|
req.blocks.push_back(hash);
|
||||||
|
@ -2280,6 +2285,7 @@ skip:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.blocks.reserve(req.blocks.size() + span.second);
|
||||||
for (size_t n = 0; n < span.second; ++n)
|
for (size_t n = 0; n < span.second; ++n)
|
||||||
{
|
{
|
||||||
req.blocks.push_back(context.m_needed_objects[n].first);
|
req.blocks.push_back(context.m_needed_objects[n].first);
|
||||||
|
@ -2579,6 +2585,7 @@ skip:
|
||||||
}
|
}
|
||||||
|
|
||||||
context.m_needed_objects.clear();
|
context.m_needed_objects.clear();
|
||||||
|
context.m_needed_objects.reserve(arg.m_block_ids.size());
|
||||||
uint64_t added = 0;
|
uint64_t added = 0;
|
||||||
std::unordered_set<crypto::hash> blocks_found;
|
std::unordered_set<crypto::hash> blocks_found;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
|
@ -51,14 +51,6 @@
|
||||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p.tx"
|
#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p.tx"
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
int get_command_from_message(const epee::byte_slice &msg)
|
|
||||||
{
|
|
||||||
return msg.size() >= sizeof(epee::levin::bucket_head2) ? SWAP32LE(((epee::levin::bucket_head2*)msg.data())->m_command) : 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
{
|
{
|
||||||
namespace levin
|
namespace levin
|
||||||
|
@ -212,7 +204,7 @@ namespace levin
|
||||||
{
|
{
|
||||||
const epee::byte_slice blob = make_tx_payload(std::move(txs), pad, fluff);
|
const epee::byte_slice blob = make_tx_payload(std::move(txs), pad, fluff);
|
||||||
p2p.for_connection(destination, [&blob](detail::p2p_context& context) {
|
p2p.for_connection(destination, [&blob](detail::p2p_context& context) {
|
||||||
on_levin_traffic(context, true, true, false, blob.size(), get_command_from_message(blob));
|
on_levin_traffic(context, true, true, false, blob.size(), NOTIFY_NEW_TRANSACTIONS::ID);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return p2p.notify(NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(blob), destination);
|
return p2p.notify(NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(blob), destination);
|
||||||
|
|
|
@ -2275,6 +2275,7 @@ bool t_rpc_command_executor::sync_info()
|
||||||
tools::success_msg_writer() << "Next needed pruning seed: " << res.next_needed_pruning_seed;
|
tools::success_msg_writer() << "Next needed pruning seed: " << res.next_needed_pruning_seed;
|
||||||
|
|
||||||
tools::success_msg_writer() << std::to_string(res.peers.size()) << " peers";
|
tools::success_msg_writer() << std::to_string(res.peers.size()) << " peers";
|
||||||
|
tools::success_msg_writer() << "Remote Host Peer_ID State Prune_Seed Height DL kB/s, Queued Blocks / MB";
|
||||||
for (const auto &p: res.peers)
|
for (const auto &p: res.peers)
|
||||||
{
|
{
|
||||||
std::string address = epee::string_tools::pad_string(p.info.address, 24);
|
std::string address = epee::string_tools::pad_string(p.info.address, 24);
|
||||||
|
|
|
@ -234,6 +234,7 @@ namespace nodetool
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const time_t now = time(nullptr);
|
const time_t now = time(nullptr);
|
||||||
|
bool added = false;
|
||||||
|
|
||||||
CRITICAL_REGION_LOCAL(m_blocked_hosts_lock);
|
CRITICAL_REGION_LOCAL(m_blocked_hosts_lock);
|
||||||
time_t limit;
|
time_t limit;
|
||||||
|
@ -244,7 +245,10 @@ namespace nodetool
|
||||||
const std::string host_str = addr.host_str();
|
const std::string host_str = addr.host_str();
|
||||||
auto it = m_blocked_hosts.find(host_str);
|
auto it = m_blocked_hosts.find(host_str);
|
||||||
if (it == m_blocked_hosts.end())
|
if (it == m_blocked_hosts.end())
|
||||||
|
{
|
||||||
m_blocked_hosts[host_str] = limit;
|
m_blocked_hosts[host_str] = limit;
|
||||||
|
added = true;
|
||||||
|
}
|
||||||
else if (it->second < limit || !add_only)
|
else if (it->second < limit || !add_only)
|
||||||
it->second = limit;
|
it->second = limit;
|
||||||
|
|
||||||
|
@ -275,7 +279,10 @@ namespace nodetool
|
||||||
conns.clear();
|
conns.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MCLOG_CYAN(el::Level::Info, "global", "Host " << host_str << " blocked.");
|
if (added)
|
||||||
|
MCLOG_CYAN(el::Level::Info, "global", "Host " << host_str << " blocked.");
|
||||||
|
else
|
||||||
|
MINFO("Host " << host_str << " block time updated.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//-----------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------
|
||||||
|
|
|
@ -452,7 +452,7 @@ namespace cryptonote
|
||||||
m_core.get_blockchain_top(res.height, top_hash);
|
m_core.get_blockchain_top(res.height, top_hash);
|
||||||
++res.height; // turn top block height into blockchain height
|
++res.height; // turn top block height into blockchain height
|
||||||
res.top_block_hash = string_tools::pod_to_hex(top_hash);
|
res.top_block_hash = string_tools::pod_to_hex(top_hash);
|
||||||
res.target_height = m_core.get_target_blockchain_height();
|
res.target_height = m_p2p.get_payload_object().is_synchronized() ? 0 : m_core.get_target_blockchain_height();
|
||||||
store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
|
store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
|
||||||
res.target = m_core.get_blockchain_storage().get_difficulty_target();
|
res.target = m_core.get_blockchain_storage().get_difficulty_target();
|
||||||
res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
|
res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
|
||||||
|
@ -2915,7 +2915,7 @@ namespace cryptonote
|
||||||
crypto::hash top_hash;
|
crypto::hash top_hash;
|
||||||
m_core.get_blockchain_top(res.height, top_hash);
|
m_core.get_blockchain_top(res.height, top_hash);
|
||||||
++res.height; // turn top block height into blockchain height
|
++res.height; // turn top block height into blockchain height
|
||||||
res.target_height = m_core.get_target_blockchain_height();
|
res.target_height = m_p2p.get_payload_object().is_synchronized() ? 0 : m_core.get_target_blockchain_height();
|
||||||
res.next_needed_pruning_seed = m_p2p.get_payload_object().get_next_needed_pruning_stripe().second;
|
res.next_needed_pruning_seed = m_p2p.get_payload_object().get_next_needed_pruning_stripe().second;
|
||||||
|
|
||||||
for (const auto &c: m_p2p.get_payload_object().get_connections())
|
for (const auto &c: m_p2p.get_payload_object().get_connections())
|
||||||
|
|
|
@ -4745,9 +4745,14 @@ bool simple_wallet::try_connect_to_daemon(bool silent, uint32_t* version)
|
||||||
if (!m_wallet->check_connection(version))
|
if (!m_wallet->check_connection(version))
|
||||||
{
|
{
|
||||||
if (!silent)
|
if (!silent)
|
||||||
fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_wallet->get_daemon_address() << ". " <<
|
{
|
||||||
tr("Daemon either is not started or wrong port was passed. "
|
if (m_wallet->is_offline())
|
||||||
"Please make sure daemon is running or change the daemon address using the 'set_daemon' command.");
|
fail_msg_writer() << tr("wallet failed to connect to daemon, because it is set to offline mode");
|
||||||
|
else
|
||||||
|
fail_msg_writer() << tr("wallet failed to connect to daemon: ") << m_wallet->get_daemon_address() << ". " <<
|
||||||
|
tr("Daemon either is not started or wrong port was passed. "
|
||||||
|
"Please make sure daemon is running or change the daemon address using the 'set_daemon' command.");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!m_allow_mismatched_daemon_version && ((*version >> 16) != CORE_RPC_VERSION_MAJOR))
|
if (!m_allow_mismatched_daemon_version && ((*version >> 16) != CORE_RPC_VERSION_MAJOR))
|
||||||
|
@ -9278,7 +9283,7 @@ bool simple_wallet::run()
|
||||||
|
|
||||||
refresh_main(0, ResetNone, true);
|
refresh_main(0, ResetNone, true);
|
||||||
|
|
||||||
m_auto_refresh_enabled = m_wallet->auto_refresh();
|
m_auto_refresh_enabled = !m_wallet->is_offline() && m_wallet->auto_refresh();
|
||||||
m_idle_thread = boost::thread([&]{wallet_idle_thread();});
|
m_idle_thread = boost::thread([&]{wallet_idle_thread();});
|
||||||
|
|
||||||
message_writer(console_color_green, false) << "Background refresh thread started";
|
message_writer(console_color_green, false) << "Background refresh thread started";
|
||||||
|
|
|
@ -1546,6 +1546,7 @@ private:
|
||||||
void finish_rescan_bc_keep_key_images(uint64_t transfer_height, const crypto::hash &hash);
|
void finish_rescan_bc_keep_key_images(uint64_t transfer_height, const crypto::hash &hash);
|
||||||
void enable_dns(bool enable) { m_use_dns = enable; }
|
void enable_dns(bool enable) { m_use_dns = enable; }
|
||||||
void set_offline(bool offline = true);
|
void set_offline(bool offline = true);
|
||||||
|
bool is_offline() const { return m_offline; }
|
||||||
|
|
||||||
uint64_t credits() const { return m_rpc_payment_state.credits; }
|
uint64_t credits() const { return m_rpc_payment_state.credits; }
|
||||||
void credit_report(uint64_t &expected_spent, uint64_t &discrepancy) const { expected_spent = m_rpc_payment_state.expected_spent; discrepancy = m_rpc_payment_state.discrepancy; }
|
void credit_report(uint64_t &expected_spent, uint64_t &discrepancy) const { expected_spent = m_rpc_payment_state.expected_spent; discrepancy = m_rpc_payment_state.discrepancy; }
|
||||||
|
|
|
@ -80,17 +80,22 @@ file(COPY
|
||||||
data/signed_monero_tx
|
data/signed_monero_tx
|
||||||
DESTINATION data)
|
DESTINATION data)
|
||||||
|
|
||||||
add_subdirectory(core_tests)
|
if (CMAKE_BUILD_TYPE STREQUAL "fuzz" OR OSSFUZZ)
|
||||||
add_subdirectory(fuzz)
|
add_subdirectory(fuzz)
|
||||||
add_subdirectory(crypto)
|
else ()
|
||||||
add_subdirectory(functional_tests)
|
add_subdirectory(core_tests)
|
||||||
add_subdirectory(performance_tests)
|
add_subdirectory(fuzz)
|
||||||
add_subdirectory(core_proxy)
|
add_subdirectory(crypto)
|
||||||
add_subdirectory(unit_tests)
|
add_subdirectory(functional_tests)
|
||||||
add_subdirectory(difficulty)
|
add_subdirectory(performance_tests)
|
||||||
add_subdirectory(block_weight)
|
add_subdirectory(core_proxy)
|
||||||
add_subdirectory(hash)
|
add_subdirectory(unit_tests)
|
||||||
add_subdirectory(net_load_tests)
|
add_subdirectory(difficulty)
|
||||||
|
add_subdirectory(block_weight)
|
||||||
|
add_subdirectory(hash)
|
||||||
|
add_subdirectory(net_load_tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BUILD_GUI_DEPS)
|
if (BUILD_GUI_DEPS)
|
||||||
add_subdirectory(libwallet_api_tests)
|
add_subdirectory(libwallet_api_tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
Binary file not shown.
|
@ -218,3 +218,13 @@ set_property(TARGET tx-extra_fuzz_tests
|
||||||
PROPERTY
|
PROPERTY
|
||||||
FOLDER "tests")
|
FOLDER "tests")
|
||||||
|
|
||||||
|
monero_add_minimal_executable(utf8_fuzz_tests utf8.cpp fuzzer.cpp)
|
||||||
|
target_link_libraries(utf8_fuzz_tests
|
||||||
|
PRIVATE
|
||||||
|
common
|
||||||
|
epee
|
||||||
|
${Boost_THREAD_LIBRARY}
|
||||||
|
${Boost_CHRONO_LIBRARY}
|
||||||
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
${EXTRA_LIBRARIES}
|
||||||
|
$ENV{LIB_FUZZING_ENGINE})
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
// Copyright (c) 2017-2020, The Monero Project
|
||||||
|
//
|
||||||
|
// All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
// materials provided with the distribution.
|
||||||
|
//
|
||||||
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
// used to endorse or promote products derived from this software without specific
|
||||||
|
// prior written permission.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
#include "include_base_utils.h"
|
||||||
|
#include "file_io_utils.h"
|
||||||
|
#include "common/utf8.h"
|
||||||
|
#include "fuzzer.h"
|
||||||
|
|
||||||
|
BEGIN_INIT_SIMPLE_FUZZER()
|
||||||
|
END_INIT_SIMPLE_FUZZER()
|
||||||
|
|
||||||
|
BEGIN_SIMPLE_FUZZER()
|
||||||
|
tools::utf8canonical(std::string((const char*)buf, len), [](wint_t c)->wint_t { return c; });
|
||||||
|
END_SIMPLE_FUZZER()
|
|
@ -15,6 +15,10 @@ On the first run, the script will complain about the missing ClangBuildAnalyzer
|
||||||
`utils/health/clang-tidy-run.sh`
|
`utils/health/clang-tidy-run.sh`
|
||||||
Performs Lint checks on the source code and stores the result in the build directory. More information on the [home page](https://clang.llvm.org/extra/clang-tidy/).
|
Performs Lint checks on the source code and stores the result in the build directory. More information on the [home page](https://clang.llvm.org/extra/clang-tidy/).
|
||||||
|
|
||||||
|
##include-what-you-use
|
||||||
|
`utils/health/clang-include-what-you-use-run.sh`
|
||||||
|
Analyses the header file hierarchy and delivers hints on how to reduce their complexity. More information on the [home page](https://include-what-you-use.org/).
|
||||||
|
|
||||||
|
|
||||||
##Valgrind checks
|
##Valgrind checks
|
||||||
`utils/health/valgrind-tests.sh`
|
`utils/health/valgrind-tests.sh`
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# Copyright (c) 2014-2020, The Monero Project
|
||||||
|
#
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
# permitted provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
# conditions and the following disclaimer.
|
||||||
|
#
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
# of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
# materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software without specific
|
||||||
|
# prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
# Include What You Use analyses the complexity of your header hierarchy and proposes optimisations.
|
||||||
|
# User documentation:
|
||||||
|
# https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md
|
||||||
|
|
||||||
|
# Build variables
|
||||||
|
PROG="include-what-you-use"
|
||||||
|
PROG_SHORT="iwyu"
|
||||||
|
DIR_BUILD="build/clang-$PROG_SHORT"
|
||||||
|
|
||||||
|
RESULT="$PROG_SHORT-result.txt"
|
||||||
|
|
||||||
|
if hash "$PROG"; then
|
||||||
|
echo "Found: $PROG"
|
||||||
|
else
|
||||||
|
echo "Couldn't find: $PROG"
|
||||||
|
echo "Please run the below command to install $PROG:"
|
||||||
|
echo "sudo apt install $PROG_SHORT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$DIR_BUILD" && cd "$DIR_BUILD"
|
||||||
|
rm `find . -name "CMakeCache.txt"` || true
|
||||||
|
|
||||||
|
UWYU_COMMAND="$PROG;-Xiwyu;any;-Xiwyu;iwyu;-Xiwyu;args" # Copy-pasted from the user docs.
|
||||||
|
|
||||||
|
cmake ../.. \
|
||||||
|
-DCMAKE_C_COMPILER=clang \
|
||||||
|
-DCMAKE_CXX_COMPILER=clang++ \
|
||||||
|
-DUSE_CCACHE=ON \
|
||||||
|
-DCMAKE_C_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \
|
||||||
|
-DCMAKE_CXX_INCLUDE_WHAT_YOU_USE="$UWYU_COMMAND" \
|
||||||
|
-DBUILD_SHARED_LIBS=ON \
|
||||||
|
-DBUILD_TESTS=ON
|
||||||
|
|
||||||
|
make clean # Clean up to generate the full report
|
||||||
|
time make -k 2>&1 | tee "$RESULT" # Run the scan. -k means: ignore errors
|
||||||
|
#time make -k easylogging 2>&1 | tee $RESULT # Quick testing: build a single target
|
||||||
|
KPI=$(cat "$RESULT" | wc -l)
|
||||||
|
tar -cJvf "$RESULT.txz" "$RESULT" # Zip the result, because it's huge.
|
||||||
|
rm -v "$RESULT"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Readable result stored in: $DIR_BUILD/$RESULT.gz"
|
||||||
|
|
||||||
|
echo "$KPI" > "kpis.txt"
|
|
@ -0,0 +1,161 @@
|
||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# Copyright (c) 2014-2020, The Monero Project
|
||||||
|
#
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
# permitted provided that the following conditions are met:
|
||||||
|
#
|
||||||
|
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
# conditions and the following disclaimer.
|
||||||
|
#
|
||||||
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
# of conditions and the following disclaimer in the documentation and/or other
|
||||||
|
# materials provided with the distribution.
|
||||||
|
#
|
||||||
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||||
|
# used to endorse or promote products derived from this software without specific
|
||||||
|
# prior written permission.
|
||||||
|
#
|
||||||
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||||
|
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
# This script is able to run valgrind's callgrind, cachegrind and memcheck for a given set of executables.
|
||||||
|
# It expects ONE PARAMETER, which points to a file with paths to executables and their arguments, written line by line.
|
||||||
|
|
||||||
|
if [ "$#" -ne 1 ]; then
|
||||||
|
echo "Please provide an argument, which points to a file with paths to executables and their arguments, written line by line. For example:"
|
||||||
|
echo ""
|
||||||
|
echo "ls -l -h"
|
||||||
|
echo "build/tests/unit_tests/unit_tests"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILE_IN="$1"
|
||||||
|
DIR_OUT="build/valgrind-output" # Using build as the base output directory, as it's ignored in .gitignore
|
||||||
|
|
||||||
|
function is_file_or_exit {
|
||||||
|
FILE="${1}"
|
||||||
|
if [ -f $FILE ]; then
|
||||||
|
echo "The input file $FILE exists. Can proceed."
|
||||||
|
else
|
||||||
|
echo "The input file $FILE doesn't exist."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function is_tool_or_exit {
|
||||||
|
TOOL="${1}"
|
||||||
|
if $(hash ${TOOL}); then
|
||||||
|
echo "${TOOL} is installed. Can proceed."
|
||||||
|
else
|
||||||
|
echo "Please install ${TOOL} to continue."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_tool_out_file_base {
|
||||||
|
EXE="${1}"
|
||||||
|
TOOL="${2}"
|
||||||
|
|
||||||
|
EXE_NAME=$(basename $EXE)
|
||||||
|
local retval="${DIR_OUT}/${EXE_NAME}-${TOOL}"
|
||||||
|
echo "$retval"
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_tool_out_file {
|
||||||
|
EXE="${1}"
|
||||||
|
TOOL="${2}"
|
||||||
|
|
||||||
|
FILE_OUT_BASE=$(get_tool_out_file_base ${EXE} ${TOOL})
|
||||||
|
local retval="--${TOOL}-out-file=${FILE_OUT_BASE}.out"
|
||||||
|
echo "$retval"
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_valgrind_4_executable {
|
||||||
|
EXE="${1}"
|
||||||
|
ARGS="${2}"
|
||||||
|
TOOL="${3}"
|
||||||
|
EXTRA_OPTS="${4}"
|
||||||
|
FILE_OUT_TOOL="${5}"
|
||||||
|
FILE_OUT_BASE=$(get_tool_out_file_base ${EXE} ${TOOL})
|
||||||
|
|
||||||
|
echo "Runnig '${TOOL}' for '${EXE}' with args '${ARGS}'"
|
||||||
|
echo "EXTRA_OPTS = ${EXTRA_OPTS}"
|
||||||
|
echo "FILE_OUT_TOOL = ${FILE_OUT_TOOL}"
|
||||||
|
if ! valgrind --tool=${TOOL} ${FILE_OUT_TOOL} --log-file="${FILE_OUT_BASE}.log" ${EXTRA_OPTS} ${EXE} ${ARGS}; then
|
||||||
|
echo "FAILED in runnig ${TOOL} for ${EXE} !"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_valgrind_4_executable_callgrind {
|
||||||
|
EXE="${1}"
|
||||||
|
ARGS="${2}"
|
||||||
|
TOOL="callgrind"
|
||||||
|
EXTRA_OPTS="--dump-instr=yes --simulate-cache=yes --collect-jumps=yes"
|
||||||
|
FILE_OUT_TOOL=$(get_tool_out_file ${EXE} ${TOOL})
|
||||||
|
|
||||||
|
run_valgrind_4_executable ${EXE} "${ARGS}" ${TOOL} "${EXTRA_OPTS}" ${FILE_OUT_TOOL}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_valgrind_4_executable_cachegrind {
|
||||||
|
EXE="${1}"
|
||||||
|
ARGS="${2}"
|
||||||
|
TOOL="cachegrind"
|
||||||
|
EXTRA_OPTS=""
|
||||||
|
FILE_OUT_TOOL=$(get_tool_out_file ${EXE} ${TOOL})
|
||||||
|
|
||||||
|
run_valgrind_4_executable ${EXE} "${ARGS}" ${TOOL} "${EXTRA_OPTS}" ${FILE_OUT_TOOL}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_valgrind_4_executable_memcheck {
|
||||||
|
EXE="${1}"
|
||||||
|
ARGS="${2}"
|
||||||
|
TOOL="memcheck"
|
||||||
|
#EXTRA_OPTS="--leak-check=yes" # Minimalistic
|
||||||
|
EXTRA_OPTS="--leak-check=full --show-leak-kinds=all --track-origins=yes"
|
||||||
|
FILE_OUT_TOOL="" # memcheck has no special out file, only the log
|
||||||
|
|
||||||
|
run_valgrind_4_executable ${EXE} "${ARGS}" ${TOOL} "${EXTRA_OPTS}" ${FILE_OUT_TOOL}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_valgrind_4_executable_all {
|
||||||
|
EXE_ARGS_ARR=(${1})
|
||||||
|
EXE=${EXE_ARGS_ARR[0]} # First element of the array
|
||||||
|
ARGS=${EXE_ARGS_ARR[@]:1} # Every next element
|
||||||
|
|
||||||
|
#EXE="ls" # A quick check of the happy path
|
||||||
|
#EXE="nothere" # A quick check of error handling - no such executable
|
||||||
|
#EXE=/bin/false # A quick check of error handling - executable returned != 0
|
||||||
|
|
||||||
|
run_valgrind_4_executable_memcheck ${EXE} "${ARGS}"
|
||||||
|
run_valgrind_4_executable_cachegrind ${EXE} "${ARGS}"
|
||||||
|
run_valgrind_4_executable_callgrind ${EXE} "${ARGS}"
|
||||||
|
}
|
||||||
|
|
||||||
|
is_tool_or_exit valgrind
|
||||||
|
is_file_or_exit "$FILE_IN"
|
||||||
|
echo "All OK."
|
||||||
|
echo "Will perform checks for the following executables and their arguments:"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
echo "$line"
|
||||||
|
done < "$FILE_IN"
|
||||||
|
|
||||||
|
mkdir -p "$DIR_OUT"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
echo "$line"
|
||||||
|
run_valgrind_4_executable_all "$line"
|
||||||
|
done < "$FILE_IN"
|
||||||
|
|
||||||
|
echo "Done. All data saved in ${DIR_OUT}"
|
||||||
|
|
Loading…
Reference in New Issue