]>
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
);
24 BOOST_AUTO_TEST_CASE(test_pdns_lock
)
26 for(unsigned int n
=0; n
< 1000; ++n
) {
27 auto p
= make_unique
<pthread_rwlock_t
>();
28 pthread_rwlock_init(p
.get(), 0);
29 g_locks
.emplace_back(std::move(p
));
32 std::vector
<ReadLock
> rlocks
;
33 for(auto& pp
: g_locks
)
34 rlocks
.emplace_back(&*pp
);
36 std::thread
thr(lthread
);
40 std::vector
<WriteLock
> wlocks
;
41 for(auto& pp
: g_locks
)
42 wlocks
.emplace_back(&*pp
);
44 // on macOS, this TryReadLock throws (EDEADLK) instead of simply failing
45 // so we catch the exception and consider that success for this test
48 TryReadLock
trl(&*g_locks
[0]);
51 catch(const PDNSException
&e
) {
57 TryReadLock
trl2(&*g_locks
[0]);
58 BOOST_CHECK(trl2
.gotIt());
60 for(auto& pp
: g_locks
) {
61 pthread_rwlock_destroy(pp
.get());
65 BOOST_AUTO_TEST_SUITE_END()