text: /*
      Copyright 2005-2006 The Apache Software Foundation or its licensors, as applicable
  
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
  
         http://www.apache.org/licenses/LICENSE-2.0
  
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  
      See the License for the specific language governing permissions and
      limitations under the License.
  */
  /**
   * @author Valentin Al. Sitnick
   * @version $Revision: 1.1 $
   *
   */
  
  /* *********************************************************************** */
  
  #include "events.h"
  #include "utils.h"
  #include "fake.h"
  
  static bool test = false;
  static bool util = false;
  static bool flag = false;
  
  /* *********************************************************************** */
  
  /**
   * test of function GetThreadListStackTraces
   */
  void GetThreadListStackTraces0101()
  {
      //Fake method for docletting only
  }
  
  /* *********************************************************************** */
  
  JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
  {
      check_AGENT_ONLOAD;
  
      Callbacks CB;
  
      cb_exc;
      cb_death;
  
      AGENT_FOR_EVENTS_TESTS_PART_I; /* events.h */
  
      jvmtiEvent events[] = { JVMTI_EVENT_EXCEPTION, JVMTI_EVENT_VM_DEATH };
  
      AGENT_FOR_EVENTS_TESTS_PART_II;
  
      fprintf(stderr, "\n-------------------------------------------------\n");
      fprintf(stderr, "\ntest GetThreadListStackTraces0101 is started\n{\n");
      fflush(stderr);
  
      return JNI_OK;
  }
  
  /* *********************************************************************** */
  
  void JNICALL callbackException(prms_EXCPT)
  {
      check_EXCPT;
  
      if (flag) return;
  
      char* name;
      char* signature;
      char* generic;
      jvmtiPhase phase;
      jvmtiError result;
      jint tc = 0;
      jint fc = 0;
      jthread* threads = NULL;
      jvmtiStackInfo* sinfo = NULL;
  
      result = jvmti_env->GetPhase(&phase);
  
      fprintf(stderr, "\tnative: GetPhase result = %d (must be zero) \n", result);
      fprintf(stderr, "\tnative: current phase is %d (must be 4 (LIVE-phase)) \n", phase);
  
      if ((result != JVMTI_ERROR_NONE) || (phase != JVMTI_PHASE_LIVE)) return;
  
      result = jvmti_env->GetMethodName(method, &name, &signature, &generic);
      fprintf(stderr, "\tnative: GetMethodName result = %d (must be zero) \n", result);
      fprintf(stderr, "\tnative: method name is %s \n", name);
      fprintf(stderr, "\tnative: signature name is %s \n", signature);
      fprintf(stderr, "\tnative: generic name is %s \n", generic);
      fflush(stderr);
  
      if (result != JVMTI_ERROR_NONE) return;
  
      if (strcmp(name, "special_method")) return;
  
      flag = true;
  
      result = jvmti_env->GetAllThreads(&tc, &threads);
      fprintf(stderr, "\tnative: GetAllThreads result = %d (must be zero) \n", result);
      fprintf(stderr, "\tnative: GetAllThreads tc = %d (must >= zero) \n", tc);
  
      if (result != JVMTI_ERROR_NONE) return;
  
      util = true;
  
      result = jvmti_env->GetThreadListStackTraces(tc, threads, fc, &sinfo);
      fprintf(stderr, "\tnative: GetThreadListStackTraces result = %d (must be zero) \n",
              result);
  
      if ((result == JVMTI_ERROR_NONE) && (sinfo != NULL))
          test = true;
  }
  
  void JNICALL callbackVMDeath(prms_VMDEATH)
  {
      check_VMDEATH;
  
      fprintf(stderr, "\n\tTest of function GetThreadListStackTraces0101    : ");
  
      if (test && util)
          fprintf(stderr, " passed \n");
      else
          fprintf(stderr, " failed \n");
  
      fprintf(stderr, "\n} /* test GetThreadListStackTraces0101 is finished */ \n");
      fflush(stderr);
  }
  
  /* *********************************************************************** */
  
  
  