Skip to content

Commit

Permalink
Debug blob snooping (#1902)
Browse files Browse the repository at this point in the history
  • Loading branch information
pludov authored May 30, 2023
1 parent 8588609 commit f8b829b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
50 changes: 48 additions & 2 deletions integs/ConnectionMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ConnectionMock::ConnectionMock()
{
fds[0] = -1;
fds[1] = -1;
pendingChar = -1;
bufferReceiveAllowed = false;
}

Expand All @@ -53,6 +54,7 @@ void ConnectionMock::release()
bufferReceiveAllowed = false;
fds[0] = -1;
fds[1] = -1;
pendingChar = -1;
}


Expand All @@ -73,8 +75,22 @@ void ConnectionMock::allowBufferReceive(bool state)
bufferReceiveAllowed = state;
}

ssize_t ConnectionMock::read(void * buffer, size_t len)
ssize_t ConnectionMock::read(void * vbuffer, size_t len)
{
unsigned char * buffer = (unsigned char*) vbuffer;
ssize_t baseLength = 0;
if (len && (pendingChar != -1)) {
((char*)buffer)[0] = pendingChar;
pendingChar = -1;
len--;
buffer++;
if (len == 0)
{
return 1;
}
baseLength = 1;
}

struct msghdr msgh;
struct iovec iov;

Expand Down Expand Up @@ -133,7 +149,7 @@ ssize_t ConnectionMock::read(void * buffer, size_t len)
}
}
}
return size;
return size + baseLength;
}

void ConnectionMock::expectBuffer(SharedBuffer &sb)
Expand Down Expand Up @@ -178,6 +194,13 @@ void ConnectionMock::expect(const std::string &str)

char ConnectionMock::readChar(const std::string &expected)
{
if (pendingChar != -1)
{
char c = pendingChar;
pendingChar = -1;
return c;
}

char buff[1];
ssize_t rd = read(buff, 1);
if (rd == 0)
Expand All @@ -192,6 +215,16 @@ char ConnectionMock::readChar(const std::string &expected)
return buff[0];
}

char ConnectionMock::peekChar(const std::string & expected) {
if (pendingChar != -1)
{
return pendingChar;
}
char ret = readChar(expected);
pendingChar = ret;
return ret;
}

enum XmlStatus { PRE, TAGNAME, WAIT_ATTRIB, ATTRIB, QUOTE, WAIT_CLOSE };

static std::string parseXmlFragmentFromString(const std::string &str)
Expand Down Expand Up @@ -237,6 +270,19 @@ std::string ConnectionMock::receiveMore()
return pendingData;
}

std::string ConnectionMock::expectBase64() {
std::string result;

while(true) {
char c = peekChar("base64");
if (c == '<') break;

result += readChar("base64");
}

return result;
}


void ConnectionMock::expectXml(const std::string &expected)
{
Expand Down
4 changes: 4 additions & 0 deletions integs/ConnectionMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ class SharedBuffer;
*/
class ConnectionMock
{
private:
int fds[2];
int pendingChar;
std::list<int> receivedFds;
bool bufferReceiveAllowed;
ssize_t read(void * buff, size_t count);
char readChar(const std::string &expected);
char peekChar(const std::string &expected);

void release();
std::string receiveMore();
Expand All @@ -49,6 +52,7 @@ class ConnectionMock

void expect(const std::string &content);
void expectXml(const std::string &xml);
std::string expectBase64();
void send(const std::string &content);
void send(const std::string &content, const SharedBuffer &buff);
void send(const std::string &content, const SharedBuffer ** buffers);
Expand Down
7 changes: 4 additions & 3 deletions integs/TestIndiserverSingleDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ TEST(IndiserverSingleDriver, ForwardAttachedBlobToDriver)
snoopDriver.cnx.send("<enableBLOB device='fakedev1' name='testblob'>Also</enableBLOB>\n");
snoopDriver.ping();

ssize_t size = 32;
ssize_t size = 10000;
driverSendAttachedBlob(fakeDriver, size);

#if 0
Expand All @@ -575,8 +575,9 @@ TEST(IndiserverSingleDriver, ForwardAttachedBlobToDriver)
EXPECT_GE( receivedFd.getSize(), 32);
#else
snoopDriver.cnx.expectXml("<setBLOBVector device='fakedev1' name='testblob' timestamp='2018-01-01T00:01:00'>");
snoopDriver.cnx.expectXml("<oneBLOB name='content' size='32' format='.fits'>\n");
snoopDriver.cnx.expect("\nMDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDE=");
snoopDriver.cnx.expectXml("<oneBLOB name='content' size='" + std::to_string(size) + "' format='.fits'>\n");
std::string base64 = snoopDriver.cnx.expectBase64();
EXPECT_EQ(base64.size(), size * 4 / 3 + 9 + (size / 800000));
snoopDriver.cnx.expectXml("</oneBLOB>\n");
snoopDriver.cnx.expectXml("</setBLOBVector>");
#endif
Expand Down
9 changes: 4 additions & 5 deletions libs/indicore/indidevapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,11 @@ int IUSnoopBLOB(XMLEle *root, IBLOBVectorProperty *bvp)

XMLAtt *fa = findXMLAtt(ep, "format");
XMLAtt *sa = findXMLAtt(ep, "size");
XMLAtt *ec = findXMLAtt(ep, "enclen");
if (fa && sa && ec)
if (fa && sa)
{
int enclen = atoi(valuXMLAtt(ec));
assert_mem(bp->blob = realloc(bp->blob, 3 * enclen / 4));
bp->bloblen = from64tobits_fast(bp->blob, pcdataXMLEle(ep), enclen);
int base64datalen = pcdatalenXMLEle(ep);
assert_mem(bp->blob = realloc(bp->blob, 3 * base64datalen / 4));
bp->bloblen = from64tobits_fast(bp->blob, pcdataXMLEle(ep), base64datalen);
indi_strlcpy(bp->format, valuXMLAtt(fa), MAXINDIFORMAT);
bp->size = atoi(valuXMLAtt(sa));
}
Expand Down

0 comments on commit f8b829b

Please sign in to comment.