Added small test program that opens and reads a few bytes from

/dev/urandom. It verifies that Haiku's dev/urandom is performance-wise
totally unusable -- it takes several seconds.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23904 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2008-02-07 02:22:48 +00:00
parent 7025a0386d
commit f38b49f162
3 changed files with 42 additions and 0 deletions

View File

@ -1,3 +1,4 @@
SubDir HAIKU_TOP src tests add-ons kernel drivers ;
SubInclude HAIKU_TOP src tests add-ons kernel drivers random ;
SubInclude HAIKU_TOP src tests add-ons kernel drivers tty ;

View File

@ -0,0 +1,3 @@
SubDir HAIKU_TOP src tests add-ons kernel drivers random ;
SimpleTest random_test : random_test.cpp ;

View File

@ -0,0 +1,38 @@
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static const char* kRandomDevice = "/dev/urandom";
int
main()
{
int fd = open(kRandomDevice, O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Error: Failed to open \"%s\": %s", kRandomDevice,
strerror(errno));
exit(1);
}
uint8_t buffer[16];
ssize_t bytesRead = read(fd, buffer, sizeof(buffer));
if (bytesRead < 0) {
fprintf(stderr, "Error: Failed to read from random device: %s",
strerror(errno));
exit(1);
}
printf("Read %d bytes from random device: ", (int)bytesRead);
for (int i = 0; i < bytesRead; i++)
printf("%02x", buffer[i]);
printf("\n");
return 0;
}