/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/c-arcmt-test/c-arcmt-test.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* c-arcmt-test.c */ |
2 | | |
3 | | #include "clang-c/Index.h" |
4 | | #include <stdlib.h> |
5 | | #include <stdio.h> |
6 | | #include <string.h> |
7 | | #if defined(_WIN32) |
8 | | #include <io.h> |
9 | | #include <fcntl.h> |
10 | | #endif |
11 | | |
12 | 24 | static int print_remappings(const char *path) { |
13 | 24 | CXRemapping remap; |
14 | 24 | unsigned i, N; |
15 | 24 | CXString origFname; |
16 | 24 | CXString transFname; |
17 | | |
18 | 24 | remap = clang_getRemappings(path); |
19 | 24 | if (!remap) |
20 | 0 | return 1; |
21 | | |
22 | 24 | N = clang_remap_getNumFiles(remap); |
23 | 54 | for (i = 0; i != N; ++i30 ) { |
24 | 30 | clang_remap_getFilenames(remap, i, &origFname, &transFname); |
25 | | |
26 | 30 | fprintf(stdout, "%s\n", clang_getCString(origFname)); |
27 | 30 | fprintf(stdout, "%s\n", clang_getCString(transFname)); |
28 | | |
29 | 30 | clang_disposeString(origFname); |
30 | 30 | clang_disposeString(transFname); |
31 | 30 | } |
32 | | |
33 | 24 | clang_remap_dispose(remap); |
34 | 24 | return 0; |
35 | 24 | } |
36 | | |
37 | 6 | static int print_remappings_filelist(const char **files, unsigned numFiles) { |
38 | 6 | CXRemapping remap; |
39 | 6 | unsigned i, N; |
40 | 6 | CXString origFname; |
41 | 6 | CXString transFname; |
42 | | |
43 | 6 | remap = clang_getRemappingsFromFileList(files, numFiles); |
44 | 6 | if (!remap) |
45 | 0 | return 1; |
46 | | |
47 | 6 | N = clang_remap_getNumFiles(remap); |
48 | 15 | for (i = 0; i != N; ++i9 ) { |
49 | 9 | clang_remap_getFilenames(remap, i, &origFname, &transFname); |
50 | | |
51 | 9 | fprintf(stdout, "%s\n", clang_getCString(origFname)); |
52 | 9 | fprintf(stdout, "%s\n", clang_getCString(transFname)); |
53 | | |
54 | 9 | clang_disposeString(origFname); |
55 | 9 | clang_disposeString(transFname); |
56 | 9 | } |
57 | | |
58 | 6 | clang_remap_dispose(remap); |
59 | 6 | return 0; |
60 | 6 | } |
61 | | |
62 | | /******************************************************************************/ |
63 | | /* Command line processing. */ |
64 | | /******************************************************************************/ |
65 | | |
66 | 0 | static void print_usage(void) { |
67 | 0 | fprintf(stderr, |
68 | 0 | "usage: c-arcmt-test -mt-migrate-directory <path>\n" |
69 | 0 | " c-arcmt-test <remap-file-path1> <remap-file-path2> ...\n\n\n"); |
70 | 0 | } |
71 | | |
72 | | /***/ |
73 | | |
74 | 30 | int carcmttest_main(int argc, const char **argv) { |
75 | 30 | clang_enableStackTraces(); |
76 | 30 | if (argc == 3 && strncmp(argv[1], "-mt-migrate-directory", 21) == 025 ) |
77 | 24 | return print_remappings(argv[2]); |
78 | | |
79 | 6 | if (argc > 1) |
80 | 6 | return print_remappings_filelist(argv+1, argc-1); |
81 | | |
82 | 0 | print_usage(); |
83 | 0 | return 1; |
84 | 6 | } |
85 | | |
86 | | /***/ |
87 | | |
88 | | /* We intentionally run in a separate thread to ensure we at least minimal |
89 | | * testing of a multithreaded environment (for example, having a reduced stack |
90 | | * size). */ |
91 | | |
92 | | typedef struct thread_info { |
93 | | int argc; |
94 | | const char **argv; |
95 | | int result; |
96 | | } thread_info; |
97 | 1.08k | void thread_runner(void *client_data_v) { |
98 | 1.08k | thread_info *client_data = client_data_v; |
99 | 1.08k | client_data->result = carcmttest_main(client_data->argc, client_data->argv); |
100 | 1.08k | } |
101 | | |
102 | 30 | static void flush_atexit(void) { |
103 | | /* stdout, and surprisingly even stderr, are not always flushed on process |
104 | | * and thread exit, particularly when the system is under heavy load. */ |
105 | 30 | fflush(stdout); |
106 | 30 | fflush(stderr); |
107 | 30 | } |
108 | | |
109 | 30 | int main(int argc, const char **argv) { |
110 | 30 | thread_info client_data; |
111 | | |
112 | 30 | atexit(flush_atexit); |
113 | | |
114 | | #if defined(_WIN32) |
115 | | if (getenv("LIBCLANG_LOGGING") == NULL) |
116 | | putenv("LIBCLANG_LOGGING=1"); |
117 | | _setmode( _fileno(stdout), _O_BINARY ); |
118 | | #else |
119 | 30 | setenv("LIBCLANG_LOGGING", "1", /*overwrite=*/0); |
120 | 30 | #endif |
121 | | |
122 | 30 | if (getenv("CINDEXTEST_NOTHREADS")) |
123 | 0 | return carcmttest_main(argc, argv); |
124 | | |
125 | 30 | client_data.argc = argc; |
126 | 30 | client_data.argv = argv; |
127 | 30 | clang_executeOnThread(thread_runner, &client_data, 0); |
128 | 30 | return client_data.result; |
129 | 30 | } |