1.1 --- a/tests/dstest_pipe_client.cc Thu Sep 01 21:40:39 2022 +0200
1.2 +++ b/tests/dstest_pipe_client.cc Thu Sep 01 21:52:41 2022 +0200
1.3 @@ -1,7 +1,7 @@
1.4 /*
1.5 * Test pipe operations.
1.6 *
1.7 - * Copyright (C) 2020, 2021 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2020, 2021, 2022 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -34,12 +34,18 @@
1.13
1.14
1.15
1.16 +/* Common size and iteration details. */
1.17 +
1.18 +const offset_t TO_TRANSFER = 600;
1.19 +const int NUMBER_OF_ITERATIONS = 3;
1.20 +
1.21 +
1.22 +
1.23 /* Use the writer to fill the pipe with data. */
1.24
1.25 static void write_pipe(file_t *writer, int number)
1.26 {
1.27 - offset_t size = 600;
1.28 - char buffer[size];
1.29 + char buffer[TO_TRANSFER];
1.30 long err;
1.31
1.32 /* Make writers blocking to permit synchronisation. */
1.33 @@ -50,15 +56,15 @@
1.34 return;
1.35 }
1.36
1.37 - for (int loop = 0; loop < 3; loop++)
1.38 + for (int loop = 0; loop < NUMBER_OF_ITERATIONS; loop++)
1.39 {
1.40 for (int region = 0; region < 26; region++)
1.41 {
1.42 - memset(buffer, (int) 'a' + region, size);
1.43 + memset(buffer, (int) 'a' + region, TO_TRANSFER);
1.44
1.45 - offset_t nwritten = client_write(writer, buffer, size);
1.46 + offset_t nwritten = client_write(writer, buffer, TO_TRANSFER);
1.47
1.48 - printf("Written %ld/%ld in #%d of %d/%d to pipe #%d...\n", nwritten, size, region, loop, 2, number);
1.49 + printf("Written %ld/%ld in #%d of %d/%d to pipe #%d...\n", nwritten, TO_TRANSFER, region, loop, 2, number);
1.50 }
1.51
1.52 sleep(1);
1.53 @@ -73,7 +79,7 @@
1.54
1.55 static void read_pipes(file_t *reader1, file_t *reader2)
1.56 {
1.57 - offset_t size = 600, totals[] = {0, 0};
1.58 + offset_t totals[] = {0, 0};
1.59 unsigned int active = 2;
1.60 long err;
1.61 file_t *reader;
1.62 @@ -93,7 +99,7 @@
1.63
1.64 while (1)
1.65 {
1.66 - char buffer[size];
1.67 + char buffer[TO_TRANSFER];
1.68 offset_t nread;
1.69
1.70 /* Wait for notification of content. */
1.71 @@ -118,21 +124,14 @@
1.72 printf("Pipe #%d notified with conditions:%s%s\n", p + 1, reader->notifications & NOTIFY_PEER_CLOSED ? " closed" : "",
1.73 reader->notifications & NOTIFY_CONTENT_AVAILABLE ? " content" : "");
1.74
1.75 - nread = client_read(reader, buffer, size);
1.76 + nread = client_read(reader, buffer, TO_TRANSFER);
1.77
1.78 while (nread)
1.79 {
1.80 totals[p] += nread;
1.81
1.82 - printf("Read %ld/%ld, total %ld, first %c, last %c, from pipe #%d...\n", nread, size, totals[p], *buffer, *(buffer + nread - 1), p + 1);
1.83 -#if 0
1.84 - for (offset_t i = 0; i < nread; i += 60)
1.85 - {
1.86 - fwrite(buffer + i, sizeof(char), nread - i > 60 ? 60 : nread - i, stdout);
1.87 - fputs("\n", stdout);
1.88 - }
1.89 -#endif
1.90 - nread = client_read(reader, buffer, size);
1.91 + printf("Read %ld/%ld, total %ld, first %c, last %c, from pipe #%d...\n", nread, TO_TRANSFER, totals[p], *buffer, *(buffer + nread - 1), p + 1);
1.92 + nread = client_read(reader, buffer, TO_TRANSFER);
1.93 }
1.94
1.95 /* Without any more content, a peer closed event should terminate reading
1.96 @@ -150,7 +149,11 @@
1.97 client_close(reader2);
1.98 client_notifier_close(notifier);
1.99
1.100 - printf("Data shown.\n");
1.101 + for (int p = 0; p < 2; p++)
1.102 + {
1.103 + printf("Data received for pipe #%d: %ld\n", p, totals[p]);
1.104 + printf("Data shown for pipe #%d: %s\n", p, totals[p] == TO_TRANSFER * 26 * NUMBER_OF_ITERATIONS ? "True" : "False");
1.105 + }
1.106 }
1.107
1.108 int main(void)