test/hotspot/gtest/gtestMain.cpp
author mikael
Mon, 09 Apr 2018 10:19:33 -0700
changeset 49552 05883543ee2a
parent 48804 8f451978683c
child 54851 f67269c129f9
permissions -rw-r--r--
8201263: Trailing backslash in VS120COMNTOOLS leads to ugly error message when running tests Reviewed-by: erikj
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     1
/*
47659
a8e9aff89f7b 8189608: Remove duplicated jni.h
ihse
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     4
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     8
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    14
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    18
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    21
 * questions.
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    22
 *
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    23
 */
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    24
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    25
#include <stdio.h>
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    26
#include <string.h>
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    27
#include <stdlib.h>
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    28
#ifdef __APPLE__
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    29
#  include <dlfcn.h>
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    30
#endif
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    31
46684
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    32
#ifdef _WIN32
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    33
#include <windows.h>
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    34
#else
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    35
#include <pthread.h>
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    36
#endif
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    37
47659
a8e9aff89f7b 8189608: Remove duplicated jni.h
ihse
parents: 47216
diff changeset
    38
#include "jni.h"
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    39
#include "unittest.hpp"
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    40
46684
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    41
// Default value for -new-thread option: true on AIX because we run into
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    42
// problems when attempting to initialize the JVM on the primordial thread.
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    43
#ifdef _AIX
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    44
const static bool DEFAULT_SPAWN_IN_NEW_THREAD = true;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    45
#else
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    46
const static bool DEFAULT_SPAWN_IN_NEW_THREAD = false;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
    47
#endif
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    48
41672
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    49
static bool is_prefix(const char* prefix, const char* str) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    50
  return strncmp(str, prefix, strlen(prefix)) == 0;
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    51
}
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    52
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    53
static bool is_suffix(const char* suffix, const char* str) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    54
  size_t suffix_len = strlen(suffix);
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    55
  size_t str_len = strlen(str);
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    56
  if (str_len < suffix_len) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    57
      return false;
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    58
  }
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    59
  return strncmp(str + (str_len - suffix_len), suffix, suffix_len) == 0;
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    60
}
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    61
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    62
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    63
static int init_jvm(int argc, char **argv, bool disable_error_handling) {
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    64
  // don't care about the program name
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    65
  argc--;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    66
  argv++;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    67
41672
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    68
  int extra_jvm_args = disable_error_handling ? 4 : 2;
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    69
  int num_jvm_options = argc + extra_jvm_args;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    70
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    71
  JavaVMOption* options = new JavaVMOption[num_jvm_options];
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    72
  options[0].optionString = (char*) "-Dsun.java.launcher.is_altjvm=true";
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    73
  options[1].optionString = (char*) "-XX:+ExecutingUnitTests";
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    74
41672
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    75
  if (disable_error_handling) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
    76
    // don't create core files or hs_err files executing assert tests
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    77
    options[2].optionString = (char*) "-XX:+SuppressFatalErrorMessage";
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    78
    options[3].optionString = (char*) "-XX:-CreateCoredumpOnCrash";
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    79
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    80
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    81
  for (int i = 0; i < argc; i++) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    82
    options[extra_jvm_args + i].optionString = argv[i];
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    83
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    84
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    85
  JavaVMInitArgs args;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    86
  args.version = JNI_VERSION_1_8;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    87
  args.nOptions = num_jvm_options;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    88
  args.options = options;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    89
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    90
  JavaVM* jvm;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    91
  JNIEnv* env;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    92
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    93
  return JNI_CreateJavaVM(&jvm, (void**)&env, &args);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    94
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    95
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    96
class JVMInitializerListener : public ::testing::EmptyTestEventListener {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    97
 private:
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    98
  int _argc;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
    99
  char** _argv;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   100
  bool _is_initialized;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   101
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   102
  void initialize_jvm() {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   103
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   104
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   105
 public:
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   106
  JVMInitializerListener(int argc, char** argv) :
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   107
    _argc(argc), _argv(argv), _is_initialized(false) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   108
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   109
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   110
  virtual void OnTestStart(const ::testing::TestInfo& test_info) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   111
    const char* name = test_info.name();
41672
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   112
    if (!_is_initialized && is_suffix("_test_vm", name)) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   113
      // we want to have hs_err and core files when we execute regular tests
48804
8f451978683c 8170941: Executing gtest with invalid -Xlog argument crashes gtestLauncher
mlarsson
parents: 47659
diff changeset
   114
      int ret_val = init_jvm(_argc, _argv, false);
8f451978683c 8170941: Executing gtest with invalid -Xlog argument crashes gtestLauncher
mlarsson
parents: 47659
diff changeset
   115
      if (ret_val != 0) {
8f451978683c 8170941: Executing gtest with invalid -Xlog argument crashes gtestLauncher
mlarsson
parents: 47659
diff changeset
   116
        ADD_FAILURE() << "Could not initialize the JVM";
8f451978683c 8170941: Executing gtest with invalid -Xlog argument crashes gtestLauncher
mlarsson
parents: 47659
diff changeset
   117
        exit(1);
8f451978683c 8170941: Executing gtest with invalid -Xlog argument crashes gtestLauncher
mlarsson
parents: 47659
diff changeset
   118
      }
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   119
      _is_initialized = true;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   120
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   121
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   122
};
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   123
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   124
static char* get_java_home_arg(int argc, char** argv) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   125
  for (int i = 0; i < argc; i++) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   126
    if (strncmp(argv[i], "-jdk", strlen(argv[i])) == 0) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   127
      return argv[i+1];
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   128
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   129
    if (is_prefix("--jdk=", argv[i])) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   130
      return argv[i] + strlen("--jdk=");
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   131
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   132
    if (is_prefix("-jdk:", argv[i])) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   133
      return argv[i] + strlen("-jdk:");
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   134
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   135
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   136
  return NULL;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   137
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   138
46684
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   139
static bool get_spawn_new_main_thread_arg(int argc, char** argv) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   140
  // -new-thread[=(true|false)]
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   141
  for (int i = 0; i < argc; i++) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   142
    if (is_prefix("-new-thread", argv[i])) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   143
      const char* v = argv[i] + strlen("-new-thread");
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   144
      if (strlen(v) == 0) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   145
        return true;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   146
      } else {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   147
        if (strcmp(v, "=true") == 0) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   148
          return true;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   149
        } else if (strcmp(v, "=false") == 0) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   150
          return false;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   151
        } else {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   152
          fprintf(stderr, "Invalid value for -new-thread (%s)", v);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   153
        }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   154
      }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   155
    }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   156
  }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   157
  return DEFAULT_SPAWN_IN_NEW_THREAD;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   158
}
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   159
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   160
static int num_args_to_skip(char* arg) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   161
  if (strcmp(arg, "-jdk") == 0) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   162
    return 2; // skip the argument after -jdk as well
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   163
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   164
  if (is_prefix("--jdk=", arg)) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   165
    return 1;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   166
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   167
  if (is_prefix("-jdk:", arg)) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   168
    return 1;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   169
  }
