tests: Assemble the output into single buffer

... before checking the content.

This test was failing randomly when the read returned only partial buffer.

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 2743b510ac)
This commit is contained in:
Jakub Jelen
2024-08-09 17:26:00 +02:00
parent dd38f523e1
commit 84dde6d302

View File

@@ -84,18 +84,24 @@ static int session_teardown(void **state)
static int check_channel_output(ssh_channel c, const char *expected)
{
char buffer[4096] = {0};
int nbytes;
int nbytes, offset = 0;
nbytes = ssh_channel_read(c, buffer, sizeof(buffer) - 1, 0);
while (nbytes > 0) {
buffer[nbytes]='\0';
ssh_log_hexdump("Read bytes:", (unsigned char *)buffer, nbytes);
buffer[offset + nbytes] = '\0';
ssh_log_hexdump("Read bytes:",
(unsigned char *)buffer,
offset + nbytes);
if (strstr(buffer, expected) != NULL)
{
return 1;
}
nbytes = ssh_channel_read(c, buffer, sizeof(buffer), 0);
/* read on */
offset = nbytes;
nbytes = ssh_channel_read(c,
buffer + offset,
sizeof(buffer) - offset - 1,
0);
}
return 0;
}