Skip to content

Commit

Permalink
Added reference count checks for cutting tool assets looking for a leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Sobel committed Feb 23, 2018
1 parent c7cbc8b commit f42adb1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion agent/agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ bool Agent::addAsset(Device *aDevice, const string &aId, const string &aAsset,
mAssets.pop_front();
mAssetMap.erase(oldref->getAssetId());

// Add secondary keys
// Remove secondary keys
AssetKeys &keys = oldref->getKeys();
AssetKeys::iterator iter;
for (iter = keys.begin(); iter != keys.end(); iter++)
Expand Down
1 change: 1 addition & 0 deletions agent/agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class Agent : public server_http

// For testing...
void setSequence(uint64_t aSeq) { mSequence = aSeq; }
std::list<AssetPtr*> *getAssets() { return &mAssets; }

// Starting
virtual void start();
Expand Down
54 changes: 54 additions & 0 deletions test/agent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,60 @@ void AgentTest::testMultiLineAsset()

}

void AgentTest::testAssetRefCounts()
{
testAddAdapter();
std::list<AssetPtr*> *assets = a->getAssets();

adapter->parseBuffer(R"ASSET(2018-02-19T22:54:03.0738Z|@ASSET@|M8010N9172N:1.0|CuttingTool|--multiline--SMOOTH
<CuttingTool toolId="0" serialNumber="0" removed="False" assetId="M8010N9172N:1.0"><CuttingToolLifeCycle><ToolLife type="MINUTES" countDirection="UP" initial="0" limit="">1</ToolLife><ToolLife type="PART_COUNT" countDirection="UP" initial="0" limit="">1</ToolLife><Location type="POT" positiveOverlap="0" negativeOverlap="0">1</Location><ProgramToolGroup>0</ProgramToolGroup><ProgramToolNumber>1.0</ProgramToolNumber><CutterStatus><Status>USED</Status><Status>ALLOCATED</Status><Status>AVAILABLE</Status></CutterStatus><Measurements><FunctionalLength code="LF" nominal="0">0</FunctionalLength><CuttingDiameterMax code="DC" nominal="0">200</CuttingDiameterMax></Measurements></CuttingToolLifeCycle></CuttingTool>
--multiline--SMOOTH
)ASSET");
CPPUNIT_ASSERT_EQUAL((unsigned int) 4, a->getMaxAssets());
CPPUNIT_ASSERT_EQUAL((unsigned int) 1, a->getAssetCount());

// Asset has two secondary indexes
AssetPtr first(*(assets->front()));
CPPUNIT_ASSERT_EQUAL((unsigned int) 4, first.getObject()->refCount());

adapter->parseBuffer(R"ASSET(2018-02-19T22:54:03.1749Z|@ASSET@|M8010N9172N:1.2|CuttingTool|--multiline--SMOOTH
<CuttingTool toolId="0" serialNumber="1" removed="False" assetId="M8010N9172N:1.2"><CuttingToolLifeCycle><ToolLife type="MINUTES" countDirection="UP" initial="0" limit=""></ToolLife><ToolLife type="PART_COUNT" countDirection="UP" initial="0" limit=""></ToolLife><Location type="POT" positiveOverlap="0" negativeOverlap="0">1</Location><ProgramToolGroup>0</ProgramToolGroup><ProgramToolNumber>1.2</ProgramToolNumber><CutterStatus><Status>NEW</Status><Status>ALLOCATED</Status><Status>AVAILABLE</Status></CutterStatus><Measurements><FunctionalLength code="LF" nominal="649640">649640</FunctionalLength><CuttingDiameterMax code="DC" nominal="-177708">100</CuttingDiameterMax></Measurements></CuttingToolLifeCycle></CuttingTool>
--multiline--SMOOTH
)ASSET");

CPPUNIT_ASSERT_EQUAL((unsigned int) 2, a->getAssetCount());
CPPUNIT_ASSERT_EQUAL((unsigned int) 2, first.getObject()->refCount());

adapter->parseBuffer(R"ASSET(2018-02-19T22:54:03.2760Z|@ASSET@|M8010N9172N:1.0|CuttingTool|--multiline--SMOOTH
<CuttingTool toolId="0" serialNumber="0" removed="False" assetId="M8010N9172N:1.0"><CuttingToolLifeCycle><ToolLife type="MINUTES" countDirection="UP" initial="0" limit=""></ToolLife><ToolLife type="PART_COUNT" countDirection="UP" initial="0" limit=""></ToolLife><Location type="POT" positiveOverlap="0" negativeOverlap="0">1</Location><ProgramToolGroup>0</ProgramToolGroup><ProgramToolNumber>1.0</ProgramToolNumber><CutterStatus><Status>NEW</Status><Status>ALLOCATED</Status><Status>AVAILABLE</Status></CutterStatus><Measurements><FunctionalLength code="LF" nominal="0">0</FunctionalLength><CuttingDiameterMax code="DC" nominal="0">0</CuttingDiameterMax></Measurements></CuttingToolLifeCycle></CuttingTool>
--multiline--SMOOTH
)ASSET");
adapter->parseBuffer(R"ASSET(2018-02-19T22:54:03.3771Z|@ASSET@|M8010N9172N:2.5|CuttingTool|--multiline--SMOOTH
<CuttingTool toolId="0" serialNumber="0" removed="False" assetId="M8010N9172N:2.5"><CuttingToolLifeCycle><ToolLife type="MINUTES" countDirection="UP" initial="0" limit="">11</ToolLife><ToolLife type="PART_COUNT" countDirection="UP" initial="0" limit="">4</ToolLife><Location type="POT" positiveOverlap="0" negativeOverlap="0">2</Location><ProgramToolGroup>0</ProgramToolGroup><ProgramToolNumber>2.5</ProgramToolNumber><CutterStatus><Status>USED</Status><Status>ALLOCATED</Status><Status>AVAILABLE</Status></CutterStatus><Measurements><FunctionalLength code="LF" nominal="615207">615207</FunctionalLength><CuttingDiameterMax code="DC" nominal="-174546">200</CuttingDiameterMax></Measurements></CuttingToolLifeCycle></CuttingTool>
--multiline--SMOOTH
)ASSET");
adapter->parseBuffer(R"ASSET(2018-02-19T22:54:03.4782Z|@ASSET@|M8010N9172N:2.2|CuttingTool|--multiline--SMOOTH
<CuttingTool toolId="0" serialNumber="0" removed="False" assetId="M8010N9172N:2.2"><CuttingToolLifeCycle><ToolLife type="MINUTES" countDirection="UP" initial="0" limit="">11</ToolLife><ToolLife type="PART_COUNT" countDirection="UP" initial="0" limit="">4</ToolLife><Location type="POT" positiveOverlap="0" negativeOverlap="0">2</Location><ProgramToolGroup>0</ProgramToolGroup><ProgramToolNumber>2.2</ProgramToolNumber><CutterStatus><Status>USED</Status><Status>ALLOCATED</Status><Status>AVAILABLE</Status></CutterStatus><Measurements><FunctionalLength code="LF" nominal="615207">615207</FunctionalLength><CuttingDiameterMax code="DC" nominal="174546">200</CuttingDiameterMax></Measurements></CuttingToolLifeCycle></CuttingTool>
--multiline--SMOOTH
)ASSET");

// First asset should now be removed (we are holding the one ref)
CPPUNIT_ASSERT_EQUAL((unsigned int) 1, first.getObject()->refCount());

// Check next asset
AssetPtr second(*(assets->front()));
CPPUNIT_ASSERT_EQUAL((unsigned int) 2, second.getObject()->refCount());
CPPUNIT_ASSERT_EQUAL(string("M8010N9172N:1.2"), second.getObject()->getAssetId());

// Update the asset
adapter->parseBuffer(R"ASSET(2018-02-19T22:54:03.1749Z|@ASSET@|M8010N9172N:1.2|CuttingTool|--multiline--SMOOTH
<CuttingTool toolId="0" serialNumber="1" removed="False" assetId="M8010N9172N:1.2"><CuttingToolLifeCycle><ToolLife type="MINUTES" countDirection="UP" initial="0" limit=""></ToolLife><ToolLife type="PART_COUNT" countDirection="UP" initial="0" limit=""></ToolLife><Location type="POT" positiveOverlap="0" negativeOverlap="0">1</Location><ProgramToolGroup>0</ProgramToolGroup><ProgramToolNumber>1.2</ProgramToolNumber><CutterStatus><Status>NEW</Status><Status>ALLOCATED</Status><Status>AVAILABLE</Status></CutterStatus><Measurements><FunctionalLength code="LF" nominal="649640">649640</FunctionalLength><CuttingDiameterMax code="DC" nominal="-177708">100</CuttingDiameterMax></Measurements></CuttingToolLifeCycle></CuttingTool>
--multiline--SMOOTH
)ASSET");

// should be deleted
CPPUNIT_ASSERT_EQUAL((unsigned int) 1, second.getObject()->refCount());
}

void AgentTest::testBadAsset()
{
Expand Down
2 changes: 2 additions & 0 deletions test/agent_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class AgentTest : public CppUnit::TestFixture
CPPUNIT_TEST(testPutBlockingFrom);
CPPUNIT_TEST(testAdapterAddAsset);
CPPUNIT_TEST(testMultiLineAsset);
CPPUNIT_TEST(testAssetRefCounts);
CPPUNIT_TEST(testAssetProbe);
CPPUNIT_TEST(testAssetStorageWithoutType);
CPPUNIT_TEST(testStreamData);
Expand Down Expand Up @@ -204,6 +205,7 @@ class AgentTest : public CppUnit::TestFixture
void testAssetBuffer();
void testAdapterAddAsset();
void testMultiLineAsset();
void testAssetRefCounts();
void testAssetProbe();
void testAssetStorageWithoutType();

Expand Down

0 comments on commit f42adb1

Please sign in to comment.