aboutsummaryrefslogtreecommitdiff
path: root/tools/c-index-test/c-index-test.c
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-09-30 20:39:47 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-09-30 20:39:47 +0000
commit6edc8001f2c2f5a95ed29259d8f2c0b9faa4bc83 (patch)
tree3ded4b4b85a34cf42609d7dea26bbfb3d721b42c /tools/c-index-test/c-index-test.c
parentc69e1cf04323f2e786d40e8a5ba84e77ee1c6827 (diff)
c-index-test: Run inside a separate thread iff we have pthread support, to
ensure we at least get some minimal testing of running in a multithreaded environment (for example, having a reduced stack size). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@115200 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/c-index-test/c-index-test.c')
-rw-r--r--tools/c-index-test/c-index-test.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index acc868e52b..4d4e117620 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -1478,7 +1478,9 @@ static void print_usage(void) {
" scan-function - scan function bodies (non-PCH)\n\n");
}
-int main(int argc, const char **argv) {
+/***/
+
+int cindextest_main(int argc, const char **argv) {
clang_enableStackTraces();
if (argc > 2 && strstr(argv[1], "-code-completion-at=") == argv[1])
return perform_code_completion(argc, argv, 0);
@@ -1538,3 +1540,55 @@ int main(int argc, const char **argv) {
print_usage();
return 1;
}
+
+/***/
+
+/* We intentionally run in a separate thread to ensure we at least minimal
+ * testing of a multithreaded environment (for example, having a reduced stack
+ * size). */
+
+#include "llvm/Config/config.h"
+#ifdef HAVE_PTHREAD_H
+
+#include <pthread.h>
+
+typedef struct thread_info {
+ int argc;
+ const char **argv;
+ int result;
+} thread_info;
+void *thread_runner(void *client_data_v) {
+ thread_info *client_data = client_data_v;
+ client_data->result = cindextest_main(client_data->argc, client_data->argv);
+ return 0;
+}
+
+int main(int argc, const char **argv) {
+ thread_info client_data;
+ pthread_t thread;
+ int res;
+
+ client_data.argc = argc;
+ client_data.argv = argv;
+ res = pthread_create(&thread, 0, thread_runner, &client_data);
+ if (res != 0) {
+ perror("thread creation failed");
+ return 1;
+ }
+
+ res = pthread_join(thread, 0);
+ if (res != 0) {
+ perror("thread join failed");
+ return 1;
+ }
+
+ return client_data.result;
+}
+
+#else
+
+int main(int argc, const char **argv) {
+ return cindextest_main(argc, argv);
+}
+
+#endif