Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Posix / arc4random.cpp
blob5e95cbc3314242ed2c01e0aaaac8f25cb9c027ae
1 // RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
2 //
3 // UNSUPPORTED: target={{.*(linux|solaris).*}}
5 #include <cstdlib>
6 #include <ctime>
7 #include <cstdio>
8 #include <inttypes.h>
10 void 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");
17 void test_seed() {
18 #ifdef __NetBSD__
19 time_t now = ::time(nullptr);
20 arc4random_addrandom((unsigned char *)&now, sizeof(now));
21 #endif
24 void test_arc4random() {
25 printf("test_arc4random\n");
26 auto i = arc4random();
27 print_buf((unsigned char *)&i, sizeof(i));
30 void test_arc4random_uniform() {
31 printf("test_arc4random_uniform\n");
32 auto i = arc4random_uniform(1024);
33 print_buf((unsigned char *)&i, sizeof(i));
36 void test_arc4random_buf10() {
37 printf("test_arc4random_buf10\n");
38 char buf[10];
39 #ifdef __NetBSD__
40 arc4random_stir();
41 #endif
42 arc4random_buf(buf, sizeof(buf));
43 print_buf((unsigned char *)buf, sizeof(buf));
46 void test_arc4random_buf256() {
47 printf("test_arc4random_buf256\n");
48 char buf[256];
49 #ifdef __NetBSD__
50 arc4random_stir();
51 #endif
52 arc4random_buf(buf, sizeof(buf));
53 print_buf((unsigned char *)buf, sizeof(buf));
56 int 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_arc4random
64 // CHECK: buf '{{.*}}'
65 // CHECK: test_arc4random_uniform
66 // CHECK: buf '{{.*}}'
67 // CHECK: test_arc4random_buf10
68 // CHECK: buf '{{.*}}'
69 // CHECK: test_arc4random_buf256
70 // CHECK: buf '{{.*}}'