pespin submitted this change.
tests/osmo_io: Rework test_file()
The amount of read and write on each callback is actually not
really managed by us but by the kernel. Instead of validating the amount
of read/write callbacks, monitor the amount of read/write bytes (and
also make sure the received a final read with len=0 to signal EOF).
Add fflush(stdout) before calling ASSERT to make sure stdout is flushed
before terminating the program.
Related: OS#6708
Change-Id: Ie1e686b407532eee76a8692dfc632af73183e614
---
M tests/osmo_io/osmo_io_test.c
1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/tests/osmo_io/osmo_io_test.c b/tests/osmo_io/osmo_io_test.c
index 82de564..d072ebe 100644
--- a/tests/osmo_io/osmo_io_test.c
+++ b/tests/osmo_io/osmo_io_test.c
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -45,18 +46,23 @@
static void *ctx = NULL;
-static unsigned file_read_wr_compl_counter = 0;
+static unsigned file_bytes_read = 0;
+static unsigned file_bytes_write_compl = 0;
+static bool file_eof_read = false;
static void file_read_cb(struct osmo_io_fd *iofd, int rc, struct msgb *msg)
{
printf("%s: read() msg with rc=%d\n", osmo_iofd_get_name(iofd), rc);
if (rc < 0)
printf("%s: error: %s\n", osmo_iofd_get_name(iofd), strerror(-rc));
- if (msg)
+ if (msg) {
printf("%s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
- file_read_wr_compl_counter++;
- talloc_free(msg);
- if (rc == 0)
+ file_bytes_read += msgb_length(msg);
+ talloc_free(msg);
+ }
+ if (rc == 0) {
+ file_eof_read = true;
osmo_iofd_close(iofd);
+ }
}
static void file_write_cb(struct osmo_io_fd *iofd, int rc, struct msgb *msg)
@@ -64,9 +70,10 @@
printf("%s: write() returned rc=%d\n", osmo_iofd_get_name(iofd), rc);
if (rc < 0)
printf("%s: error: %s\n", osmo_iofd_get_name(iofd), strerror(-rc));
- if (msg)
+ if (msg) {
printf("%s\n", osmo_hexdump(msgb_data(msg), msgb_length(msg)));
- file_read_wr_compl_counter++;
+ file_bytes_write_compl += msgb_length(msg);
+ }
}
static void test_file(void)
@@ -97,12 +104,13 @@
osmo_iofd_write_msgb(iofd, msg);
/* Allow enough cycles to handle the messages */
for (int i = 0; i < 128; i++) {
- OSMO_ASSERT(file_read_wr_compl_counter <= 1);
- if (file_read_wr_compl_counter == 1)
+ OSMO_ASSERT(file_bytes_write_compl <= sizeof(TESTDATA));
+ if (file_bytes_write_compl == sizeof(TESTDATA))
break;
osmo_select_main(1);
}
- OSMO_ASSERT(file_read_wr_compl_counter == 1);
+ fflush(stdout);
+ OSMO_ASSERT(file_bytes_write_compl == sizeof(TESTDATA));
/* Now, re-configure iofd to only read from the fd. Adjust the read/write offset beforehand: */
printf("Enable read\n");
@@ -113,12 +121,14 @@
OSMO_ASSERT(rc == 0);
/* Allow enough cycles to handle the message. We expect 2 reads, 2nd read will return 0. */
for (int i = 0; i < 128; i++) {
- OSMO_ASSERT(file_read_wr_compl_counter <= 3);
- if (file_read_wr_compl_counter == 3)
+ OSMO_ASSERT(file_bytes_read <= sizeof(TESTDATA));
+ if (file_bytes_read == sizeof(TESTDATA) && file_eof_read)
break;
osmo_select_main(1);
}
- OSMO_ASSERT(file_read_wr_compl_counter == 3);
+ fflush(stdout);
+ OSMO_ASSERT(file_bytes_read == sizeof(TESTDATA));
+ OSMO_ASSERT(file_eof_read);
osmo_iofd_free(iofd);
To view, visit change 39411. To unsubscribe, or for help writing mail filters, visit settings.