1 Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
   2 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   3 
   4 This code is free software; you can redistribute it and\\\/or modify it
   5 under the terms of the GNU General Public License version 2 only, as
   6 published by the Free Software Foundation.
   7 This code is distributed in the hope that it will be useful, but WITHOUT
   8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   9 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  10 version 2 for more details (a copy is included in the LICENSE file that
  11 accompanied this code).
  12 
  13 You should have received a copy of the GNU General Public License version
  14 2 along with this work; if not, write to the Free Software Foundation,
  15 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  16 
  17 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  18 or visit www.oracle.com if you need additional information or have any
  19 questions.
  20 
  21 ---------------------------------------------------------------------------------
  22 
  23 This directory contains source files of testbase_nsk native
  24 framework, which provides support for native tests.
  25 
  26     Source files:
  27         nsk_tools.h
  28         nsk_tools.c
  29 
  30     Naming conventions:
  31         macroses:  NSK_*
  32         functions: nsk_*
  33 
  34 Also this directory provides support for running native threads
  35 in a platform independent manner.
  36 
  37     Source files:
  38         native_thread.h
  39         native_thread.c
  40 
  41     Naming conventions:
  42         functions: THREAD_*
  43 
  44 The following source files declares a set of functions which
  45 provides support for lists of various objects
  46 
  47     Source files:
  48         nsk_list.h
  49         nsk_list.c
  50 
  51     Naming conventions:
  52         functions: nsk_list_*
  53 
  54 ---------------------------------------------------------------------------------
  55 
  56 nsk_tools.h
  57 
  58 Provides functions and macroses for the most usefull actions:
  59 
  60     - access native JVM environment in a compiler independent manner
  61 
  62         NSK_CPP_STUBn(function, env, arg1, ..., argn)
  63 
  64     - print error message with arguments
  65 
  66         NSK_COMPLAINn(format, arg1, ..., argn)
  67 
  68     - print verbose message with arguments
  69 
  70         NSK_DISPLAYn(format, arg1, ..., argn)
  71 
  72     - trace action execution
  73 
  74         NSK_TRACE(action)
  75 
  76     - trace action, check result for true/false and print error if required
  77 
  78         NSK_VERIFY(action)
  79         NSK_VERIFY_NEGATIVE(action)
  80 
  81     - set verbose and trace mode of test output
  82 
  83         void nsk_setVerboseMode(int verbose);
  84         int  nsk_getVerboseMode();
  85 
  86         void nsk_setTraceMode(int mode);
  87         int  nsk_getTraceMode();
  88 
  89     - miscelaneous functions for printing messages
  90       (hidden by above mentioned macroses)
  91 
  92 Typical example of using macroses NSK_CPP_STUB and NSK_VERIFY
  93 for accesing JVM native environment:
  94 
  95     // jvm->GetEnv(jvm, &env, version)
  96     if (!NSK_VERIFY(
  97             jvm->GetEnv(&env, JNI_VERSION_1_2) == JNI_OK)) {
  98         return JNI_ERR;
  99     }
 100 
 101 For more specific checks in invocations of JNI and JVMTI functions
 102 use special macroses defined in share/jni and share/jvmti frameworks.
 103 
 104 ---------------------------------------------------------------------------------
 105 
 106 native_thread.h
 107 
 108 Provides platform-independent support for running native threads:
 109 
 110     - manage native threads
 111 
 112     void* THREAD_new(PROCEDURE procedure, void* context);
 113     void* THREAD_start(void* thread);
 114     void  THREAD_waitFor(void* thread);
 115     void  THREAD_sleep(int seconds);
 116 
 117     - get status of native threads
 118 
 119     int THREAD_isStarted(void* thread);
 120     int THREAD_hasFinished(void* thread);
 121     int THREAD_status(void* thread);
 122 
 123 ---------------------------------------------------------------------------------
 124 
 125 nsk_list.h
 126 
 127 Provides support for lists of various objects:
 128 
 129     - managing list
 130     const void* nsk_list_Create();
 131     int         nsk_list_Destroy(const void *plist);
 132 
 133     - managing elements
 134     const void* nsk_list_Add(const void *plist, const void *p);
 135     int         nsk_list_Delete(const void *plist, int ind);
 136 
 137     - getting element info
 138     int         nsk_list_getCount(const void *plist);
 139     const void* nsk_list_Get(const void *plist, int ind);
 140 
 141 Typical example:
 142 
 143 int TOTAL_COUNT = 10;
 144 typedef struct recordStruct {
 145     int field1;
 146     int field2;
 147 } record;
 148 
 149 main() {
 150     int i;
 151     record *rec;
 152     const void *plist;
 153 
 154     /* creating list */
 155     plist = nsk_list_create();
 156 
 157     /* adding new elements */
 158     for (i = 0; i < TOTAL_COUNT; i ++) {
 159         rec = (record *)malloc(sizeof(record));
 160         rec->field1 = i;
 161         rec->field2 = i * 10;
 162         if (!nsk_list_add(plist, rec)) {
 163             free((void *)rec);
 164         }
 165     }
 166 
 167     /* getting elements */
 168     for (i = 0; i < TOTAL_COUNT; i ++) {
 169         rec = (record *)nsk_list_get(plist, i);
 170         printf("%3d %3d\n", rec->field1, rec->field2);
 171     }
 172 
 173     /* deleteing elements */
 174     for (i = 0; i < TOTAL_COUNT; i ++) {
 175         rec = (record *)nsk_list_get(plist, i);
 176         free(rec);
 177         nsk_list_remove(plist, 0);
 178     }
 179 
 180     /* destroying list */
 181     nsk_list_destroy(plist);
 182 
 183 }
 184 
 185 ---------------------------------------------------------------------------------
 186