akaros/tests/trandom.c
<<
>>
Prefs
   1
   2#define _LARGEFILE64_SOURCE /* needed to use lseek64 */
   3
   4#include <stdio.h> 
   5#include <sys/types.h>
   6#include <sys/stat.h>
   7#include <fcntl.h>
   8#include <parlib/arch/arch.h>
   9#include <unistd.h>
  10#include <errno.h>
  11#include <dirent.h>
  12#include <stdlib.h>
  13#include <string.h>
  14#include <ros/syscall.h>
  15#include <sys/time.h>
  16
  17int main(int argc, char *argv[]) 
  18{ 
  19        int fd;
  20        int i;
  21        static uint32_t data[1048576];
  22        struct timeval start_tv = {0};
  23        struct timeval end_tv = {0};
  24        int usecs;
  25        int amt = 4096;
  26
  27        if (argc > 1)
  28                amt = strtol(argv[1], 0, 0);
  29        if (amt > sizeof(data))
  30                printf("max amt to read is %d\n", sizeof(data));
  31        if (amt > sizeof(data))
  32                amt = sizeof(data);
  33        fd = open("#cons/random", 0);
  34        if (fd < 0){
  35                perror("random");
  36                exit(1);
  37        }
  38        if (gettimeofday(&start_tv, 0))
  39                perror("Start time error...");
  40        amt = read(fd, data, amt);
  41        if (amt < 0){
  42                perror("read random");
  43                exit(1);
  44        }
  45        if (gettimeofday(&end_tv, 0))
  46                perror("End time error...");
  47        usecs = (end_tv.tv_sec - start_tv.tv_sec) * 1000000
  48                + (end_tv.tv_usec - start_tv.tv_usec);
  49        printf("Read %d bytes of random in %d microseconds\n", amt, usecs);
  50        for(i = 0; i < 4; i++)
  51                printf("%08x ", data[i]);
  52        printf("\n");
  53        return 0;
  54}
  55