diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/performance_tests/main.cpp | 166 | ||||
-rw-r--r-- | tests/performance_tests/performance_tests.h | 15 | ||||
-rw-r--r-- | tests/performance_tests/rct_mlsag.h | 87 | ||||
-rw-r--r-- | tests/unit_tests/address_from_url.cpp | 3 | ||||
-rw-r--r-- | tests/unit_tests/memwipe.cpp | 2 |
5 files changed, 208 insertions, 65 deletions
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 2f3ce289d..51061dd6f 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -28,7 +28,10 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers +#include <boost/regex.hpp> + #include "common/util.h" +#include "common/command_line.h" #include "performance_tests.h" #include "performance_utils.h" @@ -47,6 +50,28 @@ #include "subaddress_expand.h" #include "sc_reduce32.h" #include "cn_fast_hash.h" +#include "rct_mlsag.h" + +namespace po = boost::program_options; + +std::string glob_to_regex(const std::string &val) +{ + std::string newval; + + bool escape = false; + for (char c: val) + { + if (c == '*') + newval += escape ? "*" : ".*"; + else if (c == '?') + newval += escape ? "?" : "."; + else if (c == '\\') + newval += '\\', escape = !escape; + else + newval += c; + } + return newval; +} int main(int argc, char** argv) { @@ -57,67 +82,92 @@ int main(int argc, char** argv) mlog_configure(mlog_get_default_log_path("performance_tests.log"), true); mlog_set_log_level(0); + po::options_description desc_options("Command line options"); + const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" }; + command_line::add_arg(desc_options, arg_filter, ""); + + po::variables_map vm; + bool r = command_line::handle_error_helper(desc_options, [&]() + { + po::store(po::parse_command_line(argc, argv, desc_options), vm); + po::notify(vm); + return true; + }); + if (!r) + return 1; + + const std::string filter = glob_to_regex(command_line::get_arg(vm, arg_filter)); + performance_timer timer; timer.start(); - TEST_PERFORMANCE3(test_construct_tx, 1, 1, false); - TEST_PERFORMANCE3(test_construct_tx, 1, 2, false); - TEST_PERFORMANCE3(test_construct_tx, 1, 10, false); - TEST_PERFORMANCE3(test_construct_tx, 1, 100, false); - TEST_PERFORMANCE3(test_construct_tx, 1, 1000, false); - - TEST_PERFORMANCE3(test_construct_tx, 2, 1, false); - TEST_PERFORMANCE3(test_construct_tx, 2, 2, false); - TEST_PERFORMANCE3(test_construct_tx, 2, 10, false); - TEST_PERFORMANCE3(test_construct_tx, 2, 100, false); - - TEST_PERFORMANCE3(test_construct_tx, 10, 1, false); - TEST_PERFORMANCE3(test_construct_tx, 10, 2, false); - TEST_PERFORMANCE3(test_construct_tx, 10, 10, false); - TEST_PERFORMANCE3(test_construct_tx, 10, 100, false); - - TEST_PERFORMANCE3(test_construct_tx, 100, 1, false); - TEST_PERFORMANCE3(test_construct_tx, 100, 2, false); - TEST_PERFORMANCE3(test_construct_tx, 100, 10, false); - TEST_PERFORMANCE3(test_construct_tx, 100, 100, false); - - TEST_PERFORMANCE3(test_construct_tx, 2, 1, true); - TEST_PERFORMANCE3(test_construct_tx, 2, 2, true); - TEST_PERFORMANCE3(test_construct_tx, 2, 10, true); - - TEST_PERFORMANCE3(test_construct_tx, 10, 1, true); - TEST_PERFORMANCE3(test_construct_tx, 10, 2, true); - TEST_PERFORMANCE3(test_construct_tx, 10, 10, true); - - TEST_PERFORMANCE3(test_construct_tx, 100, 1, true); - TEST_PERFORMANCE3(test_construct_tx, 100, 2, true); - TEST_PERFORMANCE3(test_construct_tx, 100, 10, true); - - TEST_PERFORMANCE2(test_check_tx_signature, 1, false); - TEST_PERFORMANCE2(test_check_tx_signature, 2, false); - TEST_PERFORMANCE2(test_check_tx_signature, 10, false); - TEST_PERFORMANCE2(test_check_tx_signature, 100, false); - - TEST_PERFORMANCE2(test_check_tx_signature, 2, true); - TEST_PERFORMANCE2(test_check_tx_signature, 10, true); - TEST_PERFORMANCE2(test_check_tx_signature, 100, true); - - TEST_PERFORMANCE0(test_is_out_to_acc); - TEST_PERFORMANCE0(test_is_out_to_acc_precomp); - TEST_PERFORMANCE0(test_generate_key_image_helper); - TEST_PERFORMANCE0(test_generate_key_derivation); - TEST_PERFORMANCE0(test_generate_key_image); - TEST_PERFORMANCE0(test_derive_public_key); - TEST_PERFORMANCE0(test_derive_secret_key); - TEST_PERFORMANCE0(test_ge_frombytes_vartime); - TEST_PERFORMANCE0(test_generate_keypair); - TEST_PERFORMANCE0(test_sc_reduce32); - - TEST_PERFORMANCE2(test_wallet2_expand_subaddresses, 50, 200); - - TEST_PERFORMANCE0(test_cn_slow_hash); - TEST_PERFORMANCE1(test_cn_fast_hash, 32); - TEST_PERFORMANCE1(test_cn_fast_hash, 16384); + TEST_PERFORMANCE3(filter, test_construct_tx, 1, 1, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 1, 2, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 1, 10, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 1, 100, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 1, 1000, false); + + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 1, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 2, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 10, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 100, false); + + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 1, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 2, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 10, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 100, false); + + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 1, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 2, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 10, false); + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 100, false); + + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 1, true); + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 2, true); + TEST_PERFORMANCE3(filter, test_construct_tx, 2, 10, true); + + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 1, true); + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 2, true); + TEST_PERFORMANCE3(filter, test_construct_tx, 10, 10, true); + + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 1, true); + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 2, true); + TEST_PERFORMANCE3(filter, test_construct_tx, 100, 10, true); + + TEST_PERFORMANCE2(filter, test_check_tx_signature, 1, false); + TEST_PERFORMANCE2(filter, test_check_tx_signature, 2, false); + TEST_PERFORMANCE2(filter, test_check_tx_signature, 10, false); + TEST_PERFORMANCE2(filter, test_check_tx_signature, 100, false); + + TEST_PERFORMANCE2(filter, test_check_tx_signature, 2, true); + TEST_PERFORMANCE2(filter, test_check_tx_signature, 10, true); + TEST_PERFORMANCE2(filter, test_check_tx_signature, 100, true); + + TEST_PERFORMANCE0(filter, test_is_out_to_acc); + TEST_PERFORMANCE0(filter, test_is_out_to_acc_precomp); + TEST_PERFORMANCE0(filter, test_generate_key_image_helper); + TEST_PERFORMANCE0(filter, test_generate_key_derivation); + TEST_PERFORMANCE0(filter, test_generate_key_image); + TEST_PERFORMANCE0(filter, test_derive_public_key); + TEST_PERFORMANCE0(filter, test_derive_secret_key); + TEST_PERFORMANCE0(filter, test_ge_frombytes_vartime); + TEST_PERFORMANCE0(filter, test_generate_keypair); + TEST_PERFORMANCE0(filter, test_sc_reduce32); + + TEST_PERFORMANCE2(filter, test_wallet2_expand_subaddresses, 50, 200); + + TEST_PERFORMANCE0(filter, test_cn_slow_hash); + TEST_PERFORMANCE1(filter, test_cn_fast_hash, 32); + TEST_PERFORMANCE1(filter, test_cn_fast_hash, 16384); + + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 3, false); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 5, false); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 10, false); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 100, false); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 3, true); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 5, true); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 10, true); + TEST_PERFORMANCE3(test_ringct_mlsag, 1, 100, true); std::cout << "Tests finished. Elapsed time: " << timer.elapsed_ms() / 1000 << " sec" << std::endl; diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h index a4d49fd82..589c34caf 100644 --- a/tests/performance_tests/performance_tests.h +++ b/tests/performance_tests/performance_tests.h @@ -34,6 +34,7 @@ #include <stdint.h> #include <boost/chrono.hpp> +#include <boost/regex.hpp> class performance_timer { @@ -122,8 +123,12 @@ private: }; template <typename T> -void run_test(const char* test_name) +void run_test(const std::string &filter, const char* test_name) { + boost::smatch match; + if (!filter.empty() && !boost::regex_match(std::string(test_name), match, boost::regex(filter))) + return; + test_runner<T> runner; if (runner.run()) { @@ -149,7 +154,7 @@ void run_test(const char* test_name) } #define QUOTEME(x) #x -#define TEST_PERFORMANCE0(test_class) run_test< test_class >(QUOTEME(test_class)) -#define TEST_PERFORMANCE1(test_class, a0) run_test< test_class<a0> >(QUOTEME(test_class<a0>)) -#define TEST_PERFORMANCE2(test_class, a0, a1) run_test< test_class<a0, a1> >(QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">") -#define TEST_PERFORMANCE3(test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">") +#define TEST_PERFORMANCE0(filter, test_class) run_test< test_class >(filter, QUOTEME(test_class)) +#define TEST_PERFORMANCE1(filter, test_class, a0) run_test< test_class<a0> >(filter, QUOTEME(test_class<a0>)) +#define TEST_PERFORMANCE2(filter, test_class, a0, a1) run_test< test_class<a0, a1> >(filter, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">") +#define TEST_PERFORMANCE3(filter, test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(filter, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">") diff --git a/tests/performance_tests/rct_mlsag.h b/tests/performance_tests/rct_mlsag.h new file mode 100644 index 000000000..70fb36aec --- /dev/null +++ b/tests/performance_tests/rct_mlsag.h @@ -0,0 +1,87 @@ +// Copyright (c) 2014-2017, 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. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#pragma once + +#include "ringct/rctSigs.h" +#include "cryptonote_basic/cryptonote_basic.h" + +#include "single_tx_test_base.h" + +template<size_t inputs, size_t ring_size, bool ver> +class test_ringct_mlsag : public single_tx_test_base +{ +public: + static const size_t cols = ring_size; + static const size_t rows = inputs; + static const size_t loop_count = 100; + + bool init() + { + if (!single_tx_test_base::init()) + return false; + + rct::keyV xtmp = rct::skvGen(rows); + rct::keyM xm = rct::keyMInit(rows, cols);// = [[None]*N] #just used to generate test public keys + sk = rct::skvGen(rows); + P = rct::keyMInit(rows, cols);// = keyM[[None]*N] #stores the public keys; + ind = 2; + for (size_t j = 0 ; j < rows ; j++) + { + for (size_t i = 0 ; i < cols ; i++) + { + xm[i][j] = rct::skGen(); + P[i][j] = rct::scalarmultBase(xm[i][j]); + } + } + for (size_t j = 0 ; j < rows ; j++) + { + sk[j] = xm[ind][j]; + } + IIccss = MLSAG_Gen(rct::identity(), P, sk, NULL, NULL, ind, rows); + + return true; + } + + bool test() + { + if (ver) + MLSAG_Ver(rct::identity(), P, IIccss, rows); + else + MLSAG_Gen(rct::identity(), P, sk, NULL, NULL, ind, rows); + return true; + } + +private: + rct::keyV sk; + rct::keyM P; + size_t ind; + rct::mgSig IIccss; +}; diff --git a/tests/unit_tests/address_from_url.cpp b/tests/unit_tests/address_from_url.cpp index 3630b59d3..f4ecbc295 100644 --- a/tests/unit_tests/address_from_url.cpp +++ b/tests/unit_tests/address_from_url.cpp @@ -32,6 +32,7 @@ #include "wallet/wallet2.h" #include "common/dns_utils.h" +#include "simplewallet/simplewallet.h" #include <string> TEST(AddressFromTXT, Success) @@ -83,7 +84,7 @@ TEST(AddressFromTXT, Failure) TEST(AddressFromURL, Success) { - const std::string addr = "44AFFq5kSiGBoZ4NMDwYtN18obc8AemS33DBLWs3H7otXft3XjrpDtQGv7SqSsaBYBb98uNbr2VBBEt7f2wfn3RVGQBEP3A"; + const std::string addr = MONERO_DONATION_ADDR; bool dnssec_result = false; diff --git a/tests/unit_tests/memwipe.cpp b/tests/unit_tests/memwipe.cpp index 59f50cef8..93dcc19f6 100644 --- a/tests/unit_tests/memwipe.cpp +++ b/tests/unit_tests/memwipe.cpp @@ -47,7 +47,7 @@ static void test(bool wipe) if ((intptr_t)quux == foop) { MDEBUG(std::hex << std::setw(8) << std::setfill('0') << *(uint32_t*)quux); - if (wipe) ASSERT_TRUE(memcmp(quux, "bar", 3)); + if (wipe) { ASSERT_TRUE(memcmp(quux, "bar", 3)); } } else MWARNING("We did not get the same location, cannot check"); free(quux); |