void SMemFunctionalTests::testGreaterOrEqual()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testGreaterOrEqual", 1);
}
Exemple #2
0
int test_BR_LLSC_6_20_010(MYKI_BR_ContextData_t *pData)
{
    int rv = TRUE;
    CardImage_t CardImage;

    /*
    **  Test with
    */
    if (CreateCardImage_Empty(&CardImage) < 0)
    {
        return FALSE;
    }
    CreateProduct( &CardImage, 1, PRODUCT_ID_NHOUR, 1, 1, pData->DynamicData.currentDateTime );
    CardImage.pMYKI_TAControl->ProductInUse = 1;

    /*
    ** Setup Transport locations
    **      Not a Border Trip
    */
    pData->DynamicData.transportLocationsCount = 3;

    pData->DynamicData.transportLocations[0].inner_zone = 3;
    pData->DynamicData.transportLocations[0].zone = 3;
    pData->DynamicData.transportLocations[0].outer_zone = 4;

    pData->DynamicData.transportLocations[1].inner_zone = 4;
    pData->DynamicData.transportLocations[1].zone = 4;
    pData->DynamicData.transportLocations[1].outer_zone = 5;

    pData->DynamicData.transportLocations[2].inner_zone = 5;
    pData->DynamicData.transportLocations[2].zone = 6;
    pData->DynamicData.transportLocations[2].outer_zone = 6;

    /*
    **  Run the Test and examine the results
    */
    if (!runTest(pData, RULE_RESULT_EXECUTED, 302))
    {
        return FALSE;
    }

    /*
    ** Examine conditions
    */
    if (pData->DynamicData.transportLocationsCount)
    {
        CsVerbose("test_BR_LLSC_6_20 - transportLocationsCount NOT zero as expected" );
        rv = FALSE;
    }

    if (pData->DynamicData.currentTripZoneLow != 4)
    {
        CsVerbose("test_BR_LLSC_6_20 - currentTripZoneLow NOT as expected. Was:%d",pData->DynamicData.currentTripZoneLow );
        rv = FALSE;
    }

    if (pData->DynamicData.currentTripZoneHigh != 5)
    {
        CsVerbose("test_BR_LLSC_6_20 - currentTripZoneHigh NOT as expected. Was:%d",pData->DynamicData.currentTripZoneHigh );
        rv = FALSE;
    }

    return rv;
}
Exemple #3
0
int
main (int argc, char *argv[])
{
  int i = 0;
  CRITICAL_SECTION cs;
  old_mutex_t ox;
  pthread_mutexattr_init(&ma);

  printf( "=============================================================================\n");
  printf( "\nLock plus unlock on an unlocked mutex.\n%ld iterations\n\n",
          ITERATIONS);
  printf( "%-45s %15s %15s\n",
	    "Test",
	    "Total(msec)",
	    "average(usec)");
  printf( "-----------------------------------------------------------------------------\n");

  /*
   * Time the loop overhead so we can subtract it from the actual test times.
   */

  TESTSTART
  assert(1 == one);
  assert(1 == one);
  TESTSTOP

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  overHeadMilliSecs = durationMilliSecs;


  TESTSTART
  assert((dummy_call(&i), 1) == one);
  assert((dummy_call(&i), 1) == one);
  TESTSTOP

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;

  printf( "%-45s %15ld %15.3f\n",
	    "Dummy call x 2",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);


  TESTSTART
  assert((interlocked_inc_with_conditionals(&i), 1) == one);
  assert((interlocked_dec_with_conditionals(&i), 1) == one);
  TESTSTOP

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;

  printf( "%-45s %15ld %15.3f\n",
	    "Dummy call -> Interlocked with cond x 2",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);


  TESTSTART
  assert((InterlockedIncrement(&i), 1) == one);
  assert((InterlockedDecrement(&i), 1) == one);
  TESTSTOP

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;

  printf( "%-45s %15ld %15.3f\n",
	    "InterlockedOp x 2",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);


  InitializeCriticalSection(&cs);

  TESTSTART
  assert((EnterCriticalSection(&cs), 1) == one);
  assert((LeaveCriticalSection(&cs), 1) == one);
  TESTSTOP

  DeleteCriticalSection(&cs);

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;

  printf( "%-45s %15ld %15.3f\n",
	    "Simple Critical Section",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);


  old_mutex_use = OLD_WIN32CS;
  assert(old_mutex_init(&ox, NULL) == 0);

  TESTSTART
  assert(old_mutex_lock(&ox) == zero);
  assert(old_mutex_unlock(&ox) == zero);
  TESTSTOP

  assert(old_mutex_destroy(&ox) == 0);

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;

  printf( "%-45s %15ld %15.3f\n",
	    "Old PT Mutex using a Critical Section (WNT)",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);


  old_mutex_use = OLD_WIN32MUTEX;
  assert(old_mutex_init(&ox, NULL) == 0);

  TESTSTART
  assert(old_mutex_lock(&ox) == zero);
  assert(old_mutex_unlock(&ox) == zero);
  TESTSTOP

  assert(old_mutex_destroy(&ox) == 0);

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;

  printf( "%-45s %15ld %15.3f\n",
	    "Old PT Mutex using a Win32 Mutex (W9x)",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);

  printf( ".............................................................................\n");

  /*
   * Now we can start the actual tests
   */
#ifdef PTW32_MUTEX_TYPES
  runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);

  runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);

  runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);

  runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
