lumiera_/tests/core/steam/engine/node-devel-test.cpp
Ichthyostega d80966c1fb Invocation: draft a scheme how to provide dummy-operations
After the actual processing functions are defined,
the "next level" of test framework building is to find a way
how these bare bone operations can be used easily from a test
with the goal to ''build and invoke a Render-Node''
 * we need some descriptor
 * the bare bone operation must be packaged into an ''Invocation-Adapter''
 * we need some means to configure variants of the setup
2024-11-29 05:42:19 +01:00

290 lines
9.6 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
NodeDevel(Test) - Render Node development and test support
Copyright (C)
2024, Hermann Vosseler <Ichthyostega@web.de>
  **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.
* *****************************************************************/
/** @file node-devel-test.cpp
** unit test \ref NodeDevel_test
*/
#include "lib/test/run.hpp"
#include "lib/hash-combine.hpp"
#include "lib/test/test-helper.hpp"
#include "steam/engine/test-rand-ontology.hpp" ///////////TODO
#include "lib/test/diagnostic-output.hpp"/////////////////TODO
#include "lib/iter-zip.hpp"
#include "lib/random.hpp"
//#include "lib/util.hpp"
#include <vector>
using lib::zip;
using lib::izip;
using std::vector;
namespace steam {
namespace engine{
namespace test {
namespace {
/** uninitialised local storage that can be passed
* as working buffer and accessed as TestFrame */
struct Buffer
: util::NonCopyable
{
alignas(TestFrame)
std::byte storage[sizeof(TestFrame)];
operator TestFrame* () { return std::launder (reinterpret_cast<TestFrame* > (&storage)); }
TestFrame* operator->() { return std::launder (reinterpret_cast<TestFrame* > (&storage)); }
TestFrame& operator* () { return * std::launder (reinterpret_cast<TestFrame* > (&storage)); }
TestFrame&
buildData (uint seq=0, uint family=0)
{
return * new(&storage) TestFrame{seq,family};
}
};
}
/***************************************************************//**
* @test verify support for developing Render Node functionality.
*/
class NodeDevel_test : public Test
{
virtual void
run (Arg)
{
seedRand();
TestFrame::reseed();
processing_generateFrame();
processing_generateMultichan();
processing_duplicateMultichan();
processing_manipulateMultichan();
processing_manipulateFrame();
processing_combineFrames();
testRand_simpleUsage();
}
/** @test function to generate random test data frames
*/
void
processing_generateFrame()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
Buffer buff;
CHECK (not buff->isSane());
generateFrame (buff, frameNr, flavour);
CHECK ( buff->isSane());
CHECK ( buff->isPristine());
CHECK (*buff == TestFrame(frameNr,flavour));
}
/** @test function to generate an array of random test data frames
* for consecutive channels
*/
void
processing_generateMultichan()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
uint channels = 1 + rani(50);
CHECK (1 <= channels and channels <= 50);
Buffer buff[50];
for (uint i=0; i<channels; ++i)
CHECK (not buff[i]->isSane());
generateMultichan (buff[0], channels, frameNr, flavour);
for (uint i=0; i<channels; ++i)
{
CHECK (buff[i]->isPristine());
CHECK (*(buff[i]) == TestFrame(frameNr,flavour+i));
}
}
/** @test clone copy of multichannel test data */
void
processing_duplicateMultichan()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
uint channels = 1 + rani(50);
Buffer srcBuff[50];
generateMultichan (srcBuff[0], channels, frameNr, flavour);
Buffer clone[50];
for (uint i=0; i<channels; ++i)
CHECK (not clone[i]->isSane());
duplicateMultichan (clone[0],srcBuff[0], channels);
for (uint i=0; i<channels; ++i)
{
CHECK (clone[i]->isPristine());
CHECK (*(clone[i]) == *(srcBuff[i]));
}
}
/** @test multichannel data hash-chain manipulation
* - use multichannel pseudo random input data
* - store away a clone copy before manipulation
* - the #manipulateMultichan() operates in-place in the buffers
* - each buffer has been marked with a new checksum afterwards
* - and each buffer now differs from original state
* - verify that corresponding data points over all channels
* have been linked by a hashcode-chain, seeded with the `param`
* and then consecutively hashing in data from each channel.
*/
void
processing_manipulateMultichan()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
uint channels = 1 + rani(50);
Buffer buff[50], refData[50];
generateMultichan (buff[0], channels, frameNr, flavour);
// stash away a copy of the test data for verification
duplicateMultichan(refData[0],buff[0], channels);
for (uint c=0; c<channels; ++c)
CHECK (buff[c]->isPristine());
uint64_t param = defaultGen.u64();
manipulateMultichan(buff[0], channels, param);
const uint SIZ = buff[0]->data64().size();
vector<uint64_t> xlink(SIZ, param); // temporary storage for verifying the hash-chain
for (uint c=0; c<channels; ++c)
{
CHECK (buff[c]->isSane()); // checksum matches
CHECK (not buff[c]->isPristine()); // data was indeed changed
CHECK (*(buff[c]) != *(refData[c]));
for (auto& [i, link] : izip(xlink))
{
auto const& refPoint = refData[c]->data64()[i];
lib::hash::combine (link, refPoint);
CHECK (link != refPoint);
CHECK (link == buff[c]->data64()[i]);
}
}
}
/** @test function to apply a numeric computation to test data frames;
* @remark here basically the same hash-chaining is used as for #manipulateMultichan,
* but only one hash-chain per data point is used and output is written to a different buffer.
*/
void
processing_manipulateFrame()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
Buffer iBuff, oBuff;
iBuff.buildData(frameNr,flavour);
oBuff.buildData(frameNr,flavour);
CHECK (iBuff->isPristine());
CHECK (oBuff->isPristine());
uint64_t param = defaultGen.u64();
manipulateFrame (oBuff, iBuff, param);
CHECK ( oBuff->isValid());
CHECK (not oBuff->isPristine());
CHECK ( iBuff->isPristine());
for (auto [iDat,oDat] : zip (iBuff->data64()
,oBuff->data64()))
{
CHECK (oDat != iDat);
uint64_t feed = param;
lib::hash::combine (feed, iDat);
CHECK (feed != param);
CHECK (feed != iDat);
CHECK (feed == oDat);
}
// can also process in-place
manipulateFrame (iBuff, iBuff, param);
CHECK (not iBuff->isPristine());
CHECK ( iBuff->isValid());
CHECK (*iBuff == *oBuff); // second invocation exactly reproduced data from first invocation
}
/** @test function to mix two test data frames
*/
void
processing_combineFrames()
{
size_t frameNr = defaultGen.u64();
uint flavour = defaultGen.u64();
Buffer i1Buff, i2Buff, oBuff;
i1Buff.buildData(frameNr,flavour+0);
i2Buff.buildData(frameNr,flavour+1);
oBuff.buildData();
CHECK (i1Buff->isPristine());
CHECK (i2Buff->isPristine());
CHECK (oBuff->isPristine());
double mix = defaultGen.uni();
combineFrames (oBuff, i1Buff, i2Buff, mix);
CHECK ( oBuff->isValid());
CHECK (not oBuff->isPristine());
CHECK ( i1Buff->isPristine());
CHECK ( i2Buff->isPristine());
for (auto [oDat,i1Dat,i2Dat] : zip (oBuff->data()
,i1Buff->data()
,i2Buff->data()))
CHECK (oDat == std::lround((1-mix)*i1Dat + mix*i2Dat));
// can also process in-place
combineFrames (i1Buff, i1Buff, i2Buff, mix);
CHECK (not i1Buff->isPristine());
CHECK ( i1Buff->isValid());
CHECK (*i1Buff == *oBuff); // second invocation exactly reproduced data from first invocation
}
/** @test demonstrate simple usage of test-render setup
* - access the TestRandOntology as singleton
* - create a Spec record
*/
void
testRand_simpleUsage()
{
auto spec = testRand().setupGenerator();
SHOW_EXPR(spec.PROTO);
CHECK (spec.PROTO == "generate-TestFrame"_expect);
}
};
/** Register this test class... */
LAUNCHER (NodeDevel_test, "unit node");
}}} // namespace steam::engine::test