mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +00:00
Ported thread pool and refcount tests. Failures, not sure why yet.
This commit is contained in:
parent
5f42f63078
commit
96011623ef
3 changed files with 241 additions and 278 deletions
71
Engine/source/platform/threads/test/threadPoolTest.cpp
Normal file
71
Engine/source/platform/threads/test/threadPoolTest.cpp
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2014 GarageGames, LLC
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifdef TORQUE_TESTS_ENABLED
|
||||
#include "testing/unitTesting.h"
|
||||
#include "platform/threads/threadPool.h"
|
||||
#include "console/console.h"
|
||||
#include "core/util/tVector.h"
|
||||
|
||||
TEST(ThreadPool, BasicAPI)
|
||||
{
|
||||
// Represents a single unit of work. In this test we just set an element in
|
||||
// a result vector.
|
||||
struct TestItem : public ThreadPool::WorkItem
|
||||
{
|
||||
U32 mIndex;
|
||||
Vector<U32>& mResults;
|
||||
TestItem(U32 index, Vector<U32>& results)
|
||||
: mIndex(index), mResults(results) {}
|
||||
|
||||
protected:
|
||||
virtual void execute()
|
||||
{
|
||||
mResults[mIndex] = mIndex;
|
||||
}
|
||||
};
|
||||
|
||||
// Construct the vector of results from the work items.
|
||||
const U32 numItems = 100;
|
||||
Vector<U32> results(__FILE__, __LINE__);
|
||||
results.setSize(numItems);
|
||||
for (U32 i = 0; i < numItems; i++)
|
||||
results[i] = U32(-1);
|
||||
|
||||
// Launch the work items.
|
||||
ThreadPool* pool = &ThreadPool::GLOBAL();
|
||||
for (U32 i = 0; i < numItems; i++)
|
||||
{
|
||||
ThreadSafeRef<TestItem> item(new TestItem(i, results));
|
||||
pool->queueWorkItem(item);
|
||||
}
|
||||
|
||||
// Wait for all items to complete.
|
||||
pool->flushWorkItems();
|
||||
|
||||
// Verify.
|
||||
for (U32 i = 0; i < numItems; i++)
|
||||
EXPECT_EQ(results[i], i) << "result mismatch";
|
||||
results.clear();
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue