Skip to content

Commit

Permalink
samples/bpf: Check the error of write() and read()
Browse files Browse the repository at this point in the history
test_task_rename() and test_urandom_read()
can be failed during write() and read(),
So check the result of them.

Reviewed-by: David Laight <[email protected]>
Signed-off-by: Taeung Song <[email protected]>
Acked-by: David S. Miller <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
  • Loading branch information
Taeung authored and borkmann committed Jul 5, 2018
1 parent 492b7e8 commit 02a2f00
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions samples/bpf/test_overhead_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
#define _GNU_SOURCE
#include <sched.h>
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <asm/unistd.h>
Expand Down Expand Up @@ -44,8 +45,13 @@ static void test_task_rename(int cpu)
exit(1);
}
start_time = time_get_ns();
for (i = 0; i < MAX_CNT; i++)
write(fd, buf, sizeof(buf));
for (i = 0; i < MAX_CNT; i++) {
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",
cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
close(fd);
Expand All @@ -63,8 +69,13 @@ static void test_urandom_read(int cpu)
exit(1);
}
start_time = time_get_ns();
for (i = 0; i < MAX_CNT; i++)
read(fd, buf, sizeof(buf));
for (i = 0; i < MAX_CNT; i++) {
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",
cpu, MAX_CNT * 1000000000ll / (time_get_ns() - start_time));
close(fd);
Expand Down

0 comments on commit 02a2f00

Please sign in to comment.