void preemptiveTests()
{

  static const int duration = 10;
  int ret;

  int ii;

  startAlarmHelper();

  spin(2);

  interruptsQuiet();

  potato[0] = 1;
  for(ii = 1; ii < NPOTATO; ii++){
    potato[ii] = 0;
  }

  printf("Running hot potato test. This will take %d seconds\n",
         duration);

  for(ii = 0; ii < NPOTATO; ii++){
    potatoTids[ii] = ULT_CreateThread((void (*)(void *))doPotato, (void *)ii);
    assert(ULT_isOKRet(potatoTids[ii]));
  }


  spin(duration);

  printf("Hot potato done. Cleaning up\n");

  for(ii = 0; ii < NPOTATO; ii++){
    ret = ULT_DestroyThread(ULT_ANY);
    assert(ULT_isOKRet(ret));
  }  

  printf("Done.\n");
}
Exemplo n.º 2
0
void 
lockTests()
{

  ULT_Yield(ULT_ANY);
  startAlarmHelper();
  interruptsQuiet();

  /*
   * One mailbox
   */
  Mailbox *mb = (Mailbox *)malloc(sizeof(Mailbox));
  assert(mb);
  mb_init(mb, 2, MAXMAIL);

  ULT_CreateThread((void (*)(void *))mbWorker0, mb);

  while(!mb_checkDone(mb)){
    ULT_Yield(ULT_ANY);
  }
  int jj;
  for(jj = 0; jj < 1000; jj++){
    ULT_Yield(ULT_ANY);
  }
  assert(mb_checkDone(mb));
  free(mb);


  printf("One mailbox, two threads OK\n");

  /*
   * Two mailboxen
   */
  mb = (Mailbox *)malloc(sizeof(Mailbox));
  assert(mb);
  mb_init(mb, 2, MAXMAIL);
  Mailbox *mb2 = (Mailbox *)malloc(sizeof(Mailbox));
  assert(mb2);
  mb_init(mb2, 2, MAXMAIL);

  ULT_CreateThread((void (*)(void *))mbWorker0, mb);
  ULT_CreateThread((void (*)(void *))mbWorker0, mb2);

  while(!mb_checkDone(mb)){
    ULT_Yield(ULT_ANY);
  }
  for(jj = 0; jj < 1000; jj++){
    ULT_Yield(ULT_ANY);
  }
  assert(mb_checkDone(mb));
  while(!mb_checkDone(mb2)){
    ULT_Yield(ULT_ANY);
  }
  for(jj = 0; jj < 1000; jj++){
    ULT_Yield(ULT_ANY);
  }
  assert(mb_checkDone(mb2));

  free(mb);
  free(mb2);
  printf("Two mailboxen, four threads OK\n");

  
  printf("lockTests OK\n");
}