1 // RUN: %clang_profgen -O3 -o %t %s 2 // RUN: %run %t %t.out.1 %t.out.2 %t.out.3 %t.out.4 3 // RUN: cat %t.out.1 | FileCheck %s 4 // RUN: diff %t.out.1 %t.out.2 5 // RUN: diff %t.out.2 %t.out.3 6 // RUN: diff %t.out.3 %t.out.4 7 8 #include <stdint.h> 9 #include <stdio.h> 10 #include <stdlib.h> 11 #include <string.h> 12 13 typedef struct ProfBufferIO ProfBufferIO; 14 ProfBufferIO *lprofCreateBufferIOInternal(void *File, uint32_t BufferSz); 15 void lprofDeleteBufferIO(ProfBufferIO *BufferIO); 16 17 int lprofBufferIOWrite(ProfBufferIO *BufferIO, const char *Data, uint32_t Size); 18 int lprofBufferIOFlush(ProfBufferIO *BufferIO); 19 20 int __llvm_profile_runtime = 0; 21 22 const char *SmallData = "ABC\n"; 23 const char *MediumData = 24 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\n"; 25 char LargeData[10 * 1024]; 26 int main(int argc, const char *argv[]) { 27 ProfBufferIO *BufferIO; 28 FILE *File[4]; 29 uint32_t IOBufferSize[4] = {8, 128, 8 * 1024, 11 * 1024}; 30 int I, J; 31 if (argc < 5) 32 return 1; 33 34 for (I = 0; I < 10 * 1024 - 2; I++) 35 LargeData[I] = 'A'; 36 37 LargeData[I++] = '\n'; 38 LargeData[I++] = '\0'; 39 40 for (J = 0; J < 4; J++) { 41 File[J] = fopen(argv[1 + J], "w"); 42 if (!File[J]) 43 return 1; 44 45 BufferIO = lprofCreateBufferIOInternal(File[J], IOBufferSize[J]); 46 47 lprofBufferIOWrite(BufferIO, "Short Strings:\n", 48 strlen("Short Strings:\n")); 49 for (I = 0; I < 1024; I++) { 50 lprofBufferIOWrite(BufferIO, SmallData, strlen(SmallData)); 51 } 52 lprofBufferIOWrite(BufferIO, "Long Strings:\n", strlen("Long Strings:\n")); 53 for (I = 0; I < 1024; I++) { 54 lprofBufferIOWrite(BufferIO, MediumData, strlen(MediumData)); 55 } 56 lprofBufferIOWrite(BufferIO, "Extra Long Strings:\n", 57 strlen("Extra Long Strings:\n")); 58 for (I = 0; I < 10; I++) { 59 lprofBufferIOWrite(BufferIO, LargeData, strlen(LargeData)); 60 } 61 lprofBufferIOWrite(BufferIO, "Mixed Strings:\n", strlen("Mixed Strings:\n")); 62 for (I = 0; I < 1024; I++) { 63 lprofBufferIOWrite(BufferIO, MediumData, strlen(MediumData)); 64 lprofBufferIOWrite(BufferIO, SmallData, strlen(SmallData)); 65 } 66 lprofBufferIOWrite(BufferIO, "Endings:\n", strlen("Endings:\n")); 67 lprofBufferIOWrite(BufferIO, "END\n", strlen("END\n")); 68 lprofBufferIOWrite(BufferIO, "ENDEND\n", strlen("ENDEND\n")); 69 lprofBufferIOWrite(BufferIO, "ENDENDEND\n", strlen("ENDENDEND\n")); 70 lprofBufferIOWrite(BufferIO, "ENDENDENDEND\n", strlen("ENDENDENDEND\n")); 71 lprofBufferIOFlush(BufferIO); 72 73 lprofDeleteBufferIO(BufferIO); 74 75 fclose(File[J]); 76 } 77 return 0; 78 } 79 80 // CHECK-LABEL: Short Strings: 81 // CHECK: ABC 82 // CHECK-NEXT: ABC 83 // CHECK-NEXT: ABC 84 // CHECK-NEXT: ABC 85 // CHECK-NEXT: ABC 86 // CHECK-NEXT: ABC 87 // CHECK-NEXT: ABC 88 // CHECK-NEXT: ABC 89 // CHECK-NEXT: ABC 90 // CHECK-NEXT: ABC 91 // CHECK-NEXT: ABC 92 // CHECK-NEXT: ABC 93 // CHECK-NEXT: ABC 94 // CHECK-NEXT: ABC 95 // CHECK-LABEL: Long Strings: 96 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 97 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 98 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 99 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 100 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 101 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 102 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 103 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 104 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 105 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 106 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 107 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 108 // CHECK-LABEL: Mixed Strings: 109 // CHECK: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 110 // CHECK-NEXT: ABC 111 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 112 // CHECK-NEXT: ABC 113 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 114 // CHECK-NEXT: ABC 115 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 116 // CHECK-NEXT: ABC 117 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 118 // CHECK-NEXT: ABC 119 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 120 // CHECK-NEXT: ABC 121 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 122 // CHECK-NEXT: ABC 123 // CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 124 // CHECK-NEXT: ABC 125 // CHECK-LABEL: Endings: 126 // CHECK: END 127 // CHECK-NEXT: ENDEND 128 // CHECK-NEXT: ENDENDEND 129 // CHECK-NEXT: ENDENDENDEND 130