Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
Update source/tests
Browse files Browse the repository at this point in the history
- reduce std::cout usage significantly
- replace global _argc/_argv with test_argc/test_argv
  • Loading branch information
jrmadsen committed Oct 11, 2023
1 parent 1f5f729 commit 4d8f152
Show file tree
Hide file tree
Showing 26 changed files with 352 additions and 400 deletions.
20 changes: 10 additions & 10 deletions source/tests/aligned_allocator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,14 @@ TEST_F(aligned_allocator_tests, m128)
});

// print the solution and initial factors for record-keeping
std::cout << "\nsizeof(__m128) = " << sizeof(__m128) << std::endl;
details::print(std::cout, "initial factors", factors);
details::print(std::cout, "solution", solution);
// std::cout << "\nsizeof(__m128) = " << sizeof(__m128) << std::endl;
// details::print(std::cout, "initial factors", factors);
// details::print(std::cout, "solution", solution);

for(std::size_t i = 0; i < niter; ++i)
{
// print current iteration
std::cout << "\niteration " << i << ":\n";
// std::cout << "\niteration " << i << ":\n";

// create two __m128 packed vectors to add together
lhs.push_back(_mm_set_ps(factors[3], factors[2], factors[1], factors[0]));
Expand Down Expand Up @@ -234,7 +234,7 @@ TEST_F(aligned_allocator_tests, m128)
lhs.erase(lhs.begin());
rhs.erase(rhs.begin());
}
std::cout << std::endl;
// std::cout << std::endl;
}

//--------------------------------------------------------------------------------------//
Expand Down Expand Up @@ -264,14 +264,14 @@ TEST_F(aligned_allocator_tests, m128d)
});

// print the solution and initial factors for record-keeping
std::cout << "\nsizeof(__m128d) = " << sizeof(__m128d) << std::endl;
details::print(std::cout, "initial factors", factors);
details::print(std::cout, "solution", solution);
// std::cout << "\nsizeof(__m128d) = " << sizeof(__m128d) << std::endl;
// details::print(std::cout, "initial factors", factors);
// details::print(std::cout, "solution", solution);

for(std::size_t i = 0; i < niter; ++i)
{
// print current iteration
std::cout << "\niteration " << i << ":\n";
// std::cout << "\niteration " << i << ":\n";

// create two __m128 packed vectors to add together
lhs.push_back(_mm_set_pd(factors[1], factors[0]));
Expand Down Expand Up @@ -303,7 +303,7 @@ TEST_F(aligned_allocator_tests, m128d)
lhs.erase(lhs.begin());
rhs.erase(rhs.begin());
}
std::cout << std::endl;
// std::cout << std::endl;
}

//--------------------------------------------------------------------------------------//
8 changes: 4 additions & 4 deletions source/tests/archive_storage_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ class archive_storage_tests : public ::testing::Test
tim::settings::cout_output() = false;
tim::settings::text_output() = true;
tim::settings::flamegraph_output() = false;
tim::dmp::initialize(_argc, _argv);
tim::timemory_init(_argc, _argv);
tim::dmp::initialize(test_argc, test_argv);
tim::timemory_init(test_argc, test_argv);
tim::settings::dart_output() = true;
tim::settings::dart_count() = 1;
tim::settings::banner() = false;
Expand All @@ -159,14 +159,14 @@ class archive_storage_tests : public ::testing::Test
threads.emplace_back(std::thread(details::generate_history, 5, 2));
for(auto& itr : threads)
itr.join();
std::cout << "Configured" << std::endl;
// std::cout << "Configured" << std::endl;
}

static void TearDownTestSuite()
{
tim::timemory_finalize();
tim::dmp::finalize();
std::cout << "Finalized" << std::endl;
// std::cout << "Finalized" << std::endl;
}

static std::map<std::string, std::string> f_results;
Expand Down
40 changes: 20 additions & 20 deletions source/tests/argparse_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
#include <thread>
#include <vector>

static int _argc = 0;
static char** _argv = nullptr;
static int test_argc = 0;
static char** test_argv = nullptr;
static int _margc = 0;
static char** _margv = nullptr;
static int _log_once = 0;
Expand Down Expand Up @@ -96,11 +96,11 @@ parse_function()
inline void
cleanup()
{
if(_argv)
if(test_argv)
{
for(int i = 0; i < _argc; ++i)
free(_argv[i]);
delete[] _argv;
for(int i = 0; i < test_argc; ++i)
free(test_argv[i]);
delete[] test_argv;
}
}
//
Expand Down Expand Up @@ -197,13 +197,13 @@ parse(argparse_t& parser, Args&&... args)
.max_count(1);
parser.add_argument({ "--load" }, "Extra libraries to load");

