MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / TEST

Function TEST

Engine/source/platform/test/threadStaticTest.cpp:34–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32DITTS(F32, gUnitTestF32, 1.0);
33
34TEST(ThreadStatic, BasicAPI)
35{
36 // ThreadStatic list should be initialized right now, so lets see if it has
37 // any entries.
38 EXPECT_FALSE(_TorqueThreadStaticReg::getStaticList().empty())
39 << "Self-registration has failed, or no statics declared";
40
41 // Spawn a new copy.
42 TorqueThreadStaticListHandle testInstance = _TorqueThreadStaticReg::spawnThreadStaticsInstance();
43
44 // Test the copy
45 ASSERT_EQ(_TorqueThreadStaticReg::getStaticList(0).size(), testInstance->size())
46 << "Spawned static list has a different size from master copy.";
47
48 // Traverse the list and compare it to the initial value copy (index 0)
49 for(S32 i = 0; i < _TorqueThreadStaticReg::getStaticList().size(); i++)
50 {
51 _TorqueThreadStatic *master = _TorqueThreadStaticReg::getStaticList()[i];
52 _TorqueThreadStatic *cpy = (*testInstance)[i];
53
54 // Make sure it is not the same memory
55 EXPECT_NE(master, cpy)
56 << "Copy not spawned properly.";
57
58 // Make sure the sizes are the same
59 ASSERT_EQ(master->getMemInstSize(), cpy->getMemInstSize())
60 << "Size mismatch between master and copy";
61
62 // Make sure the initialization occurred properly
63 EXPECT_EQ(0, dMemcmp(master->getMemInstPtr(), cpy->getMemInstPtr(), master->getMemInstSize()))
64 << "Initial value for spawned list is not correct";
65 }
66
67 // Test metrics if enabled
68#ifdef TORQUE_ENABLE_THREAD_STATIC_METRICS
69 U32 fooHitCount = (*testInstance)[_gUnitTestFooTorqueThreadStatic::getListIndex()]->getHitCount();
70#endif
71
72 // Set/get some values (If we test static metrics, this is hit 1)
73 ATTS_(gUnitTestFoo, 1) = 55;
74
75 // Test to see that the master copy and the spawned copy differ
76 // (If we test metrics, this is hit 2, for the instance, and hit 1 for the master)
77 EXPECT_NE(ATTS_(gUnitTestFoo, 0), ATTS_(gUnitTestFoo, 1))
78 << "Assignment for spawned instanced memory failed";
79
80#ifdef TORQUE_ENABLE_THREAD_STATIC_METRICS
81 U32 fooHitCount2 = (*testInstance)[_gUnitTestFooTorqueThreadStatic::getListIndex()]->getHitCount();
82 EXPECT_EQ(fooHitCount2, (fooHitCount + 2))
83 << "Thread static metric hit count failed";
84#endif
85
86 // Destroy instances
87 _TorqueThreadStaticReg::destroyInstance(testInstance);
88}
89
90#ifdef TORQUE_ENABLE_PROFILER
91#include "math/mRandom.h"

Callers

nothing calls this directly

Calls 9

getListIndexFunction · 0.85
getMemInstPtrMethod · 0.80
randIMethod · 0.60
dMemcmpFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
isEnabledMethod · 0.45
dumpToConsoleMethod · 0.45
enableMethod · 0.45

Tested by

no test coverage detected