Skip to content

Commit

Permalink
Adding more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jun 1, 2017
1 parent 56d66b1 commit 848bfc0
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 4 deletions.
Expand Up @@ -72,7 +72,7 @@ namespace hpx { namespace parallel { inline namespace v1
util::loop_with_cleanup_n_with_token(
first, count, tok,
[](FwdIter it) {
::new (sstatic_cast<void*>(std::addressof(*it)))
::new (static_cast<void*>(std::addressof(*it)))
value_type;
},
[](FwdIter it) {
Expand Down
Expand Up @@ -26,6 +26,15 @@ void test_uninitialized_default_construct()
test_uninitialized_default_construct_async(execution::par(execution::task),
IteratorTag());

test_uninitialized_default_construct2(execution::seq, IteratorTag());
test_uninitialized_default_construct2(execution::par, IteratorTag());
test_uninitialized_default_construct2(execution::par_unseq, IteratorTag());

test_uninitialized_default_construct_async2(execution::seq(execution::task),
IteratorTag());
test_uninitialized_default_construct_async2(execution::par(execution::task),
IteratorTag());

#if defined(HPX_HAVE_GENERIC_EXECUTION_POLICY)
test_uninitialized_default_construct(execution_policy(execution::seq),
IteratorTag());
Expand Down
Expand Up @@ -30,6 +30,11 @@ struct default_constructable
int value_;
};

struct value_constructable
{
int value_;
};

std::size_t const data_size = 10007;

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -91,6 +96,86 @@ void test_uninitialized_default_construct_async(ExPolicy && policy, IteratorTag)
std::free(p);
}

template <typename ExPolicy, typename IteratorTag>
void test_uninitialized_default_construct2(ExPolicy && policy, IteratorTag)
{
static_assert(
hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
"hpx::parallel::execution::is_execution_policy<ExPolicy>::value");

typedef value_constructable* base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;

value_constructable* p = (value_constructable*)std::malloc(
data_size * sizeof(value_constructable));
std::memset(p, 0xcd, data_size * sizeof(value_constructable));

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

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](value_constructable v1)
{
if (sizeof(value_constructable) == 2)
{
HPX_TEST_EQ(v1.value_, 0xcdcd);
}
else if (sizeof(value_constructable) == 4)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcd);
}
else if (sizeof(value_constructable) == 8)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcdcdcdcdcd);
}
++count;
});
HPX_TEST_EQ(count, data_size);

std::free(p);
}

template <typename ExPolicy, typename IteratorTag>
void test_uninitialized_default_construct_async2(ExPolicy && policy, IteratorTag)
{
typedef value_constructable* base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;

value_constructable* p = (value_constructable*)std::malloc(
data_size * sizeof(value_constructable));
std::memset(p, 0xcd, data_size * sizeof(value_constructable));

auto f =
hpx::parallel::uninitialized_default_construct(
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](value_constructable v1)
{
if (sizeof(value_constructable) == 2)
{
HPX_TEST_EQ(v1.value_, 0xcdcd);
}
else if (sizeof(value_constructable) == 4)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcd);
}
else if (sizeof(value_constructable) == 8)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcdcdcdcdcd);
}
++count;
});
HPX_TEST_EQ(count, data_size);

std::free(p);
}

///////////////////////////////////////////////////////////////////////////////
template <typename ExPolicy, typename IteratorTag>
void test_uninitialized_default_construct_exception(ExPolicy policy, IteratorTag)
Expand Down
Expand Up @@ -26,6 +26,11 @@ struct default_constructable
int value_;
};

struct value_constructable
{
int value_;
};

std::size_t const data_size = 10007;

////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -64,9 +69,9 @@ void test_uninitialized_default_construct_n_async(ExPolicy policy, IteratorTag)
typedef default_constructable* base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;

default_constructable* p =
(default_constructable*)std::malloc(data_size * sizeof(std::size_t));
std::memset(p, 0, data_size * sizeof(default_constructable));
default_constructable* p = (default_constructable*)std::malloc(
data_size * sizeof(default_constructable));
std::memset(p, 0xcd, data_size * sizeof(default_constructable));

auto f =
hpx::parallel::uninitialized_default_construct_n(policy,
Expand All @@ -85,6 +90,84 @@ void test_uninitialized_default_construct_n_async(ExPolicy policy, IteratorTag)
std::free(p);
}

template <typename ExPolicy, typename IteratorTag>
void test_uninitialized_default_construct_n2(ExPolicy policy, IteratorTag)
{
static_assert(
hpx::parallel::execution::is_execution_policy<ExPolicy>::value,
"hpx::parallel::execution::is_execution_policy<ExPolicy>::value");

typedef value_constructable* base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;

value_constructable* p = (value_constructable*)std::malloc(
data_size * sizeof(value_constructable));
std::memset(p, 0xcd, data_size * sizeof(value_constructable));

hpx::parallel::uninitialized_default_construct_n(policy,
iterator(p), data_size);

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](value_constructable v1)
{
if (sizeof(value_constructable) == 2)
{
HPX_TEST_EQ(v1.value_, 0xcdcd);
}
else if (sizeof(value_constructable) == 4)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcd);
}
else if (sizeof(value_constructable) == 8)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcdcdcdcdcd);
}
++count;
});
HPX_TEST_EQ(count, data_size);

std::free(p);
}

template <typename ExPolicy, typename IteratorTag>
void test_uninitialized_default_construct_n_async2(ExPolicy policy, IteratorTag)
{
typedef value_constructable* base_iterator;
typedef test::test_iterator<base_iterator, IteratorTag> iterator;

value_constructable* p =
(value_constructable*)std::malloc(data_size * sizeof(value_constructable));
std::memset(p, 0xcd, data_size * sizeof(value_constructable));

auto f =
hpx::parallel::uninitialized_default_construct_n(policy,
iterator(p), data_size);
f.wait();

std::size_t count = 0;
std::for_each(p, p + data_size,
[&count](value_constructable v1)
{
if (sizeof(value_constructable) == 2)
{
HPX_TEST_EQ(v1.value_, 0xcdcd);
}
else if (sizeof(value_constructable) == 4)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcd);
}
else if (sizeof(value_constructable) == 8)
{
HPX_TEST_EQ(v1.value_, 0xcdcdcdcdcdcdcdcd);
}
++count;
});
HPX_TEST_EQ(count, data_size);

std::free(p);
}

template <typename IteratorTag>
void test_uninitialized_default_construct_n()
{
Expand All @@ -99,6 +182,15 @@ void test_uninitialized_default_construct_n()
test_uninitialized_default_construct_n_async(execution::par(execution::task),
IteratorTag());

test_uninitialized_default_construct_n2(execution::seq, IteratorTag());
test_uninitialized_default_construct_n2(execution::par, IteratorTag());
test_uninitialized_default_construct_n2(execution::par_unseq, IteratorTag());

test_uninitialized_default_construct_n_async(execution::seq(execution::task),
IteratorTag());
test_uninitialized_default_construct_n_async2(execution::par(execution::task),
IteratorTag());

#if defined(HPX_HAVE_GENERIC_EXECUTION_POLICY)
test_uninitialized_default_construct_n(
execution_policy(execution::seq), IteratorTag());
Expand Down

0 comments on commit 848bfc0

Please sign in to comment.