#else
  runTest("Non-blocking lock", 0);
#endif

  printf( "=============================================================================\n");

  /*
   * End of tests.
   */

  pthread_mutexattr_destroy(&ma);

  return 0;
}
Exemple #4
0
TEST(WTF_Condition, TenProducersTenConsumersHundredSlotsNotifyAll)
{
    runTest(10, 10, 100, 50000, TacticallyNotifyAll);
}
Exemple #5
0
int test_BR_LLSC_6_20_008(MYKI_BR_ContextData_t *pData)
{
    int rv = TRUE;
    CardImage_t CardImage;

    pData->InternalData.TransportMode       = TRANSPORT_MODE_BUS;
    pData->DynamicData.lineId               = 1;
    pData->DynamicData.stopId               = 1;

    /*
    **  Test with
    */

    if ( CreateCardImage_Empty( &CardImage ) < 0 )
    {
        return FALSE;
    }

    CreateProduct( &CardImage, 1, PRODUCT_ID_NHOUR, 1, 1, pData->DynamicData.currentDateTime + 60 );    // Don't care but make it sensible

    CardImage.pMYKI_TAProduct[ 0 ]->LastUsage.DateTime = pData->DynamicData.currentDateTime - 60;       // Don't care but make it sensible
    CardImage.pMYKI_TAProduct[ 0 ]->LastUsage.Location.EntryPointId = 10500;    // Station ID
    CardImage.pMYKI_TAProduct[ 0 ]->LastUsage.Location.RouteId      = 0;        // Not set
    CardImage.pMYKI_TAProduct[ 0 ]->LastUsage.Location.StopId       = 0;        // Not set
    CardImage.pMYKI_TAProduct[ 0 ]->LastUsage.ProviderId            = 0;        // Rail provider
    CardImage.pMYKI_TAProduct[ 0 ]->LastUsage.Zone                  = 0;        // Don't care

    CardImage.pMYKI_TAControl->ProductInUse = 1;

    /*
    ** Setup Transport locations
    **      Not a Border Trip
    */
    pData->DynamicData.transportLocationsCount = 2;

    pData->DynamicData.transportLocations[0].inner_zone = 3;
    pData->DynamicData.transportLocations[0].zone = 3;
    pData->DynamicData.transportLocations[0].outer_zone = 4;

    pData->DynamicData.transportLocations[1].inner_zone = 4;
    pData->DynamicData.transportLocations[1].zone = 4;
    pData->DynamicData.transportLocations[1].outer_zone = 5;

    /*
    ** Forced Scan Off not set (testing scan-on/off modes of transport instead)
    */
     pData->DynamicData.isForcedScanOff = FALSE;

    /*
    **  Run the Test and examine the results
    */
    if (!runTest(pData, RULE_RESULT_EXECUTED, 102))
    {
        return FALSE;
    }

    /*
    ** Examine conditions
    */
    if (pData->DynamicData.transportLocationsCount)
    {
        CsVerbose("test_BR_LLSC_6_20 - transportLocationsCount NOT zero as expected" );
        rv = FALSE;
    }

    if (pData->DynamicData.currentTripZoneLow != 4)
    {
        CsVerbose("test_BR_LLSC_6_20 - currentTripZoneLow NOT as expected. Was:%d",pData->DynamicData.currentTripZoneLow );
        rv = FALSE;
    }

    if (pData->DynamicData.currentTripZoneHigh != 4)
    {
        CsVerbose("test_BR_LLSC_6_20 - currentTripZoneHigh NOT as expected. Was:%d",pData->DynamicData.currentTripZoneHigh );
        rv = FALSE;
    }

    return rv;
}
Exemple #6
0
int
main(void){

  srand(NdbTick_CurrentMillisecond());
#if 0
  for(int i = 0; i<100; i++)
    ndbout_c("randRange(0, 3) = %d", randRange(0, 3));
  return 0;
#endif
  SignalSender ss;
  
  ndbout << "Connecting...";
  if(!ss.connect(30)){
    ndbout << "failed" << endl << "Exiting" << endl;
    return 0;
  }
  ndbout << "done" << endl;
  ndbout_c("Connected as block=%d node=%d",
	   refToBlock(ss.getOwnRef()), refToNode(ss.getOwnRef()));
  
  Uint32 data[25];
  Uint32 sec0[70];
  Uint32 sec1[123];
  Uint32 sec2[10];
  
  data[0] = ss.getOwnRef();
  data[1] = 1;
  data[2] = 76; 
  data[3] = 1;
  data[4] = 1;
  data[5] = 70;
  data[6] = 123;
  data[7] = 10;
  const Uint32 theDataLen = 18;

  for(Uint32 i = 0; i<70; i++)
    sec0[i] = i;
  
  for(Uint32 i = 0; i<123; i++)
    sec1[i] = 70+i;

  for(Uint32 i = 0; i<10; i++)
    sec2[i] = (i + 1)*(i + 1);
  
  SimpleSignal signal1;
  signal1.set(ss, 0, CMVMI, GSN_TESTSIG, theDataLen + 2);  
  signal1.header.m_noOfSections = 1;
  signal1.header.m_fragmentInfo = 1;

  memcpy(&signal1.theData[0], data, 4 * theDataLen );
  signal1.theData[theDataLen + 0] = 0;
  signal1.theData[theDataLen + 1] = 7; // FragmentId
  
  signal1.ptr[0].sz = 60;
  signal1.ptr[0].p = &sec0[0];
  
  SimpleSignal signal2;
  
  Uint32 idx = 0;
  memcpy(&signal2.theData[0], data, 4 * theDataLen );
  signal2.theData[theDataLen + idx] = 0; idx++;
  signal2.theData[theDataLen + idx] = 1; idx++;
  //signal2.theData[theDataLen + idx] = 2; idx++;
  signal2.theData[theDataLen + idx] = 7; idx++; // FragmentId

  signal2.set(ss, 0, CMVMI, GSN_TESTSIG, theDataLen + idx);
  signal2.header.m_fragmentInfo = 3;
  signal2.header.m_noOfSections = idx - 1;
  
  signal2.ptr[0].sz = 10;
  signal2.ptr[0].p = &sec0[60];
  
  signal2.ptr[1].sz = 123;
  signal2.ptr[1].p = &sec1[0];
  
  signal2.ptr[2].sz = 10;
  signal2.ptr[2].p = &sec2[0];
  
  char * buf;
  while((buf = readline("Enter command: "))){
    add_history(buf);
    data[1] = atoi(buf);
    if(strcmp(buf, "r") == 0){
      SimpleSignal * ret1 = ss.waitFor();
      (* ret1).print();
      delete ret1;
      continue;
    }
    if(strcmp(buf, "a") == 0){
      runTest(ss, 10, true);
      print_help();
      continue;
    }
    if(strcmp(buf, "b") == 0){
      runTest(ss, 100, false);
      print_help();
      continue;
    }
    if(strcmp(buf, "c") == 0){
      runTest(ss, 1000000, false);
      print_help();
      continue;
    }
    
    if(data[1] >= 1 && data[1] <= 12){
      Uint32 nodeId = ss.getAliveNode();
      ndbout_c("Sending 2 fragmented to node %d", nodeId);
      ss.sendSignal(nodeId, &signal1);
      ss.sendSignal(nodeId, &signal2);

      if(data[1] >= 5){
	continue;
      }
      ndbout_c("Waiting for signal from %d", nodeId);
      
      SimpleSignal * ret1 = ss.waitFor((Uint16)nodeId);
      (* ret1).print();
      Uint32 count = ret1->theData[4] - 1;
      delete ret1;
      while(count > 0){
	ndbout << "Waiting for " << count << " signals... ";
	SimpleSignal * ret1 = ss.waitFor();
	ndbout_c("received from node %d", 
		 refToNode(ret1->header.theSendersBlockRef));
	(* ret1).print();
	delete ret1;
	count--;
      }
    } else if (data[1] == 13) {
      const Uint32 count = 3500;
      const Uint32 loop = 1000;

      signal1.set(ss, 0, CMVMI, GSN_TESTSIG, 25);
      signal1.header.m_fragmentInfo = 0;
      signal1.header.m_noOfSections = 0;
      signal1.theData[1] = 14; 
      signal1.theData[3] = 0;   // Print
      signal1.theData[8] = count;
      signal1.theData[9] = loop;
      Uint32 nodeId = ss.getAliveNode();
      ndbout_c("Sending 25 len signal to node %d", nodeId);
      ss.sendSignal(nodeId, &signal1);

      Uint32 total;
      {
	SimpleSignal * ret1 = ss.waitFor((Uint16)nodeId);
	ndbout_c("received from node %d", 
		 refToNode(ret1->header.theSendersBlockRef));
	total = ret1->theData[10] - 1;
	delete ret1;
      }

      do {
	ndbout << "Waiting for " << total << " signals... " << flush;
	SimpleSignal * ret1 = ss.waitFor((Uint16)nodeId);
	ndbout_c("received from node %d", 
		 refToNode(ret1->header.theSendersBlockRef));
	delete ret1;
	total --;
      } while(total > 0);
    } else {
      print_help();
    }
  }
  ndbout << "Exiting" << endl;
};
Exemple #7
0
TEST(WTF_Condition, OneProducerOneConsumerHundredSlots)
{
    runTest(1, 1, 100, 1000000, TacticallyNotifyAll);
}
void SMemFunctionalTests::testNegStringFloat()
{
	runTest("testNegStringFloat", 5);
}
void SMemFunctionalTests::testNegQueryNoHash()
{
	runTest("testNegQueryNoHash", 1);
}
void SMemFunctionalTests::testSimpleNonCueBasedRetrievalOfNonExistingLTI()
{
	runTest("testSimpleNonCueBasedRetrievalOfNonExistingLTI", 1);
}
void SMemFunctionalTests::testNegQuery()
{
	runTest("testNegQuery", 248);
}
void SMemFunctionalTests::testMaxDoublePrecision()
{
	runTest("testMaxDoublePrecision", 5);
}
void SMemFunctionalTests::testMaxDoublePrecision_Irrational()
{
	runTest("testMaxDoublePrecision-Irrational", 5);
}
void SMemFunctionalTests::testSimpleFloat()
{
	runTest("testSimpleFloat", 5);
}
void SMemFunctionalTests::testLess()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testLess", 1);
}
void SMemFunctionalTests::testSimpleNonCueBasedRetrieval()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testSimpleNonCueBasedRetrieval", 2);
}
Exemple #17
0
int main(int argc, const char * argv[])
{
    printf("XPC Tests-c ");
    
#ifdef _WIN32
    printf("(Windows)\n");
#elif (__APPLE__)
    printf("(Mac) \n");
#elif (__linux)
    printf("(Linux) \n");
#else
	printf("(Unable to determine operating system) \n")
#endif
    
	// Basic Networking
	runTest(testOpen, "open");
	runTest(testClose, "close");
	// Datarefs
	runTest(testGETD_Basic, "GETD");
	runTest(testGETD_Types, "GETD (types)");
	runTest(testGETD_TestFloat, "GETD (test float)");
	runTest(testDREF, "DREF");
	// Pause
	runTest(testSIMU_Basic, "SIMU");
	runTest(testSIMU_Toggle, "SIMU (toggle)");
	// CTRL
	runTest(testCTRL_Player, "CTRL (player)");
	runTest(testCTRL_NonPlayer, "CTRL (non-player)");
	runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)");
	// POSI
	runTest(testPOSI_Player, "POSI (player)");
	runTest(testPOSI_NonPlayer, "POSI (non-player)");
	// Data
	runTest(testDATA, "DATA");
	// Text
	runTest(testTEXT, "TEXT");
	// Waypoints
	runTest(testWYPT, "WYPT");
	// View
	runTest(testView, "VIEW");
	// setConn
	runTest(testCONN, "CONN");
    
    printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed );
	printf("Press any key to exit.");
	getchar();
    
    return 0;
}
void SMemFunctionalTests::testSimpleStore()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testSimpleStore", 2);
}
Exemple #19
0
int
main (int argc, char *argv[])
{
  pthread_mutexattr_init(&ma);

  printf( "=============================================================================\n");
  printf( "Trylock plus unlock on an unlocked mutex.\n");
  printf( "%ld iterations.\n\n", ITERATIONS);
  printf( "%-45s %15s %15s\n",
	    "Test",
	    "Total(msec)",
	    "average(usec)");
  printf( "-----------------------------------------------------------------------------\n");

  /*
   * Time the loop overhead so we can subtract it from the actual test times.
   */

  TESTSTART
  TESTSTOP

  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  overHeadMilliSecs = durationMilliSecs;

  old_mutex_use = OLD_WIN32CS;
  assert(old_mutex_init(&ox, NULL) == 0);
  TESTSTART
  (void) old_mutex_trylock(&ox);
  (void) old_mutex_unlock(&ox);
  TESTSTOP
  assert(old_mutex_destroy(&ox) == 0);
  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  printf( "%-45s %15ld %15.3f\n",
	    "Old PT Mutex using a Critical Section (WNT)",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);

  old_mutex_use = OLD_WIN32MUTEX;
  assert(old_mutex_init(&ox, NULL) == 0);
  TESTSTART
  (void) old_mutex_trylock(&ox);
  (void) old_mutex_unlock(&ox);
  TESTSTOP
  assert(old_mutex_destroy(&ox) == 0);
  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  printf( "%-45s %15ld %15.3f\n",
	    "Old PT Mutex using a Win32 Mutex (W9x)",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS);

  printf( ".............................................................................\n");

  /*
   * Now we can start the actual tests
   */
#ifdef  __PTW32_MUTEX_TYPES
  runTest("PTHREAD_MUTEX_DEFAULT", PTHREAD_MUTEX_DEFAULT);

  runTest("PTHREAD_MUTEX_NORMAL", PTHREAD_MUTEX_NORMAL);

  runTest("PTHREAD_MUTEX_ERRORCHECK", PTHREAD_MUTEX_ERRORCHECK);

  runTest("PTHREAD_MUTEX_RECURSIVE", PTHREAD_MUTEX_RECURSIVE);
#else
  runTest("Non-blocking lock", 0);
#endif

  printf( ".............................................................................\n");

  pthread_mutexattr_setrobust(&ma, PTHREAD_MUTEX_ROBUST);

#ifdef  __PTW32_MUTEX_TYPES
  runTest("PTHREAD_MUTEX_DEFAULT (Robust)", PTHREAD_MUTEX_DEFAULT);

  runTest("PTHREAD_MUTEX_NORMAL (Robust)", PTHREAD_MUTEX_NORMAL);

  runTest("PTHREAD_MUTEX_ERRORCHECK (Robust)", PTHREAD_MUTEX_ERRORCHECK);

  runTest("PTHREAD_MUTEX_RECURSIVE (Robust)", PTHREAD_MUTEX_RECURSIVE);
#else
  runTest("Non-blocking lock", 0);
#endif

  printf( "=============================================================================\n");

  /*
   * End of tests.
   */

  pthread_mutexattr_destroy(&ma);

  return 0;
}
void SMemFunctionalTests::testISupport()
{
	runTest("smem-i-support", 6);
}
Exemple #21
0
TEST(WTF_Condition, TenProducersTenConsumersOneSlot)
{
    runTest(10, 10, 1, 50000, TacticallyNotifyAll);
}
void SMemFunctionalTests::testISupportWithLearning()
{
	std::string result = agent->ExecuteCommandLine("chunk always") ;
	runTest("smem-i-support", 6);
}
Exemple #23
0
TEST(WTF_Condition, TenProducersTenConsumersHundredSlotsNotifyOne)
{
    runTest(10, 10, 100, 50000, AlwaysNotifyOne);
}
void SMemFunctionalTests::testBadMathQuery()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testBadMathQuery", 2);
}
Exemple #25
0
int test_BR_LLSC_6_20_009(MYKI_BR_ContextData_t *pData)
{
    int rv = TRUE;
    CardImage_t CardImage;
    MYKI_CD_DifferentialPricing_t differentialPricing;

    /*
    **  Test with
    */
    if (CreateCardImage_Empty(&CardImage) < 0)
    {
        return FALSE;
    }
    CreateProduct( &CardImage, 1, PRODUCT_ID_NHOUR, 1, 1, pData->DynamicData.currentDateTime );
    CardImage.pMYKI_TAControl->ProductInUse = 1;

    /*
    ** Setup Transport locations
    **      Not a Border Trip
    */
    pData->DynamicData.transportLocationsCount = 2;

    pData->DynamicData.transportLocations[0].inner_zone = 3;
    pData->DynamicData.transportLocations[0].zone = 3;
    pData->DynamicData.transportLocations[0].outer_zone = 4;

    pData->DynamicData.transportLocations[1].inner_zone = 4;
    pData->DynamicData.transportLocations[1].zone = 4;
    pData->DynamicData.transportLocations[1].outer_zone = 5;

    /*
    ** Setup a Differential Price to be processed by the Rule
    */
    differentialPricing.discount_type = MYKI_CD_DISCOUNT_TYPE_PERCENT;
    differentialPricing.applied_discount = 33;
    strcpy(differentialPricing.short_desc,"Test 008");

    MYKI_CD_setDifferentialPriceStructure(&differentialPricing);

    /*
    **  Run the Test and examine the results
    */
    if (!runTest(pData, RULE_RESULT_EXECUTED, 202))
    {
        return FALSE;
    }

    /*
    ** Examine conditions
    */
    if (pData->DynamicData.transportLocationsCount)
    {
        CsVerbose("test_BR_LLSC_6_20 - transportLocationsCount NOT zero as expected" );
        rv = FALSE;
    }

    if (pData->DynamicData.currentTripZoneLow != 4)
    {
        CsVerbose("test_BR_LLSC_6_20 - currentTripZoneLow NOT as expected. Was:%d",pData->DynamicData.currentTripZoneLow );
        rv = FALSE;
    }

    if (pData->DynamicData.currentTripZoneHigh != 4)
    {
        CsVerbose("test_BR_LLSC_6_20 - currentTripZoneHigh NOT as expected. Was:%d",pData->DynamicData.currentTripZoneHigh );
        rv = FALSE;
    }

    if (pData->DynamicData.offPeakDiscountRate != 33)
    {
        CsVerbose("test_BR_LLSC_6_20 - offPeakDiscountRate NOT as expected" );
        rv = FALSE;
    }

    if (pData->DynamicData.isOffPeak != TRUE)
    {
        CsVerbose("test_BR_LLSC_6_20 - isOffPeak NOT as expected" );
        rv = FALSE;
    }

    return rv;
}
void SMemFunctionalTests::testMaxMultivalued()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testMaxMultivalued", 1);
}
Exemple #27
0
static void testWebKitDOMXPathNSResolverCustom(WebViewTest* test, gconstpointer)
{
    test->loadURI(kServer->getURIForPath("/custom").data());
    test->waitUntilLoadFinished();
    runTest(test, "custom");
}
void SMemFunctionalTests::testMaxNegQuery()
{
	SoarHelper::setStopPhase(agent, SoarHelper::StopPhase::OUTPUT);
	runTest("testMaxNegation", 1);
}
Exemple #29
0
int main (int argc, char** argv) {
    if(argc < 4) {
        std::cout << "3 command line arguments are needed.\nPlease execute with ./hw0 <input_filename> <process #> <number of match list>\n";
        return 0;
    }
    FILE* fPtr; //file pointer to file to be parsed
    char *line; //line to parse file line by line

    fPtr = fopen(argv[1], "r");
    int total_rows = 0;
    line = (char*)malloc(sizeof(char)*LINE_MAX);
    VectorsMap points;
    Parser fileParser;
    //vectors that will be generated for the runs.
    std::vector<std::vector<float>> generated_vectors(30);

    //parse the file line by line
    while(fgets(line, LINE_MAX, fPtr)) {
        //make sure that we do not read an empty line
        if(line[0] != '\0') {
            //send the line to be further parsed
            points.push_back(fileParser.parseLine(line));
            //increment total rows count
            total_rows++;
        }
    }
    free(line);
    fclose(fPtr);

    srand(34122);
    int i,j, process_count=atoi(argv[2]), num_max=atoi(argv[3]), size=0;
    //the size of the search vectors
    int sizes[] = {9,11,17,29};
    int sizes_count = 4;
    //will hold the offsets for each process
    std::vector<segment> segments(process_count);

    //initialize shared memory
    size_t memory_space = process_count*4*num_max;
    float shm_size = memory_space * sizeof(float);
    int shmId;
    // use current time as seed for random generator
    std::srand(std::time(0));
    key_t shmKey = std::rand();
    int shmFlag = IPC_CREAT | 0666;
    float * shm;

    /* Initialize shared memory */
    if((shmId = shmget(shmKey, shm_size, shmFlag)) < 0)
    {
        std::cerr << "Init: Failed to initialize shared memory (" << shmId << ")" << std::endl;
        exit(1);
    }

    if((shm = (float *)shmat(shmId, NULL, 0)) == (float *) -1)
    {
        std::cerr << "Init: Failed to attach shared memory (" << shmId << ")" << std::endl;
        exit(1);
    }
    //get number of items for each process in shared memory
    const unsigned int per_procc_mem = num_max*4;
    //initialize offsets
    for(i=0; i< process_count; i++) {
        //get segments for dataset
        int size = total_rows/process_count;
        segments.at(i).start = size*i;
        segments.at(i).end = size*i + size;

        //get segments for shared memory location segment for each process
        segments.at(i).shm_start = i*per_procc_mem;
        segments.at(i).shm_end = i*per_procc_mem + per_procc_mem;

        //if at the last process, check to see if the division is not even
        if(i==process_count-1)
            segments.at(i).end += total_rows%process_count;
    }

    //create the final results vector
    //reserve enough space to be able to merge all of our processes' stuff
    std::vector<ResultType> final_results;
    std::vector<float> copy;
    final_results.reserve(process_count*num_max);

    //create start and end chrono time points
    std::chrono::time_point<std::chrono::system_clock> start, end;
    std::map<int, double> times;

    //loop through the 4 different sizes of vectors
    for(i=0; i<sizes_count; i++) {


        std::cout << "\n\n==============TEST BEGIN==================\n" << std::endl;
        //run the test:
        copy = generateScottVector(sizes[i]);
        final_results = circularSubvectorMatch(sizes[i], &copy, &points, num_max, 0, total_rows, 0, 0, NULL, true);
        copy.clear();
        //run the test
        if(runTest(sizes[i], &final_results, num_max)) {
            std::cout << "Test was SUCCESSFUL against vector: \n" << std::endl;
            std::cout << scottgs::vectorToCSV(generateScottVector(sizes[i])) << "\n\n" << std::endl;
        } else {
            std::cout << "Test FAILED against vector: \n" << std::endl;
            std::cout << scottgs::vectorToCSV(generateScottVector(sizes[i])) << "\n\n" << std::endl;
            //exit(-1);
        }
        std::cout << "Expected vector results" << std::endl;
        printVector(num_max, final_results, sizes[i]);
        std::cout << "\n\nGenerated vector results" << std::endl;
        printVector(num_max, generateVectorTest(sizes[i]), sizes[i]);

        final_results.clear();
        std::cout << "\n\n==============TEST END==================\n\n\n" << std::endl;


        //generate 30 random vectors of size size[i]
        for(int ii=0; ii< 30; ii++) {
            generated_vectors.at(ii) = generateRandomVector(sizes[i]);
        }

        //for testing purposes I am only doing 1.
        //generated_vectors.at(0).reserve(sizes[i]);
        //generated_vectors.at(0) = generateScottVector(sizes[i]);
        //loop through the (30 vectors specified in the description)
        for(j=0; j<30; j++) {
            //let the first process print the results.
            std::cout << "\n-----------------" << std::endl;
            std::cout << "Search: "<< sizes[i] << "-D" << std::endl;
            std::cout << "-----------------" << std::endl;
            //get an object of the process spawner class..
            start = std::chrono::system_clock::now();
            scottgs::Splitter splitter;
            for (int p = 0; p < process_count; ++p)
            {
                pid_t pid = splitter.spawn();
                if (pid < 0)
                {
                    std::cerr << "Could not fork!!! ("<< pid <<")" << std::endl;
                    // do not exit, we may have a process
                    // spawned from an earlier iteration
                    break;
                }
                if (0 == pid) // Child
                {
                    /* Attach shared memory */
                    if((shm = (float *)shmat(shmId, NULL, 0)) == (float *) -1)
                    {
                        std::cerr << "Init: Failed to attach shared memory (" << shmId << ")" << std::endl;
                        exit(1);
                    }

                    //let only process 0 to print this vector.
                    if(p == 0) {
                        std::cout << "\nSearch Vector: " << std::endl;
                        //print the created vector.
                        std::cout << scottgs::vectorToCSV(generated_vectors[j]) << std::endl;
                    }

                    //perform the test(delete this as it is not needed)
                    //pas the size of the search vector, the auto generated vector, the vectors from the file,
                    //the number of top results to return, and the offset from which to search.
                    circularSubvectorMatch(sizes[i], &generated_vectors[j], &points, num_max, segments.at(p).start, segments.at(p).end, segments.at(p).shm_start, segments.at(p).shm_end, shm, false);

                    //child exists
                    _exit(0);
                }//end if pid==0
            }
            //wait for all children before looping again..
            splitter.reap_all();
            //calculate end time.
            end = std::chrono::system_clock::now();
            //now perform printing and stuff. from shared memory.
            //print end time
            std::chrono::duration<double, std::milli> elapsed_seconds = end-start;
            //std::cout << "\nTime: " << elapsed_seconds.count() << " milliseconds\n" << std::endl;
            //keep a record of the time
            times[sizes[i]] += elapsed_seconds.count();

            //print top num_max results
            printResults(shm, num_max, process_count, sizes[i]);
        }//end 30 vectors loop
    }//end vector_size loop
    std::cout << "\n-----------------" << std::endl;
    std::cout << "Final Results:" << std::endl;
    std::cout << "-----------------\n" << std::endl;
    std::cout << "Size" << "|" << "Average Time" << std::endl;
    std::cout << "-----------------" << std::endl;
    std::cout << times[sizes[0]]/1 << " " << times[sizes[1]]/1 << " " << times[sizes[2]]/1 << " " << times[sizes[3]]/1 << std::endl;

    //detach the memory
    shmdt(shm);
    //delete shared memory after we are done with it.
    shmctl(shmId, IPC_RMID, NULL);

    return 0;
}
Exemple #30
0
int
main (int argc, char *argv[])
{
  assert(pthread_mutexattr_init(&ma) == 0);

  printf( "=============================================================================\n");
  printf( "\nLock plus unlock on a locked mutex.\n");
  printf("%ld iterations, four locks/unlocks per iteration.\n\n", ITERATIONS);

  printf( "%-45s %15s %15s\n",
	    "Test",
	    "Total(msec)",
	    "average(usec)");
  printf( "-----------------------------------------------------------------------------\n");

  /*
   * Time the loop overhead so we can subtract it from the actual test times.
   */

  running = 1;
  assert(pthread_create(&worker, NULL, overheadThread, NULL) == 0);
  TESTSTART
  sched_yield();
  sched_yield();
  TESTSTOP
  running = 0;
  assert(pthread_join(worker, NULL) == 0);
  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  overHeadMilliSecs = durationMilliSecs;


  InitializeCriticalSection(&cs1);
  InitializeCriticalSection(&cs2);
  EnterCriticalSection(&cs1);
  EnterCriticalSection(&cs2);
  running = 1;
  assert(pthread_create(&worker, NULL, CSThread, NULL) == 0);
  TESTSTART
  LeaveCriticalSection(&cs1);
  sched_yield();
  LeaveCriticalSection(&cs2);
  EnterCriticalSection(&cs1);
  EnterCriticalSection(&cs2);
  TESTSTOP
  running = 0;
  LeaveCriticalSection(&cs2);
  LeaveCriticalSection(&cs1);
  assert(pthread_join(worker, NULL) == 0);
  DeleteCriticalSection(&cs2);
  DeleteCriticalSection(&cs1);
  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  printf( "%-45s %15ld %15.3f\n",
	    "Simple Critical Section",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS / 4 );


  old_mutex_use = OLD_WIN32CS;
  assert(old_mutex_init(&ox1, NULL) == 0);
  assert(old_mutex_init(&ox2, NULL) == 0);
  assert(old_mutex_lock(&ox1) == 0);
  assert(old_mutex_lock(&ox2) == 0);
  running = 1;
  assert(pthread_create(&worker, NULL, oldThread, NULL) == 0);
  TESTSTART
  (void) old_mutex_unlock(&ox1);
  sched_yield();
  (void) old_mutex_unlock(&ox2);
  (void) old_mutex_lock(&ox1);
  (void) old_mutex_lock(&ox2);
  TESTSTOP
  running = 0;
  assert(old_mutex_unlock(&ox1) == 0);
  assert(old_mutex_unlock(&ox2) == 0);
  assert(pthread_join(worker, NULL) == 0);
  assert(old_mutex_destroy(&ox2) == 0);
  assert(old_mutex_destroy(&ox1) == 0);
  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  printf( "%-45s %15ld %15.3f\n",
	    "Old PT Mutex using a Critical Section (WNT)",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS / 4);


  old_mutex_use = OLD_WIN32MUTEX;
  assert(old_mutex_init(&ox1, NULL) == 0);
  assert(old_mutex_init(&ox2, NULL) == 0);
  assert(old_mutex_lock(&ox1) == 0);
  assert(old_mutex_lock(&ox2) == 0);
  running = 1;
  assert(pthread_create(&worker, NULL, oldThread, NULL) == 0);
  TESTSTART
  (void) old_mutex_unlock(&ox1);
  sched_yield();
  (void) old_mutex_unlock(&ox2);
  (void) old_mutex_lock(&ox1);
  (void) old_mutex_lock(&ox2);
  TESTSTOP
  running = 0;
  assert(old_mutex_unlock(&ox1) == 0);
  assert(old_mutex_unlock(&ox2) == 0);
  assert(pthread_join(worker, NULL) == 0);
  assert(old_mutex_destroy(&ox2) == 0);
  assert(old_mutex_destroy(&ox1) == 0);
  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;
  printf( "%-45s %15ld %15.3f\n",
	    "Old PT Mutex using a Win32 Mutex (W9x)",
          durationMilliSecs,
          (float) durationMilliSecs * 1E3 / ITERATIONS / 4);

  printf( ".............................................................................\n");

  /*
   * Now we can start the actual tests
   */
#ifdef PTW32_MUTEX_TYPES
  runTest("PTHREAD_MUTEX_DEFAULT (W9x,WNT)", PTHREAD_MUTEX_DEFAULT);

  runTest("PTHREAD_MUTEX_NORMAL (W9x,WNT)", PTHREAD_MUTEX_NORMAL);

  runTest("PTHREAD_MUTEX_ERRORCHECK (W9x,WNT)", PTHREAD_MUTEX_ERRORCHECK);

  runTest("PTHREAD_MUTEX_RECURSIVE (W9x,WNT)", PTHREAD_MUTEX_RECURSIVE);
#else
  runTest("Blocking locks", 0);
#endif

  printf( "=============================================================================\n");
  /*
   * End of tests.
   */

  pthread_mutexattr_destroy(&ma);

  return 0;
}