]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-lock_hh.cc
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_NO_MAIN
6 #include <boost/test/unit_test.hpp>
10 using namespace boost
;
12 BOOST_AUTO_TEST_SUITE(test_lock_hh
)
14 static std::vector
<std::unique_ptr
<pthread_rwlock_t
> > g_locks
;
18 std::vector
<ReadLock
> rlocks
;
19 for(auto& pp
: g_locks
)
20 rlocks
.emplace_back(&*pp
);
23 BOOST_AUTO_TEST_CASE(test_pdns_lock
)
25 for(unsigned int n
=0; n
< 1000; ++n
) {
26 auto p
= make_unique
<pthread_rwlock_t
>();
27 pthread_rwlock_init(p
.get(), 0);
28 g_locks
.emplace_back(std::move(p
));
31 std::vector
<ReadLock
> rlocks
;
32 for(auto& pp
: g_locks
)
33 rlocks
.emplace_back(&*pp
);
35 std::thread
thr(lthread
);
39 std::vector
<WriteLock
> wlocks
;
40 for(auto& pp
: g_locks
)
41 wlocks
.emplace_back(&*pp
);
43 // on macOS, this TryReadLock throws (EDEADLK) instead of simply failing
44 // so we catch the exception and consider that success for this test
47 TryReadLock
trl(&*g_locks
[0]);
50 catch(const PDNSException
&e
) {
58 TryReadLock
trl2(&*g_locks
[0]);
59 BOOST_CHECK(trl2
.gotIt());
62 for(auto& pp
: g_locks
) {
63 pthread_rwlock_destroy(pp
.get());
67 BOOST_AUTO_TEST_SUITE_END()