instrprof-bufferio.c revision 1.1.1.1
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 13typedef struct ProfBufferIO ProfBufferIO; 14ProfBufferIO *llvmCreateBufferIOInternal(FILE *File, uint32_t DefaultBufferSz); 15void llvmDeleteBufferIO(ProfBufferIO *BufferIO); 16 17int llvmBufferIOWrite(ProfBufferIO *BufferIO, const char *Data, uint32_t Size); 18int llvmBufferIOFlush(ProfBufferIO *BufferIO); 19 20int __llvm_profile_runtime = 0; 21 22const char *SmallData = "ABC\n"; 23const char *MediumData = 24 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\n"; 25char LargeData[10 * 1024]; 26int 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 = llvmCreateBufferIOInternal(File[J], IOBufferSize[J]); 46 47 llvmBufferIOWrite(BufferIO, "Short Strings:\n", strlen("Short Strings:\n")); 48 for (I = 0; I < 1024; I++) { 49 llvmBufferIOWrite(BufferIO, SmallData, strlen(SmallData)); 50 } 51 llvmBufferIOWrite(BufferIO, "Long Strings:\n", strlen("Long Strings:\n")); 52 for (I = 0; I < 1024; I++) { 53 llvmBufferIOWrite(BufferIO, MediumData, strlen(MediumData)); 54 } 55 llvmBufferIOWrite(BufferIO, "Extra Long Strings:\n", 56 strlen("Extra Long Strings:\n")); 57 for (I = 0; I < 10; I++) { 58 llvmBufferIOWrite(BufferIO, LargeData, strlen(LargeData)); 59 } 60 llvmBufferIOWrite(BufferIO, "Mixed Strings:\n", strlen("Mixed Strings:\n")); 61 for (I = 0; I < 1024; I++) { 62 llvmBufferIOWrite(BufferIO, MediumData, strlen(MediumData)); 63 llvmBufferIOWrite(BufferIO, SmallData, strlen(SmallData)); 64 } 65 llvmBufferIOWrite(BufferIO, "Endings:\n", strlen("Endings:\n")); 66 llvmBufferIOWrite(BufferIO, "END\n", strlen("END\n")); 67 llvmBufferIOWrite(BufferIO, "ENDEND\n", strlen("ENDEND\n")); 68 llvmBufferIOWrite(BufferIO, "ENDENDEND\n", strlen("ENDENDEND\n")); 69 llvmBufferIOWrite(BufferIO, "ENDENDENDEND\n", strlen("ENDENDENDEND\n")); 70 llvmBufferIOFlush(BufferIO); 71 72 llvmDeleteBufferIO(BufferIO); 73 74 fclose(File[J]); 75 } 76 return 0; 77} 78 79// CHECK-LABEL: Short Strings: 80// CHECK: ABC 81// CHECK-NEXT: 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-LABEL: Long Strings: 95// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 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-LABEL: Mixed Strings: 108// CHECK: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 109// CHECK-NEXT: ABC 110// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 111// CHECK-NEXT: ABC 112// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 113// CHECK-NEXT: ABC 114// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 115// CHECK-NEXT: ABC 116// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 117// CHECK-NEXT: ABC 118// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 119// CHECK-NEXT: ABC 120// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 121// CHECK-NEXT: ABC 122// CHECK-NEXT: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 123// CHECK-NEXT: ABC 124// CHECK-LABEL: Endings: 125// CHECK: END 126// CHECK-NEXT: ENDEND 127// CHECK-NEXT: ENDENDEND 128// CHECK-NEXT: ENDENDENDEND 129