selftests/bpf: test_sockmap, fix data verification
authorPrashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Thu, 31 May 2018 04:42:39 +0000 (13:42 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Sat, 2 Jun 2018 04:13:56 +0000 (06:13 +0200)
When data verification is enabled, some tests fail because verification is done
incorrectly. Following changes fix it.

- Identify the size of data block to be verified
- Reset verification counter when data block size is reached
- Fixed the value printed in case of verfication failure

Fixes: 16962b2404ac ("bpf: sockmap, add selftests")
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/testing/selftests/bpf/test_sockmap.c

index 5cd0550..2bc70e1 100644 (file)
@@ -337,8 +337,15 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
                int fd_flags = O_NONBLOCK;
                struct timeval timeout;
                float total_bytes;
+               int bytes_cnt = 0;
+               int chunk_sz;
                fd_set w;
 
+               if (opt->sendpage)
+                       chunk_sz = iov_length * cnt;
+               else
+                       chunk_sz = iov_length * iov_count;
+
                fcntl(fd, fd_flags);
                total_bytes = (float)iov_count * (float)iov_length * (float)cnt;
                err = clock_gettime(CLOCK_MONOTONIC, &s->start);
@@ -393,9 +400,14 @@ static int msg_loop(int fd, int iov_count, int iov_length, int cnt,
                                                        errno = -EIO;
                                                        fprintf(stderr,
                                                                "detected data corruption @iov[%i]:%i %02x != %02x, %02x ?= %02x\n",
-                                                               i, j, d[j], k - 1, d[j+1], k + 1);
+                                                               i, j, d[j], k - 1, d[j+1], k);
                                                        goto out_errno;
                                                }
+                                               bytes_cnt++;
+                                               if (bytes_cnt == chunk_sz) {
+                                                       k = 0;
+                                                       bytes_cnt = 0;
+                                               }
                                                recv--;
                                        }
                                }