forked from OSchip/llvm-project
[libc++/abi] Clean up uses of <iostream> in the test suite
We used <iostream> in several places where we don't actually need the full power of <iostream>, 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 <iostream> can't.
This commit is contained in:
parent
9b1c06c0e8
commit
cc69d211d0
|
@ -15,10 +15,10 @@
|
|||
// resizes or shrinks at the correct time.
|
||||
|
||||
#include <deque>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <stack>
|
||||
#include <queue>
|
||||
#include <stack>
|
||||
|
||||
#include "min_allocator.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
|
@ -31,12 +31,12 @@ struct ContainerAdaptor : public Adaptor {
|
|||
|
||||
template <class Deque>
|
||||
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 <class T>
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
// Extension: constructing from NULL is UB; we just make it a failed iterator
|
||||
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
|
|
@ -13,12 +13,11 @@
|
|||
// map& operator=(const map& m);
|
||||
|
||||
#include <map>
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <iterator>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "../../../test_compare.h"
|
||||
|
@ -78,7 +77,7 @@ public:
|
|||
bool balanced_allocs() {
|
||||
std::vector<int> 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<std::vector<int>>(temp2));
|
||||
std::cout << "There were " << temp2.size() << " different allocators\n";
|
||||
std::printf("There were %lu different allocators\n", temp2.size());
|
||||
|
||||
for (std::vector<int>::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<std::vector<int>>(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<int>::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**)
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include <cassert>
|
||||
#include <tuple>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
class Moveable
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include <set>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <functional>
|
||||
#include <random>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "min_allocator.h"
|
||||
|
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
// unordered_multimap(unordered_multimap&& u, const allocator_type& a);
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
@ -272,5 +270,5 @@ int main(int, char**)
|
|||
assert(c0.empty());
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#include "filesystem_test_helper.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
TEST_SUITE(directory_entry_obs_testsuite)
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "test_macros.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
#include "filesystem_test_helper.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace fs;
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "test_macros.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
#include "filesystem_test_helper.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace fs;
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "test_iterators.h"
|
||||
#include "count_new.h"
|
||||
#include "filesystem_test_helper.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
template <class CharT>
|
||||
|
|
|
@ -15,13 +15,10 @@
|
|||
// path lexically_normal() const;
|
||||
|
||||
#include "filesystem_include.h"
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -16,13 +16,10 @@
|
|||
// path lexically_proximate(const path& p) const;
|
||||
|
||||
#include "filesystem_include.h"
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#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);
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "test_macros.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
#include "filesystem_test_helper.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace fs;
|
||||
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include "rapid-cxx-test.h"
|
||||
#include "filesystem_test_helper.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace fs;
|
||||
|
||||
using CO = fs::copy_options;
|
||||
|
|
|
@ -18,9 +18,10 @@
|
|||
// error_code& ec) noexcept;
|
||||
|
||||
#include "filesystem_include.h"
|
||||
#include <type_traits>
|
||||
#include <chrono>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
|
|
|
@ -19,18 +19,16 @@
|
|||
#include "filesystem_include.h"
|
||||
#include <type_traits>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "rapid-cxx-test.h"
|
||||
#include "filesystem_test_helper.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
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));
|
||||
|
|
|
@ -15,13 +15,10 @@
|
|||
// path proximate(const path& p, const path& base, error_code& ec);
|
||||
|
||||
#include "filesystem_include.h"
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
#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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,8 @@
|
|||
// path weakly_canonical(const path& p, error_code& ec);
|
||||
|
||||
#include "filesystem_include.h"
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
#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;
|
||||
|
|
|
@ -1,5 +1,2 @@
|
|||
import os
|
||||
import sys
|
||||
|
||||
if 'c++filesystem-disabled' in config.available_features:
|
||||
config.unsupported = True
|
||||
|
|
|
@ -6,18 +6,17 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cassert>
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <class T>
|
||||
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<typename T>
|
|||
void check_limits()
|
||||
{
|
||||
const bool is_unsigned = std::is_unsigned<T>::value;
|
||||
T minv = numeric_limits<T>::min();
|
||||
T maxv = numeric_limits<T>::max();
|
||||
T minv = std::numeric_limits<T>::min();
|
||||
T maxv = std::numeric_limits<T>::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);
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
#include <locale>
|
||||
#include <cassert>
|
||||
#include <iostream> // 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<C>& np = std::use_facet<std::numpunct<C> >(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;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,10 @@
|
|||
// RUN: %{exec} %t.exe
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <ios>
|
||||
#include <istream>
|
||||
#include <map>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <vector>
|
||||
|
||||
|
@ -85,8 +84,6 @@ void basic_tests()
|
|||
std::vector<size_t> 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<size_t>(std::cout, " "));
|
||||
std::cout << std::endl;
|
||||
for (size_t i = 0; i < v.size(); ++i)
|
||||
assert(v[i] == (i+1) * 4);
|
||||
}
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "test_macros.h"
|
||||
#include "debug_mode_helper.h"
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <cassert>
|
||||
#include <cstdio> // for printf
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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<heap_size>(
|
||||
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<heap_size>(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
|
||||
|
|
|
@ -9,17 +9,17 @@
|
|||
// UNSUPPORTED: no-exceptions
|
||||
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <exception>
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#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 ()
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef LIBCXXABI_NO_TIMER
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
class timer
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ public:
|
|||
using std::chrono::duration_cast;
|
||||
TimePoint end = Clock::now();
|
||||
MicroSeconds us = duration_cast<MicroSeconds>(end - m_start);
|
||||
std::cout << us.count() << " microseconds\n";
|
||||
std::printf("%d microseconds\n", us.count());
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
// UNSUPPORTED: no-exceptions
|
||||
|
||||
#include <typeinfo>
|
||||
#include <iostream>
|
||||
|
||||
// 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<D&> (*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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
|
||||
// UNSUPPORTED: no-exceptions
|
||||
|
||||
#include <iostream>
|
||||
#include <cxxabi.h>
|
||||
#include <new>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "support/timer.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cxxabi.h>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
// 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();
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <__threading_support>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -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.
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <deque>
|
||||
|
||||
#include <__threading_support>
|
||||
|
@ -20,169 +20,169 @@ typedef std::deque<void *> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,36 +8,36 @@
|
|||
|
||||
#include "cxxabi.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@
|
|||
|
||||
#include "cxxabi.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue