-
Notifications
You must be signed in to change notification settings - Fork 78
Make NdPluginAttribute compression aware, add unit tests for NDPluginAttribute #583
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * AttributePluginWrapper.cpp | ||
| * | ||
| * Created on: 27 Apr 2026 | ||
| * Author: Jakub Wlodek | ||
| */ | ||
|
|
||
| #include "AttributePluginWrapper.h" | ||
|
|
||
| AttributePluginWrapper::AttributePluginWrapper(const std::string& port, | ||
| const std::string& detectorPort, | ||
| int maxAttributes) | ||
| : NDPluginAttribute(port.c_str(), 50, 0, detectorPort.c_str(), 0, | ||
| maxAttributes, 0, 0, 0, 0), | ||
| AsynPortClientContainer(port) | ||
| { | ||
| } | ||
|
|
||
| AttributePluginWrapper::~AttributePluginWrapper() | ||
| { | ||
| cleanup(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * AttributePluginWrapper.h | ||
| * | ||
| * Created on: 27 Apr 2026 | ||
| * Author: Jakub Wlodek | ||
| */ | ||
|
|
||
| #ifndef ADAPP_PLUGINTESTS_ATTRIBUTEPLUGINWRAPPER_H_ | ||
| #define ADAPP_PLUGINTESTS_ATTRIBUTEPLUGINWRAPPER_H_ | ||
|
|
||
| #include <NDPluginAttribute.h> | ||
| #include "AsynPortClientContainer.h" | ||
|
|
||
| class AttributePluginWrapper : public NDPluginAttribute, public AsynPortClientContainer | ||
| { | ||
| public: | ||
| AttributePluginWrapper(const std::string& port, const std::string& detectorPort, | ||
| int maxAttributes); | ||
| virtual ~AttributePluginWrapper(); | ||
| }; | ||
|
|
||
| #endif /* ADAPP_PLUGINTESTS_ATTRIBUTEPLUGINWRAPPER_H_ */ |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,147 @@ | ||||||
| /* | ||||||
| * test_NDPluginAttribute.cpp | ||||||
| * | ||||||
| * Tests NDPluginAttribute, including with compressed arrays. | ||||||
| * | ||||||
| * Created on: 27 Apr 2026 | ||||||
| * Author: Jakub Wlodek | ||||||
| */ | ||||||
|
|
||||||
| #include <string.h> | ||||||
| #include <stdlib.h> | ||||||
|
|
||||||
| #include "boost/test/unit_test.hpp" | ||||||
|
|
||||||
| #include <NDPluginDriver.h> | ||||||
| #include <NDArray.h> | ||||||
| #include <asynDriver.h> | ||||||
| #include <Codec.h> | ||||||
| #include <NDPluginAttribute.h> | ||||||
| #include <NDPluginCodec.h> | ||||||
|
|
||||||
| #include "testingutilities.h" | ||||||
| #include "AttributePluginWrapper.h" | ||||||
|
|
||||||
| #define TEST_XSIZE 8 | ||||||
| #define TEST_YSIZE 8 | ||||||
| #define TEST_NELEMENTS (TEST_XSIZE * TEST_YSIZE) | ||||||
|
|
||||||
| struct AttributeTestFixture | ||||||
| { | ||||||
| NDArrayPool *arrayPool; | ||||||
| asynNDArrayDriver *dummy_driver; | ||||||
| AttributePluginWrapper *attr; | ||||||
|
|
||||||
| AttributeTestFixture() | ||||||
| { | ||||||
| std::string dummy_port("simAttr"), testport("testAttr"); | ||||||
| uniqueAsynPortName(dummy_port); | ||||||
| uniqueAsynPortName(testport); | ||||||
|
|
||||||
| dummy_driver = new asynNDArrayDriver( | ||||||
| dummy_port.c_str(), 1, 0, 0, | ||||||
| asynGenericPointerMask, asynGenericPointerMask, 0, 0, 0, 0); | ||||||
| arrayPool = dummy_driver->pNDArrayPool; | ||||||
|
|
||||||
| attr = new AttributePluginWrapper(testport.c_str(), dummy_port.c_str(), 4); | ||||||
| attr->start(); | ||||||
|
|
||||||
| attr->write(NDPluginDriverEnableCallbacksString, 1); | ||||||
| attr->write(NDPluginDriverBlockingCallbacksString, 1); | ||||||
| } | ||||||
|
|
||||||
| ~AttributeTestFixture() | ||||||
| { | ||||||
| delete attr; | ||||||
| delete dummy_driver; | ||||||
| } | ||||||
|
|
||||||
| NDArray *createTestArray(bool compress = false) | ||||||
| { | ||||||
| size_t dims[2] = {TEST_XSIZE, TEST_YSIZE}; | ||||||
| NDArray *arr = arrayPool->alloc(2, dims, NDUInt16, 0, NULL); | ||||||
| epicsUInt16 *pData = (epicsUInt16 *)arr->pData; | ||||||
| for (int i = 0; i < TEST_NELEMENTS; i++) { | ||||||
| pData[i] = (epicsUInt16)(i % 256); | ||||||
| } | ||||||
| #ifdef HAVE_ZLIB | ||||||
| if (compress) { | ||||||
| NDCodecStatus_t status; | ||||||
| char errorMessage[256] = ""; | ||||||
| NDArray *compressed = compressZlib(arr, 6, &status, errorMessage); | ||||||
| arr->release(); | ||||||
| return compressed; | ||||||
| } | ||||||
| #else | ||||||
| (void)compress; | ||||||
| #endif | ||||||
| return arr; | ||||||
| } | ||||||
|
|
||||||
| void processArray(NDArray *pArray) | ||||||
| { | ||||||
| attr->lock(); | ||||||
| attr->processCallbacks(pArray); | ||||||
| attr->unlock(); | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| BOOST_FIXTURE_TEST_SUITE(AttributePluginTests, AttributeTestFixture) | ||||||
|
|
||||||
| /* Test that NDPluginAttribute reads attributes from an uncompressed array */ | ||||||
| BOOST_AUTO_TEST_CASE(test_attribute_uncompressed) | ||||||
| { | ||||||
| NDArray *input = createTestArray(); | ||||||
| double testVal = 42.5; | ||||||
| input->pAttributeList->add("TestAttr", "", NDAttrFloat64, &testVal); | ||||||
|
|
||||||
| attr->write(NDPluginAttributeAttrNameString, std::string("TestAttr"), 0); | ||||||
|
|
||||||
| processArray(input); | ||||||
|
|
||||||
| double readVal = attr->readDouble(NDPluginAttributeValString, 0); | ||||||
| BOOST_CHECK_CLOSE(readVal, 42.5, 0.001); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| input->release(); | ||||||
| } | ||||||
|
|
||||||
| #ifdef HAVE_ZLIB | ||||||
| /* Test that NDPluginAttribute accepts a zlib-compressed array and still reads attributes */ | ||||||
| BOOST_AUTO_TEST_CASE(test_attribute_compressed_array) | ||||||
| { | ||||||
| NDArray *input = createTestArray(true); | ||||||
| BOOST_REQUIRE(input != NULL); | ||||||
| BOOST_CHECK_EQUAL(input->codec.name, codecName[NDCODEC_ZLIB]); | ||||||
|
|
||||||
| double testVal = 99.0; | ||||||
| input->pAttributeList->add("CompAttr", "", NDAttrFloat64, &testVal); | ||||||
|
|
||||||
| attr->write(NDPluginAttributeAttrNameString, std::string("CompAttr"), 0); | ||||||
|
|
||||||
| processArray(input); | ||||||
|
|
||||||
| double readVal = attr->readDouble(NDPluginAttributeValString, 0); | ||||||
| BOOST_CHECK_CLOSE(readVal, 99.0, 0.001); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| input->release(); | ||||||
| } | ||||||
|
|
||||||
| /* Test that uniqueId is readable from a compressed array */ | ||||||
| BOOST_AUTO_TEST_CASE(test_attribute_compressed_unique_id) | ||||||
| { | ||||||
| NDArray *input = createTestArray(true); | ||||||
| BOOST_REQUIRE(input != NULL); | ||||||
| input->uniqueId = 12345; | ||||||
|
|
||||||
| attr->write(NDPluginAttributeAttrNameString, std::string("NDArrayUniqueId"), 0); | ||||||
|
|
||||||
| processArray(input); | ||||||
|
|
||||||
| double readVal = attr->readDouble(NDPluginAttributeValString, 0); | ||||||
| BOOST_CHECK_CLOSE(readVal, 12345.0, 0.001); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||||||
|
|
||||||
| input->release(); | ||||||
| } | ||||||
| #endif /* HAVE_ZLIB */ | ||||||
|
|
||||||
| BOOST_AUTO_TEST_SUITE_END() | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are using in the other tests, missing
BOOST_REQUIRE(input != NULL)