| 989 | } |
| 990 | |
| 991 | static void dump_coverage(void) |
| 992 | { |
| 993 | uint64_t start; |
| 994 | uint8_t *coverage; |
| 995 | unsigned long phys_offset; |
| 996 | #define phys_to_virt(x) ((void *)(unsigned long)(x) + phys_offset) |
| 997 | |
| 998 | if (!cbmem_drv_get_cbmem_entry(CBMEM_ID_COVERAGE, &coverage, NULL, &start)) |
| 999 | die("No coverage information found\n"); |
| 1000 | |
| 1001 | /* Map coverage area */ |
| 1002 | phys_offset = (unsigned long)coverage - (unsigned long)start; |
| 1003 | |
| 1004 | printf("Dumping coverage data...\n"); |
| 1005 | |
| 1006 | struct file *file = (struct file *)coverage; |
| 1007 | while (file && file->magic == COVERAGE_MAGIC) { |
| 1008 | FILE *f; |
| 1009 | char *filename; |
| 1010 | |
| 1011 | debug(" -> %s\n", (char *)phys_to_virt(file->filename)); |
| 1012 | filename = strdup((char *)phys_to_virt(file->filename)); |
| 1013 | if (mkpath(filename, 0755) == -1) { |
| 1014 | perror("Directory for coverage data could " |
| 1015 | "not be created"); |
| 1016 | exit(1); |
| 1017 | } |
| 1018 | f = fopen(filename, "wb"); |
| 1019 | if (!f) { |
| 1020 | printf("Could not open %s: %s\n", |
| 1021 | filename, strerror(errno)); |
| 1022 | exit(1); |
| 1023 | } |
| 1024 | if (fwrite((void *)phys_to_virt(file->data), |
| 1025 | file->len, 1, f) != 1) { |
| 1026 | printf("Could not write to %s: %s\n", |
| 1027 | filename, strerror(errno)); |
| 1028 | exit(1); |
| 1029 | } |
| 1030 | fclose(f); |
| 1031 | free(filename); |
| 1032 | |
| 1033 | if (file->next) |
| 1034 | file = (struct file *)phys_to_virt(file->next); |
| 1035 | else |
| 1036 | file = NULL; |
| 1037 | } |
| 1038 | free(coverage); |
| 1039 | } |
| 1040 | |
| 1041 | static void print_version(void) |
| 1042 | { |
no test coverage detected