[cfe-commits] r115200 - /cfe/trunk/tools/c-index-test/c-index-test.c

Daniel Dunbar daniel at zuster.org
Thu Sep 30 13:39:47 PDT 2010


Author: ddunbar
Date: Thu Sep 30 15:39:47 2010
New Revision: 115200

URL: http://llvm.org/viewvc/llvm-project?rev=115200&view=rev
Log:
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).

Modified:
    cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=115200&r1=115199&r2=115200&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Sep 30 15:39:47 2010
@@ -1478,7 +1478,9 @@
     "   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 @@
   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





More information about the cfe-commits mailing list