Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / FreeBSD / md5.cpp
blob13325880a023a14e993457c57e9e9126b8792cfe
1 // RUN: %clangxx -O0 -g %s -o %t -lmd && %run %t 2>&1 | FileCheck %s
3 #include <sys/param.h>
5 #include <assert.h>
6 #include <md5.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
11 void test1() {
12 MD5_CTX ctx;
13 uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
14 uint8_t digest[MD5_DIGEST_LENGTH];
15 size_t entropysz = sizeof(entropy);
16 size_t digestsz = sizeof(digest);
18 MD5Init(&ctx);
19 MD5Update(&ctx, entropy, entropysz);
20 MD5Final(digest, &ctx);
22 printf("test1: '");
23 for (size_t i = 0; i < digestsz; i++)
24 printf("%02x", digest[i]);
25 printf("'\n");
28 void test2() {
29 MD5_CTX ctx;
30 uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
31 char digest[MD5_DIGEST_STRING_LENGTH];
32 size_t entropysz = sizeof(entropy);
34 MD5Init(&ctx);
35 MD5Update(&ctx, entropy, entropysz);
36 char *p = MD5End(&ctx, digest);
37 assert(p);
39 printf("test2: '%s'\n", digest);
42 void test3() {
43 MD5_CTX ctx;
44 uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
45 size_t entropysz = sizeof(entropy);
47 MD5Init(&ctx);
48 MD5Update(&ctx, entropy, entropysz);
49 char *p = MD5End(&ctx, NULL);
50 assert(strlen(p) == MD5_DIGEST_STRING_LENGTH - 1);
52 printf("test3: '%s'\n", p);
54 free(p);
57 void test4() {
58 char digest[MD5_DIGEST_STRING_LENGTH];
60 char *p = MD5File("/etc/fstab", digest);
61 assert(p == digest);
63 printf("test4: '%s'\n", p);
66 void test5() {
67 char *p = MD5File("/etc/fstab", NULL);
68 assert(strlen(p) == MD5_DIGEST_STRING_LENGTH - 1);
70 printf("test5: '%s'\n", p);
72 free(p);
75 void test6() {
76 uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
77 char digest[MD5_DIGEST_STRING_LENGTH];
78 size_t entropysz = sizeof(entropy);
80 char *p = MD5Data(entropy, entropysz, digest);
81 assert(p == digest);
83 printf("test6: '%s'\n", p);
86 void test7() {
87 uint8_t entropy[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66};
88 size_t entropysz = sizeof(entropy);
90 char *p = MD5Data(entropy, entropysz, NULL);
91 assert(strlen(p) == MD5_DIGEST_STRING_LENGTH - 1);
93 printf("test7: '%s'\n", p);
95 free(p);
98 int main(void) {
99 printf("MD5\n");
101 test1();
102 test2();
103 test3();
104 test4();
105 test5();
106 test6();
107 test7();
109 // CHECK: MD5
110 // CHECK: test1: '86e65b1ef4a830af347ac05ab4f0e999'
111 // CHECK: test2: '86e65b1ef4a830af347ac05ab4f0e999'
112 // CHECK: test3: '86e65b1ef4a830af347ac05ab4f0e999'
113 // CHECK: test4: '{{.*}}'
114 // CHECK: test5: '{{.*}}'
115 // CHECK: test6: '86e65b1ef4a830af347ac05ab4f0e999'
116 // CHECK: test7: '86e65b1ef4a830af347ac05ab4f0e999'
118 return 0;