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     - print error message with arguments
  61 
  62         NSK_COMPLAINn(format, arg1, ..., argn)
  63 
  64     - print verbose message with arguments
  65 
  66         NSK_DISPLAYn(format, arg1, ..., argn)
  67 
  68     - trace action execution
  69 
  70         NSK_TRACE(action)
  71 
  72     - trace action, check result for true/false and print error if required
  73 
  74         NSK_VERIFY(action)
  75         NSK_VERIFY_NEGATIVE(action)
  76 
  77     - set verbose and trace mode of test output
  78 
  79         void nsk_setVerboseMode(int verbose);
  80         int  nsk_getVerboseMode();
  81 
  82         void nsk_setTraceMode(int mode);
  83         int  nsk_getTraceMode();
  84 
  85     - miscelaneous functions for printing messages
  86       (hidden by above mentioned macroses)
  87 
  88 Typical example of using the NSK_VERIFY macro
  89 for accesing JVM native environment:
  90 
  91     // jvm->GetEnv(jvm, &env, version)
  92     if (!NSK_VERIFY(
  93             jvm->GetEnv(&env, JNI_VERSION_1_2) == JNI_OK)) {
  94         return JNI_ERR;
  95     }
  96 
  97 For more specific checks in invocations of JNI and JVMTI functions
  98 use special macroses defined in share/jni and share/jvmti frameworks.
  99 
 100 ---------------------------------------------------------------------------------
 101 
 102 native_thread.h
 103 
 104 Provides platform-independent support for running native threads:
 105 
 106     - manage native threads
 107 
 108     void* THREAD_new(PROCEDURE procedure, void* context);
 109     void* THREAD_start(void* thread);
 110     void  THREAD_waitFor(void* thread);
 111     void  THREAD_sleep(int seconds);
 112 
 113     - get status of native threads
 114 
 115     int THREAD_isStarted(void* thread);
 116     int THREAD_hasFinished(void* thread);
 117     int THREAD_status(void* thread);
 118 
 119 ---------------------------------------------------------------------------------
 120 
 121 nsk_list.h
 122 
 123 Provides support for lists of various objects:
 124 
 125     - managing list
 126     const void* nsk_list_Create();
 127     int         nsk_list_Destroy(const void *plist);
 128 
 129     - managing elements
 130     const void* nsk_list_Add(const void *plist, const void *p);
 131     int         nsk_list_Delete(const void *plist, int ind);
 132 
 133     - getting element info
 134     int         nsk_list_getCount(const void *plist);
 135     const void* nsk_list_Get(const void *plist, int ind);
 136 
 137 Typical example:
 138 
 139 int TOTAL_COUNT = 10;
 140 typedef struct recordStruct {
 141     int field1;
 142     int field2;
 143 } record;
 144 
 145 main() {
 146     int i;
 147     record *rec;
 148     const void *plist;
 149 
 150     /* creating list */
 151     plist = nsk_list_create();
 152 
 153     /* adding new elements */
 154     for (i = 0; i < TOTAL_COUNT; i ++) {
 155         rec = (record *)malloc(sizeof(record));
 156         rec->field1 = i;
 157         rec->field2 = i * 10;
 158         if (!nsk_list_add(plist, rec)) {
 159             free((void *)rec);
 160         }
 161     }
 162 
 163     /* getting elements */
 164     for (i = 0; i < TOTAL_COUNT; i ++) {
 165         rec = (record *)nsk_list_get(plist, i);
 166         printf("%3d %3d\n", rec->field1, rec->field2);
 167     }
 168 
 169     /* deleteing elements */
 170     for (i = 0; i < TOTAL_COUNT; i ++) {
 171         rec = (record *)nsk_list_get(plist, i);
 172         free(rec);
 173         nsk_list_remove(plist, 0);
 174     }
 175 
 176     /* destroying list */
 177     nsk_list_destroy(plist);
 178 
 179 }
 180 
 181 ---------------------------------------------------------------------------------
 182