[igt-dev] [PATCH i-g-t 1/1] runner: Increase buffer size for reading outputs

Petri Latvala petri.latvala at intel.com
Fri Sep 14 11:21:39 UTC 2018


The law of chosen magic numbers: The number selected is wrong.

Chose another magic number for the size of the buffer used to read
test outputs and kernel log records. It's now 2048, up from 256. Also
added a warning print if that's still not enough for kernel logs.

The lesson to learn here is that the /dev/kmsg interface does not give
you a truncated log record as initially thought, but reports an
undocumented EINVAL instead. Subsequent reads give the next record, so
the failsafe added will make sure any future EINVALs will only drop
the record that is too long instead of everything from that point
onwards.

Signed-off-by: Petri Latvala <petri.latvala at intel.com>
---
 runner/executor.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/runner/executor.c b/runner/executor.c
index 36117af6..701ca80d 100644
--- a/runner/executor.c
+++ b/runner/executor.c
@@ -242,7 +242,7 @@ static void dump_dmesg(int kmsgfd, int outfd)
 	unsigned flags;
 	unsigned long long seq, cmpseq, usec;
 	char cont;
-	char buf[256];
+	char buf[2048];
 	ssize_t r;
 
 	if (comparefd < 0)
@@ -323,7 +323,7 @@ static int monitor_output(pid_t child,
 			   struct settings *settings)
 {
 	fd_set set;
-	char buf[256];
+	char buf[2048];
 	char *outbuf = NULL;
 	size_t outbufsize = 0;
 	char current_subtest[256] = {};
@@ -539,11 +539,13 @@ static int monitor_output(pid_t child,
 		if (kmsgfd >= 0 && FD_ISSET(kmsgfd, &set)) {
 			s = read(kmsgfd, buf, sizeof(buf));
 			if (s < 0) {
-				if (errno != EPIPE) {
+				if (errno != EPIPE && errno != EINVAL) {
 					fprintf(stderr, "Error reading from kmsg, stopping monitoring: %s\n",
 						strerror(errno));
 					close(kmsgfd);
 					kmsgfd = -1;
+				} else if (errno == EINVAL) {
+					fprintf(stderr, "Warning: Buffer too small for kernel log record, record lost.\n");
 				}
 			} else {
 				write(outputs[_F_DMESG], buf, s);
-- 
2.18.0



More information about the igt-dev mailing list