diff --git a/.github/workflows/build-test-lin-container.yml b/.github/workflows/build-test-lin-container.yml index 4d3df0ea7..3bd29c054 100644 --- a/.github/workflows/build-test-lin-container.yml +++ b/.github/workflows/build-test-lin-container.yml @@ -178,6 +178,7 @@ jobs: name: TestResults_${{ inputs.flav }} path: | CI_test_result_${{inputs.flav}}.xml + ${{ github.workspace }}/data/SaveOrCompareFail/** - name: Upload build logs diff --git a/.github/workflows/build-test-lin-wsl.yml b/.github/workflows/build-test-lin-wsl.yml index 4c036c248..a193b781a 100644 --- a/.github/workflows/build-test-lin-wsl.yml +++ b/.github/workflows/build-test-lin-wsl.yml @@ -190,6 +190,7 @@ jobs: name: TestResults_${{ inputs.flav }} path: | CI_test_result_${{inputs.flav}}.xml + ${{ github.workspace }}/data/SaveOrCompareFail/** - name: Upload build logs diff --git a/.github/workflows/build-test-lin.yml b/.github/workflows/build-test-lin.yml index d45e77064..44c9bf4ab 100644 --- a/.github/workflows/build-test-lin.yml +++ b/.github/workflows/build-test-lin.yml @@ -174,6 +174,7 @@ jobs: name: TestResults_${{ inputs.flav }} path: | CI_test_result_${{inputs.flav}}.xml + ${{ github.workspace }}/data/SaveOrCompareFail/** - name: Upload build logs diff --git a/.github/workflows/build-test-win.yml b/.github/workflows/build-test-win.yml index f2fee82ae..d330c3829 100644 --- a/.github/workflows/build-test-win.yml +++ b/.github/workflows/build-test-win.yml @@ -182,6 +182,7 @@ jobs: name: TestResults_${{ inputs.flav }} path: | CI_test_result_${{inputs.flav}}.xml + ${{ github.workspace }}/data/SaveOrCompareFail/** - name: Upload build logs diff --git a/base/CMakeLists.txt b/base/CMakeLists.txt index 771c2a3cb..4e461fb91 100755 --- a/base/CMakeLists.txt +++ b/base/CMakeLists.txt @@ -221,6 +221,7 @@ SET(CORE_FILES_H include/MotionVectorExtractor.h include/OverlayModule.h include/OrderedCacheOfFiles.h + include/TestSignalGeneratorSrc.h ) IF(ENABLE_WINDOWS) @@ -278,6 +279,7 @@ SET(IP_FILES src/Overlay.cpp src/OverlayFactory.h src/OverlayFactory.cpp + src/TestSignalGeneratorSrc.cpp ) @@ -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} ) diff --git a/base/include/TestSignalGeneratorSrc.h b/base/include/TestSignalGeneratorSrc.h new file mode 100644 index 000000000..fcda4e943 --- /dev/null +++ b/base/include/TestSignalGeneratorSrc.h @@ -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 + void serialize(Archive &ar, const unsigned int version) + { + ar &boost::serialization::base_object(*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 mDetail; + size_t outputFrameSize; + framemetadata_sp mOutputMetadata; + std::string mOutputPinId; +}; diff --git a/base/src/TestSignalGeneratorSrc.cpp b/base/src/TestSignalGeneratorSrc.cpp new file mode 100644 index 000000000..c4640309b --- /dev/null +++ b/base/src/TestSignalGeneratorSrc.cpp @@ -0,0 +1,131 @@ +#include "TestSignalGeneratorSrc.h" +#include "Module.h" +#include +#include + +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(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; +} diff --git a/base/test/testSignalGeneratorSrc_tests.cpp b/base/test/testSignalGeneratorSrc_tests.cpp new file mode 100644 index 000000000..de503bef6 --- /dev/null +++ b/base/test/testSignalGeneratorSrc_tests.cpp @@ -0,0 +1,86 @@ +#include "TestSignalGeneratorSrc.h" +#include "Module.h" +#include "RawImageMetadata.h" +#include +#include +#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 getQue() { return Module::getQue(); } + +protected: + bool validateOutputPins() + { + return true; + } + bool validateInputPins() + { + return true; + } +}; +BOOST_AUTO_TEST_CASE(Basic) +{ + auto source = boost::shared_ptr(new TestSignalGenerator(TestSignalGeneratorProps(400, 400))); + auto sink = boost::shared_ptr(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(static_cast(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(new TestSignalGenerator(TestSignalGeneratorProps(640, 360))); + auto sink = boost::shared_ptr(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(static_cast(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(static_cast(outputFrame->data())); + readDataSizeTest = outputFrame->size(); + Test_Utils::saveOrCompare("./data/TestSample2.raw",pReadDataTest,readDataSizeTest, 0); +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/base/test/test_utils.cpp b/base/test/test_utils.cpp index ace2fce0a..1487d2b20 100755 --- a/base/test/test_utils.cpp +++ b/base/test/test_utils.cpp @@ -2,6 +2,7 @@ #include "test_utils.h" #include "Logger.h" #include +#include #include "iostream" #include #include @@ -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"< tolerance) { + LOG_ERROR<<"Mismatch has crossed tolerance. Mismatch "< tolerance "<