MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
event_ipc_worker.cpp File Reference

Child-process consumer for event IPC regression tests. More...

#include <string>
#include <unistd.h>
#include <mxl/flow.h>
Include dependency graph for event_ipc_worker.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Verify event delivery in a separate reader process.

Detailed Description

Child-process consumer for event IPC regression tests.

Definition in file event_ipc_worker.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Verify event delivery in a separate reader process.

Parameters
argcMust be seven, including the executable name.
argvDomain, flow ID, first expected timestamp, entry count, readiness pipe descriptor and start pipe descriptor follow the executable name.
Returns
Zero if delivery, payload validation and teardown succeed; nonzero otherwise.

Definition at line 19 of file event_ipc_worker.cpp.

20{
21 if (argc != 7)
22 {
23 return 1;
24 }
25 auto const offset = std::stoull(argv[3]);
26 auto const count = std::stoull(argv[4]);
27 auto instance = mxlCreateInstance(argv[1], "{}");
28 auto reader = mxlFlowReader{};
29 if ((instance == nullptr) || (mxlCreateFlowReader(instance, argv[2], "", &reader) != MXL_STATUS_OK))
30 {
31 return 2;
32 }
33 auto ready = 'R';
34 if ((::write(std::stoi(argv[5]), &ready, 1) != 1) || (::read(std::stoi(argv[6]), &ready, 1) != 1))
35 {
36 return 3;
37 }
38 for (auto i = std::uint64_t{0}; i < count; ++i)
39 {
40 auto info = mxlEventInfo{};
41 auto payload = static_cast<std::uint8_t*>(nullptr);
42 if ((mxlFlowReaderGetEvent(reader, 5000000000ULL, &info, &payload) != MXL_STATUS_OK) || (info.timestamp != offset + i) ||
43 (info.offset != 0) || (info.complete != 1) || (info.eventSize != info.timestamp % (MXL_DATA_FORMAT_GRAIN_SIZE + 1)))
44 {
45 return 4;
46 }
47 for (auto byte = std::uint32_t{0}; byte < info.eventSize; ++byte)
48 {
49 if (payload[byte] != static_cast<std::uint8_t>((info.timestamp * 29) + (std::uint64_t{byte} * 7)))
50 {
51 return 5;
52 }
53 }
54 }
55 if ((mxlReleaseFlowReader(instance, reader) != MXL_STATUS_OK) || (mxlDestroyInstance(instance) != MXL_STATUS_OK))
56 {
57 return 6;
58 }
59 return 0;
60}
#define MXL_DATA_FORMAT_GRAIN_SIZE
Definition dataformat.h:15
MXL_EXPORT mxlStatus mxlFlowReaderGetEvent(mxlFlowReader reader, uint64_t timeoutNs, mxlEventInfo *event, uint8_t **payload)
Definition flow.cpp:726
MXL_EXPORT mxlStatus mxlReleaseFlowReader(mxlInstance instance, mxlFlowReader reader)
Definition flow.cpp:177
struct mxlFlowReader_t * mxlFlowReader
Definition flow.h:205
struct mxlEventInfo_t mxlEventInfo
Metadata for one event queue entry, either a complete event or a fragment.
MXL_EXPORT mxlStatus mxlCreateFlowReader(mxlInstance instance, char const *flowId, char const *options, mxlFlowReader *reader)
Definition flow.cpp:136
MXL_EXPORT mxlStatus mxlDestroyInstance(mxlInstance in_instance)
Definition mxl.cpp:106
@ MXL_STATUS_OK
Definition mxl.h:23
MXL_EXPORT mxlInstance mxlCreateInstance(char const *in_mxlDomain, char const *in_options)
Definition mxl.cpp:45
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.
mxlFlowReader reader