Skip to content

Commit

Permalink
Merge pull request #2709 from STEllAR-GROUP/fixing_destroy_tests
Browse files Browse the repository at this point in the history
Fixing UB in destroy tests
  • Loading branch information
hkaiser committed Jun 25, 2017
2 parents 792f247 + 3f9a9db commit c147074
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
26 changes: 9 additions & 17 deletions tests/unit/parallel/algorithms/destroy_tests.hpp
Expand Up @@ -26,6 +26,8 @@

#include "test_utils.hpp"

boost::atomic<std::size_t> destruct_count(0);

struct destructable
{
destructable()
Expand All @@ -34,7 +36,7 @@ struct destructable

~destructable()
{
std::memset(&value_, 0xcd, sizeof(value_));
++destruct_count;
}

std::uint32_t value_;
Expand Down Expand Up @@ -64,18 +66,13 @@ void test_destroy(ExPolicy && policy, IteratorTag)
::new (static_cast<void*>(std::addressof(d))) destructable;
});

destruct_count.store(0);

hpx::parallel::destroy(
std::forward<ExPolicy>(policy),
iterator(p), iterator(p + data_size));

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](destructable v1)
{
HPX_TEST_EQ(v1.value_, (std::uint32_t)0xcdcdcdcd);
++count;
});
HPX_TEST_EQ(count, data_size);
HPX_TEST_EQ(destruct_count.load(), data_size);

std::free(p);
}
Expand All @@ -97,20 +94,15 @@ void test_destroy_async(ExPolicy && policy, IteratorTag)
::new (static_cast<void*>(std::addressof(d))) destructable;
});

destruct_count.store(0);

auto f =
hpx::parallel::destroy(
std::forward<ExPolicy>(policy),
iterator(p), iterator(p + data_size));
f.wait();

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](destructable v1)
{
HPX_TEST_EQ(v1.value_, (std::uint32_t)0xcdcdcdcd);
++count;
});
HPX_TEST_EQ(count, data_size);
HPX_TEST_EQ(destruct_count.load(), data_size);

std::free(p);
}
Expand Down
26 changes: 9 additions & 17 deletions tests/unit/parallel/algorithms/destroyn.cpp
Expand Up @@ -23,6 +23,8 @@

#include "test_utils.hpp"

boost::atomic<std::size_t> destruct_count(0);

struct destructable
{
destructable()
Expand All @@ -31,7 +33,7 @@ struct destructable

~destructable()
{
std::memset(&value_, 0xcd, sizeof(value_));
++destruct_count;
}

std::uint32_t value_;
Expand Down Expand Up @@ -61,18 +63,13 @@ void test_destroy_n(ExPolicy policy, IteratorTag)
::new (static_cast<void*>(std::addressof(d))) destructable;
});

destruct_count.store(0);

hpx::parallel::destroy_n(
std::forward<ExPolicy>(policy),
iterator(p), data_size);

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](destructable v1)
{
HPX_TEST_EQ(v1.value_, (std::uint32_t)0xcdcdcdcd);
++count;
});
HPX_TEST_EQ(count, data_size);
HPX_TEST_EQ(destruct_count.load(), data_size);

std::free(p);
}
Expand All @@ -94,20 +91,15 @@ void test_destroy_n_async(ExPolicy policy, IteratorTag)
::new (static_cast<void*>(std::addressof(d))) destructable;
});

destruct_count.store(0);

auto f =
hpx::parallel::destroy_n(
std::forward<ExPolicy>(policy),
iterator(p), data_size);
f.wait();

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](destructable v1)
{
HPX_TEST_EQ(v1.value_, (std::uint32_t)0xcdcdcdcd);
++count;
});
HPX_TEST_EQ(count, data_size);
HPX_TEST_EQ(destruct_count.load(), data_size);

std::free(p);
}
Expand Down

0 comments on commit c147074

Please sign in to comment.