brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 5e95cbc Raw
72 lines · cpp
1// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s2//3// UNSUPPORTED: target={{.*(linux|solaris).*}}4 5#include <cstdlib>6#include <ctime>7#include <cstdio>8#include <inttypes.h>9 10void print_buf(unsigned char *buf, size_t buflen) {11  printf("buf '");12  for (auto i = 0; i < buflen; i ++)13    printf("%" PRIx8, buf[i]);14  printf("'\n");15}16 17void test_seed() {18#ifdef __NetBSD__19  time_t now = ::time(nullptr);20  arc4random_addrandom((unsigned char *)&now, sizeof(now));21#endif22}23 24void test_arc4random() {25  printf("test_arc4random\n");26  auto i = arc4random();27  print_buf((unsigned char *)&i, sizeof(i));28}29 30void test_arc4random_uniform() {31  printf("test_arc4random_uniform\n");32  auto i = arc4random_uniform(1024);33  print_buf((unsigned char *)&i, sizeof(i));34}35 36void test_arc4random_buf10() {37  printf("test_arc4random_buf10\n");38  char buf[10];39#ifdef __NetBSD__40  arc4random_stir();41#endif42  arc4random_buf(buf, sizeof(buf));43  print_buf((unsigned char *)buf, sizeof(buf));44}45 46void test_arc4random_buf256() {47  printf("test_arc4random_buf256\n");48  char buf[256];49#ifdef __NetBSD__50  arc4random_stir();51#endif52  arc4random_buf(buf, sizeof(buf));53  print_buf((unsigned char *)buf, sizeof(buf));54}55 56int main(void) {57  test_seed();58  test_arc4random();59  test_arc4random_uniform();60  test_arc4random_buf10();61  test_arc4random_buf256();62  return 0;63  // CHECK: test_arc4random64  // CHECK: buf '{{.*}}'65  // CHECK: test_arc4random_uniform66  // CHECK: buf '{{.*}}'67  // CHECK: test_arc4random_buf1068  // CHECK: buf '{{.*}}'69  // CHECK: test_arc4random_buf25670  // CHECK: buf '{{.*}}'71}72