7 #include "external/llvm_compiler_rt/lib/profile/InstrProfiling.h"
8 #include "sw/device/lib/base/crc32.h"
11 #include "sw/device/lib/testing/test_framework/coverage.h"
19 int __llvm_profile_runtime;
24 static char buf[0x8000] = {0};
32 void coverage_send_buffer(
void) {
36 uint64_t buf_size_u64 = __llvm_profile_get_size_for_buffer();
37 if (buf_size_u64 >
sizeof(buf)) {
38 LOG_ERROR(
"ERROR: LLVM profile buffer is too large: %u bytes.",
39 (uint32_t)buf_size_u64);
42 size_t buf_size = (size_t)buf_size_u64;
43 __llvm_profile_write_buffer(buf);
45 uint32_t checksum = crc32(buf, buf_size);
46 LOG_INFO(
"LLVM profile data (length: %u bytes, CRC32: 0x%08x):",
47 (uint32_t)buf_size, checksum);
51 kBytesFirstLine = kBytesPerLine - 1,
53 size_t bytes_this_line =
54 buf_size < kBytesFirstLine ? buf_size : kBytesFirstLine;
55 char *read_ptr = (
char *)buf + buf_size - bytes_this_line;
56 LOG_INFO(
"0x%!x", bytes_this_line, read_ptr);
57 buf_size -= bytes_this_line;
58 while (buf_size > 0) {
59 size_t bytes_this_line =
60 buf_size < kBytesPerLine ? buf_size : kBytesPerLine;
61 read_ptr -= bytes_this_line;
62 LOG_INFO(
"%!x", bytes_this_line, read_ptr);
63 buf_size -= bytes_this_line;