_argc = sizeof...(Args) + 1;
_argv = new char*[_argc];
_argv[0] = strdup(_arg0);
test_argc = sizeof...(Args) + 1;
test_argv = new char*[test_argc];
test_argv[0] = strdup(_arg0);
int i = 1;
TIMEMORY_FOLD_EXPRESSION((_argv[i] = strdup(std::forward<Args>(args)), ++i));
TIMEMORY_FOLD_EXPRESSION((test_argv[i] = strdup(std::forward<Args>(args)), ++i));

auto err = parse_function()(parser, _argc, _argv);
auto err = parse_function()(parser, test_argc, test_argv);

// only log the help function once
auto _log_id = _log_once++;
Expand Down Expand Up @@ -575,11 +575,11 @@ TEST_F(argparse_tests, parse_known_options)
EXPECT_TRUE(arg.at(2) == "and");
EXPECT_TRUE(arg.at(3) == "long");

EXPECT_EQ(_argc, 3);
EXPECT_EQ(std::string(_argv[0]), std::string(_arg0));
EXPECT_EQ(std::string(_argv[1]), std::string("10"));
EXPECT_EQ(std::string(_argv[2]), std::string("20"));
EXPECT_TRUE(_argv[3] == nullptr);
EXPECT_EQ(test_argc, 3);
EXPECT_EQ(std::string(test_argv[0]), std::string(_arg0));
EXPECT_EQ(std::string(test_argv[1]), std::string("10"));
EXPECT_EQ(std::string(test_argv[2]), std::string("20"));
EXPECT_TRUE(test_argv[3] == nullptr);

details::parse_function() = orig;
}
Expand Down Expand Up @@ -613,10 +613,10 @@ TEST_F(argparse_tests, parse_known_options_without_options)
EXPECT_FALSE(parser.get<bool>("p"));
EXPECT_FALSE(parser.get<bool>("pid"));

EXPECT_EQ(_argc, 3);
EXPECT_EQ(std::string(_argv[0]), std::string(_arg0));
EXPECT_EQ(std::string(_argv[1]), std::string("10"));
EXPECT_EQ(std::string(_argv[2]), std::string("20"));
EXPECT_EQ(test_argc, 3);
EXPECT_EQ(std::string(test_argv[0]), std::string(_arg0));
EXPECT_EQ(std::string(test_argv[1]), std::string("10"));
EXPECT_EQ(std::string(test_argv[2]), std::string("20"));

details::parse_function() = orig;
}
Expand Down
28 changes: 14 additions & 14 deletions source/tests/cache_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,14 @@ TEST_F(cache_tests, io)

