2014-10-15 19:52:27 +00:00
|
|
|
//============================================================================
|
|
|
|
// Copyright (c) Kitware, Inc.
|
|
|
|
// All rights reserved.
|
|
|
|
// See LICENSE.txt for details.
|
2019-04-15 23:24:21 +00:00
|
|
|
//
|
2014-10-15 19:52:27 +00:00
|
|
|
// This software is distributed WITHOUT ANY WARRANTY; without even
|
|
|
|
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE. See the above copyright notice for more information.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/exec/arg/FetchTagArrayDirectOut.h>
|
|
|
|
|
2022-02-16 12:50:39 +00:00
|
|
|
#include <vtkm/exec/testing/ThreadIndicesTesting.h>
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
#include <vtkm/testing/Testing.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace
|
|
|
|
{
|
2014-10-15 19:52:27 +00:00
|
|
|
|
2018-02-27 14:25:25 +00:00
|
|
|
static constexpr vtkm::Id ARRAY_SIZE = 10;
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
static vtkm::Id g_NumSets;
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-10-15 19:52:27 +00:00
|
|
|
struct TestPortal
|
|
|
|
{
|
2017-08-16 15:34:21 +00:00
|
|
|
using ValueType = T;
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
vtkm::Id GetNumberOfValues() const { return ARRAY_SIZE; }
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
void Set(vtkm::Id index, const ValueType& value) const
|
|
|
|
{
|
2014-10-23 16:59:18 +00:00
|
|
|
VTKM_TEST_ASSERT(index >= 0, "Bad portal index.");
|
|
|
|
VTKM_TEST_ASSERT(index < this->GetNumberOfValues(), "Bad portal index.");
|
2014-10-15 19:52:27 +00:00
|
|
|
VTKM_TEST_ASSERT(test_equal(value, TestValue(index, ValueType())),
|
|
|
|
"Tried to set invalid value.");
|
|
|
|
g_NumSets++;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-10-15 19:52:27 +00:00
|
|
|
struct FetchArrayDirectOutTests
|
|
|
|
{
|
|
|
|
|
2015-09-23 19:38:49 +00:00
|
|
|
void operator()()
|
2014-10-15 19:52:27 +00:00
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
TestPortal<T> execObject;
|
|
|
|
|
2017-08-16 15:34:21 +00:00
|
|
|
using FetchType = vtkm::exec::arg::Fetch<vtkm::exec::arg::FetchTagArrayDirectOut,
|
|
|
|
vtkm::exec::arg::AspectTagDefault,
|
|
|
|
TestPortal<T>>;
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
FetchType fetch;
|
|
|
|
|
|
|
|
g_NumSets = 0;
|
|
|
|
|
|
|
|
for (vtkm::Id index = 0; index < ARRAY_SIZE; index++)
|
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
vtkm::exec::arg::ThreadIndicesTesting indices(index);
|
2015-10-07 18:14:00 +00:00
|
|
|
|
2014-10-15 19:52:27 +00:00
|
|
|
// This is a no-op, but should be callable.
|
2015-09-23 19:38:49 +00:00
|
|
|
T value = fetch.Load(indices, execObject);
|
2014-10-15 19:52:27 +00:00
|
|
|
|
|
|
|
value = TestValue(index, T());
|
|
|
|
|
|
|
|
// The portal will check to make sure we are setting a good value.
|
2015-09-23 19:38:49 +00:00
|
|
|
fetch.Store(indices, execObject, value);
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VTKM_TEST_ASSERT(g_NumSets == ARRAY_SIZE,
|
|
|
|
"Array portal's set not called correct number of times."
|
|
|
|
"Store method must be wrong.");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TryType
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename T>
|
2014-10-15 19:52:27 +00:00
|
|
|
void operator()(T) const
|
|
|
|
{
|
2015-09-23 19:38:49 +00:00
|
|
|
FetchArrayDirectOutTests<T>()();
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestExecObjectFetch()
|
|
|
|
{
|
2016-08-24 22:02:18 +00:00
|
|
|
vtkm::testing::Testing::TryTypes(TryType());
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-01-01 22:19:02 +00:00
|
|
|
int UnitTestFetchArrayDirectOut(int argc, char* argv[])
|
2014-10-15 19:52:27 +00:00
|
|
|
{
|
2019-01-01 22:19:02 +00:00
|
|
|
return vtkm::testing::Testing::Run(TestExecObjectFetch, argc, argv);
|
2014-10-15 19:52:27 +00:00
|
|
|
}
|