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:
parent
7025a0386d
commit
f38b49f162
@ -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 ;
|
||||
|
3
src/tests/add-ons/kernel/drivers/random/Jamfile
Normal file
3
src/tests/add-ons/kernel/drivers/random/Jamfile
Normal file
@ -0,0 +1,3 @@
|
||||
SubDir HAIKU_TOP src tests add-ons kernel drivers random ;
|
||||
|
||||
SimpleTest random_test : random_test.cpp ;
|
38
src/tests/add-ons/kernel/drivers/random/random_test.cpp
Normal file
38
src/tests/add-ons/kernel/drivers/random/random_test.cpp
Normal 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user