Commit 02a2f000 authored by Taeung Song's avatar Taeung Song Committed by Daniel Borkmann

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: default avatarDavid Laight <David.Laight@ACULAB.COM>
Signed-off-by: default avatarTaeung Song <treeze.taeung@gmail.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 492b7e89
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
#include <sched.h> #include <sched.h>
#include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <sys/types.h> #include <sys/types.h>
#include <asm/unistd.h> #include <asm/unistd.h>
...@@ -44,8 +45,13 @@ static void test_task_rename(int cpu) ...@@ -44,8 +45,13 @@ static void test_task_rename(int cpu)
exit(1); exit(1);
} }
start_time = time_get_ns(); start_time = time_get_ns();
for (i = 0; i < MAX_CNT; i++) for (i = 0; i < MAX_CNT; i++) {
write(fd, buf, sizeof(buf)); if (write(fd, buf, sizeof(buf)) < 0) {
printf("task rename failed: %s\n", strerror(errno));
close(fd);
return;
}
}
printf("task_rename:%d: %lld events per sec\n", printf("task_rename:%d: %lld events per sec\n",
cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
close(fd); close(fd);
...@@ -63,8 +69,13 @@ static void test_urandom_read(int cpu) ...@@ -63,8 +69,13 @@ static void test_urandom_read(int cpu)
exit(1); exit(1);
} }
start_time = time_get_ns(); start_time = time_get_ns();
for (i = 0; i < MAX_CNT; i++) for (i = 0; i < MAX_CNT; i++) {
read(fd, buf, sizeof(buf)); if (read(fd, buf, sizeof(buf)) < 0) {
printf("failed to read from /dev/urandom: %s\n", strerror(errno));
close(fd);
return;
}
}
printf("urandom_read:%d: %lld events per sec\n", printf("urandom_read:%d: %lld events per sec\n",
cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time)); cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
close(fd); close(fd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment