Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing UB in destroy tests #2709

Merged
merged 1 commit into from Jun 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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