TEST_F(cache_tests, validation)
{
puts("\n>>> INITIAL CACHE <<<\n");
puts(print_rusage_cache(*cache.at(0)).c_str());
puts("\n>>> BUNDLE <<<\n");
std::cout << *bundle << std::endl;
puts("\n>>> CACHE BUNDLE <<<\n");
std::cout << *cache_bundle << std::endl;
puts("\n>>> FINAL CACHE <<<\n");
puts(print_rusage_cache(*cache.at(1)).c_str());
// puts("\n>>> INITIAL CACHE <<<\n");
// puts(print_rusage_cache(*cache.at(0)).c_str());
// puts("\n>>> BUNDLE <<<\n");
// std::cout << *bundle << std::endl;
// puts("\n>>> CACHE BUNDLE <<<\n");
// std::cout << *cache_bundle << std::endl;
// puts("\n>>> FINAL CACHE <<<\n");
// puts(print_rusage_cache(*cache.at(1)).c_str());

EXPECT_NEAR(tot_size, bundle->get<peak_rss>()->get(), peak_tolerance);
EXPECT_NEAR(std::get<0>(bundle->get<current_peak_rss>()->get()),
Expand Down Expand Up @@ -683,12 +683,12 @@ TEST_F(cache_tests, complete_tuple)
_bundle.store(mpl::piecewise_ignore<perfetto_trace>{}, 1000.0);
_bundle.stop(_ecache);

puts("\n>>> INITIAL CACHE <<<\n");
puts(print_rusage_cache(_bcache).c_str());
puts("\n>>> BUNDLE <<<\n");
std::cout << _bundle << std::endl;
puts("\n>>> FINAL CACHE <<<\n");
puts(print_rusage_cache(_ecache).c_str());
// puts("\n>>> INITIAL CACHE <<<\n");
// puts(print_rusage_cache(_bcache).c_str());
// puts("\n>>> BUNDLE <<<\n");
// std::cout << _bundle << std::endl;
// puts("\n>>> FINAL CACHE <<<\n");
// puts(print_rusage_cache(_ecache).c_str());

_bundle.push(mpl::piecewise_select<data_tracker_floating, data_tracker_integer,
data_tracker_unsigned>{});
Expand Down
52 changes: 26 additions & 26 deletions source/tests/component_bundle_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ TEST_F(component_bundle_tests, variadic)
sizes[6] = bundle_t::size();
}

std::cout << "\n";
for(size_t i = 0; i < nz; ++i)
std::cout << "size[" << i << "] = " << sizes[i] << std::endl;
std::cout << "\n";
// std::cout << "\n";
// for(size_t i = 0; i < nz; ++i)
// std::cout << "size[" << i << "] = " << sizes[i] << std::endl;
// std::cout << "\n";

EXPECT_EQ(sizes[0], sizes[1]);

Expand All @@ -184,8 +184,8 @@ TEST_F(component_bundle_tests, variadic)
auto csize = tim::storage<cpu_clock>::instance()->size();
auto psize = tim::storage<peak_rss>::instance()->size();

std::cout << "\nbundle : " << tim::demangle<bundle_t>() << "\n";
std::cout << "\n";
// std::cout << "\nbundle : " << tim::demangle<bundle_t>() << "\n";
// std::cout << "\n";
long nfib = 30;
long ival = 200;
long nitr = 1000;
Expand Down Expand Up @@ -221,9 +221,9 @@ TEST_F(component_bundle_tests, get)
using rhs_t = tim::auto_bundle_t<TIMEMORY_API, wall_clock*, cpu_clock*,
cpu_roofline<float>*, gpu_roofline<double>>;

using lhs_data_t = typename lhs_t::data_type;
using rhs_data_t = typename rhs_t::data_type;
using rhs_comp_t = typename rhs_t::component_type;
// using lhs_data_t = typename lhs_t::data_type;
// using rhs_data_t = typename rhs_t::data_type;
// using rhs_comp_t = typename rhs_t::component_type;

lhs_t::get_initializer() = [](auto& cl) {
cl.template initialize<wall_clock, user_clock>();
Expand All @@ -247,20 +247,20 @@ TEST_F(component_bundle_tests, get)
auto cb = lhs.get();
auto ab = rhs.get();

std::cout << "\n" << std::flush;
// std::cout << "\n" << std::flush;

std::cout << "rhs_t = " << tim::demangle<rhs_t>() << "\n";
std::cout << "lhs_t = " << tim::demangle<lhs_t>() << "\n";
std::cout << "rhs_comp_t = " << tim::demangle<rhs_comp_t>() << "\n";
std::cout << "\n" << std::flush;
// std::cout << "rhs_t = " << tim::demangle<rhs_t>() << "\n";
// std::cout << "lhs_t = " << tim::demangle<lhs_t>() << "\n";
// std::cout << "rhs_comp_t = " << tim::demangle<rhs_comp_t>() << "\n";
// std::cout << "\n" << std::flush;

std::cout << "lhs_data_t = " << tim::demangle<lhs_data_t>() << "\n";
std::cout << "rhs_data_t = " << tim::demangle<rhs_data_t>() << "\n";
std::cout << "\n" << std::flush;
// std::cout << "lhs_data_t = " << tim::demangle<lhs_data_t>() << "\n";
// std::cout << "rhs_data_t = " << tim::demangle<rhs_data_t>() << "\n";
// std::cout << "\n" << std::flush;

std::cout << "cb = " << tim::demangle<decltype(cb)>() << "\n";
std::cout << "ab = " << tim::demangle<decltype(ab)>() << "\n";
std::cout << "\n" << std::flush;
// std::cout << "cb = " << tim::demangle<decltype(cb)>() << "\n";
// std::cout << "ab = " << tim::demangle<decltype(ab)>() << "\n";
// std::cout << "\n" << std::flush;

tim::invoke::print(std::cout, lhs, rhs);

Expand Down Expand Up @@ -719,9 +719,9 @@ run(Args&&... args)

// this should have no effect
foo.stop();
std::cout << tim::demangle<BundleT>() << std::endl;
std::cout << foo << std::endl;
std::cout << bar << std::endl;
// std::cout << tim::demangle<BundleT>() << std::endl;
// std::cout << foo << std::endl;
// std::cout << bar << std::endl;
}
//
auto
Expand Down Expand Up @@ -930,8 +930,8 @@ rekey(const std::string& _initial)
auto _other_srcloc =
TIMEMORY_SOURCE_LOCATION(TIMEMORY_CAPTURE_MODE(blank), _other.c_str());

std::cout << "[" << tim::demangle<Tp>() << "] initial: " << _initial
<< ", random: " << _other << std::endl;
// std::cout << "[" << tim::demangle<Tp>() << "] initial: " << _initial
// << ", random: " << _other << std::endl;

{
Tp _obj{ _initial };
Expand Down Expand Up @@ -969,7 +969,7 @@ rekey(const std::string& _initial)
EXPECT_NE(_obj.hash(), _init_hash) << "[" << tim::demangle<Tp>() << "] " << _obj;
}

std::cout << std::endl;
// std::cout << std::endl;
}

