2011-10-31 00:13:35 +01:00
|
|
|
|
/*
|
|
|
|
|
|
TestFrame(Test) - verify proper operation of dummy data frames
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file testframe-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref TestFrame_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2024-11-20 05:50:44 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/engine/testframe.hpp"
|
2011-11-01 03:36:35 +01:00
|
|
|
|
#include "lib/util.hpp"
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
2024-11-10 00:40:20 +01:00
|
|
|
|
#include <climits>
|
2017-01-05 00:56:46 +01:00
|
|
|
|
#include <memory>
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
|
|
|
|
|
using test::Test;
|
2011-11-01 03:36:35 +01:00
|
|
|
|
using util::isSameObject;
|
2017-01-05 00:56:46 +01:00
|
|
|
|
using std::unique_ptr;
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2011-10-31 00:13:35 +01:00
|
|
|
|
namespace engine{
|
|
|
|
|
|
namespace test {
|
2011-11-01 03:36:35 +01:00
|
|
|
|
|
2011-10-31 00:13:35 +01:00
|
|
|
|
namespace { // used internally
|
|
|
|
|
|
|
|
|
|
|
|
const uint CHAN_COUNT = 30; // independent families of test frames to generate
|
|
|
|
|
|
const uint NUM_FRAMES = 1000; // number of test frames in each of these families
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
corruptMemory(void* base, uint offset, uint count)
|
|
|
|
|
|
{
|
|
|
|
|
|
char* accessor = reinterpret_cast<char*> (base);
|
|
|
|
|
|
while (count--)
|
2024-11-13 02:23:23 +01:00
|
|
|
|
accessor[offset+count] = rani(CHAR_MAX);
|
2011-10-31 00:13:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
} // (End) internal defs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/***************************************************************//**
|
2011-10-31 00:13:35 +01:00
|
|
|
|
* @test verify test helper for engine tests: a dummy data frame.
|
|
|
|
|
|
* TestFrame instances can be created right away, without any
|
|
|
|
|
|
* external library dependencies. A test frame is automatically
|
|
|
|
|
|
* filled with random data; multiple frames are arranged in
|
2024-11-05 21:23:13 +01:00
|
|
|
|
* sequences and channels, causing the random data to be
|
2011-10-31 00:13:35 +01:00
|
|
|
|
* reproducible yet different in each frame.
|
|
|
|
|
|
*
|
|
|
|
|
|
* To ease writing unit tests, TestFrame provides comparison
|
|
|
|
|
|
* and assignment and tracks lifecycle automatically. As tests
|
|
|
|
|
|
* regarding the engine typically have to deal with buffer
|
|
|
|
|
|
* management, an arbitrary memory location can be interpreted
|
|
|
|
|
|
* as TestFrame and checked for corruption.
|
|
|
|
|
|
*/
|
|
|
|
|
|
class TestFrame_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
virtual void
|
2024-11-05 21:23:13 +01:00
|
|
|
|
run (Arg)
|
2011-10-31 00:13:35 +01:00
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
2024-11-20 05:50:44 +01:00
|
|
|
|
TestFrame::reseed();
|
|
|
|
|
|
|
|
|
|
|
|
simpleUsage();
|
|
|
|
|
|
verifyDataContent();
|
2011-10-31 00:13:35 +01:00
|
|
|
|
verifyFrameLifecycle();
|
|
|
|
|
|
verifyFrameSeries();
|
2011-11-01 03:36:35 +01:00
|
|
|
|
useFrameTable();
|
2011-10-31 00:13:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2024-11-20 05:50:44 +01:00
|
|
|
|
simpleUsage()
|
2011-10-31 00:13:35 +01:00
|
|
|
|
{
|
|
|
|
|
|
CHECK (1024 < sizeof(TestFrame));
|
|
|
|
|
|
|
2024-11-20 05:50:44 +01:00
|
|
|
|
TestFrame frame;
|
|
|
|
|
|
CHECK (frame.isValid());
|
|
|
|
|
|
|
|
|
|
|
|
++frame.data()[5];
|
|
|
|
|
|
CHECK (not frame.isValid());
|
|
|
|
|
|
|
|
|
|
|
|
frame.markChecksum();
|
|
|
|
|
|
CHECK (frame.isValid());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (isSameObject(frame, frame.data())); // payload data stored embedded
|
|
|
|
|
|
CHECK (sizeof(TestFrame) > frame.data().size()); // additional metadata placed behind
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
verifyDataContent()
|
|
|
|
|
|
{
|
2011-10-31 00:13:35 +01:00
|
|
|
|
TestFrame frameA;
|
|
|
|
|
|
TestFrame frameB;
|
|
|
|
|
|
TestFrame frameC(5);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (frameA == frameB);
|
|
|
|
|
|
CHECK (frameA != frameC);
|
|
|
|
|
|
CHECK (frameB != frameC);
|
|
|
|
|
|
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (frameA.data() == frameB.data());
|
|
|
|
|
|
CHECK (frameA.data() != frameC.data());
|
|
|
|
|
|
for (uint i=0; i<frameA.data().size(); ++i)
|
|
|
|
|
|
CHECK (frameA.data()[i] == frameB.data()[i]);
|
|
|
|
|
|
|
2024-11-20 21:44:50 +01:00
|
|
|
|
// can access data as uint64_t
|
|
|
|
|
|
CHECK (frameA.data()[ 8] == char(frameA.data64()[1])); // assuming little-endian
|
|
|
|
|
|
CHECK (frameA.data()[16] == char(frameA.data64()[2]));
|
|
|
|
|
|
CHECK (frameA.data()[24] == char(frameA.data64()[3]));
|
|
|
|
|
|
CHECK (frameA.data()[32] == char(frameA.data64()[4]));
|
|
|
|
|
|
CHECK (frameA.data().size() == 8*frameA.data64().size());
|
|
|
|
|
|
|
2011-10-31 00:13:35 +01:00
|
|
|
|
CHECK (frameA.isAlive());
|
|
|
|
|
|
CHECK (frameB.isAlive());
|
|
|
|
|
|
CHECK (frameC.isAlive());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (frameA.isSane());
|
|
|
|
|
|
CHECK (frameB.isSane());
|
|
|
|
|
|
CHECK (frameC.isSane());
|
|
|
|
|
|
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (frameA.isValid());
|
|
|
|
|
|
CHECK (frameB.isValid());
|
|
|
|
|
|
CHECK (frameC.isValid());
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (frameA.isPristine());
|
|
|
|
|
|
CHECK (frameB.isPristine());
|
|
|
|
|
|
CHECK (frameC.isPristine());
|
|
|
|
|
|
|
2011-10-31 00:13:35 +01:00
|
|
|
|
void * frameMem = &frameB;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (frameA == frameMem);
|
2024-11-20 05:50:44 +01:00
|
|
|
|
corruptMemory (frameMem,20,5);
|
|
|
|
|
|
CHECK ( frameB.isSane()); // still has valid metadata header
|
|
|
|
|
|
CHECK (not frameB.isValid()); // data checksum does not match any more
|
|
|
|
|
|
CHECK (not frameB.isPristine()); // data does not match the original generation sequence
|
|
|
|
|
|
|
|
|
|
|
|
frameB.markChecksum();
|
|
|
|
|
|
CHECK ( frameB.isSane()); // still has valid metadata header
|
|
|
|
|
|
CHECK ( frameB.isValid()); // data matches the new recorded checksum
|
|
|
|
|
|
CHECK (not frameB.isPristine()); // but data still does not match the original generation sequence
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
|
|
|
|
|
frameB = frameC;
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (frameB.isSane());
|
|
|
|
|
|
CHECK (frameA != frameB);
|
|
|
|
|
|
CHECK (frameA != frameC);
|
|
|
|
|
|
CHECK (frameB == frameC);
|
2024-11-20 05:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
corruptMemory (frameMem, 0,sizeof(TestFrame));
|
|
|
|
|
|
CHECK (not frameB.isSane()); // now also the metadata was corrupted...
|
|
|
|
|
|
CHECK (not frameB.isValid());
|
|
|
|
|
|
VERIFY_FAIL ("corrupted metadata"
|
|
|
|
|
|
, frameB.markChecksum() ); // reject to store new checksum in the corrupted header
|
|
|
|
|
|
VERIFY_FAIL ("target TestFrame already dead or unaccessible"
|
|
|
|
|
|
, frameB = frameC); // reject to assign new content to a corrupted target
|
2011-10-31 00:13:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
verifyFrameLifecycle()
|
|
|
|
|
|
{
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (not TestFrame::isDead (this));
|
|
|
|
|
|
CHECK (not TestFrame::isAlive (this));
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
2016-01-10 12:33:47 +01:00
|
|
|
|
static char buffer[sizeof(TestFrame)];
|
|
|
|
|
|
TestFrame* frame = new(&buffer) TestFrame(23);
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
2016-01-10 12:33:47 +01:00
|
|
|
|
CHECK ( TestFrame::isAlive (frame));
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (not frame->isDead());
|
|
|
|
|
|
CHECK ( frame->isAlive());
|
|
|
|
|
|
CHECK ( frame->isValid());
|
2016-01-10 12:33:47 +01:00
|
|
|
|
|
|
|
|
|
|
frame->~TestFrame();
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK ( TestFrame::isDead (frame));
|
|
|
|
|
|
CHECK (not TestFrame::isAlive (frame));
|
|
|
|
|
|
CHECK ( frame->isValid());
|
|
|
|
|
|
CHECK ( frame->isSane());
|
2011-10-31 00:13:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @test build sequences of test frames,
|
|
|
|
|
|
* organised into multiple families (channels).
|
|
|
|
|
|
* Verify that adjacent frames hold differing data
|
|
|
|
|
|
*/
|
|
|
|
|
|
void
|
|
|
|
|
|
verifyFrameSeries()
|
|
|
|
|
|
{
|
2017-01-05 00:56:46 +01:00
|
|
|
|
unique_ptr<TestFrame> thisFrames[CHAN_COUNT];
|
|
|
|
|
|
unique_ptr<TestFrame> prevFrames[CHAN_COUNT];
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
|
|
|
|
|
for (uint i=0; i<CHAN_COUNT; ++i)
|
|
|
|
|
|
thisFrames[i].reset (new TestFrame(0, i));
|
|
|
|
|
|
|
|
|
|
|
|
for (uint nr=1; nr<NUM_FRAMES; ++nr)
|
|
|
|
|
|
for (uint i=0; i<CHAN_COUNT; ++i)
|
|
|
|
|
|
{
|
2011-10-31 02:20:32 +01:00
|
|
|
|
thisFrames[i].swap (prevFrames[i]);
|
2011-10-31 00:13:35 +01:00
|
|
|
|
thisFrames[i].reset (new TestFrame(nr, i));
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (thisFrames[i]->isPristine());
|
|
|
|
|
|
CHECK (prevFrames[i]->isPristine());
|
2011-10-31 00:13:35 +01:00
|
|
|
|
CHECK (prevFrames[i]->isAlive());
|
|
|
|
|
|
|
2011-11-01 03:36:35 +01:00
|
|
|
|
CHECK (*thisFrames[i] != *prevFrames[i]); // differs from predecessor within the same channel
|
2011-10-31 00:13:35 +01:00
|
|
|
|
|
2011-10-31 02:20:32 +01:00
|
|
|
|
for (uint j=0; j<i; ++j)
|
|
|
|
|
|
{
|
|
|
|
|
|
ENSURE (j!=i);
|
|
|
|
|
|
CHECK (*thisFrames[i] != *thisFrames[j]); // differs from frames in other channels at this point
|
2011-11-01 03:36:35 +01:00
|
|
|
|
CHECK (*thisFrames[i] != *prevFrames[j]); // differs cross wise from predecessors in other channels
|
2011-10-31 02:20:32 +01:00
|
|
|
|
} } }
|
2011-11-01 03:36:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
2024-11-20 05:50:44 +01:00
|
|
|
|
|
|
|
|
|
|
/** @test the table of test frames computed on demand */
|
2011-11-01 03:36:35 +01:00
|
|
|
|
void
|
|
|
|
|
|
useFrameTable()
|
|
|
|
|
|
{
|
2024-11-20 05:50:44 +01:00
|
|
|
|
TestFrame& frX = testData(50,3);
|
|
|
|
|
|
TestFrame& frY = testData(50,2);
|
|
|
|
|
|
TestFrame& frZ = testData(50,3);
|
2011-11-01 03:36:35 +01:00
|
|
|
|
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (frX.isPristine());
|
|
|
|
|
|
CHECK (frY.isPristine());
|
|
|
|
|
|
CHECK (frZ.isPristine());
|
2011-11-01 03:36:35 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (frX != frY);
|
|
|
|
|
|
CHECK (frX == frZ);
|
|
|
|
|
|
CHECK (frY != frZ);
|
|
|
|
|
|
|
|
|
|
|
|
CHECK (isSameObject (frX, frZ));
|
|
|
|
|
|
|
|
|
|
|
|
corruptMemory(&frZ,40,20);
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK (not frX.isPristine());
|
|
|
|
|
|
CHECK (not testData(50,3).isPristine());
|
|
|
|
|
|
CHECK ( testData(51,3).isPristine());
|
|
|
|
|
|
CHECK ( testData(49,3).isPristine());
|
|
|
|
|
|
|
|
|
|
|
|
char c = testData(49,3).data()[5]; // some arbitrary content
|
2011-11-01 03:36:35 +01:00
|
|
|
|
|
2024-11-18 02:45:37 +01:00
|
|
|
|
TestFrame::reseed();
|
2011-11-01 03:36:35 +01:00
|
|
|
|
|
2024-11-20 05:50:44 +01:00
|
|
|
|
CHECK ( testData(50,3).isPristine());
|
|
|
|
|
|
CHECK (c != testData(49,3).data()[5]); // content regenerated with different seed
|
|
|
|
|
|
|
|
|
|
|
|
TestFrame o{49,3}; // all data content is reproducible with the new seed
|
|
|
|
|
|
CHECK (not isSameObject(o, testData(49,3)));
|
|
|
|
|
|
CHECK (o == testData(49,3));
|
|
|
|
|
|
CHECK (o.data()[5] == testData(49,3).data()[5]);
|
2011-11-01 03:36:35 +01:00
|
|
|
|
}
|
2011-10-31 00:13:35 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
|
LAUNCHER (TestFrame_test, "unit engine");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::engine::test
|