(file) Return to util.h CVS log (file) (dir) Up to [OMI] / omi / tests / util

  1 krisbash 1.1 /*
  2              **==============================================================================
  3              **
  4              ** Open Management Infrastructure (OMI)
  5              **
  6              ** Copyright (c) Microsoft Corporation
  7              ** 
  8              ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9              ** use this file except in compliance with the License. You may obtain a copy 
 10              ** of the License at 
 11              **
 12              **     http://www.apache.org/licenses/LICENSE-2.0 
 13              **
 14              ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15              ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16              ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17              ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18              **
 19              ** See the Apache 2 License for the specific language governing permissions 
 20              ** and limitations under the License.
 21              **
 22 krisbash 1.1 **==============================================================================
 23              */
 24              
 25              #ifndef _tests_util_util_h
 26              #define _tests_util_util_h
 27              
 28              
 29              #ifdef _MSC_VER
 30              #include <windows.h>
 31              #endif
 32              #include <MI.h>
 33              #include <pal/thread.h>
 34              #include <pal/sleep.h>
 35              #include <pal/sem.h>
 36              #include <pal/hashmap.h>
 37              #include <base/batch.h>
 38              
 39              PAL_BEGIN_EXTERNC
 40              
 41              /* global batch object */
 42              extern Batch* g_batch;
 43 krisbash 1.1 
 44              /* global log file, each module needs to define g_logfile */
 45              extern FILE* g_logfile;
 46              
 47              /* Write to global log file */
 48              void WriteLog(const char* fmt, ...);
 49              void FlushLog(FILE* file);
 50              
 51              
 52              /* Compare MI_Char string */
 53              int StringCompare(const MI_Char* s1, const MI_Char* s2);
 54              
 55              
 56              void _WriteHeader(
 57                  const char* file,
 58                  unsigned int line);
 59              
 60              INLINE int __MyLogFalse() { return 0; }
 61              
 62              # define LOGMSG(ARGS) \
 63                  do \
 64 krisbash 1.1     { \
 65                      _WriteHeader(__FILE__, __LINE__); \
 66                      WriteLog ARGS; \
 67                  } \
 68                  while (__MyLogFalse())
 69              
 70              /* Convert Ansi string to MI_Char string */
 71              MI_Char* ansiToMI(const char* src);
 72              /* Convert MI_Char string to ansi string (ascii only) */
 73              char* MIToansi(const MI_Char* src);
 74              
 75              #define CHKMIRESULTPOST(r,msg) \
 76                  if (r != MI_RESULT_OK) \
 77                  { \
 78                      LOGMSG(("(%s) failed with error code (%d)",msg,r)); \
 79                      MI_PostResult(context, r); \
 80                      return; \
 81                  }
 82              
 83              #define CHKMIRESULTRETURN(r,msg) \
 84                  if (r != MI_RESULT_OK) \
 85 krisbash 1.1     { \
 86                      LOGMSG(("(%s) failed with error code (%d)",msg,r)); \
 87                      return r; \
 88                  }
 89              
 90              #define CHKSETPROPERTY(r, pname) \
 91                  if (r != MI_RESULT_OK) \
 92                  { \
 93                      LOGMSG(("set property (%s) failed with error (%d)", pname, r )); \
 94                      return r; \
 95                  }
 96              
 97              #define CHKSETPROPERTYGOTO(r, pname, label) \
 98                  if (r != MI_RESULT_OK) \
 99                  { \
100                      LOGMSG(("set property (%s) failed with error (%d)", pname, r )); \
101                      goto label; \
102                  }
103              
104              #define ONNULLGOTO(value, pname, label) \
105                  if (value == NULL) \
106 krisbash 1.1     { \
107                      LOGMSG(("value of (%s) is NULL", pname)); \
108                      goto label; \
109                  }
110              
111              #define FREE(ptr) \
112                  if (ptr) \
113                  { \
114                      PAL_Free(ptr); \
115                      ptr = NULL; \
116                  } \
117              
118              const char* gethomedir();
119              
120              
121              MI_Result StartOmiserver();
122              MI_Result StopOmiserver();
123              
124              
125              /*
126              **==============================================================================
127 krisbash 1.1 **
128              ** Test structure for consume instance results
129              **
130              **==============================================================================
131              */
132              typedef struct _InstanceOperationStruct
133              {
134                  MI_Boolean sync; /* async / sync */
135                  MI_Uint32 operationTimeout; /* timeout value for the operation */
136              
137                  /* operation results */
138                  MI_Uint32 count;
139              
140                  volatile ptrdiff_t finished; /* condication variable for terminating the operation */    
141              
142                  MI_Result finalResult;
143              
144                  /* MI objects */
145                  MI_Application app; /* application object */
146                  MI_Session session; /* test application */
147              
148 krisbash 1.1 }InstanceOperationStruct;
149              
150              /*
151              **==============================================================================
152              **
153              ** Read instance for given class
154              **
155              **==============================================================================
156              */
157              MI_Result EnumerateInstance(
158                  _In_ InstanceOperationStruct* ios,
159                  _In_z_ const MI_Char* nameSpace,
160                  _In_z_ const MI_Char* className);
161              
162              /*
163              **==============================================================================
164              **
165              ** String hash map implementation based on hashmap
166              **
167              **==============================================================================
168              */
169 krisbash 1.1 typedef struct _StringBucket /* derives from HashBucket */
170              {
171                  struct _StringBucket* next;
172                  MI_Char* key;
173                  MI_Uint32 count;
174              }
175              StringBucket;
176              
177              typedef struct _StringHashMap
178              {
179                  HashMap map;
180              }StringHashMap;
181              
182              /* returns:
183                 -  0 : success
184                 - <0 : out of memory
185              */ 
186              int StringHashMap_Init(
187                  _Out_ StringHashMap* self);
188              
189              void StringHashMap_Destroy(
190 krisbash 1.1     _In_ _Post_invalid_ StringHashMap* self);
191              
192              /* returns:
193                 -  non-null : found
194                 -  null     : key not present
195              */
196              _Ret_maybenull_ StringBucket* StringHashMap_Find(
197                  _In_ StringHashMap* self,
198                  _In_z_ const MI_Char* key);
199              
200              /* returns:
201                 -  0 : inserted the new item
202                 -  1 : the item is already present (and HashMap was not modified)
203                 
204                 (there are no failure paths / no other return value is possible)
205              */
206              int StringHashMap_Insert(
207                  _In_ StringHashMap* self,
208                  _In_z_ const MI_Char* key);
209              
210              /* returns:
211 krisbash 1.1    -  0 : success
212                 - -1 : key not found - hashmap remains unchanged.
213              */
214              int StringHashMap_Remove(
215                  _In_ StringHashMap* self,
216                  _In_ const MI_Char* key);
217              
218              /* 
219                 Returns one element from the hash table. May be invoked
220                 multiple times (e.g. if you remove the element), returning
221                 null when empty.
222               
223                 *iter should be zero initialized before first call
224              */
225              _Ret_maybenull_ 
226              const StringBucket* StringHashMap_Top(
227                  _In_ StringHashMap* self,
228                  _Inout_ size_t *iter);
229              
230              MI_Result StartServer_Assert();
231              MI_Result StopServer_Assert();
232 krisbash 1.1 
233              PAL_END_EXTERNC
234              
235              #endif /* _tests_util_util_h */

ViewCVS 0.9.2