template <typename BundleT>
Expand Down
36 changes: 18 additions & 18 deletions source/tests/data_tracker_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ TEST_F(data_tracker_tests, convergence_test)
tim::trait::runtime_enabled<err_tracker_type_d>::set(true);

auto _run = [&err_diffs, &num_iters, nthreads](size_t i, auto lbl, size_t nitr,
size_t modulo) {
size_t /*modulo*/) {
details::get_rng().seed(1000 * i);
auto _name = TIMEMORY_JOIN('/', details::get_test_name(), lbl);

Expand Down Expand Up @@ -382,16 +382,16 @@ TEST_F(data_tracker_tests, convergence_test)
num_iters.at(i) += num_iter;
_bundle.stop();

if(j % modulo == (modulo - 1))
{
tim::auto_lock_t _lk{ tim::type_mutex<decltype(std::cout)>() };
if(tim::settings::debug())
std::cout << "\niteration " << i << "\n" << _tcout.str() << std::endl;
std::cout << "\niteration " << i << "\n\t" << _bundle
<< "\n\tnum_iter : " << num_iter << "\n\terror : " << err
<< "\n"
<< std::endl;
}
// if(j % modulo == (modulo - 1))
// {
// tim::auto_lock_t _lk{ tim::type_mutex<decltype(std::cout)>() };
// if(tim::settings::debug())
// std::cout << "\niteration " << i << "\n" << _tcout.str() << std::endl;
// std::cout << "\niteration " << i << "\n\t" << _bundle
// << "\n\tnum_iter : " << num_iter << "\n\terror : " << err
// << "\n"
// << std::endl;
// }
}
};

Expand All @@ -418,22 +418,22 @@ TEST_F(data_tracker_tests, convergence_test)
auto err_storage = tim::storage<err_tracker_type>::instance()->get();
auto wc_storage = tim::storage<wall_clock>::instance()->get();

for(auto& itr : itr_storage)
std::cout << itr.prefix() << " :: " << itr.data() << std::endl;
// for(auto& itr : itr_storage)
// std::cout << itr.prefix() << " :: " << itr.data() << std::endl;
for(auto& itr : wc_storage)
{
std::cout << itr.prefix() << " :: " << itr.data() << std::endl;
// std::cout << itr.prefix() << " :: " << itr.data() << std::endl;
ASSERT_EQ(itr.prefix().find("ignore"), std::string::npos)
<< itr.prefix() << " :: " << itr.data() << "\n";
}

ASSERT_EQ(itr_storage.size(), nthreads);
ASSERT_EQ(err_storage.size(), nthreads);

for(size_t i = 0; i < nthreads; ++i)
{
std::cout << itr_storage.at(i).data() << std::endl;
}
// for(size_t i = 0; i < nthreads; ++i)
// {
// std::cout << itr_storage.at(i).data() << std::endl;
// }

std::sort(itr_storage.begin(), itr_storage.end(), _compare);
std::sort(err_storage.begin(), err_storage.end(), _compare);
Expand Down
Loading

0 comments on commit 4d8f152

Please sign in to comment.