diff options
| author | Taeung Song <treeze.taeung@gmail.com> | 2018-07-04 09:36:38 -0400 |
|---|---|---|
| committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-07-05 03:58:52 -0400 |
| commit | 02a2f000a3629274bfad60bfc4de9edec49e63e7 (patch) | |
| tree | c19b1e7d24a41fe68c63fb4bb3f16c299bcde64d /samples | |
| parent | 492b7e894587c151be681f86d4d1d086375f7b45 (diff) | |
samples/bpf: Check the error of write() and read()
test_task_rename() and test_urandom_read()
can be failed during write() and read(),
So check the result of them.
Reviewed-by: David Laight <David.Laight@ACULAB.COM>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'samples')
| -rw-r--r-- | samples/bpf/test_overhead_user.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/samples/bpf/test_overhead_user.c b/samples/bpf/test_overhead_user.c index 6caf47afa635..9d6dcaa9db92 100644 --- a/samples/bpf/test_overhead_user.c +++ b/samples/bpf/test_overhead_user.c | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | */ | 6 | */ |
| 7 | #define _GNU_SOURCE | 7 | #define _GNU_SOURCE |
| 8 | #include <sched.h> | 8 | #include <sched.h> |
| 9 | #include <errno.h> | ||
| 9 | #include <stdio.h> | 10 | #include <stdio.h> |
| 10 | #include <sys/types.h> | 11 | #include <sys/types.h> |
| 11 | #include <asm/unistd.h> | 12 | #include <asm/unistd.h> |
| @@ -44,8 +45,13 @@ static void test_task_rename(int cpu) | |||
| 44 | exit(1); | 45 | exit(1); |
| 45 | } | 46 | } |
| 46 | start_time = time_get_ns(); | 47 | start_time = time_get_ns(); |
| 47 | for (i = 0; i < MAX_CNT; i++) | 48 | for (i = 0; i < MAX_CNT; i++) { |
| 48 | write(fd, buf, sizeof(buf)); | 49 | if (write(fd, buf, sizeof(buf)) < 0) { |
| 50 | printf("task rename failed: %s\n", strerror(errno)); | ||
| 51 | close(fd); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | } | ||
| 49 | printf("task_rename:%d: %lld events per sec\n", | 55 | printf("task_rename:%d: %lld events per sec\n", |
| 50 | cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); | 56 | cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); |
| 51 | close(fd); | 57 | close(fd); |
| @@ -63,8 +69,13 @@ static void test_urandom_read(int cpu) | |||
| 63 | exit(1); | 69 | exit(1); |
| 64 | } | 70 | } |
| 65 | start_time = time_get_ns(); | 71 | start_time = time_get_ns(); |
| 66 | for (i = 0; i < MAX_CNT; i++) | 72 | for (i = 0; i < MAX_CNT; i++) { |
| 67 | read(fd, buf, sizeof(buf)); | 73 | if (read(fd, buf, sizeof(buf)) < 0) { |
| 74 | printf("failed to read from /dev/urandom: %s\n", strerror(errno)); | ||
| 75 | close(fd); | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | } | ||
| 68 | printf("urandom_read:%d: %lld events per sec\n", | 79 | printf("urandom_read:%d: %lld events per sec\n", |
| 69 | cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); | 80 | cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); |
| 70 | close(fd); | 81 | close(fd); |
