(file) Return to test_e2e.cpp CVS log (file) (dir) Up to [OMI] / omi / tests / indication

   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              #include <ut/ut.h>
  26              #include <MI.h>
  27              #include <miapi/Application.h>
  28              #include <pal/lock.h>
  29              #include <pal/atomic.h>
  30              #include <miapi/Options.h>
  31              #include <tests/util/indiprvdconfig.h>
  32              
  33              using namespace std;
  34              
  35              #define MAX_CLASS 10
  36              #define TEST_MAX_PAGES 1024
  37              
  38              /* in order to link to test_util.lib */
  39              Batch* g_batch;
  40              FILE* g_logfile;
  41              char* g_dirpath;
  42              
  43 krisbash 1.1 # if !defined(_MSC_VER)
  44              
  45              /*
  46              **==============================================================================
  47              **
  48              ** Defines structure to hold each indication result
  49              **
  50              **==============================================================================
  51              */
  52              typedef struct _IndicationResult IndicationResult;
  53              
  54              struct _IndicationResult
  55              {
  56                  IndicationResult* next;
  57                  MI_Instance *indication;
  58                  MI_Char* machineid;
  59                  MI_Char* bookmark;
  60              };
  61              
  62              /*
  63              **==============================================================================
  64 krisbash 1.1 **
  65              ** Defines structure to hold expected results
  66              **
  67              **==============================================================================
  68              */
  69              typedef struct _OperationResult
  70              {
  71                  /* common operation results */
  72                  MI_Uint32 numInstances; /* how many instances received */
  73                  MI_Result finalResult; /* final result of the operation */
  74                  MI_Instance *errorDetails;
  75                  MI_Char* errorString;
  76              
  77                  /* Expected items */
  78                  MI_Char* bookmark; /* bookmark of indication */
  79              
  80                  /* Actual results from server */
  81                  IndicationResult* head;/* list of indication result, inc. instance, bookmark, and machineid */
  82                  IndicationResult* tail;
  83              }OperationResult;
  84              
  85 krisbash 1.1 /*
  86              **==============================================================================
  87              **
  88              ** Test structure for Alert Indication end to end test
  89              **
  90              **==============================================================================
  91              */
  92              struct AlertTestStruct
  93              {
  94                  /* Configurations */
  95                  MI_Boolean sync; /* async / sync */
  96                  const MI_Char* nameSpace; /* target namespace */
  97                  const MI_Char* querylang;
  98                  const MI_Char* queryexpr;
  99                  MI_Uint32 operationTimeout; /* timeout value for the operation */
 100                  MI_Uint32 targetclassCount;
 101                  Config targetclassConfig[MAX_CLASS];  /* configuration of the target classes */
 102                  const char** targetclassnames; /* list of target class names */
 103              
 104                  /* memory allocator */
 105                  Batch batch; /* Batch allocator for this test structure */
 106 krisbash 1.1 
 107                  /* MI objects */
 108                  MI_Application app; /* application object */
 109                  MI_Session session; /* test application */
 110              
 111                  /* operation results */
 112                  OperationResult actual;
 113              
 114                  /* expected results */
 115                  OperationResult expect;
 116              
 117                  volatile ptrdiff_t finished; /* condication variable for terminating the operation */    
 118              };
 119              
 120              /*
 121              **==============================================================================
 122              **
 123              ** moudle level test setup
 124              **
 125              **==============================================================================
 126              */
 127 krisbash 1.1 NitsModuleSetup(IndicationE2ESetup)
 128                  NitsTrace(PAL_T("IndicationE2ESetup started"));
 129                  g_batch = Batch_New( 64 );
 130                  NitsAssertOrReturn( g_batch != NULL, PAL_T("Failed to create batch") );
 131              NitsEndModuleSetup
 132              
 133              /*
 134              **==============================================================================
 135              **
 136              ** moudle level test cleanup
 137              **
 138              **==============================================================================
 139              */
 140              NitsCleanup(IndicationE2ESetup)
 141                  NitsTrace(PAL_T("IndicationE2ESetup cleaned"));
 142                  if ( g_batch )
 143                  {
 144                      Batch_Delete( g_batch );
 145                      g_batch = NULL;
 146                  }
 147              
 148 krisbash 1.1     NitsAssert(PAL_TRUE, PAL_T(""));
 149              NitsEndCleanup
 150              
 151              /*
 152              **==============================================================================
 153              **
 154              ** Setup function, it is called before running each test case
 155              ** NOTE: for "nits -fault" run, this function will be called once and only once
 156              ** for each test case.
 157              **
 158              **==============================================================================
 159              */
 160              static void _setup(_In_ AlertTestStruct* ats)
 161              {
 162                  MI_Application *application = &ats->app;
 163              
 164                  Batch_Init(&ats->batch, TEST_MAX_PAGES);
 165                  ats->app.ft = NULL;
 166                  if (NitsCompare(MI_Application_Initialize(0, NULL, NULL, application),
 167                      MI_RESULT_OK,
 168                      PAL_T("MI_Application_Initialize returns OK")))
 169 krisbash 1.1     {
 170                      NitsAssert(application->ft != NULL,
 171                          PAL_T("MI_Application_Initialize returns object with function table"));
 172                      if (application->ft == NULL)
 173                          return;
 174                  }
 175                  else
 176                      return;
 177              
 178                  ats->session.ft = NULL;
 179                  if (NitsCompare(MI_Application_NewSession(&ats->app, NULL, NULL, NULL, NULL, NULL, &ats->session),
 180                      MI_RESULT_OK,
 181                      PAL_T("MI_Application_NewSession returns OK")))
 182                  {
 183                      NitsAssert(ats->session.ft != NULL,
 184                          PAL_T("MI_Application_NewSession returns object with function table"));
 185                      if (ats->session.ft == NULL)
 186                          return;
 187                  }
 188                  else
 189                      return;
 190 krisbash 1.1 
 191                  ats->finished = 0;
 192              }
 193              
 194              NitsSetup0(AlertTest_Setup, AlertTestStruct)
 195                  _setup(NitsContext()->_AlertTestStruct);
 196              NitsEndSetup
 197              
 198              /*
 199              **==============================================================================
 200              **
 201              ** Cleanup function, it is called after run each test case
 202              ** NOTE: for "nits -fault" run, this function will be called once and only once
 203              ** for each test case.
 204              **
 205              **==============================================================================
 206              */
 207              static void _cleanup(_In_ AlertTestStruct* ats)
 208              {
 209                  MI_Application *application = &ats->app;
 210                  MI_Session *session = &ats->session;
 211 krisbash 1.1 
 212                  if (NULL != session->ft)
 213                      NitsCompare(MI_Session_Close(session, NULL, NULL), MI_RESULT_OK, PAL_T("Failed to close MI_Session"));
 214                  if (NULL != application->ft)
 215                  NitsCompare(MI_Application_Close(application), MI_RESULT_OK, PAL_T("Failed to close MI_Application"));
 216              
 217                  Batch_Destroy(&ats->batch);
 218              }
 219              
 220              NitsCleanup(AlertTest_Setup)
 221                  _cleanup (NitsContext()->_AlertTestStruct);   
 222              NitsEndCleanup
 223              
 224              /*
 225              **==============================================================================
 226              **
 227              ** Store indication result for validation purpose
 228              **
 229              **==============================================================================
 230              */
 231              static void _CacheIndicationResult(
 232 krisbash 1.1     _In_ AlertTestStruct* ats,
 233                  _In_opt_ const MI_Instance* inst,
 234                  _In_opt_z_ const MI_Char* bookmark,
 235                  _In_opt_z_ const MI_Char* machineid,
 236                  _In_ MI_Boolean moreResults,
 237                  _In_ MI_Result result,
 238                  _In_opt_z_ const MI_Char* errorString,
 239                  _In_opt_ const MI_Instance* errorDetails)
 240              {
 241                  if (inst)
 242                  {
 243                      ats->actual.numInstances++;
 244              
 245                      IndicationResult* ir = (IndicationResult*)Batch_GetClear(&ats->batch, sizeof(IndicationResult));
 246                      NitsAssert(ir != NULL, PAL_T("Failed to create IndicationResult, out of memory"));
 247                      if ( ir )
 248                      {
 249                          if (bookmark)
 250                              ir->bookmark = Batch_Tcsdup(&ats->batch, bookmark);
 251                          if (machineid)
 252                              ir->machineid = Batch_Tcsdup(&ats->batch, machineid);
 253 krisbash 1.1             MI_Result r = MI_Instance_Clone(inst, &ir->indication);
 254                          NitsCompare(r, MI_RESULT_OK, PAL_T("Clone errorDetails failed"));
 255                          ir->next = NULL;
 256                          if (NULL == ats->actual.tail)
 257                              ats->actual.head = ir;
 258                          else
 259                              ats->actual.tail->next = ir;
 260                          ats->actual.tail = ir;
 261                      }
 262                  }
 263              
 264                  if (moreResults == MI_FALSE)
 265                  {
 266                      if (result != MI_RESULT_OK)
 267                      {
 268                          if (errorString)
 269                          {
 270                              ats->actual.errorString = Batch_Tcsdup(&ats->batch, errorString);
 271                              NitsAssert(ats->actual.errorString != NULL, PAL_T("out of memory"));
 272                          }
 273                          if (errorDetails)
 274 krisbash 1.1             {
 275                              MI_Result r = Instance_Clone(errorDetails, &ats->actual.errorDetails, &ats->batch);
 276                              NitsCompare(r, MI_RESULT_OK, PAL_T("Clone errorDetails failed"));
 277                          }
 278                      }
 279                      ats->actual.finalResult = result;
 280                      ats->finished = 1;
 281                  }
 282              }
 283              
 284              /*
 285              **==============================================================================
 286              **
 287              ** Consume indication result
 288              **
 289              **==============================================================================
 290              */
 291              static MI_Result _ConsumeIndicationResults(
 292                  _In_ AlertTestStruct* ats,
 293                  _In_ MI_Operation *miOperation)
 294              {
 295 krisbash 1.1     MI_Result miResult;
 296              
 297                  if (ats->sync == MI_TRUE)
 298                  {
 299                      MI_Boolean moreResults = MI_FALSE;
 300                      do
 301                      {
 302                          const MI_Instance *miInstanceResult = NULL;
 303                          MI_Result _miResult;
 304                          const MI_Char *errorString = NULL;
 305                          const MI_Instance *errorDetails = NULL;
 306                          const MI_Char *bookmark;
 307                          const MI_Char *machineid;
 308              
 309                          _miResult = MI_Operation_GetIndication(miOperation, &miInstanceResult, &bookmark, &machineid, &moreResults, &miResult, &errorString, &errorDetails);
 310                          if (_miResult != MI_RESULT_OK)
 311                          {
 312                              miResult = _miResult;
 313                          }
 314                          _CacheIndicationResult(ats, miInstanceResult, bookmark, machineid, moreResults, miResult, errorString, errorDetails);
 315                          
 316 krisbash 1.1         } while ((miResult == MI_RESULT_OK) && (moreResults == MI_TRUE));
 317                  }
 318                  else
 319                  {
 320                      ptrdiff_t finished;
 321                      finished = ats->finished;
 322                      while (!finished)
 323                      {
 324                          CondLock_Wait((ptrdiff_t)&ats->finished, &ats->finished, finished, CONDLOCK_DEFAULT_SPINCOUNT);
 325                          finished = ats->finished;
 326                      }
 327                      miResult = ats->actual.finalResult;
 328                  }
 329                  return miResult;
 330              }
 331              
 332              /*
 333              **==============================================================================
 334              **
 335              ** Create operation options, such as time out
 336              **
 337 krisbash 1.1 **==============================================================================
 338              */
 339              static MI_Result _CreateOperationOptions(
 340                  _In_ AlertTestStruct* ats,
 341                  _Out_ MI_OperationOptions *options)
 342              {
 343                  MI_Application application;
 344                  MI_Result miResult;
 345                  MI_Interval timeoutInterval;
 346                  MI_Uint64 currentTimeout = ats->operationTimeout * 1000;
 347              
 348                  miResult = MI_Session_GetApplication(&ats->session, &application);
 349                  if (miResult != MI_RESULT_OK)
 350                      return miResult;
 351              
 352                  miResult = MI_Application_NewOperationOptions(&application, MI_FALSE, options);
 353                  if (miResult != MI_RESULT_OK)
 354                      return miResult;
 355              
 356                  memset((void*)&timeoutInterval, 0, sizeof(timeoutInterval));
 357              
 358 krisbash 1.1     timeoutInterval.microseconds = currentTimeout%1000000;
 359                  currentTimeout /= 1000000;
 360              
 361                  timeoutInterval.seconds = currentTimeout % 60;
 362                  currentTimeout /= 60;
 363              
 364                  timeoutInterval.minutes = currentTimeout % 60;
 365                  currentTimeout /= 60;
 366              
 367                  timeoutInterval.hours = currentTimeout % 24;
 368                  currentTimeout /= 24;
 369              
 370                  timeoutInterval.days = (MI_Uint32) currentTimeout;
 371              
 372                  miResult = MI_OperationOptions_SetTimeout(options, &timeoutInterval);
 373                  if (miResult != MI_RESULT_OK)
 374                  {
 375                      goto cleanup;
 376                  }
 377              
 378                  return miResult;
 379 krisbash 1.1 
 380              cleanup:
 381                  MI_OperationOptions_Delete(options);
 382                  memset(options, 0, sizeof(*options));
 383                  return miResult;
 384              }
 385              
 386              /*
 387              **==============================================================================
 388              **
 389              ** Async operation, the callback to receive indication results
 390              **
 391              **==============================================================================
 392              */
 393              NITS_EXTERN_C void MI_CALL _IndicationResultCallback(
 394                  _In_opt_     MI_Operation *operation,
 395                  _In_     void *callbackContext,
 396                  _In_opt_ const MI_Instance *instance,
 397                  _In_opt_z_ const MI_Char *bookmark,
 398                  _In_opt_z_ const MI_Char *machineID,
 399                           MI_Boolean moreResults,
 400 krisbash 1.1     _In_     MI_Result resultCode,
 401                  _In_opt_z_ const MI_Char *errorString,
 402                  _In_opt_ const MI_Instance *errorDetails,
 403                  _In_opt_ MI_Result (MI_CALL * resultAcknowledgement)(_In_ MI_Operation *operation))
 404              {
 405                  AlertTestStruct* ats = (AlertTestStruct*)callbackContext;
 406                  _CacheIndicationResult(ats, instance, bookmark, machineID, moreResults, resultCode, errorString, errorDetails);
 407                  if (moreResults == MI_FALSE)
 408                      CondLock_Broadcast((ptrdiff_t)&ats->finished);
 409              }
 410              
 411              /*
 412              **==============================================================================
 413              **
 414              ** Read modify result
 415              **
 416              **==============================================================================
 417              */
 418              static MI_Result _ConsumeInstanceResults(_In_ MI_Operation *miOperation)
 419              {
 420                  MI_Result miResult;
 421 krisbash 1.1     MI_Boolean moreResults = MI_FALSE;
 422                  do
 423                  {
 424                      const MI_Instance *miInstanceResult = NULL;
 425                      MI_Result _miResult;
 426                      const MI_Char *errorString = NULL;
 427                      const MI_Instance *errorDetails = NULL;
 428              
 429                      _miResult = MI_Operation_GetInstance(
 430                          miOperation,
 431                          &miInstanceResult,
 432                          &moreResults,
 433                          &miResult,
 434                          &errorString,
 435                          &errorDetails);
 436                      if (_miResult != MI_RESULT_OK)
 437                      {
 438                          miResult = _miResult;
 439                      }
 440                  } while ((miResult == MI_RESULT_OK) && (moreResults == MI_TRUE));
 441              
 442 krisbash 1.1     return miResult;
 443              }
 444              
 445              /*
 446              **==============================================================================
 447              **
 448              ** Modify configuration instance for indication class
 449              **
 450              **==============================================================================
 451              */
 452              static MI_Result _ModifyInstance(
 453                  _In_ AlertTestStruct* ats,
 454                  _In_ MI_Instance* instance)
 455              {
 456                  MI_Result miResult;
 457                  MI_Operation miOperation = MI_OPERATION_NULL;
 458                  MI_OperationCallbacks *callbacks = NULL;
 459              
 460                  MI_Session_ModifyInstance(&ats->session, 0, NULL, ats->nameSpace, instance, callbacks, &miOperation);
 461              
 462                  miResult = _ConsumeInstanceResults(&miOperation);
 463 krisbash 1.1 
 464                  MI_Operation_Close(&miOperation);
 465              
 466                  return miResult;
 467              }
 468              
 469              /*
 470              **==============================================================================
 471              **
 472              ** Modify configuration(s) of target class(es)
 473              **
 474              **==============================================================================
 475              */
 476              static MI_Result _ConfigTargetClasses(
 477                  _In_ AlertTestStruct* ats)
 478              {
 479                  MI_Instance *instance;
 480                  MI_Uint32 i;
 481                  for (i = 0; i < ats->targetclassCount; i++)
 482                  {
 483                      MI_Result r = Config_ToInstance(&ats->batch, (const Config*)&ats->targetclassConfig[i], &instance);
 484 krisbash 1.1         NitsCompare(r, MI_RESULT_OK, PAL_T("Convert config to instance failed"));
 485                      if (r != MI_RESULT_OK)
 486                      {
 487                          return r;
 488                      }
 489                      r = _ModifyInstance(ats, instance);
 490                      MI_Instance_Delete(instance);
 491                      NitsCompare(r, MI_RESULT_OK, PAL_T("Modify config instance failed"));
 492                      if (r != MI_RESULT_OK)
 493                      {
 494                          return r;
 495                      }
 496                  }
 497                  return MI_RESULT_OK;
 498              }
 499              
 500              /*
 501              **==============================================================================
 502              **
 503              ** Read configuration of target class
 504              **
 505 krisbash 1.1 **==============================================================================
 506              
 507              static MI_Result _ReadConfig(
 508                  _In_ AlertTestStruct* ats,
 509                  _In_z_ const MI_Char* classname,
 510                  _Out_ Config* config)
 511              {
 512                  memset(config, 0, sizeof(Config));
 513                  return MI_RESULT_OK;
 514              }
 515              */
 516              
 517              /* Sorts all the OperationResults received into HashMap buckets by class name. */
 518              static void _BucketizeByClassName(
 519                  StringHashMap* map,
 520                  OperationResult* opResultList,
 521                  MI_Uint32 expectedResultCount,
 522                  MI_Boolean checkID )
 523              {
 524                  NitsAssert((opResultList->head != NULL) && (opResultList->tail != NULL), PAL_T("indication list is NULL"));
 525                  
 526 krisbash 1.1     MI_Uint32 expectedcount = 0;
 527                  MI_Value v;
 528                  MI_Result r = MI_RESULT_OK;
 529                  IndicationResult* ir = opResultList->head;
 530                  int rv;
 531                  rv = StringHashMap_Init( map );
 532                  NitsAssert( rv == 0, PAL_T("Initialize string hashmap failed") );
 533                  if ( rv != 0 )
 534                      return;
 535                  opResultList->tail = opResultList->head = NULL;
 536              
 537                  while ( ir != NULL )
 538                  {
 539                      expectedcount++;
 540                      if (checkID)
 541                      {
 542                          r = MI_Instance_GetElement( ir->indication, MI_T("id"), &v, NULL, NULL, NULL );
 543                          NitsCompare( r, MI_RESULT_OK, PAL_T("Unable to extract id") );
 544                      }
 545                      const MI_Char* classname = NULL;
 546                      if ( r == MI_RESULT_OK )
 547 krisbash 1.1         {
 548                          r = MI_Instance_GetClassName( ir->indication, &classname );
 549                          NitsCompare( r, MI_RESULT_OK, PAL_T("number of indication is not expected") );
 550                      }
 551              
 552                      if ( r == MI_RESULT_OK && classname )
 553                      {
 554                          StringBucket* b = StringHashMap_Find( map, classname );
 555                          if ( NULL == b )
 556                          {
 557                              rv = StringHashMap_Insert( map, classname );
 558                              NitsAssert( rv == 0, PAL_T("Failed to insert class to map") );
 559                              if ( rv == 0 )
 560                              {
 561                                  b = StringHashMap_Find( map, classname );
 562                              }
 563                          }
 564                          NitsAssert( b != NULL, PAL_T("Failed to find hash bucket for class") );
 565                          if ( b )
 566                          {
 567                              b->count ++;
 568 krisbash 1.1                 //
 569                              // Validate the id value is as expected
 570                              //
 571                              if (checkID)
 572                              {
 573                                  NitsCompare(v.uint32, b->count, PAL_T("Unexpected id property value of the indication"));
 574                              }
 575                          }
 576                      }
 577                      MI_Instance_Delete(ir->indication);
 578                      ir->indication = NULL;
 579                      ir = ir->next;
 580                  }
 581              
 582                  //
 583                  // Validate total indication count is correct
 584                  //
 585                  NitsCompare(expectedcount, expectedResultCount, PAL_T("number of indication is not expected"));
 586              }
 587              
 588              /* Non-destructively iterates through the posted indications and attempts to match
 589 krisbash 1.1  * posted bookmarks against their expected values. */
 590              void _VerifyBookmarks(
 591                  _In_ AlertTestStruct* ats )
 592              {
 593                  OperationResult* actual = &ats->actual;
 594              
 595                  if (0 == actual->numInstances)
 596                      return;
 597              
 598                  MI_Boolean bookmarksPresent = MI_FALSE;
 599              
 600                  for ( MI_Uint32 i = 0; i < ats->targetclassCount; i ++ )
 601                  {
 602                      if (NULL != ats->targetclassConfig[i].subscribeBookmark)
 603                      {
 604                          bookmarksPresent = MI_TRUE;
 605                          break;
 606                      }
 607                  }
 608              
 609                  // There are no bookmarks specified in the configs, so there is nothing to check against.
 610 krisbash 1.1     if ( ! bookmarksPresent)
 611                      return;
 612              
 613                  // Iterate through the list of indication results and compare bookmarks against
 614                  // expected values.
 615                  IndicationResult* ir = actual->head;
 616                  while (NULL != ir)
 617                  {
 618                      if (ir->bookmark)
 619                      {
 620                          const MI_Char* classname = NULL;
 621                          MI_Result r = MI_RESULT_OK;
 622                          MI_Boolean matchFound = MI_FALSE;
 623                          r = MI_Instance_GetClassName( ir->indication, &classname );
 624                          NitsCompare( r, MI_RESULT_OK, PAL_T("Unable to access classname") );
 625              
 626                          for ( MI_Uint32 i = 0; i < ats->targetclassCount; i ++ )
 627                          {
 628                              if (NULL != ats->targetclassConfig[i].subscribeBookmark)
 629                              {
 630                                  MI_Char* bm = ansiToMI( ats->targetclassConfig[i].subscribeBookmark );
 631 krisbash 1.1                     if (0 == Tcscmp(ir->bookmark, bm))
 632                                  {
 633                                      matchFound = MI_TRUE;
 634                                      break;
 635                                  }
 636                              }
 637                          }
 638                          NitsAssert( MI_TRUE == matchFound, PAL_T("bookmark could not be matched against expected values") );
 639                      }
 640                      ir = ir->next;
 641                  }
 642              }
 643              
 644              /*
 645              **==============================================================================
 646              **
 647              ** Validate subscribe result
 648              **
 649              **==============================================================================
 650              */
 651              static void _ValidateSubscribeResult(
 652 krisbash 1.1     _In_ AlertTestStruct* ats )
 653              {
 654                  OperationResult* actual = &ats->actual;
 655                  OperationResult* expect = &ats->expect;
 656                  NitsCompare(actual->finalResult, expect->finalResult, PAL_T("final result is not expected"));
 657                  NitsCompare(actual->numInstances, expect->numInstances, PAL_T("number of indication is not expected"));
 658              
 659                  /* Validate bookmarks if requested */
 660                  _VerifyBookmarks( ats );
 661              
 662                  /* Validate indication id property value */
 663                  /* NOTE: All indication classes with in the test provider contains id property */
 664                  /* the provider is located under $ROOT/samples/Providers/Test_Indication */
 665                  if (actual->numInstances > 0)
 666                  {
 667                      StringHashMap map;
 668                      
 669                      _BucketizeByClassName( &map, actual, expect->numInstances, MI_TRUE );
 670              
 671                      //
 672                      // Validate each class's indication count
 673 krisbash 1.1         //
 674                      MI_Uint32 indicationCountPerClass = ats->expect.numInstances / ats->targetclassCount;
 675                      for ( MI_Uint32 i = 0; i < ats->targetclassCount; i ++ )
 676                      {
 677                          MI_Char* cn = ansiToMI( ats->targetclassnames[i] );
 678                          NitsAssert( cn != NULL, PAL_T("Failed to convert classname to MI_Char string") );
 679                          StringBucket* b = StringHashMap_Find( &map, cn );
 680                          NitsAssert( b != NULL, PAL_T("Failed to find hash bucket for class") );
 681                          if ( b )
 682                          {
 683                              NitsCompare(indicationCountPerClass, b->count, PAL_T("Unexpected indication(s)' count"));
 684                              StringHashMap_Remove( &map, cn );
 685                          }
 686                      }
 687              
 688                      //
 689                      // Validate no class was left
 690                      //
 691                      {
 692                          size_t iter = 0;
 693                          const StringBucket* b = StringHashMap_Top( &map, &iter );
 694 krisbash 1.1             NitsAssert( b == NULL, PAL_T("Unexpect class left in the hashmap") );
 695                      }
 696                      StringHashMap_Destroy( &map );
 697                  }
 698                  /* TODO validate other results */
 699              }
 700              
 701              /*
 702              **==============================================================================
 703              **
 704              ** Config target class; Kick off subscribe request; Validate the result
 705              **
 706              **==============================================================================
 707              */
 708              static void Config_Subscribe_Validate(_In_ AlertTestStruct* ats)
 709              {
 710                  MI_Result miResult;
 711                  MI_OperationOptions miOperationOptions;
 712                  MI_Operation miOperation = MI_OPERATION_NULL;
 713                  MI_OperationCallbacks _callbacks = MI_OPERATIONCALLBACKS_NULL;
 714                  MI_OperationCallbacks *callbacks = NULL;
 715 krisbash 1.1     const MI_Char *nameSpace;
 716              
 717                  /* Cleanup actual result */
 718                  memset((void*)&ats->actual, 0, sizeof(ats->actual));
 719              
 720                  /* Configure target indciation class(es)' behavior */
 721                  miResult = _ConfigTargetClasses(ats);
 722                  if (miResult != MI_RESULT_OK)
 723                  {
 724                      NitsCompare(miResult, MI_RESULT_OK, PAL_T("Configure target class failed"));
 725                      return;
 726                  }
 727              
 728                  /* Kick off subscribe request */
 729                  if (ats->sync == MI_FALSE)
 730                  {
 731                      _callbacks.callbackContext = ats;
 732                      _callbacks.indicationResult = _IndicationResultCallback;
 733                      callbacks = &_callbacks;
 734                      ats->finished = 0;
 735                  }
 736 krisbash 1.1 
 737                  nameSpace = ats->nameSpace;
 738              
 739                  miResult = _CreateOperationOptions(ats, &miOperationOptions);
 740                  if (miResult != MI_RESULT_OK)
 741                  {
 742                      NitsCompare(miResult, MI_RESULT_OK, PAL_T("creat OperationOptions failed"));
 743                      return;
 744                  }
 745              
 746                  MI_Session_Subscribe(&ats->session, 0, &miOperationOptions, nameSpace, ats->querylang, ats->queryexpr, NULL, callbacks, &miOperation);
 747                  _ConsumeIndicationResults(ats, &miOperation);
 748                  MI_Operation_Close(&miOperation);
 749                  MI_OperationOptions_Delete(&miOperationOptions);
 750              
 751                  /* Validate subscribe result */
 752                  _ValidateSubscribeResult(ats);
 753              }
 754              
 755              
 756              /*
 757 krisbash 1.1 **==============================================================================
 758              **
 759              ** Default test structure
 760              **
 761              **==============================================================================
 762              */
 763              static struct AlertTestStruct ATS1 = {
 764                  MI_FALSE,
 765                  MI_T("root/cimv2"),
 766                  MI_T("CQL"),
 767                  MI_T("SELECT * FROM R_INDICATIONC3"),
 768                  0,
 769                  1,
 770              };
 771              
 772              /*
 773              **==============================================================================
 774              **
 775              ** For following tests, each test case needs to run twice w.r.t.
 776              ** delivering mechanism of the indication - one sync, another async;
 777              **
 778 krisbash 1.1 ** To avoid the duplicate test code, following structure was introduced to
 779              ** indicate the way of deliver indication
 780              **
 781              **==============================================================================
 782              */
 783              struct Sync_Struct
 784              {
 785                  MI_Boolean sync;
 786              };
 787              
 788              NitsSetup1(IndicationDelivery_Sync, Sync_Struct, AlertTest_Setup, ATS1)
 789              {
 790                  NitsContext()->_Sync_Struct->sync = MI_TRUE;
 791              }
 792              NitsEndSetup
 793              
 794              NitsSetup1(IndicationDelivery_Async, Sync_Struct, AlertTest_Setup, ATS1)
 795              {
 796                  NitsContext()->_Sync_Struct->sync = MI_FALSE;
 797              }
 798              NitsEndSetup
 799 krisbash 1.1 
 800              NitsSplit2(IndicationDelivery_Method, Sync_Struct, IndicationDelivery_Sync, IndicationDelivery_Async)
 801              NitsEndSplit
 802              
 803              
 804              /*
 805              **==============================================================================
 806              **
 807              ** Setup function, it is called before running each test case
 808              ** NOTE: for "nits -fault" run, this function will be called once and only once
 809              ** for each test case.
 810              **
 811              **==============================================================================
 812              */
 813              NitsSetup0(AlertTest_StartServer_Setup, AlertTestStruct)
 814                  /*
 815                   * MI_Application_Intialize create global log file handler _os,
 816                   * MI_Application_Close closes it,
 817                   * thus the test case needs to make sure not closing _os while
 818                   * there are active MI_Application(s) objects
 819                   */
 820 krisbash 1.1     NitsAssert( StartServer_Assert() == MI_RESULT_OK, PAL_T(" Failed to start server "));
 821                  _setup(NitsContext()->_AlertTestStruct);
 822              NitsEndSetup
 823              
 824              /*
 825              **==============================================================================
 826              **
 827              ** Cleanup function, it is called after run each test case
 828              ** NOTE: for "nits -fault" run, this function will be called once and only once
 829              ** for each test case.
 830              **
 831              **==============================================================================
 832              */
 833              NitsCleanup(AlertTest_StartServer_Setup)
 834                  /*
 835                   * MI_Application_Intialize create global log file handler _os
 836                   * MI_Application_Close closes it,
 837                   * thus the test case needs to make sure not closing _os while
 838                   * there are active MI_Application(s) objects
 839                   */
 840                  NitsAssert( StopServer_Assert() == MI_RESULT_OK, PAL_T(" Failed to stop server "));
 841 krisbash 1.1     _cleanup (NitsContext()->_AlertTestStruct);
 842              NitsEndCleanup
 843              
 844              /*
 845              **==============================================================================
 846              **
 847              ** One alert indication class
 848              **
 849              **==============================================================================
 850              */
 851              NitsTest1(Test_Alert_OneClass_Success, AlertTest_StartServer_Setup, ATS1)
 852              {
 853                  //
 854                  // There are issues in product code (such as protocol.c:_ProtocolSocket_Aux_ConnectEvent)
 855                  // does not handle out of memory (fault injection case), we cannot enable fault injection
 856                  // until those issues are fixed
 857                  //
 858                  NitsDisableFaultSim;
 859              
 860                  AlertTestStruct* ats = NitsContext()->_AlertTest_StartServer_Setup->_AlertTestStruct;
 861                  ats->sync = MI_TRUE;
 862 krisbash 1.1     const char* classname = "R_INDICATIONC3";
 863                  ats->targetclassnames = &classname;
 864                  MI_Uint32 indicationCount = 20;
 865                  MI_Uint32 intervalMS = 1;
 866              
 867                  SetConfig(&ats->targetclassConfig[0],
 868                      (char*)classname, /* className */
 869                      0, /* testGroup */
 870                      intervalMS, /* intervalMS */
 871                      indicationCount, /* failAfterCount */
 872                      MI_RESULT_FAILED, /* failResult */
 873                      0, /* initBehavior */
 874                      MI_RESULT_OK, /* initResultCode */
 875                      0, /* initTimeoutMS */
 876                      0, /* finalizeBehavior */
 877                      MI_RESULT_OK, /* finalizeResultCode */
 878                      0, /* postBehavior */
 879                      0, /* miscTestSubGroup */
 880                      "TestSubscribeBookmark", /* subscribeBookmark */
 881                      NULL, /* providerBookmark */
 882                      NULL, /* dialect */
 883 krisbash 1.1         NULL, /* expression */
 884                      0, /* evalResult */
 885                      0, /* logLoadUnloadCall */
 886                      0, /* currentSubscriptionTypes */
 887                      0 /* MI_Uint32 supportedSubscriptionTypes */);
 888              
 889                  //
 890                  // Final result aggregated by mgrstand.c:SubscribeElem
 891                  // if all indication class (provider) post OK during unsubscribe call,
 892                  // then final result is MI_RESULT_OK;
 893                  // current Test_Indication class do post MI_RESULT_OK during unsubscribe
 894                  //  call, thus the expected result is OK
 895                  //
 896                  memset((void*)&ats->expect, 0, sizeof(OperationResult));
 897                  ats->expect.finalResult = MI_RESULT_OK;
 898                  ats->expect.numInstances = indicationCount;
 899                  Config_Subscribe_Validate(ats);
 900              }
 901              NitsEndTest
 902              
 903              /*
 904 krisbash 1.1 **==============================================================================
 905              **
 906              ** Complex alert indication class
 907              **
 908              **==============================================================================
 909              */
 910              static struct AlertTestStruct ATS2 = {
 911                  MI_FALSE,
 912                  MI_T("root/cimv2"),
 913                  MI_T("CQL"),
 914                  MI_T("SELECT * FROM Test_INDICATION"),
 915                  0,
 916                  1,
 917              };
 918              
 919              NitsTest1(Test_Alert_ComplexClass_Success, AlertTest_StartServer_Setup, ATS2)
 920              {
 921                  //
 922                  // There are issues in product code (such as protocol.c:_ProtocolSocket_Aux_ConnectEvent)
 923                  // does not handle out of memory (fault injection case), we cannot enable fault injection
 924                  // until those issues are fixed
 925 krisbash 1.1     //
 926                  NitsDisableFaultSim;
 927              
 928                  AlertTestStruct* ats = NitsContext()->_AlertTest_StartServer_Setup->_AlertTestStruct;
 929                  ats->sync = MI_TRUE;
 930                  const char* classname = "Test_INDICATION";
 931                  ats->targetclassnames = &classname;
 932                  MI_Uint32 indicationCount = 10;
 933                  MI_Uint32 intervalMS = 0;
 934              
 935                  SetConfig(&ats->targetclassConfig[0],
 936                      (char*)classname, /* className */
 937                      0, /* testGroup */
 938                      intervalMS, /* intervalMS */
 939                      indicationCount, /* failAfterCount */
 940                      MI_RESULT_FAILED, /* failResult */
 941                      0, /* initBehavior */
 942                      MI_RESULT_OK, /* initResultCode */
 943                      0, /* initTimeoutMS */
 944                      0, /* finalizeBehavior */
 945                      MI_RESULT_OK, /* finalizeResultCode */
 946 krisbash 1.1         0, /* postBehavior */
 947                      0, /* miscTestSubGroup */
 948                      NULL, /* subscribeBookmark */
 949                      NULL, /* providerBookmark */
 950                      NULL, /* dialect */
 951                      NULL, /* expression */
 952                      0, /* evalResult */
 953                      0, /* logLoadUnloadCall */
 954                      0, /* currentSubscriptionTypes */
 955                      0 /* MI_Uint32 supportedSubscriptionTypes */);
 956              
 957                  //
 958                  // Final result aggregated by mgrstand.c:SubscribeElem
 959                  // if all indication class (provider) post OK during unsubscribe call,
 960                  // then final result is MI_RESULT_OK;
 961                  // current Test_Indication class do post MI_RESULT_OK during unsubscribe
 962                  //  call, thus the expected result is OK
 963                  //
 964                  memset((void*)&ats->expect, 0, sizeof(OperationResult));
 965                  ats->expect.finalResult = MI_RESULT_OK;
 966                  ats->expect.numInstances = 10;
 967 krisbash 1.1     Config_Subscribe_Validate(ats);
 968              }
 969              NitsEndTest
 970              
 971              /*
 972              **==============================================================================
 973              **
 974              ** Multiple class success
 975              **
 976              **==============================================================================
 977              */
 978              NitsTest1(Test_Alert_PolymorphismClasses_Success, AlertTest_StartServer_Setup, ATS1)
 979              {
 980                  //
 981                  // There are issues in product code (such as protocol.c:_ProtocolSocket_Aux_ConnectEvent)
 982                  // does not handle out of memory (fault injection case), we cannot enable fault injection
 983                  // until those issues are fixed
 984                  //
 985                  NitsDisableFaultSim;
 986              
 987                  AlertTestStruct* ats = NitsContext()->_AlertTest_StartServer_Setup->_AlertTestStruct;
 988 krisbash 1.1     MI_Uint32 failAfterCount = 5;
 989                  MI_Uint32 intervalMS = 1;
 990                  MI_Uint32 classCount = g_classcount_All;
 991                  ats->targetclassnames = g_AlertIndicationClassNames_All;
 992                  ats->targetclassCount = classCount;
 993                  ats->querylang = MI_T("WQL");
 994                  ats->queryexpr = MI_T("SELECT * FROM L_INDICATION");
 995                  ats->sync = MI_FALSE;
 996              
 997                  SetConfigs(classCount,
 998                      (Config*)ats->targetclassConfig,
 999                      ats->targetclassnames, /* className */
1000                      0, /* testGroup */
1001                      intervalMS, /* intervalMS */
1002                      failAfterCount, /* failAfterCount */
1003                      MI_RESULT_FAILED, /* failResult */
1004                      0, /* initBehavior */
1005                      MI_RESULT_OK, /* initResultCode */
1006                      0, /* initTimeoutMS */
1007                      0, /* finalizeBehavior */
1008                      MI_RESULT_OK, /* finalizeResultCode */
1009 krisbash 1.1         0, /* postBehavior */
1010                      0, /* miscTestSubGroup */
1011                      NULL, /* subscribeBookmark */
1012                      NULL, /* providerBookmark */
1013                      NULL, /* dialect */
1014                      NULL, /* expression */
1015                      0, /* evalResult */
1016                      0, /* logLoadUnloadCall */
1017                      0, /* currentSubscriptionTypes */
1018                      0 /* MI_Uint32 supportedSubscriptionTypes */);
1019              
1020                  //
1021                  // Final result aggregated by mgrstand.c:SubscribeElem
1022                  // if all indication class (provider) post OK during unsubscribe call,
1023                  // then final result is MI_RESULT_OK;
1024                  // current Test_Indication class do post MI_RESULT_OK during unsubscribe
1025                  //  call, thus the expected result is OK
1026                  //
1027                  memset((void*)&ats->expect, 0, sizeof(OperationResult));
1028                  ats->expect.finalResult = MI_RESULT_OK;
1029                  ats->expect.numInstances = failAfterCount * classCount;
1030 krisbash 1.1 
1031                  Config_Subscribe_Validate(ats);
1032              }
1033              NitsEndTest
1034              
1035              /* Synchronously invoke ThreadControl on the Lifecycle class to trigger
1036               * background posting of indications. */
1037              void _Lifecycle_InvokeThreadControl(
1038                  _In_ AlertTestStruct* ats,
1039                  _In_ const MI_Char* className,
1040                  _In_ const MI_Char* key,
1041                  _In_ MI_Uint32 operation )
1042              {
1043                  MI_Operation miOperation = MI_OPERATION_NULL;
1044                  MI_Result miResult = MI_RESULT_OK;
1045                  MI_Instance* lifecycleInstance = NULL;
1046                  MI_Instance* params = NULL;
1047                  MI_Value value;
1048              
1049                  /* Initialize instance to invoke method upon */
1050                  {
1051 krisbash 1.1         miResult = MI_Application_NewInstance( 
1052                          &ats->app,
1053                          className,
1054                          NULL,
1055                          &lifecycleInstance );
1056                      NitsCompare( miResult, MI_RESULT_OK, PAL_T("Failed to create lifecycle instance for invoke") );
1057                      if (MI_RESULT_OK != miResult)
1058                          goto Life_InvokeThreadControl_DONE;
1059              
1060                      value.string = (MI_Char*)key;
1061                      miResult = MI_Instance_AddElement( lifecycleInstance, MI_T("key"), &value, MI_STRING, MI_FLAG_KEY );
1062                      NitsCompare( miResult, MI_RESULT_OK, PAL_T("Failed to add operation to lifecycle instance") );
1063                      if (MI_RESULT_OK != miResult)
1064                          goto Life_InvokeThreadControl_DONE;
1065                  }
1066              
1067                  /* Initialize parameters to invoke method upon */
1068                  {
1069                      miResult = MI_Application_NewParameterSet( &ats->app, NULL, &params);
1070                      NitsCompare( miResult, MI_RESULT_OK, PAL_T("Unable to allocate param set") );
1071                      if (MI_RESULT_OK != miResult)
1072 krisbash 1.1             goto Life_InvokeThreadControl_DONE;
1073              
1074                      value.uint32 = operation;
1075                      miResult = MI_Instance_AddElement( params, MI_T("operation"), &value, MI_UINT32, 0 );
1076                      NitsCompare( miResult, MI_RESULT_OK, PAL_T("Failed to add operation to lifecycle instance") );
1077                      if (MI_RESULT_OK != miResult)
1078                          goto Life_InvokeThreadControl_DONE;
1079                  }
1080              
1081                  MI_Session_Invoke(
1082                      &ats->session,
1083                      0,
1084                      NULL,
1085                      ats->nameSpace,
1086                      className,
1087                      MI_T("ThreadControl"),
1088                      lifecycleInstance,
1089                      params,
1090                      NULL,
1091                      &miOperation );
1092              
1093 krisbash 1.1     miResult = _ConsumeInstanceResults( &miOperation );
1094                  NitsCompare( MI_RESULT_OK, miResult, PAL_T("Error while getting results from InvokeThreadControl") );
1095                  MI_Operation_Close(&miOperation);
1096              
1097              Life_InvokeThreadControl_DONE:
1098                  if (lifecycleInstance)
1099                      MI_Instance_Delete( lifecycleInstance );
1100              
1101                  if (params)
1102                      MI_Instance_Delete( params );
1103              }
1104              
1105              /*
1106              **==============================================================================
1107              **
1108              ** Validate subscribe result for lifecycle indications
1109              **
1110              **==============================================================================
1111              */
1112              static void _ValidateLifecycleResult(
1113                  _In_ AlertTestStruct* ats )
1114 krisbash 1.1 {
1115                  OperationResult* actual = &ats->actual;
1116                  OperationResult* expect = &ats->expect;
1117                  NitsCompare(actual->finalResult, expect->finalResult, PAL_T("final result is not expected"));
1118                  NitsCompare(actual->numInstances, expect->numInstances, PAL_T("number of indication is not expected"));
1119              
1120                  /* Validate indication id property value */
1121                  /* NOTE: All indication classes with in the test provider contains id property */
1122                  /* the provider is located under $ROOT/samples/Providers/Test_Indication */
1123                  if (actual->numInstances > 0)
1124                  {
1125                      StringHashMap map;
1126                      
1127                      _BucketizeByClassName( &map, actual, expect->numInstances, MI_FALSE );
1128              
1129                      //
1130                      // Validate each class's indication count
1131                      //
1132                      MI_Uint32 createCount = 0;
1133                      for ( MI_Uint32 i = 0; i < ats->targetclassCount; i ++ )
1134                      {
1135 krisbash 1.1             if (ats->targetclassConfig[i].currentSubscriptionTypes & MI_LIFECYCLE_INDICATION_CREATE)
1136                              createCount += (ats->targetclassCount * ats->targetclassConfig[i].failAfterCount);
1137                          // TODO: Add other counts when needed
1138                      }
1139              
1140                      if (createCount > 0)
1141                      {
1142                          StringBucket* b = StringHashMap_Find( &map, MI_T("CIM_InstCreation") );
1143                          NitsAssert( b != NULL, PAL_T("Failed to find hash bucket for CIM_InstCreation") );
1144                          if ( b )
1145                          {
1146                              NitsCompare(createCount, b->count, PAL_T("Unexpected indication(s)' count"));
1147                              StringHashMap_Remove( &map, MI_T("CIM_InstCreation") );
1148                          }
1149                      }
1150              
1151                      //
1152                      // Validate no class was left
1153                      //
1154                      {
1155                          size_t iter = 0;
1156 krisbash 1.1             const StringBucket* b = StringHashMap_Top( &map, &iter );
1157                          NitsAssert( b == NULL, PAL_T("Unexpect class left in the hashmap") );
1158                      }
1159                      StringHashMap_Destroy( &map );
1160                  }
1161                  /* TODO validate other results */
1162              }
1163              
1164              
1165              /*
1166              **==============================================================================
1167              **
1168              ** Config target lifecycle class; Kick off subscribe request; Validate the result
1169              **
1170              **==============================================================================
1171              */
1172              static void Lifecycle_Config_Subscribe_Validate(
1173                  _In_ AlertTestStruct* ats,
1174                  _In_ const MI_Char* classToFire )
1175              {
1176                  MI_Result miResult;
1177 krisbash 1.1     MI_OperationOptions miOperationOptions;
1178                  MI_Operation miOperation = MI_OPERATION_NULL;
1179                  MI_OperationCallbacks _callbacks = MI_OPERATIONCALLBACKS_NULL;
1180                  MI_OperationCallbacks *callbacks = NULL;
1181                  const MI_Char *nameSpace;
1182              
1183                  /* Cleanup actual result */
1184                  memset((void*)&ats->actual, 0, sizeof(ats->actual));
1185              
1186                  /* Configure target indciation class(es)' behavior */
1187                  miResult = _ConfigTargetClasses(ats);
1188                  if (miResult != MI_RESULT_OK)
1189                  {
1190                      NitsCompare(miResult, MI_RESULT_OK, PAL_T("Configure target class failed"));
1191                      return;
1192                  }
1193              
1194                  /* Kick off subscribe request */
1195                  if (ats->sync == MI_FALSE)
1196                  {
1197                      _callbacks.callbackContext = ats;
1198 krisbash 1.1         _callbacks.indicationResult = _IndicationResultCallback;
1199                      callbacks = &_callbacks;
1200                      ats->finished = 0;
1201                  }
1202              
1203                  nameSpace = ats->nameSpace;
1204              
1205                  miResult = _CreateOperationOptions(ats, &miOperationOptions);
1206                  if (miResult != MI_RESULT_OK)
1207                  {
1208                      NitsCompare(miResult, MI_RESULT_OK, PAL_T("creat OperationOptions failed"));
1209                      return;
1210                  }
1211              
1212                  MI_Session_Subscribe(&ats->session, 0, &miOperationOptions, nameSpace, ats->querylang, ats->queryexpr, NULL, callbacks, &miOperation);
1213              
1214                  /* Invoke thread control to start the Lifecycle fire thread */
1215                  _Lifecycle_InvokeThreadControl( ats, classToFire, classToFire, MI_LIFECYCLE_INDICATION_CREATE );
1216                  
1217                  _ConsumeIndicationResults(ats, &miOperation);
1218                  MI_Operation_Close(&miOperation);
1219 krisbash 1.1     MI_OperationOptions_Delete(&miOperationOptions);
1220              
1221                  /* Validate subscribe result */
1222                  _ValidateLifecycleResult(ats);
1223              }
1224              
1225              
1226              /*
1227              **==============================================================================
1228              **
1229              ** One lifecycle indication class
1230              **
1231              **==============================================================================
1232              */
1233              static struct AlertTestStruct ATS_Lifecycle = {
1234                  MI_FALSE,
1235                  MI_T("root/cimv2"),
1236                  MI_T("CQL"),
1237                  MI_T("SELECT * FROM CIM_InstIndication WHERE SourceInstance ISA L_LifecycleC2"),  // Generic is Test_Class
1238                  0,
1239                  1,
1240 krisbash 1.1 };
1241              
1242              NitsTest1(Test_Lifecycle_OneClass_Success, AlertTest_StartServer_Setup, ATS_Lifecycle)
1243              {
1244                  //
1245                  // There are issues in product code (such as protocol.c:_ProtocolSocket_Aux_ConnectEvent)
1246                  // does not handle out of memory (fault injection case), we cannot enable fault injection
1247                  // until those issues are fixed
1248                  //
1249                  NitsDisableFaultSim;
1250              
1251                  AlertTestStruct* ats = NitsContext()->_AlertTest_StartServer_Setup->_AlertTestStruct;
1252                  ats->sync = MI_TRUE;
1253                  const char* classname = "L_LifecycleC2";
1254                  ats->targetclassnames = &classname;
1255                  ats->targetclassCount = 1;
1256                  MI_Uint32 indicationCount = 20;
1257                  MI_Uint32 intervalMS = 1;
1258              
1259                  SetConfig(&ats->targetclassConfig[0],
1260                      (char*)classname, /* className */
1261 krisbash 1.1         0, /* testGroup */
1262                      intervalMS, /* intervalMS */
1263                      indicationCount, /* failAfterCount */
1264                      MI_RESULT_FAILED, /* failResult */
1265                      0, /* initBehavior */
1266                      MI_RESULT_OK, /* initResultCode */
1267                      0, /* initTimeoutMS */
1268                      0, /* finalizeBehavior */
1269                      MI_RESULT_OK, /* finalizeResultCode */
1270                      0, /* postBehavior */
1271                      0, /* miscTestSubGroup */
1272                      NULL, /* subscribeBookmark */
1273                      NULL, /* providerBookmark */
1274                      NULL, /* dialect */
1275                      NULL, /* expression */
1276                      0, /* evalResult */
1277                      0, /* logLoadUnloadCall */
1278                      MI_LIFECYCLE_INDICATION_CREATE, /* currentSubscriptionTypes */
1279                      MI_LIFECYCLE_INDICATION_CREATE  /* MI_Uint32 supportedSubscriptionTypes */);
1280              
1281                  //
1282 krisbash 1.1     // Final result aggregated by mgrstand.c:SubscribeElem
1283                  // if all indication class (provider) post OK during unsubscribe call,
1284                  // then final result is MI_RESULT_OK;
1285                  // current Test_Indication class do post MI_RESULT_OK during unsubscribe
1286                  //  call, thus the expected result is OK
1287                  //
1288                  memset((void*)&ats->expect, 0, sizeof(OperationResult));
1289                  ats->expect.finalResult = MI_RESULT_OK;
1290                  ats->expect.numInstances = indicationCount;
1291                  Lifecycle_Config_Subscribe_Validate(ats, MI_T("L_LifecycleC2"));
1292              }
1293              NitsEndTest
1294              
1295              static struct AlertTestStruct ATS_Lifecycle_LeftClassC2 = {
1296                  MI_FALSE,
1297                  MI_T("root/cimv2"),
1298                  MI_T("CQL"),
1299                  MI_T("SELECT * FROM CIM_InstIndication WHERE SourceInstance ISA L_LifecycleC2"),
1300                  0,
1301                  1,
1302              };
1303 krisbash 1.1 
1304              const char* g_LifecycleIndicationClassNames_Left[] =
1305              {
1306                  "L_IndicationC1",
1307                  "L_IndicationC2"
1308              };
1309              MI_Uint32 g_LifecycleClassCount_Left = 2;
1310              
1311              NitsTest1(Test_Lifecycle_Complex_Success, AlertTest_StartServer_Setup, ATS_Lifecycle_LeftClassC2)
1312              {
1313                  //
1314                  // There are issues in product code (such as protocol.c:_ProtocolSocket_Aux_ConnectEvent)
1315                  // does not handle out of memory (fault injection case), we cannot enable fault injection
1316                  // until those issues are fixed
1317                  //
1318                  NitsDisableFaultSim;
1319              
1320                  AlertTestStruct* ats = NitsContext()->_AlertTest_StartServer_Setup->_AlertTestStruct;
1321                  ats->sync = MI_TRUE;
1322                  MI_Uint32 classCount = g_LifecycleClassCount_Left;
1323                  ats->targetclassnames = g_LifecycleIndicationClassNames_Left;
1324 krisbash 1.1     ats->targetclassCount = classCount;
1325                  MI_Uint32 failAfterCount = 5;
1326                  MI_Uint32 intervalMS = 1;
1327              
1328                  SetConfigs(classCount,
1329                      (Config*)ats->targetclassConfig,
1330                      ats->targetclassnames, /* className */
1331                      0, /* testGroup */
1332                      intervalMS, /* intervalMS */
1333                      failAfterCount, /* failAfterCount */
1334                      MI_RESULT_FAILED, /* failResult */
1335                      0, /* initBehavior */
1336                      MI_RESULT_OK, /* initResultCode */
1337                      0, /* initTimeoutMS */
1338                      0, /* finalizeBehavior */
1339                      MI_RESULT_OK, /* finalizeResultCode */
1340                      0, /* postBehavior */
1341                      0, /* miscTestSubGroup */
1342                      NULL, /* subscribeBookmark */
1343                      NULL, /* providerBookmark */
1344                      NULL, /* dialect */
1345 krisbash 1.1         NULL, /* expression */
1346                      0, /* evalResult */
1347                      0, /* logLoadUnloadCall */
1348                      MI_LIFECYCLE_INDICATION_CREATE, /* currentSubscriptionTypes */
1349                      MI_LIFECYCLE_INDICATION_CREATE /* MI_Uint32 supportedSubscriptionTypes */);
1350              
1351                  //
1352                  // Final result aggregated by mgrstand.c:SubscribeElem
1353                  // if all indication class (provider) post OK during unsubscribe call,
1354                  // then final result is MI_RESULT_OK;
1355                  // current Test_Indication class do post MI_RESULT_OK during unsubscribe
1356                  //  call, thus the expected result is OK
1357                  //
1358                  memset((void*)&ats->expect, 0, sizeof(OperationResult));
1359                  ats->expect.finalResult = MI_RESULT_OK;
1360                  ats->expect.numInstances = failAfterCount * classCount * 2;
1361                  
1362                  Lifecycle_Config_Subscribe_Validate(ats, MI_T("L_LifecycleC2"));
1363              }
1364              NitsEndTest
1365              
1366 krisbash 1.1 #endif
1367              

ViewCVS 0.9.2