From cc69d211d0d65d7bf0335fecbc323f784ac3afcc Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 13 Oct 2020 15:47:31 -0400 Subject: [PATCH] [libc++/abi] Clean up uses of in the test suite We used in several places where we don't actually need the full power of , and where using basic `std::printf` is enough. This is better, since `std::printf` can be supported on systems that don't have a notion of locales, while can't. --- .../deque/spare_block_handling.pass.cpp | 16 +-- libcxx/test/libcxx/iterators/failed.pass.cpp | 1 - .../map/map.cons/copy_assign.pass.cpp | 32 +++-- .../map.modifiers/insert_or_assign.pass.cpp | 2 - .../set.cons/assign_initializer_list.pass.cpp | 1 - .../forwardlist.ops/sort_pred.pass.cpp | 1 - .../unord.multimap.cnstr/move_alloc.pass.cpp | 4 +- .../directory_entry.obs/file_size.pass.cpp | 2 - .../increment.pass.cpp | 1 - .../begin_end.pass.cpp | 1 - .../path.member/path.assign/source.pass.cpp | 1 - .../path.gen/lexically_normal.pass.cpp | 17 +-- .../lexically_relative_and_proximate.pass.cpp | 22 ++-- .../rec.dir.itr.nonmembers/begin_end.pass.cpp | 1 - .../fs.op.copy_file/copy_file.pass.cpp | 2 - .../fs.op.copy_file/copy_file_large.pass.cpp | 5 +- .../last_write_time.pass.cpp | 15 +-- .../fs.op.proximate/proximate.pass.cpp | 37 +++--- .../weakly_canonical.pass.cpp | 16 +-- .../input.output/filesystems/lit.local.cfg | 3 - .../test_min_max.pass.cpp | 17 ++- .../thousands_sep.pass.cpp | 8 +- .../namespace/addressable_functions.sh.cpp | 4 +- .../inclusive.scan/inclusive_scan_op.pass.cpp | 1 - ...sform_exclusive_scan_init_bop_uop.pass.cpp | 1 - .../transform_inclusive_scan_bop_uop.pass.cpp | 3 - libcxx/test/support/container_debug_tests.h | 3 - libcxx/test/support/filesystem_test_helper.h | 3 +- libcxxabi/src/fallback_malloc.cpp | 24 ++-- .../test/catch_multi_level_pointer.pass.cpp | 8 +- libcxxabi/test/cxa_bad_typeid.pass.cpp | 3 +- libcxxabi/test/support/timer.h | 4 +- libcxxabi/test/test_aux_runtime.pass.cpp | 11 +- .../test_aux_runtime_op_array_new.pass.cpp | 3 +- libcxxabi/test/test_demangle.pass.cpp | 30 ++--- .../test/test_exception_storage.pass.cpp | 30 +++-- libcxxabi/test/test_fallback_malloc.pass.cpp | 112 ++++++++-------- libcxxabi/test/test_vector1.pass.cpp | 124 +++++++++--------- libcxxabi/test/test_vector2.pass.cpp | 24 ++-- 39 files changed, 271 insertions(+), 322 deletions(-) diff --git a/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp b/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp index e5f79618fc90..3a583be96e8e 100644 --- a/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp +++ b/libcxx/test/libcxx/containers/sequences/deque/spare_block_handling.pass.cpp @@ -15,10 +15,10 @@ // resizes or shrinks at the correct time. #include -#include +#include #include -#include #include +#include #include "min_allocator.h" #include "rapid-cxx-test.h" @@ -31,12 +31,12 @@ struct ContainerAdaptor : public Adaptor { template static void print(const Deque& d) { - std::cout << d.size() - << " : __front_spare() == " << d.__front_spare() - << " : __back_spare() == " << d.__back_spare() - << " : __capacity() == " << d.__capacity() - << " : bytes allocated == " - << malloc_allocator_base::outstanding_bytes << '\n'; + std::printf("%lu : __front_spare() == %lu" + " : __back_spare() == %lu" + " : __capacity() == %lu" + " : bytes allocated == %lu\n", + d.size(), d.__front_spare(), d.__back_spare(), d.__capacity(), + malloc_allocator_base::outstanding_bytes); } template diff --git a/libcxx/test/libcxx/iterators/failed.pass.cpp b/libcxx/test/libcxx/iterators/failed.pass.cpp index 07c4de132cae..c47101e20cd1 100644 --- a/libcxx/test/libcxx/iterators/failed.pass.cpp +++ b/libcxx/test/libcxx/iterators/failed.pass.cpp @@ -15,7 +15,6 @@ // Extension: constructing from NULL is UB; we just make it a failed iterator #include -#include #include #include "test_macros.h" diff --git a/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp index 578958aa0c1b..813669c66c4c 100644 --- a/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp @@ -13,12 +13,11 @@ // map& operator=(const map& m); #include -#include -#include #include +#include +#include #include - -#include +#include #include "test_macros.h" #include "../../../test_compare.h" @@ -78,7 +77,7 @@ public: bool balanced_allocs() { std::vector temp1, temp2; - std::cout << "Allocations = " << ca_allocs.size() << ", deallocatons = " << ca_deallocs.size() << std::endl; + std::printf("Allocations = %lu, deallocations = %lu\n", ca_allocs.size(), ca_deallocs.size()); if (ca_allocs.size() != ca_deallocs.size()) return false; @@ -86,27 +85,32 @@ bool balanced_allocs() { std::sort(temp1.begin(), temp1.end()); temp2.clear(); std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter>(temp2)); - std::cout << "There were " << temp2.size() << " different allocators\n"; + std::printf("There were %lu different allocators\n", temp2.size()); for (std::vector::const_iterator it = temp2.begin(); it != temp2.end(); ++it ) { - std::cout << *it << ": " << std::count(ca_allocs.begin(), ca_allocs.end(), *it) << " vs " << std::count(ca_deallocs.begin(), ca_deallocs.end(), *it) << std::endl; - if ( std::count(ca_allocs.begin(), ca_allocs.end(), *it) != std::count(ca_deallocs.begin(), ca_deallocs.end(), *it)) + std::ptrdiff_t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it); + std::ptrdiff_t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it); + std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs); + if (allocs != deallocs) return false; - } + } temp1 = ca_allocs; std::sort(temp1.begin(), temp1.end()); temp2.clear(); std::unique_copy(temp1.begin(), temp1.end(), std::back_inserter>(temp2)); - std::cout << "There were " << temp2.size() << " different (de)allocators\n"; + std::printf("There were %lu different (de)allocators\n", temp2.size()); + for (std::vector::const_iterator it = ca_deallocs.begin(); it != ca_deallocs.end(); ++it ) { - std::cout << *it << ": " << std::count(ca_allocs.begin(), ca_allocs.end(), *it) << " vs " << std::count(ca_deallocs.begin(), ca_deallocs.end(), *it) << std::endl; - if ( std::count(ca_allocs.begin(), ca_allocs.end(), *it) != std::count(ca_deallocs.begin(), ca_deallocs.end(), *it)) + std::ptrdiff_t const allocs = std::count(ca_allocs.begin(), ca_allocs.end(), *it); + std::ptrdiff_t const deallocs = std::count(ca_deallocs.begin(), ca_deallocs.end(), *it); + std::printf("%d: %ld vs %ld\n", *it, allocs, deallocs); + if (allocs != deallocs) return false; - } + } return true; - } +} #endif int main(int, char**) diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp index bdde35cff7c7..633d9acca162 100644 --- a/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp @@ -25,8 +25,6 @@ #include #include -#include - #include "test_macros.h" class Moveable diff --git a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp index 7a8b46ac7ca6..b04d7f576bac 100644 --- a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -16,7 +16,6 @@ #include #include -#include #include "test_macros.h" #include "min_allocator.h" diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp index 6af5df873f28..ec28a22b891a 100644 --- a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include "test_macros.h" #include "min_allocator.h" diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp index 42ddd93c232d..519b429a7b53 100644 --- a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp @@ -16,8 +16,6 @@ // unordered_multimap(unordered_multimap&& u, const allocator_type& a); -#include - #include #include #include @@ -272,5 +270,5 @@ int main(int, char**) assert(c0.empty()); } - return 0; + return 0; } diff --git a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp index 203130d02f78..881643c42265 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_entry/directory_entry.obs/file_size.pass.cpp @@ -22,8 +22,6 @@ #include "filesystem_test_helper.h" #include "rapid-cxx-test.h" -#include - #include "test_macros.h" TEST_SUITE(directory_entry_obs_testsuite) diff --git a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/increment.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/increment.pass.cpp index 20bd70defa62..09b513974aaa 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/increment.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/increment.pass.cpp @@ -23,7 +23,6 @@ #include "test_macros.h" #include "rapid-cxx-test.h" #include "filesystem_test_helper.h" -#include using namespace fs; diff --git a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.nonmembers/begin_end.pass.cpp b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.nonmembers/begin_end.pass.cpp index 3b58e60bede4..be8a1be0b023 100644 --- a/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.nonmembers/begin_end.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.nonmembers/begin_end.pass.cpp @@ -23,7 +23,6 @@ #include "test_macros.h" #include "rapid-cxx-test.h" #include "filesystem_test_helper.h" -#include using namespace fs; diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp index c8df32446cfd..e02049821c11 100644 --- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.assign/source.pass.cpp @@ -30,7 +30,6 @@ #include "test_iterators.h" #include "count_new.h" #include "filesystem_test_helper.h" -#include template diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp index bb0ad1da30c7..c8753b02f7f3 100644 --- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_normal.pass.cpp @@ -15,13 +15,10 @@ // path lexically_normal() const; #include "filesystem_include.h" -#include -#include -#include -#include +#include +#include #include "test_macros.h" -#include "test_iterators.h" #include "count_new.h" #include "filesystem_test_helper.h" @@ -130,11 +127,11 @@ int main(int, char**) { const fs::path output = p.lexically_normal(); if (!PathEq(output, TC.expect)) { Failed = true; - std::cerr << "TEST CASE #" << ID << " FAILED: \n"; - std::cerr << " Input: '" << TC.input << "'\n"; - std::cerr << " Expected: '" << TC.expect << "'\n"; - std::cerr << " Output: '" << output.native() << "'"; - std::cerr << std::endl; + std::printf("TEST CASE #%d FAILED:\n" + " Input: '%s'\n" + " Expected: '%s'\n" + " Output: '%s'\n", + ID, TC.input.c_str(), TC.expect.c_str(), output.native().c_str()); } } return Failed; diff --git a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp index 3fa1a00e715e..a2a6d6292185 100644 --- a/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.path/path.member/path.gen/lexically_relative_and_proximate.pass.cpp @@ -16,13 +16,10 @@ // path lexically_proximate(const path& p) const; #include "filesystem_include.h" -#include -#include -#include -#include +#include +#include #include "test_macros.h" -#include "test_iterators.h" #include "count_new.h" #include "filesystem_test_helper.h" @@ -65,13 +62,14 @@ int main(int, char**) { auto ReportErr = [&](const char* Testing, fs::path const& Output, fs::path const& Expected) { Failed = true; - std::cerr << "TEST CASE #" << ID << " FAILED: \n"; - std::cerr << " Testing: " << Testing << "\n"; - std::cerr << " Input: '" << TC.input << "'\n"; - std::cerr << " Base: '" << TC.base << "'\n"; - std::cerr << " Expected: '" << Expected << "'\n"; - std::cerr << " Output: '" << Output.native() << "'"; - std::cerr << std::endl; + std::printf("TEST CASE #%d FAILED:\n" + " Testing: %s\n" + " Input: '%s'\n" + " Base: '%s'\n" + " Expected: '%s'\n" + " Output: '%s'\n", + ID, Testing, TC.input.c_str(), TC.base.c_str(), + Expected.c_str(), Output.native().c_str()); }; if (!PathEq(output, TC.expect)) ReportErr("path::lexically_relative", output, TC.expect); diff --git a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.nonmembers/begin_end.pass.cpp b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.nonmembers/begin_end.pass.cpp index 3d2b9b668183..c4bb5a78ac90 100644 --- a/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.nonmembers/begin_end.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/class.rec.dir.itr/rec.dir.itr.nonmembers/begin_end.pass.cpp @@ -23,7 +23,6 @@ #include "test_macros.h" #include "rapid-cxx-test.h" #include "filesystem_test_helper.h" -#include using namespace fs; diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp index e91e739db1e0..0d2a55544a1a 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file.pass.cpp @@ -25,8 +25,6 @@ #include "rapid-cxx-test.h" #include "filesystem_test_helper.h" -#include - using namespace fs; using CO = fs::copy_options; diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file_large.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file_large.pass.cpp index 8b4fdb294fcf..d7bdbdb2de17 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file_large.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.copy_file/copy_file_large.pass.cpp @@ -18,9 +18,10 @@ // error_code& ec) noexcept; #include "filesystem_include.h" -#include -#include #include +#include +#include +#include #include "test_macros.h" #include "rapid-cxx-test.h" diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp index d87d6f275b94..c24d28b341c9 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp @@ -19,18 +19,16 @@ #include "filesystem_include.h" #include #include -#include +#include #include #include "test_macros.h" #include "rapid-cxx-test.h" #include "filesystem_test_helper.h" -#include -#include - #include #include +#include using namespace fs; @@ -113,7 +111,6 @@ Times GetTimes(path const& p) { #ifndef TEST_HAS_NO_EXCEPTIONS throw ec; #else - std::cerr << ec.message() << std::endl; std::exit(EXIT_FAILURE); #endif } @@ -131,7 +128,6 @@ Times GetSymlinkTimes(path const& p) { #ifndef TEST_HAS_NO_EXCEPTIONS throw ec; #else - std::cerr << ec.message() << std::endl; std::exit(EXIT_FAILURE); #endif } @@ -399,9 +395,9 @@ TEST_CASE(get_last_write_time_dynamic_env_test) SleepFor(Sec(2)); // update file and add a file to the directory. Make sure the times increase. - std::ofstream of(file, std::ofstream::app); - of << "hello"; - of.close(); + std::FILE* of = std::fopen(file.c_str(), "a"); + std::fwrite("hello", 1, sizeof("hello"), of); + std::fclose(of); env.create_file("dir/file1", 1); file_time_type ftime2 = last_write_time(file); @@ -454,7 +450,6 @@ TEST_CASE(set_last_write_time_dynamic_env_test) {"dir, just_before_epoch_time", dir, just_before_epoch_time} }; for (const auto& TC : cases) { - std::cerr << "Test Case = " << TC.case_name << "\n"; const auto old_times = GetTimes(TC.p); file_time_type old_time; TEST_REQUIRE(ConvertFromTimeSpec(old_time, old_times.write)); diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp index 40db06bb286f..f166a254b8b9 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.proximate/proximate.pass.cpp @@ -15,13 +15,10 @@ // path proximate(const path& p, const path& base, error_code& ec); #include "filesystem_include.h" -#include -#include -#include #include +#include #include "test_macros.h" -#include "test_iterators.h" #include "count_new.h" #include "rapid-cxx-test.h" #include "filesystem_test_helper.h" @@ -103,28 +100,28 @@ TEST_CASE(basic_test) { const fs::path output = fs::proximate(p, TC.base, ec); if (ec) { TEST_CHECK(!ec); - std::cerr << "TEST CASE #" << ID << " FAILED: \n"; - std::cerr << " Input: '" << TC.input << "'\n"; - std::cerr << " Base: '" << TC.base << "'\n"; - std::cerr << " Expected: '" << TC.expect << "'\n"; - - std::cerr << std::endl; + std::printf("TEST CASE #%d FAILED:\n" + " Input: '%s'\n" + " Base: '%s'\n" + " Expected: '%s'\n", + ID, TC.input.c_str(), TC.base.c_str(), TC.expect.c_str()); } else if (!PathEq(output, TC.expect)) { TEST_CHECK(PathEq(output, TC.expect)); const path canon_input = fs::weakly_canonical(TC.input); const path canon_base = fs::weakly_canonical(TC.base); const path lexically_p = canon_input.lexically_proximate(canon_base); - std::cerr << "TEST CASE #" << ID << " FAILED: \n"; - std::cerr << " Input: '" << TC.input << "'\n"; - std::cerr << " Base: '" << TC.base << "'\n"; - std::cerr << " Expected: '" << TC.expect << "'\n"; - std::cerr << " Output: '" << output.native() << "'\n"; - std::cerr << " Lex Prox: '" << lexically_p.native() << "'\n"; - std::cerr << " Canon Input: " << canon_input << "\n"; - std::cerr << " Canon Base: " << canon_base << "\n"; - - std::cerr << std::endl; + std::printf("TEST CASE #%d FAILED:\n" + " Input: '%s'\n" + " Base: '%s'\n" + " Expected: '%s'\n" + " Output: '%s'\n" + " Lex Prox: '%s'\n" + " Canon Input: '%s'\n" + " Canon Base: '%s'\n", + ID, TC.input.c_str(), TC.base.c_str(), TC.expect.c_str(), + output.native().c_str(), lexically_p.native().c_str(), + canon_input.c_str(), canon_base.c_str()); } } } diff --git a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp index 15dd65f23789..e15012f2d0f4 100644 --- a/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp +++ b/libcxx/test/std/input.output/filesystems/fs.op.funcs/fs.op.weakly_canonical/weakly_canonical.pass.cpp @@ -14,10 +14,8 @@ // path weakly_canonical(const path& p, error_code& ec); #include "filesystem_include.h" -#include -#include -#include -#include +#include +#include #include "test_macros.h" #include "test_iterators.h" @@ -67,11 +65,11 @@ int main(int, char**) { const fs::path output = fs::weakly_canonical(p); if (!PathEq(output, TC.expect)) { Failed = true; - std::cerr << "TEST CASE #" << ID << " FAILED: \n"; - std::cerr << " Input: '" << TC.input << "'\n"; - std::cerr << " Expected: '" << TC.expect << "'\n"; - std::cerr << " Output: '" << output.native() << "'"; - std::cerr << std::endl; + std::printf("TEST CASE #%d FAILED:\n" + " Input: '%s'\n" + " Expected: '%s'\n" + " Output: '%s'\n", + ID, TC.input.c_str(), TC.expect.c_str(), output.native().c_str()); } } return Failed; diff --git a/libcxx/test/std/input.output/filesystems/lit.local.cfg b/libcxx/test/std/input.output/filesystems/lit.local.cfg index 99c45a7097ec..682a2ab1c63b 100644 --- a/libcxx/test/std/input.output/filesystems/lit.local.cfg +++ b/libcxx/test/std/input.output/filesystems/lit.local.cfg @@ -1,5 +1,2 @@ -import os -import sys - if 'c++filesystem-disabled' in config.available_features: config.unsupported = True diff --git a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp index 5a2e081055ba..dd77f7db92cf 100644 --- a/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp +++ b/libcxx/test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/test_min_max.pass.cpp @@ -6,18 +6,17 @@ // //===----------------------------------------------------------------------===// +#include #include #include -#include -#include +#include +#include #include "test_macros.h" -using namespace std; - template bool check_stream_failed(std::string const& val) { - istringstream ss(val); + std::istringstream ss(val); T result; return !(ss >> result); } @@ -26,16 +25,16 @@ template void check_limits() { const bool is_unsigned = std::is_unsigned::value; - T minv = numeric_limits::min(); - T maxv = numeric_limits::max(); + T minv = std::numeric_limits::min(); + T maxv = std::numeric_limits::max(); - ostringstream miniss, maxiss; + std::ostringstream miniss, maxiss; assert(miniss << minv); assert(maxiss << maxv); std::string mins = miniss.str(); std::string maxs = maxiss.str(); - istringstream maxoss(maxs), minoss(mins); + std::istringstream maxoss(maxs), minoss(mins); T new_minv, new_maxv; assert(maxoss >> new_maxv); diff --git a/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp b/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp index b1c814fd84db..620408ef82d1 100644 --- a/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp +++ b/libcxx/test/std/localization/locale.categories/facet.numpunct/locale.numpunct.byname/thousands_sep.pass.cpp @@ -21,7 +21,6 @@ #include #include -#include // FIXME: for debugging purposes only #include "test_macros.h" #include "platform_support.h" // locale name macros @@ -67,11 +66,6 @@ int main(int, char**) { typedef char C; const std::numpunct& np = std::use_facet >(l); - if (np.thousands_sep() != sep) { - std::cout << "np.thousands_sep() = '" << np.thousands_sep() << "'\n"; - std::cout << "sep = '" << sep << "'\n"; - std::cout << std::endl; - } assert(np.thousands_sep() == sep); } { @@ -81,5 +75,5 @@ int main(int, char**) } } - return 0; + return 0; } diff --git a/libcxx/test/std/namespace/addressable_functions.sh.cpp b/libcxx/test/std/namespace/addressable_functions.sh.cpp index 3d5fe1121481..9b5e80ec1b01 100644 --- a/libcxx/test/std/namespace/addressable_functions.sh.cpp +++ b/libcxx/test/std/namespace/addressable_functions.sh.cpp @@ -18,8 +18,10 @@ // RUN: %{exec} %t.exe #include -#include +#include +#include #include +#include #include #include diff --git a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp index affb284b6acd..322b502369f3 100644 --- a/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/inclusive.scan/inclusive_scan_op.pass.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include diff --git a/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp index 21087f45b7d7..301fb2f24242 100644 --- a/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp index bb9fa0729b4d..9caec15ab853 100644 --- a/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp +++ b/libcxx/test/std/numerics/numeric.ops/transform.inclusive.scan/transform_inclusive_scan_bop_uop.pass.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -85,8 +84,6 @@ void basic_tests() std::vector v(10); std::fill(v.begin(), v.end(), 3); std::transform_inclusive_scan(v.begin(), v.end(), v.begin(), std::plus<>(), add_one{}); - std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; for (size_t i = 0; i < v.size(); ++i) assert(v[i] == (i+1) * 4); } diff --git a/libcxx/test/support/container_debug_tests.h b/libcxx/test/support/container_debug_tests.h index e0b0df3b3b60..781d49f97560 100644 --- a/libcxx/test/support/container_debug_tests.h +++ b/libcxx/test/support/container_debug_tests.h @@ -23,9 +23,6 @@ #include #include #include -#include -#include -#include #include "test_macros.h" #include "debug_mode_helper.h" diff --git a/libcxx/test/support/filesystem_test_helper.h b/libcxx/test/support/filesystem_test_helper.h index 5cccca9f0493..2a626f79daa4 100644 --- a/libcxx/test/support/filesystem_test_helper.h +++ b/libcxx/test/support/filesystem_test_helper.h @@ -9,7 +9,6 @@ #include #include // for printf #include -#include #include #include #include @@ -309,7 +308,7 @@ struct CWDGuard { char* ret = ::getcwd(OldCWD, sizeof(OldCWD)); assert(ret && "getcwd failed"); } - ~CWDGuard() { + ~CWDGuard() { int ret = ::chdir(OldCWD); assert(ret == 0 && "chdir failed"); } diff --git a/libcxxabi/src/fallback_malloc.cpp b/libcxxabi/src/fallback_malloc.cpp index fdae40764abe..8c0fd6c8db4b 100644 --- a/libcxxabi/src/fallback_malloc.cpp +++ b/libcxxabi/src/fallback_malloc.cpp @@ -144,29 +144,26 @@ void fallback_free(void* ptr) { mutexor mtx(&heap_mutex); #ifdef DEBUG_FALLBACK_MALLOC - std::cout << "Freeing item at " << offset_from_node(cp) << " of size " - << cp->len << std::endl; + std::printf("Freeing item at %d of size %d\n", offset_from_node(cp), cp->len); #endif for (p = freelist, prev = 0; p && p != list_end; prev = p, p = node_from_offset(p->next_node)) { #ifdef DEBUG_FALLBACK_MALLOC - std::cout << " p, cp, after (p), after(cp) " << offset_from_node(p) << ' ' - << offset_from_node(cp) << ' ' << offset_from_node(after(p)) - << ' ' << offset_from_node(after(cp)) << std::endl; + std::printf(" p=%d, cp=%d, after(p)=%d, after(cp)=%d\n", + offset_from_node(p), offset_from_node(cp), + offset_from_node(after(p)), offset_from_node(after(cp))); #endif if (after(p) == cp) { #ifdef DEBUG_FALLBACK_MALLOC - std::cout << " Appending onto chunk at " << offset_from_node(p) - << std::endl; + std::printf(" Appending onto chunk at %d\n", offset_from_node(p)); #endif p->len = static_cast( p->len + cp->len); // make the free heap_node larger return; } else if (after(cp) == p) { // there's a free heap_node right after #ifdef DEBUG_FALLBACK_MALLOC - std::cout << " Appending free chunk at " << offset_from_node(p) - << std::endl; + std::printf(" Appending free chunk at %d\n", offset_from_node(p)); #endif cp->len = static_cast(cp->len + p->len); if (prev == 0) { @@ -179,8 +176,7 @@ void fallback_free(void* ptr) { } // Nothing to merge with, add it to the start of the free list #ifdef DEBUG_FALLBACK_MALLOC - std::cout << " Making new free list entry " << offset_from_node(cp) - << std::endl; + std::printf(" Making new free list entry %d\n", offset_from_node(cp)); #endif cp->next_node = offset_from_node(freelist); freelist = cp; @@ -195,11 +191,11 @@ size_t print_free_list() { for (p = freelist, prev = 0; p && p != list_end; prev = p, p = node_from_offset(p->next_node)) { - std::cout << (prev == 0 ? "" : " ") << "Offset: " << offset_from_node(p) - << "\tsize: " << p->len << " Next: " << p->next_node << std::endl; + std::printf("%sOffset: %d\tsize: %d Next: %d\n", + (prev == 0 ? "" : " "), offset_from_node(p), p->len, p->next_node); total_free += p->len; } - std::cout << "Total Free space: " << total_free << std::endl; + std::printf("Total Free space: %d\n", total_free); return total_free; } #endif diff --git a/libcxxabi/test/catch_multi_level_pointer.pass.cpp b/libcxxabi/test/catch_multi_level_pointer.pass.cpp index 5aa0915ff94e..895e611d7d0a 100644 --- a/libcxxabi/test/catch_multi_level_pointer.pass.cpp +++ b/libcxxabi/test/catch_multi_level_pointer.pass.cpp @@ -9,17 +9,17 @@ // UNSUPPORTED: no-exceptions #include +#include #include -#include // Roll our own assertion macro to get better error messages out of the tests. // In particular on systems that don't use __PRETTY_FUNCTION__ in assertions. #define my_assert(pred, msg) do_assert(pred, msg, __LINE__, __PRETTY_FUNCTION__) void do_assert(bool assert_passed, const char* msg, int line, const char* func) { - if (assert_passed) return; - std::cerr << __FILE__ << ":" << line << " " << func - << ": Assertion Failed `" << msg << "'\n\n"; + if (assert_passed) + return; + std::printf("%s:%d %s: Assertion Failed '%s'\n\n", __FILE__, line, func, msg); std::abort(); } diff --git a/libcxxabi/test/cxa_bad_typeid.pass.cpp b/libcxxabi/test/cxa_bad_typeid.pass.cpp index fc491d7802b0..a1afe5280c0c 100644 --- a/libcxxabi/test/cxa_bad_typeid.pass.cpp +++ b/libcxxabi/test/cxa_bad_typeid.pass.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include "test_macros.h" @@ -28,7 +27,7 @@ std::string test_bad_typeid(Derived *p) { return typeid(*p).name(); } -void my_terminate() { std::cout << "A" << std::endl; exit(0); } +void my_terminate() { exit(0); } int main () { diff --git a/libcxxabi/test/support/timer.h b/libcxxabi/test/support/timer.h index 98a5dc0b68c1..7109627f62ad 100644 --- a/libcxxabi/test/support/timer.h +++ b/libcxxabi/test/support/timer.h @@ -13,7 +13,7 @@ #ifndef LIBCXXABI_NO_TIMER #include -#include +#include class timer { @@ -31,7 +31,7 @@ public: using std::chrono::duration_cast; TimePoint end = Clock::now(); MicroSeconds us = duration_cast(end - m_start); - std::cout << us.count() << " microseconds\n"; + std::printf("%d microseconds\n", us.count()); } private: diff --git a/libcxxabi/test/test_aux_runtime.pass.cpp b/libcxxabi/test/test_aux_runtime.pass.cpp index 585fd7dcbc67..c79e0f508728 100644 --- a/libcxxabi/test/test_aux_runtime.pass.cpp +++ b/libcxxabi/test/test_aux_runtime.pass.cpp @@ -9,7 +9,6 @@ // UNSUPPORTED: no-exceptions #include -#include // Test taken from 5.2.8.2 // When typeid is applied to a glvalue expression whose type is a polymorphic @@ -30,7 +29,7 @@ bool bad_typeid_test () { try {bool b = typeid(*bp) == typeid (A); ((void)b); } catch ( const std::bad_typeid &) { return true; } return false; - } +} // The value of a failed cast to pointer type is the null pointer value of @@ -46,20 +45,18 @@ bool bad_cast_test () { try { D &dr = dynamic_cast (*bp); ((void)dr); } catch ( const std::bad_cast & ) { return true; } return false; - } +} int main ( ) { int ret_val = 0; if ( !bad_typeid_test ()) { - std::cerr << "TypeID test failed!" << std::endl; ret_val = 1; } if ( !bad_cast_test ()) { - std::cerr << "Bad cast test failed!" << std::endl; - ret_val = 1; + ret_val = 2; } return ret_val; - } +} diff --git a/libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp b/libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp index cc73c3c758b9..943ebe8bb63e 100644 --- a/libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp +++ b/libcxxabi/test/test_aux_runtime_op_array_new.pass.cpp @@ -8,8 +8,8 @@ // UNSUPPORTED: no-exceptions -#include #include +#include // If the expression passed to operator new[] would result in an overflow, the // allocation function is not called, and a std::bad_array_new_length exception @@ -31,7 +31,6 @@ int main(int, char**) { int ret_val = 0; if ( !bad_array_new_length_test ()) { - std::cerr << "Bad array new length test failed!" << std::endl; ret_val = 1; } diff --git a/libcxxabi/test/test_demangle.pass.cpp b/libcxxabi/test/test_demangle.pass.cpp index f72b2eadf619..cbbccb14feed 100644 --- a/libcxxabi/test/test_demangle.pass.cpp +++ b/libcxxabi/test/test_demangle.pass.cpp @@ -7,11 +7,11 @@ //===----------------------------------------------------------------------===// #include "support/timer.h" -#include -#include +#include +#include #include #include -#include +#include // Is long double fp80? (Only x87 extended double has 64-bit mantissa) #define LDBL_FP80 (__LDBL_MANT_DIG__ == 64) @@ -29901,17 +29901,16 @@ void test() char* demang = __cxxabiv1::__cxa_demangle(cases[i][0], buf, &len, &status); if (demang == 0 || std::strcmp(demang, cases[i][1]) != 0) { - std::cout << "ERROR demangling " << cases[i][0] << '\n' - << "expected: " << cases[i][1] << std::endl; + std::printf("ERROR demangling %s\nexpected: %s\n", cases[i][0], cases[i][1]); if (demang) { - std::cout << " reality: " << demang << '\n' << std::endl; + std::printf(" reality: %s\n", demang); buf = demang; failed = true; } else { - std::cout << "Got instead: NULL, " << status << '\n'; + std::printf("Got instead: NULL, %d\n", status); failed = true; } } @@ -29934,7 +29933,8 @@ void test_invalid_cases() char* demang = __cxxabiv1::__cxa_demangle(invalid_cases[i], buf, &len, &status); if (status != -2) { - std::cout << invalid_cases[i] << " should be invalid but is not\n" << " got status = " << status << '\n'; + std::printf("%s should be invalid but is not\n", invalid_cases[i]); + std::printf("Got status %d\n", status); assert(status == -2); } else @@ -29964,8 +29964,8 @@ void test_xfail_cases() char* demang = __cxxabiv1::__cxa_demangle(xfail_cases[i], buf, &len, &status); if (status != -2) { - std::cout << xfail_cases[i] << " was documented as xfail but passed\n" - << "got status = " << status << '\n'; + std::printf("%s was documented as xfail but passed\n", xfail_cases[i]); + std::printf("Got status = %d\n", status); assert(status == -2); } else @@ -29987,8 +29987,8 @@ void testFPLiterals() char* demang = __cxxabiv1::__cxa_demangle(fpCase->mangled, buf, &len, &status); if (demang == 0) { - std::cout << fpCase->mangled << " -> " << fpCase->expecting[0] << '\n'; - std::cout << "Got instead: NULL, " << status << '\n'; + std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str()); + std::printf("Got instead: NULL, %d\n", status); assert(false); continue; } @@ -29996,8 +29996,8 @@ void testFPLiterals() std::string *e_end = fpCase->expecting + NEF; if (std::find(e_beg, e_end, demang) == e_end) { - std::cout << fpCase->mangled << " -> " << fpCase->expecting[0] << '\n'; - std::cout << "Got instead: " << demang << '\n'; + std::printf("%s -> %s\n", fpCase->mangled, fpCase->expecting[0].c_str()); + std::printf("Got instead: %s\n", demang); assert(false); continue; } @@ -30008,7 +30008,7 @@ void testFPLiterals() int main(int, char**) { - std::cout << "Testing " << N << " symbols." << std::endl; + std::printf("Testing %d symbols.\n", N); { timer t; test(); diff --git a/libcxxabi/test/test_exception_storage.pass.cpp b/libcxxabi/test/test_exception_storage.pass.cpp index 305a97024dfc..5c29c4524a41 100644 --- a/libcxxabi/test/test_exception_storage.pass.cpp +++ b/libcxxabi/test/test_exception_storage.pass.cpp @@ -6,9 +6,9 @@ // //===----------------------------------------------------------------------===// -#include #include -#include +#include +#include #include <__threading_support> #include @@ -19,19 +19,19 @@ typedef __cxxabiv1::__cxa_eh_globals globals_t ; void *thread_code (void *parm) { size_t *result = (size_t *) parm; globals_t *glob1, *glob2; - + glob1 = __cxxabiv1::__cxa_get_globals (); if ( NULL == glob1 ) - std::cerr << "Got null result from __cxa_get_globals" << std::endl; + std::printf("Got null result from __cxa_get_globals\n"); glob2 = __cxxabiv1::__cxa_get_globals_fast (); if ( glob1 != glob2 ) - std::cerr << "Got different globals!" << std::endl; - + std::printf("Got different globals!\n"); + *result = (size_t) glob1; sleep ( 1 ); return parm; - } +} #ifndef _LIBCXXABI_HAS_NO_THREADS #define NUMTHREADS 10 @@ -49,18 +49,20 @@ int main () { for ( int i = 0; i < NUMTHREADS; ++i ) std::__libcpp_thread_join ( &threads [ i ] ); - for ( int i = 0; i < NUMTHREADS; ++i ) + for ( int i = 0; i < NUMTHREADS; ++i ) { if ( 0 == thread_globals [ i ] ) { - std::cerr << "Thread #" << i << " had a zero global" << std::endl; + std::printf("Thread #%d had a zero global\n", i); retVal = 1; - } - + } + } + std::sort ( thread_globals, thread_globals + NUMTHREADS ); - for ( int i = 1; i < NUMTHREADS; ++i ) + for ( int i = 1; i < NUMTHREADS; ++i ) { if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) { - std::cerr << "Duplicate thread globals (" << i-1 << " and " << i << ")" << std::endl; + std::printf("Duplicate thread globals (%d and %d)\n", i-1, i); retVal = 2; - } + } + } #else // _LIBCXXABI_HAS_NO_THREADS size_t thread_globals; // Check that __cxa_get_globals() is not NULL. diff --git a/libcxxabi/test/test_fallback_malloc.pass.cpp b/libcxxabi/test/test_fallback_malloc.pass.cpp index 3b3fd9b0fe98..8b986599a680 100644 --- a/libcxxabi/test/test_fallback_malloc.pass.cpp +++ b/libcxxabi/test/test_fallback_malloc.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include +#include #include #include <__threading_support> @@ -20,169 +20,169 @@ typedef std::deque container; container alloc_series ( size_t sz ) { container ptrs; void *p; - + while ( NULL != ( p = fallback_malloc ( sz ))) ptrs.push_back ( p ); return ptrs; - } +} container alloc_series ( size_t sz, float growth ) { container ptrs; void *p; - + while ( NULL != ( p = fallback_malloc ( sz ))) { ptrs.push_back ( p ); sz *= growth; - } + } return ptrs; - } +} container alloc_series ( const size_t *first, size_t len ) { container ptrs; const size_t *last = first + len; void * p; - + for ( const size_t *iter = first; iter != last; ++iter ) { if ( NULL == (p = fallback_malloc ( *iter ))) break; ptrs.push_back ( p ); - } + } return ptrs; - } +} void *pop ( container &c, bool from_end ) { void *ptr; if ( from_end ) { ptr = c.back (); c.pop_back (); - } + } else { ptr = c.front (); c.pop_front (); - } - return ptr; } + return ptr; +} void exhaustion_test1 () { container ptrs; - + init_heap (); - std::cout << "Constant exhaustion tests" << std::endl; - + std::printf("Constant exhaustion tests\n"); + // Delete in allocation order ptrs = alloc_series ( 32 ); - std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl; + std::printf("Allocated %lu 32 byte chunks\n", ptrs.size()); print_free_list (); for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter ) fallback_free ( *iter ); print_free_list (); - std::cout << "----" << std::endl; + std::printf("----\n"); // Delete in reverse order ptrs = alloc_series ( 32 ); - std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl; + std::printf("Allocated %lu 32 byte chunks\n", ptrs.size()); for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter ) fallback_free ( *iter ); print_free_list (); - std::cout << "----" << std::endl; + std::printf("----\n"); // Alternate deletions ptrs = alloc_series ( 32 ); - std::cout << "Allocated " << ptrs.size () << " 32 byte chunks" << std::endl; + std::printf("Allocated %lu 32 byte chunks\n", ptrs.size()); while ( ptrs.size () > 0 ) fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 )); print_free_list (); - } - +} + void exhaustion_test2 () { container ptrs; init_heap (); - - std::cout << "Growing exhaustion tests" << std::endl; + + std::printf("Growing exhaustion tests\n"); // Delete in allocation order ptrs = alloc_series ( 32, 1.5 ); - std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl; + + std::printf("Allocated %lu { 32, 48, 72, 108, 162 ... } byte chunks\n", ptrs.size()); print_free_list (); for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter ) fallback_free ( *iter ); print_free_list (); - std::cout << "----" << std::endl; - + std::printf("----\n"); + // Delete in reverse order print_free_list (); ptrs = alloc_series ( 32, 1.5 ); - std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl; + std::printf("Allocated %lu { 32, 48, 72, 108, 162 ... } byte chunks\n", ptrs.size()); for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter ) fallback_free ( *iter ); print_free_list (); - std::cout << "----" << std::endl; + std::printf("----\n"); // Alternate deletions ptrs = alloc_series ( 32, 1.5 ); - std::cout << "Allocated " << ptrs.size () << " { 32, 48, 72, 108, 162 ... } byte chunks" << std::endl; + std::printf("Allocated %lu { 32, 48, 72, 108, 162 ... } byte chunks\n", ptrs.size()); while ( ptrs.size () > 0 ) fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 )); - print_free_list (); - - } + print_free_list (); + +} void exhaustion_test3 () { const size_t allocs [] = { 124, 60, 252, 60, 4 }; container ptrs; init_heap (); - - std::cout << "Complete exhaustion tests" << std::endl; + + std::printf("Complete exhaustion tests\n"); // Delete in allocation order ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] )); - std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl; + std::printf("Allocated %lu chunks\n", ptrs.size()); print_free_list (); for ( container::iterator iter = ptrs.begin (); iter != ptrs.end (); ++iter ) fallback_free ( *iter ); print_free_list (); - std::cout << "----" << std::endl; - + std::printf("----\n"); + // Delete in reverse order print_free_list (); ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] )); - std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl; + std::printf("Allocated %lu chunks\n", ptrs.size()); for ( container::reverse_iterator iter = ptrs.rbegin (); iter != ptrs.rend (); ++iter ) fallback_free ( *iter ); print_free_list (); - std::cout << "----" << std::endl; + std::printf("----\n"); // Alternate deletions ptrs = alloc_series ( allocs, sizeof ( allocs ) / sizeof ( allocs[0] )); - std::cout << "Allocated " << ptrs.size () << " chunks" << std::endl; + std::printf("Allocated %lu chunks\n", ptrs.size()); while ( ptrs.size () > 0 ) fallback_free ( pop ( ptrs, ptrs.size () % 1 == 1 )); - print_free_list (); - - } + print_free_list (); + +} + - int main () { print_free_list (); char *p = (char *) fallback_malloc ( 1024 ); // too big! - std::cout << "fallback_malloc ( 1024 ) --> " << (unsigned long ) p << std::endl; + std::printf("fallback_malloc ( 1024 ) --> %lu\n", (unsigned long ) p); print_free_list (); - + p = (char *) fallback_malloc ( 32 ); - std::cout << "fallback_malloc ( 32 ) --> " << (unsigned long) (p - heap) << std::endl; + std::printf("fallback_malloc ( 32 ) --> %lu\n", (unsigned long) (p - heap)); if ( !is_fallback_ptr ( p )) - std::cout << "### p is not a fallback pointer!!" << std::endl; - + std::printf("### p is not a fallback pointer!!\n"); + print_free_list (); fallback_free ( p ); print_free_list (); - - std::cout << std::endl; - exhaustion_test1 (); std::cout << std::endl; - exhaustion_test2 (); std::cout << std::endl; - exhaustion_test3 (); std::cout << std::endl; + + exhaustion_test1(); + exhaustion_test2(); + exhaustion_test3(); return 0; - } +} diff --git a/libcxxabi/test/test_vector1.pass.cpp b/libcxxabi/test/test_vector1.pass.cpp index 10b77b0c3b04..86230c755954 100644 --- a/libcxxabi/test/test_vector1.pass.cpp +++ b/libcxxabi/test/test_vector1.pass.cpp @@ -8,36 +8,36 @@ #include "cxxabi.h" -#include -#include #include +#include +#include #include "test_macros.h" // Wrapper routines void *my_alloc2 ( size_t sz ) { void *p = std::malloc ( sz ); -// std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p ); +// std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p ); return p; - } - +} + void my_dealloc2 ( void *p ) { -// std::printf ( "Freeing %lx\n", (unsigned long) p ); - std::free ( p ); - } +// std::printf ( "Freeing %lx\n", (unsigned long) p ); + std::free ( p ); +} void my_dealloc3 ( void *p, size_t ) { -// std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz ); - std::free ( p ); - } +// std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz ); + std::free ( p ); +} void my_construct ( void * ) { // std::printf ( "Constructing %lx\n", (unsigned long) p ); - } +} void my_destruct ( void * ) { // std::printf ( "Destructing %lx\n", (unsigned long) p ); - } +} int gCounter; void count_construct ( void * ) { ++gCounter; } @@ -72,7 +72,7 @@ struct vec_on_stack { void *storage; vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct )) {} ~vec_on_stack () CAN_THROW {__cxxabiv1::__cxa_vec_delete ( storage, 40, 8, throw_destruct ); } - }; +}; // Test calls with empty constructors and destructors int test_empty ( ) { @@ -86,7 +86,7 @@ int test_empty ( ) { __cxxabiv1::__cxa_vec_delete ( one, 40, 0, NULL ); __cxxabiv1::__cxa_vec_delete2( two, 40, 0, NULL, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete3( three, 40, 0, NULL, my_dealloc3 ); - + // Try with no padding one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, my_construct, my_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, my_construct, my_destruct, my_alloc2, my_dealloc2 ); @@ -96,7 +96,7 @@ int test_empty ( ) { __cxxabiv1::__cxa_vec_delete2( two, 40, 0, my_destruct, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete3( three, 40, 0, my_destruct, my_dealloc3 ); -// Padding and no con/destructors +// Padding and no con/destructors one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, NULL, NULL ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc2 ); three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, NULL, NULL, my_alloc2, my_dealloc3 ); @@ -105,7 +105,7 @@ int test_empty ( ) { __cxxabiv1::__cxa_vec_delete2( two, 40, 8, NULL, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete3( three, 40, 8, NULL, my_dealloc3 ); -// Padding with con/destructors +// Padding with con/destructors one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, my_construct, my_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc2 ); three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, my_construct, my_destruct, my_alloc2, my_dealloc3 ); @@ -115,7 +115,7 @@ int test_empty ( ) { __cxxabiv1::__cxa_vec_delete3( three, 40, 8, my_destruct, my_dealloc3 ); return 0; - } +} // Make sure the constructors and destructors are matched int test_counted ( ) { @@ -123,24 +123,24 @@ int test_counted ( ) { void *one, *two, *three; // Try with no padding - gCounter = 0; + gCounter = 0; one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, count_construct, count_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc2 ); three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, count_construct, count_destruct, my_alloc2, my_dealloc3 ); - + __cxxabiv1::__cxa_vec_delete ( one, 40, 0, count_destruct ); __cxxabiv1::__cxa_vec_delete2( two, 40, 0, count_destruct, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete3( three, 40, 0, count_destruct, my_dealloc3 ); - -// Since there was no padding, the # of elements in the array are not stored + +// Since there was no padding, the # of elements in the array are not stored // and the destructors are not called. if ( gCounter != 30 ) { - std::cerr << "Mismatched Constructor/Destructor calls (1)" << std::endl; - std::cerr << " Expected 30, got " << gCounter << std::endl; + std::printf("Mismatched Constructor/Destructor calls (1)\n"); + std::printf(" Expected 30, got %d\n", gCounter); retVal = 1; - } - - gCounter = 0; + } + + gCounter = 0; one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, count_construct, count_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc2 ); three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, count_construct, count_destruct, my_alloc2, my_dealloc3 ); @@ -150,14 +150,14 @@ int test_counted ( ) { __cxxabiv1::__cxa_vec_delete3( three, 40, 8, count_destruct, my_dealloc3 ); if ( gCounter != 0 ) { - std::cerr << "Mismatched Constructor/Destructor calls (2)" << std::endl; - std::cerr << " Expected 0, got " << gCounter << std::endl; + std::printf("Mismatched Constructor/Destructor calls (2)\n"); + std::printf(" Expected 0, got %d\n", gCounter); retVal = 1; - } + } return retVal; - } - +} + #ifndef TEST_HAS_NO_EXCEPTIONS // Make sure the constructors and destructors are matched int test_exception_in_constructor ( ) { @@ -173,24 +173,23 @@ int test_exception_in_constructor ( ) { one = __cxxabiv1::__cxa_vec_new ( 10, 40, 0, throw_construct, throw_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); three = __cxxabiv1::__cxa_vec_new3( 10, 40, 0, throw_construct, throw_destruct, my_alloc2, my_dealloc3 ); - } + } catch ( int i ) {} - + __cxxabiv1::__cxa_vec_delete ( one, 40, 0, throw_destruct ); __cxxabiv1::__cxa_vec_delete2( two, 40, 0, throw_destruct, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete3( three, 40, 0, throw_destruct, my_dealloc3 ); - -// Since there was no padding, the # of elements in the array are not stored + +// Since there was no padding, the # of elements in the array are not stored // and the destructors are not called. // Since we threw after 15 calls to the constructor, we should see 5 calls to // the destructor from the partially constructed array. if ( gConstructorCounter - gDestructorCounter != 10 ) { - std::cerr << "Mismatched Constructor/Destructor calls (1C)" << std::endl; - std::cerr << gConstructorCounter << " constructors, but " << - gDestructorCounter << " destructors" << std::endl; + std::printf("Mismatched Constructor/Destructor calls (1C)\n"); + std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter); retVal = 1; - } - + } + gConstructorCounter = gDestructorCounter = 0; gConstructorThrowTarget = 15; gDestructorThrowTarget = -1; @@ -199,22 +198,21 @@ int test_exception_in_constructor ( ) { one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); three = __cxxabiv1::__cxa_vec_new3( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc3 ); - } + } catch ( int i ) {} - + __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); __cxxabiv1::__cxa_vec_delete3( three, 40, 8, throw_destruct, my_dealloc3 ); if ( gConstructorCounter != gDestructorCounter ) { - std::cerr << "Mismatched Constructor/Destructor calls (2C)" << std::endl; - std::cerr << gConstructorCounter << " constructors, but " << - gDestructorCounter << " destructors" << std::endl; + std::printf("Mismatched Constructor/Destructor calls (2C)\n"); + std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter); retVal = 1; - } + } return retVal; - } +} #endif #ifndef TEST_HAS_NO_EXCEPTIONS @@ -232,25 +230,24 @@ int test_exception_in_destructor ( ) { one = two = NULL; one = __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct ); two = __cxxabiv1::__cxa_vec_new2( 10, 40, 8, throw_construct, throw_destruct, my_alloc2, my_dealloc2 ); - } + } catch ( int i ) {} - + try { __cxxabiv1::__cxa_vec_delete ( one, 40, 8, throw_destruct ); __cxxabiv1::__cxa_vec_delete2( two, 40, 8, throw_destruct, my_dealloc2 ); assert(false); - } + } catch ( int i ) {} - + // We should have thrown in the middle of cleaning up "two", which means that // there should be 20 calls to the destructor and the try block should exit // before the assertion. if ( gConstructorCounter != 20 || gDestructorCounter != 20 ) { - std::cerr << "Unexpected Constructor/Destructor calls (1D)" << std::endl; - std::cerr << "Expected (20, 20), but got (" << gConstructorCounter << ", " << - gDestructorCounter << ")" << std::endl; + std::printf("Unexpected Constructor/Destructor calls (1D)\n"); + std::printf("Expected (20, 20), but got (%d, %d)\n", gConstructorCounter, gDestructorCounter); retVal = 1; - } + } // Try throwing from a destructor - should be fine. gConstructorCounter = gDestructorCounter = 0; @@ -258,19 +255,18 @@ int test_exception_in_destructor ( ) { gDestructorThrowTarget = 5; try { vec_on_stack v; } catch ( int i ) {} - + if ( gConstructorCounter != gDestructorCounter ) { - std::cerr << "Mismatched Constructor/Destructor calls (2D)" << std::endl; - std::cerr << gConstructorCounter << " constructors, but " << - gDestructorCounter << " destructors" << std::endl; + std::printf("Mismatched Constructor/Destructor calls (2D)\n"); + std::printf("%d constructors, but %d destructors\n", gConstructorCounter, gDestructorCounter); retVal = 1; - } + } return retVal; - } +} #endif -int main () { +int main(int, char**) { int retVal = 0; retVal += test_empty (); retVal += test_counted (); @@ -279,4 +275,4 @@ int main () { retVal += test_exception_in_destructor (); #endif return retVal; - } +} diff --git a/libcxxabi/test/test_vector2.pass.cpp b/libcxxabi/test/test_vector2.pass.cpp index 21b5e860e143..dd09d2a8848f 100644 --- a/libcxxabi/test/test_vector2.pass.cpp +++ b/libcxxabi/test/test_vector2.pass.cpp @@ -10,8 +10,9 @@ #include "cxxabi.h" -#include +#include #include +#include void my_terminate () { exit ( 0 ); } @@ -20,25 +21,25 @@ void *my_alloc2 ( size_t sz ) { void *p = std::malloc ( sz ); // std::printf ( "Allocated %ld bytes at %lx\n", sz, (unsigned long) p ); return p; - } +} void my_dealloc2 ( void *p ) { // std::printf ( "Freeing %lx\n", (unsigned long) p ); std::free ( p ); - } +} void my_dealloc3 ( void *p, size_t ) { // std::printf ( "Freeing %lx (size %ld)\n", (unsigned long) p, sz ); std::free ( p ); - } +} void my_construct ( void *) { // std::printf ( "Constructing %lx\n", (unsigned long) p ); - } +} void my_destruct ( void *) { // std::printf ( "Destructing %lx\n", (unsigned long) p ); - } +} int gCounter; void count_construct ( void * ) { ++gCounter; } @@ -56,7 +57,7 @@ struct vec_on_stack { void *storage; vec_on_stack () : storage ( __cxxabiv1::__cxa_vec_new ( 10, 40, 8, throw_construct, throw_destruct )) {} ~vec_on_stack () { __cxxabiv1::__cxa_vec_delete ( storage, 40, 8, throw_destruct ); } - }; +}; // Make sure the constructors and destructors are matched @@ -69,16 +70,17 @@ void test_exception_in_destructor ( ) { try { vec_on_stack v; throw 3; - } - catch ( int i ) {} + } catch ( int i ) { - std::cerr << "should never get here" << std::endl; } + assert(false && "should never get here"); +} + int main () { std::set_terminate ( my_terminate ); test_exception_in_destructor (); return 1; // we failed if we get here - } +}