Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestSignalGenerator Module #270

Merged
merged 19 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-test-lin-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ jobs:
name: TestResults_${{ inputs.flav }}
path: |
CI_test_result_${{inputs.flav}}.xml
${{ github.workspace }}/data/SaveOrCompareFail/**


- name: Upload build logs
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-test-lin-wsl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ jobs:
name: TestResults_${{ inputs.flav }}
path: |
CI_test_result_${{inputs.flav}}.xml
${{ github.workspace }}/data/SaveOrCompareFail/**


- name: Upload build logs
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-test-lin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ jobs:
name: TestResults_${{ inputs.flav }}
path: |
CI_test_result_${{inputs.flav}}.xml
${{ github.workspace }}/data/SaveOrCompareFail/**


- name: Upload build logs
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ jobs:
name: TestResults_${{ inputs.flav }}
path: |
CI_test_result_${{inputs.flav}}.xml
${{ github.workspace }}/data/SaveOrCompareFail/**


- name: Upload build logs
Expand Down
3 changes: 3 additions & 0 deletions base/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ SET(CORE_FILES_H
include/MotionVectorExtractor.h
include/OverlayModule.h
include/OrderedCacheOfFiles.h
include/TestSignalGeneratorSrc.h
)

IF(ENABLE_WINDOWS)
Expand Down Expand Up @@ -278,6 +279,7 @@ SET(IP_FILES
src/Overlay.cpp
src/OverlayFactory.h
src/OverlayFactory.cpp
src/TestSignalGeneratorSrc.cpp
)


Expand Down Expand Up @@ -555,6 +557,7 @@ SET(UT_FILES
test/mp4_getlivevideots_tests.cpp
test/mp4_dts_strategy_tests.cpp
test/overlaymodule_tests.cpp
test/testSignalGeneratorSrc_tests.cpp
${ARM64_UT_FILES}
${CUDA_UT_FILES}
)
Expand Down
52 changes: 52 additions & 0 deletions base/include/TestSignalGeneratorSrc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once
#include "Module.h"

class TestSignalGeneratorProps : public ModuleProps
{
public:
TestSignalGeneratorProps() {}
TestSignalGeneratorProps(int _width, int _height)
: width(_width), height(_height) {}

~TestSignalGeneratorProps() {}

int width = 0;
int height = 0;

private:
friend class boost::serialization::access;

template <class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar &boost::serialization::base_object<ModuleProps>(*this);
ar &width;
ar &height;
}
};

class TestSignalGenerator : public Module
{
public:
TestSignalGenerator(TestSignalGeneratorProps _props);
~TestSignalGenerator();

bool init();
bool term();
void setProps(TestSignalGeneratorProps &props);
TestSignalGeneratorProps getProps();

protected:
bool produce();
bool validateOutputPins();
void setMetadata(framemetadata_sp &metadata);
bool handlePropsChange(frame_sp &frame);


private:
class Detail;
boost::shared_ptr<Detail> mDetail;
size_t outputFrameSize;
framemetadata_sp mOutputMetadata;
std::string mOutputPinId;
};
131 changes: 131 additions & 0 deletions base/src/TestSignalGeneratorSrc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include "TestSignalGeneratorSrc.h"
#include "Module.h"
#include <cstdlib>
#include <cstdint>

class TestSignalGenerator::Detail
{
public:
Detail(TestSignalGeneratorProps &_props)
: mProps(_props), start_shade(0), end_shade(255), current_shade(start_shade) {}

~Detail() {}

bool generate(frame_sp &frame)
{
auto frame_ptr = frame->data();
uint8_t* x = static_cast<uint8_t*>(frame_ptr);

for (int height = 0; height < mProps.height * 1.5; height++)
{
memset(x, current_shade, mProps.width);
x += mProps.width;
current_shade += 1;
if (current_shade > end_shade)
{
current_shade = start_shade;
}
}
return true;
}

void setProps(const TestSignalGeneratorProps &_props)
{
mProps = _props;
reset();
}
void reset()
{
current_shade = start_shade;
}

TestSignalGeneratorProps mProps;
uint8_t start_shade = 0;
uint8_t end_shade = 255;
uint8_t current_shade = 0;
};

TestSignalGenerator::TestSignalGenerator(TestSignalGeneratorProps _props)
: Module(SOURCE, "TestSignalGenerator", _props), outputFrameSize(0)
{
mDetail.reset(new Detail(_props));
mOutputMetadata = framemetadata_sp(new RawImagePlanarMetadata(_props.width, _props.height, ImageMetadata::ImageType::YUV420, size_t(0), CV_8U));
mOutputPinId = addOutputPin(mOutputMetadata);
}

TestSignalGenerator::~TestSignalGenerator()
{
mDetail->~Detail();
}

bool TestSignalGenerator::validateOutputPins()
{
if (getNumberOfOutputPins() != 1)
{
LOG_ERROR << "<" << getId() << ">::validateOutputPins size is expected to be 1. Actual<" << getNumberOfOutputPins() << ">";
return false;
}
framemetadata_sp metadata = getFirstOutputMetadata();
auto frameType = metadata->getFrameType();
if (frameType != FrameMetadata::RAW_IMAGE_PLANAR)
{
LOG_ERROR << "<" << getId() << ">::validateOutputPins output frameType should be RAW_IMAGE_PLANAR. Actual<" << frameType << ">";
return false;
}

return true;
}

bool TestSignalGenerator::init()
{
if (!Module::init())
{
return false;
}
outputFrameSize = (getProps().width * getProps().height * 3) >> 1;

return true;
}

bool TestSignalGenerator::produce()
{
auto mPinId = getOutputPinIdByType(FrameMetadata::RAW_IMAGE_PLANAR);
frame_container frames;
frame_sp frame = makeFrame(outputFrameSize);
mDetail->generate(frame);
frames.insert(make_pair(mPinId, frame));
send(frames);
return true;
}

bool TestSignalGenerator::term()
{
return Module::term();
}

void TestSignalGenerator::setMetadata(framemetadata_sp &metadata)
{
if (!metadata->isSet())
{
return;
}
}

bool TestSignalGenerator::handlePropsChange(frame_sp &frame)
{
TestSignalGeneratorProps props;
bool ret = Module::handlePropsChange(frame, props);
mDetail->setProps(props);
outputFrameSize = (props.width * props.height * 3) >> 1;
return ret;
}

void TestSignalGenerator::setProps(TestSignalGeneratorProps &props)
{
Module::addPropsToQueue(props);
}

TestSignalGeneratorProps TestSignalGenerator::getProps()
{
return mDetail->mProps;
}
86 changes: 86 additions & 0 deletions base/test/testSignalGeneratorSrc_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include "TestSignalGeneratorSrc.h"
#include "Module.h"
#include "RawImageMetadata.h"
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include "PipeLine.h"
#include "test_utils.h"
#include "ExternalSinkModule.h"
#include "FrameContainerQueue.h"
#include"FileWriterModule.h"

BOOST_AUTO_TEST_SUITE(TestSignalGenerator_tests)

class SinkModuleProps : public ModuleProps
{
public:
SinkModuleProps() : ModuleProps(){};
};

class SinkModule : public Module
{
public:
SinkModule(SinkModuleProps props) : Module(SINK, "sinkModule", props){};
boost::shared_ptr<FrameContainerQueue> getQue() { return Module::getQue(); }

protected:
bool validateOutputPins()
{
return true;
}
bool validateInputPins()
{
return true;
}
};
BOOST_AUTO_TEST_CASE(Basic)
{
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(400, 400)));
auto sink = boost::shared_ptr<ExternalSinkModule>(new ExternalSinkModule());
source->setNext(sink);
BOOST_TEST(source->init());
BOOST_TEST(sink->init());
source->step();
auto frames = sink->try_pop();
BOOST_TEST(frames.size() == 1);
auto outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
const uint8_t* pReadDataTest = const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data()));
unsigned int readDataSizeTest = outputFrame->size();
Test_Utils::saveOrCompare("./data/TestSample.raw", pReadDataTest, readDataSizeTest,0);
}

BOOST_AUTO_TEST_CASE(getSetProps)
{
auto source = boost::shared_ptr<TestSignalGenerator>(new TestSignalGenerator(TestSignalGeneratorProps(640, 360)));
auto sink = boost::shared_ptr<SinkModule>(new SinkModule(SinkModuleProps()));
source->setNext(sink);
source->init();
sink->init();
source->step();
auto sinkQue = sink->getQue();
frame_container frames;
frames = sinkQue->pop();
auto frameMetadata = frames.begin()->second->getMetadata();
auto currentProps = source->getProps();
BOOST_TEST(frames.size() == 1);
auto outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
const uint8_t* pReadDataTest = const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data()));
unsigned int readDataSizeTest = outputFrame->size();
Test_Utils::saveOrCompare("./data/TestSample1.raw", pReadDataTest,readDataSizeTest, 0);
TestSignalGeneratorProps newProps(400, 400);
source->setProps(newProps);
source->step();
sinkQue = sink->getQue();
frames = sinkQue->pop();
frameMetadata = frames.begin()->second->getMetadata();
BOOST_TEST(frames.size() == 1);
outputFrame = frames.cbegin()->second;
BOOST_TEST(outputFrame->getMetadata()->getFrameType() == FrameMetadata::RAW_IMAGE_PLANAR);
pReadDataTest = const_cast<const uint8_t *>(static_cast<uint8_t *>(outputFrame->data()));
readDataSizeTest = outputFrame->size();
Test_Utils::saveOrCompare("./data/TestSample2.raw",pReadDataTest,readDataSizeTest, 0);
}

BOOST_AUTO_TEST_SUITE_END()
27 changes: 26 additions & 1 deletion base/test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "test_utils.h"
#include "Logger.h"
#include <boost/test/unit_test.hpp>
#include <boost/test/framework.hpp>
#include "iostream"
#include <boost/filesystem.hpp>
#include <fstream>
Expand Down Expand Up @@ -76,9 +77,11 @@ bool CompareData(const uint8_t* data01, const uint8_t* data02, unsigned int data
else
{
mismatch += 1;
LOG_ERROR<<"The mismatch occured at data element"<<i;

if (mismatch > tolerance)
{
LOG_ERROR<<"Mismatch has crossed tolerance. Mismatch "<<mismatch<<" > tolerance "<<tolerance;
break;
}
}
Expand Down Expand Up @@ -110,12 +113,34 @@ bool Test_Utils::saveOrCompare(const char* fileName, const unsigned char* dataTo

if (boost::filesystem::is_regular_file(fileName))
{
const std::string strFullFileName = fileName;
std::string strFileBaseName = strFullFileName;
std::string strExtension;
std::string nameOfFile;
auto test_name = std::string(boost::unit_test::framework::current_test_case().p_name);
const size_t fileBaseIndex = strFullFileName.find_last_of(".");
const size_t fileBaseLocation = strFullFileName.find_last_of("/");
Vinayak-YB marked this conversation as resolved.
Show resolved Hide resolved
if (std::string::npos != fileBaseIndex)
{
strFileBaseName = strFullFileName.substr(0U, fileBaseIndex);
strExtension = strFullFileName.substr(fileBaseIndex);
}
if (std::string::npos != fileBaseLocation)
Vinayak-YB marked this conversation as resolved.
Show resolved Hide resolved
{
nameOfFile = strFullFileName.substr(fileBaseLocation + 1, fileBaseIndex - fileBaseLocation -1);
}

const uint8_t* dataRead = nullptr;
unsigned int dataSize = 0U;
BOOST_TEST(readFile(fileName, dataRead, dataSize));
BOOST_TEST(dataSize == sizeToSC);

compareRes = CompareData(dataToSC, dataRead, dataSize, tolerance);
if(!compareRes)
{
boost::filesystem::create_directory("./data/SaveOrCompareFail");
Vinayak-YB marked this conversation as resolved.
Show resolved Hide resolved
std::string saveFile = "./data/SaveOrCompareFail/" + test_name + nameOfFile + strExtension;
writeFile(saveFile.c_str(), dataToSC, sizeToSC);
}
BOOST_TEST(compareRes);

SAFE_DELETE_ARRAY(dataRead);
Expand Down
Binary file added data/TestSample.raw
Binary file not shown.
Binary file added data/TestSample1.raw
Binary file not shown.
Binary file added data/TestSample2.raw
Binary file not shown.
Loading