summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2014-11-24 22:38:57 +0000
committerEric Fiselier <eric@efcs.ca>2014-11-24 22:38:57 +0000
commit30ad829825ee45cab4bc132e5145b2cb7eef4c45 (patch)
treec35bbfcf863c174f951a48e2a4bf242b071a1459 /test
parent1b4ddb114e91d196cf3a652124e70560edf3816c (diff)
[libcxxabi] Refactor test timing logic and disable by default.
Summary: When using LIT the timing output is entirely unused but introduces a dependency on `<chrono>`. When libc++ is built without a montonic clock this causes some of the tests to fail. This patch factors out all of the timing logic into `support/timer.hpp` and disables it by default. To enable the timing you must define `LIBCXXABI_TIME_TESTS`. Reviewers: mclow.lists, danalbert, jroelofs Reviewed By: jroelofs Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D6391 git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@222701 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/dynamic_cast14.cpp11
-rw-r--r--test/dynamic_cast3.cpp11
-rw-r--r--test/dynamic_cast5.cpp10
-rw-r--r--test/dynamic_cast_stress.cpp14
-rw-r--r--test/lit.cfg4
-rw-r--r--test/support/timer.hpp46
-rw-r--r--test/test_demangle.cpp16
7 files changed, 69 insertions, 43 deletions
diff --git a/test/dynamic_cast14.cpp b/test/dynamic_cast14.cpp
index 2145fb4..c929e38 100644
--- a/test/dynamic_cast14.cpp
+++ b/test/dynamic_cast14.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include "support/timer.hpp"
namespace t1
{
@@ -2172,18 +2173,10 @@ void test()
} // t3
-#include <chrono>
-#include <iostream>
-
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef Clock::time_point time_point;
- typedef std::chrono::duration<double, std::micro> NS;
- time_point t0 = Clock::now();
+ timer t;
t1::test();
t2::test();
t3::test();
- time_point t1 = Clock::now();
- std::cout << NS(t1-t0).count() << " microseconds\n";
}
diff --git a/test/dynamic_cast3.cpp b/test/dynamic_cast3.cpp
index 2ce77f3..afd4ad8 100644
--- a/test/dynamic_cast3.cpp
+++ b/test/dynamic_cast3.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include "support/timer.hpp"
/*
@@ -2406,15 +2407,9 @@ void test()
} // t41
-#include <chrono>
-#include <iostream>
-
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef Clock::time_point time_point;
- typedef std::chrono::duration<double, std::micro> NS;
- time_point t0 = Clock::now();
+ timer t;
t1::test();
t2::test();
t3::test();
@@ -2456,6 +2451,4 @@ int main()
t39::test();
t40::test();
t41::test();
- time_point t1 = Clock::now();
- std::cout << NS(t1-t0).count() << " microseconds\n";
}
diff --git a/test/dynamic_cast5.cpp b/test/dynamic_cast5.cpp
index 8986969..d7064f4 100644
--- a/test/dynamic_cast5.cpp
+++ b/test/dynamic_cast5.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include <cassert>
+#include "support/timer.hpp"
namespace t1
{
@@ -1298,15 +1299,10 @@ void test()
} // t9
-#include <chrono>
-#include <iostream>
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef Clock::time_point time_point;
- typedef std::chrono::duration<double, std::micro> NS;
- time_point t0 = Clock::now();
+ timer t;
t1::test();
t2::test();
t3::test();
@@ -1316,6 +1312,4 @@ int main()
t7::test();
t8::test();
t9::test();
- time_point t1 = Clock::now();
- std::cout << NS(t1-t0).count() << " microseconds\n";
}
diff --git a/test/dynamic_cast_stress.cpp b/test/dynamic_cast_stress.cpp
index c3e5d0a..95276b2 100644
--- a/test/dynamic_cast_stress.cpp
+++ b/test/dynamic_cast_stress.cpp
@@ -9,8 +9,7 @@
#include <cassert>
#include <tuple>
-#include <chrono>
-#include <iostream>
+#include "support/timer.hpp"
template <std::size_t Indx, std::size_t Depth>
struct C
@@ -50,17 +49,16 @@ struct A
void test()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef std::chrono::duration<double, std::micro> US;
const std::size_t Width = 10;
const std::size_t Depth = 5;
A<Width, Depth> a;
typedef B<Width/2, Depth> Destination;
// typedef A<Width, Depth> Destination;
- auto t0 = Clock::now();
- Destination* b = dynamic_cast<Destination*>((C<Width/2, 0>*)&a);
- auto t1 = Clock::now();
- std::cout << US(t1-t0).count() << " microseconds\n";
+ Destination *b = nullptr;
+ {
+ timer t;
+ b = dynamic_cast<Destination*>((C<Width/2, 0>*)&a);
+ }
assert(b != 0);
}
diff --git a/test/lit.cfg b/test/lit.cfg
index 490796b..2d7c403 100644
--- a/test/lit.cfg
+++ b/test/lit.cfg
@@ -237,6 +237,10 @@ if link_flags_str is not None:
# Configure extra compiler flags.
+# Always disable timed test when using LIT since the output gets lost and since
+# using the timer requires <chrono> as a dependancy.
+compile_flags += ['-DLIBCXXABI_NO_TIMER']
+
san = lit_config.params.get('llvm_use_sanitizer', None)
if san is None:
san = getattr(config, 'llvm_use_sanitizer', None)
diff --git a/test/support/timer.hpp b/test/support/timer.hpp
new file mode 100644
index 0000000..a3d51d7
--- /dev/null
+++ b/test/support/timer.hpp
@@ -0,0 +1,46 @@
+#ifndef TIMER_HPP
+#define TIMER_HPP
+
+// Define LIBCXXABI_NO_TIMER to disable testing with a timer.
+#ifndef LIBCXXABI_NO_TIMER
+
+#include <chrono>
+#include <iostream>
+
+class timer
+{
+ typedef std::chrono::high_resolution_clock Clock;
+ typedef Clock::time_point TimePoint;
+ typedef std::chrono::microseconds MicroSeconds;
+public:
+ timer() : m_start(Clock::now()) {}
+
+ timer(timer const &) = delete;
+ timer & operator=(timer const &) = delete;
+
+ ~timer()
+ {
+ using std::chrono::duration_cast;
+ TimePoint end = Clock::now();
+ MicroSeconds us = duration_cast<MicroSeconds>(end - m_start);
+ std::cout << us.count() << " microseconds\n";
+ }
+
+private:
+ TimePoint m_start;
+};
+
+#else /* LIBCXXABI_NO_TIMER */
+
+class timer
+{
+public:
+ timer() {}
+ timer(timer const &) = delete;
+ timer & operator=(timer const &) = delete;
+ ~timer() {}
+};
+
+#endif /* LIBCXXABI_TIME_TESTS */
+
+#endif /* TIMER_HPP */ \ No newline at end of file
diff --git a/test/test_demangle.cpp b/test/test_demangle.cpp
index 15cb3a1..8a4685a 100644
--- a/test/test_demangle.cpp
+++ b/test/test_demangle.cpp
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
+#include "support/timer.hpp"
#include <iostream>
#include <string>
#include <cstdlib>
#include <cxxabi.h>
#include <cassert>
-#include <chrono>
// Is long double fp80? (Only x87 extended double has 64-bit mantissa)
#define LDBL_FP80 (__LDBL_MANT_DIG__ == 64)
@@ -29664,14 +29664,12 @@ void test2()
int main()
{
- typedef std::chrono::high_resolution_clock Clock;
- typedef std::chrono::duration<double> sec;
- Clock::time_point t0 = Clock::now();
- test();
- test2();
- Clock::time_point t1 = Clock::now();
- std::cout << sec(t1-t0).count() << " seconds for test\n";
- std::cout << N / sec(t1-t0).count() / 1000000. << " million symbols per second\n";
+ std::cout << "Testing " << N << " symbols." << std::endl;
+ {
+ timer t;
+ test();
+ test2();
+ }
#if 0
std::string input;
while (std::cin)