46684
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   170
  if (is_prefix("-new-thread", arg)) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   171
    return 1;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   172
  }
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   173
  return 0;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   174
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   175
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   176
static char** remove_test_runner_arguments(int* argcp, char **argv) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   177
  int argc = *argcp;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   178
  char** new_argv = (char**) malloc(sizeof(char*) * argc);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   179
  int new_argc = 0;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   180
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   181
  int i = 0;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   182
  while (i < argc) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   183
    int args_to_skip = num_args_to_skip(argv[i]);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   184
    if (args_to_skip == 0) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   185
      new_argv[new_argc] = argv[i];
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   186
      i++;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   187
      new_argc++;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   188
    } else {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   189
      i += num_args_to_skip(argv[i]);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   190
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   191
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   192
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   193
  *argcp = new_argc;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   194
  return new_argv;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   195
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   196
46684
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   197
static void runUnitTestsInner(int argc, char** argv) {
41672
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   198
  ::testing::InitGoogleTest(&argc, argv);
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   199
  ::testing::GTEST_FLAG(death_test_style) = "threadsafe";
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   200
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   201
  bool is_vmassert_test = false;
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   202
  bool is_othervm_test = false;
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   203
  // death tests facility is used for both regular death tests, other vm and vmassert tests
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   204
  if (::testing::internal::GTEST_FLAG(internal_run_death_test).length() > 0) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   205
    // when we execute death test, filter value equals to test name
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   206
    const char* test_name = ::testing::GTEST_FLAG(filter).c_str();
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   207
    const char* const othervm_suffix = "_other_vm_test"; // TEST_OTHER_VM
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   208
    const char* const vmassert_suffix = "_vm_assert_test"; // TEST_VM_ASSERT(_MSG)
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   209
    if (is_suffix(othervm_suffix, test_name)) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   210
      is_othervm_test = true;
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   211
    } else if (is_suffix(vmassert_suffix, test_name)) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   212
      is_vmassert_test = true;
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   213
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   214
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   215
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   216
  char* java_home = get_java_home_arg(argc, argv);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   217
  if (java_home == NULL) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   218
    fprintf(stderr, "ERROR: You must specify a JDK to use for running the unit tests.\n");
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   219
    exit(1);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   220
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   221
#ifndef _WIN32
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   222
  int overwrite = 1; // overwrite an eventual existing value for JAVA_HOME
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   223
  setenv("JAVA_HOME", java_home, overwrite);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   224
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   225
// workaround for JDK-7131356
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   226
#ifdef __APPLE__
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   227
  size_t len = strlen(java_home) + strlen("/lib/jli/libjli.dylib") + 1;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   228
  char* path = new char[len];
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   229
  snprintf(path, len, "%s/lib/jli/libjli.dylib", java_home);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   230
  dlopen(path, RTLD_NOW | RTLD_GLOBAL);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   231
#endif // __APPLE__
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   232
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   233
#else  // _WIN32
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   234
  char* java_home_var = "_ALT_JAVA_HOME_DIR";
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   235
  size_t len = strlen(java_home) + strlen(java_home_var) + 2;
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   236
  char * envString = new char[len];
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   237
  sprintf_s(envString, len, "%s=%s", java_home_var, java_home);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   238
  _putenv(envString);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   239
#endif // _WIN32
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   240
  argv = remove_test_runner_arguments(&argc, argv);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   241
41672
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   242
  if (is_vmassert_test || is_othervm_test) {
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   243
    // both vmassert and other vm tests require inited jvm
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   244
    // but only vmassert tests disable hs_err and core file generation
b40421cd8b48 8166129: hitting vmassert during gtest execution doesn't generate core and hs_err files
iignatyev
parents: 38255
diff changeset
   245
    if (init_jvm(argc, argv, is_vmassert_test) != 0) {
38255
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   246
      abort();
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   247
    }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   248
  } else {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   249
    ::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners();
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   250
    listeners.Append(new JVMInitializerListener(argc, argv));
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   251
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   252
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   253
  int result = RUN_ALL_TESTS();
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   254
  if (result != 0) {
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   255
    fprintf(stderr, "ERROR: RUN_ALL_TESTS() failed. Error %d\n", result);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   256
    exit(2);
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   257
  }
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   258
}
5784bccf53b0 8148244: Finalize and integrate GTest implementation
iignatyev
parents:
diff changeset
   259
46684
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   260
// Thread support for -new-thread option
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   261
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   262
struct args_t {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   263
  int argc; char** argv;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   264
};
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   265
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   266
#define STACK_SIZE 0x200000
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   267
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   268
#ifdef _WIN32
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   269
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   270
static DWORD WINAPI thread_wrapper(void* p) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   271
  const args_t* const p_args = (const args_t*) p;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   272
  runUnitTestsInner(p_args->argc, p_args->argv);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   273
  return 0;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   274
}
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   275
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   276
static void run_in_new_thread(const args_t* args) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   277
  HANDLE hdl;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   278
  hdl = CreateThread(NULL, STACK_SIZE, thread_wrapper, (void*)args, 0, NULL);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   279
  if (hdl == NULL) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   280
    fprintf(stderr, "Failed to create main thread\n");
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   281
    exit(2);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   282
  }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   283
  WaitForSingleObject(hdl, INFINITE);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   284
}
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   285
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   286
#else
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   287
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   288
extern "C" void* thread_wrapper(void* p) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   289
  const args_t* const p_args = (const args_t*) p;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   290
  runUnitTestsInner(p_args->argc, p_args->argv);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   291
  return 0;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   292
}
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   293
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   294
static void run_in_new_thread(const args_t* args) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   295
  pthread_t tid;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   296
  pthread_attr_t attr;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   297
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   298
  pthread_attr_init(&attr);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   299
  pthread_attr_setstacksize(&attr, STACK_SIZE);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   300
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   301
  if (pthread_create(&tid, &attr, thread_wrapper, (void*)args) != 0) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   302
    fprintf(stderr, "Failed to create main thread\n");
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   303
    exit(2);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   304
  }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   305
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   306
  if (pthread_join(tid, NULL) != 0) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   307
    fprintf(stderr, "Failed to join main thread\n");
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   308
    exit(2);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   309
  }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   310
}
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   311
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   312
#endif
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   313
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   314
extern "C"
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   315
JNIEXPORT void JNICALL runUnitTests(int argc, char** argv) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   316
  const bool spawn_new_main_thread = get_spawn_new_main_thread_arg(argc, argv);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   317
  if (spawn_new_main_thread) {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   318
    args_t args;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   319
    args.argc = argc;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   320
    args.argv = argv;
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   321
    run_in_new_thread(&args);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   322
  } else {
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   323
    runUnitTestsInner(argc, argv);
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   324
  }
a8121315a5b9 8179327: gtestLauncher should run tests on a separate thread (optionally)
stuefe
parents: 41672
diff changeset
   325
}