Example #1
0
int main() {
  Write("Creating test locks and CVs, should be successful\n", 50, ConsoleOutput);
  lock1 = CreateLock("Lock1", 5, 0);
	lock2 = CreateLock("Lock2", 5, 0);
	cond1 = CreateCondition("Condition1", 10, 0);
	cond2 = CreateCondition("Condition2", 10, 0);
  lock3 = CreateLock("Lock3", 5, 0);
  lock4 = CreateLock("Lock4", 5, 0);
  cond3 = CreateCondition("Condition3", 10, 0);
  cond4 = CreateCondition("Condition4", 10, 0);
	condToBeDestroyed = CreateCondition("condToBeDestroyed", 17, 0);

  theLockThatDoesntExist = lock1+10;
  theCondThatDoesntExist = cond1+10;
  Write("Destroying CV, should see both successful and unsuccesful attempts.\n", 68, ConsoleOutput);
  Write("Destroying condToBeDestroyed\n", 29, ConsoleOutput);
  DestroyCondition(condToBeDestroyed);
  Write("Destroying theCondThatDoesntExist\n", 34, ConsoleOutput);
  DestroyCondition(theCondThatDoesntExist);
  Write("Waiting theCondThatDoesntExist\n", 32, ConsoleOutput);
  Acquire(lock1);
  Wait(lock1, theCondThatDoesntExist);
  Write("Signaling theCondThatDoesntExist\n", 34, ConsoleOutput);
  Acquire(lock1);
  Signal(lock1, theCondThatDoesntExist);
  Release(lock1);
  Write("Broadcasting theCondThatDoesntExist\n", 36, ConsoleOutput);
  Broadcast(lock1,theCondThatDoesntExist);
	Write("Finshing condInit\n", 18, ConsoleOutput);
	Exit(0);
}
Example #2
0
void testCase1()
{
	int conditionId = -1;
	int i;
	Print("CREATE CONDITION SYSTEM CALL TEST\n\n");

	Print("PASSING CONDITION NAME LENGTH > MAX_CV_NAME \n\n");
	conditionId = CreateCondition((char*)"ConditionName",400);
	Print("------------------------------------------------------\n");

	Print("PASSING CONDITION NAME LENGTH < 0 \n\n");
	conditionId = CreateCondition((char*)"ConditionName",-4);
	Print("------------------------------------------------------\n");

	Print("PASSING INVALID VIRTUAL ADDR \n\n");
	conditionId = CreateCondition((char*)0xdeadbeef,10);
	Print("------------------------------------------------------\n");

	Print("CREATING MORE number of Conditions than MAX_CVS = 2000 \n\n");
	for(i = 0;i<2001;i++)
	{
		conditionId = CreateCondition((char*)"ConditionNo",10);
		Print1("CONDITION ID RECEIVED IS %d\n",conditionId);
	}
	Print("------------------------------------------------------\n");

	Print("CREATING CONDITION SUCCESS CASE \n");
	conditionId = CreateCondition((char*)"ConditionNo",10);
	Print("------------------------------------------------------\n");
}
void negativecase1()
{
    int Lock1,CV1;

    Lock1=CreateLock("USERLOCK",-6);/*Invalid Addr Length*/
    Lock1= CreateLock("USERLOCK",65000);/*Address Length exceeded address size*/
    CV1=CreateCondition("USERCV",-2);/*Invalid Addr Length*/
    CV1=CreateCondition("USERCV",400000);/*Address Length exceeded address size*/
    CV1=CreateCondition("USERCV",0);/*Invalid Address Length*/

}
Example #4
0
void createServerMVs(int numCustomers, int numberOfSenators) {
	int i;
	/*global shared data between the clerks that are used for filing purposes */
	numCustomersLeft = CreateMV("numCustomersLeft", 16, 1);
	bribesEnabled = CreateMV("bribesEnabled", 13, 1);

	customersWithCompletedApps = CreateMV("customersWithCompletedApps", 26, numCustomers);
	customersWithCompletedPics = CreateMV("customersWithCompletedPics", 26, numCustomers);
	passportClerkChecked = CreateMV("passportClerkChecked", 20, numCustomers);
	cashierChecked = CreateMV("cashierChecked", 14, numCustomers);
	gottenPassport = CreateMV("gottenPassport", 14, numCustomers);
	cashReceived = CreateMV("cashReceived", 12, numCustomers);

	appClerkCurrentCustomer = CreateMV("appClerkCurrentCustomer", 23, numCustomers);
	pictureClerkCurrentCustomer = CreateMV("pictureClerkCurrentCustomer", 27, numCustomers);
	passportClerkCurrentCustomer = CreateMV("passportClerkCurrentCustomer", 28, numCustomers);
	cashierCurrentCustomer = CreateMV("cashierCurrentCustomer", 22, numCustomers);

	senatorLock = CreateLock("senatorLock", 11);
	senatorCV = CreateCondition("senatorCV", 9);
	isSenator = CreateMV("isSenator", 9, numCustomers);
	senatorWorking = CreateMV("senatorWorking", 14, 1);
	clerksCanWork = CreateMV("clerksCanWork", 13, 1);

	newCustomerId = CreateMV("newCustomerId", 13, 1);
	newCustomerIdLock = CreateLock("newCustomerIdLock", 17);

	/*Initialize everything*/

	/*
	numCustomersLeft = size;
	bribesEnabled = 1;
	newCustomerId = 0;
	*/
}
Example #5
0
/* --------------------------------------------------
// TestSuite()
//     This is the main thread of the test suite.  It runs the
//     following tests:
//
//       1.  Show that a thread trying to release a lock it does not
//       hold does not work
//
//       2.  Show that Signals are not stored -- a Signal with no
//       thread waiting is ignored
//
//       3.  Show that Signal only wakes 1 thread
//
//	 4.  Show that Broadcast wakes all waiting threads
//
//       5.  Show that Signalling a thread waiting under one lock
//       while holding another is a Fatal error
//
//     Fatal errors terminate the thread in question.
// --------------------------------------------------*/
void TestSuite() {
	int i;

	t1_l1 = CreateLock();
	t2_l1 = CreateLock();
	t3_l1 = CreateLock();
	t3_c1 = CreateCondition();	

	/*Test 1*/
	
	Write("Starting Test1.\n", 22, ConsoleOutput);

	/*Uncomment for Lock test*/
	/*Acquire(t1_l1);

	Write("t1_t1 Acquired Lock.\n", 22, ConsoleOutput);
	for (i = 0; i < 300000; i++);
	Write("t1_t1 Releasing Lock.\n", 22, ConsoleOutput);

	Release(t1_l1);

	Exit(0);*/

	/*Uncomment for CV Test (Comment above)*/
	Acquire(t3_l1);
	Write("t3_waiter Acquired Lock.\n", 27, ConsoleOutput);
	Wait(t3_c1, t3_l1);
	Write("t3_waiter Freed.\n", 17, ConsoleOutput);
	Release(t3_l1);

	Exit(0);
}
void Lockdestroytest()
{
    int lockd,cvd;

    lockd=CreateLock("lockd",5);
    cvd=CreateCondition("cvd",3);
}
int
main()
{
    char* nameCV = "CV";
    int CV = 0, i = 0;
    int returnValue = 0;
    
    Printx("Owner process is creating a new CV\n",37,1);
    CV = CreateCondition(nameCV,2);
    if (CV == -1){
   		Printx("Owner process not able to create CV\n",38,1);
    }
    
    Printx("Owner process is destroying the CV\n",37,1);
    returnValue = DestroyCondition(CV);
    if (returnValue == -1){
   		Printx("Owner not able to destroy CV\n",31,1);
    }
    
    Printx("Owner process is attempting to destroy the CV again\n",54,1);
    returnValue = DestroyCondition(CV);
    if (returnValue == -1){
   		Printx("Owner not able to destroy CV\n",31,1);
    }
    
    
    Exit(0);
    /* not reached */
}
    void SCXWQLSelectStatementCMPI::SetExp(CMPISelectExp *exp)
    {
        SCX_LOGTRACE(this->m_log, L"SetExp(CMPISelectExp *exp)");
        if(exp)
        {
            cmpiExp = exp;
            CMPIStatus st;
            CMPISelectCond *cond = exp->ft->getDOC(exp, &st);
            if(CMPI_RC_OK != st.rc)
            {
                throw SCXInternalErrorException(L"GetDoc failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION);
            }

            unsigned i = cond->ft->getCountAndType(cond, NULL, &st);
            if(CMPI_RC_OK != st.rc)
            {
                throw SCXInternalErrorException(L"GetCountAndType failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION);
            }

            for (unsigned j = 0; j< i; j++)
            {
                SCXHandle<Condition> c = CreateCondition(cond->ft->getSubCondAt(cond, j, &st));
                if(CMPI_RC_OK != st.rc)
                    throw SCXInternalErrorException(L"getSubCondAt failed in CMPI: " + StrFromUTF8(st.msg->ft->getCharPtr(st.msg, NULL) ? st.msg->ft->getCharPtr(st.msg, NULL) : ""), SCXSRCLOCATION);
                this->doc.push_back(*c);
            } 
        }
        SCX_LOGTRACE(this->m_log, L"Exit SetExp(CMPISelectExp *exp)");
    }
Example #9
0
Pipe_t *
CreatePipe(const char *name, unsigned size)
{
	char buf[200];
	Pipe_t *p = Malloc(sizeof(Pipe_t));

	p->head = p->tail = p->buf = Malloc(p->size = size);
	p->end = p->buf + size;
	p->monitor = CreateMonitor(name);
	p->name = GetName(p->monitor);
	sprintf(buf, "get %s", name);
	p->cond_get = CreateCondition(buf, p->monitor);
	sprintf(buf, "put %s", name);
	p->cond_put = CreateCondition(buf, p->monitor);

	return p;
}
void Lockdestroytest()
{
  int lockd,cvd;
  
  lockd=CreateLock("lockd",5);
  DestroyLock(lockd);/* you cannot destroy as client 1 is also using this lock*/
  cvd=CreateCondition("cvd",3);
  DestroyCondition(cvd);
}
Example #11
0
HRESULT ShellItemsLoader::EnumerateFolderItemsRecursive(IShellItem* currentBrowseLocation, ShellFileType fileType, std::vector<ComPtr<IShellItem> >& shellItems)
{
    ComPtr<ISearchFolderItemFactory> searchFolderItemFactory;
    ComPtr<IShellItemArray> searchScope;

    HRESULT hr = CoCreateInstance(
        CLSID_SearchFolderItemFactory,
        nullptr,
        CLSCTX_INPROC_SERVER,
        IID_PPV_ARGS(&searchFolderItemFactory));
    if (SUCCEEDED(hr))
    {
        hr = CreateScope(currentBrowseLocation, &searchScope);
    }

    if (SUCCEEDED(hr))
    {
        hr = searchFolderItemFactory->SetScope(searchScope);
    }

    ComPtr<ICondition> searchCondition;
    if (SUCCEEDED(hr))
    {
        hr = CreateCondition(fileType, &searchCondition);
    }

    if (SUCCEEDED(hr))
    {
        hr = searchFolderItemFactory->SetCondition(searchCondition);
    }

    ComPtr<IShellItem> shellItemSearch;
    if (SUCCEEDED(hr))
    {
        hr = searchFolderItemFactory->GetShellItem(IID_PPV_ARGS(&shellItemSearch));
    }

    // Do something with shellItemSearch
    if (SUCCEEDED(hr))
    {
        ComPtr<IEnumShellItems> enumItems;
        hr = shellItemSearch->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&enumItems));
        if (SUCCEEDED(hr))
        {
            // note, this consumes all errors
            ComPtr<IShellItem> shellItem;
            unsigned long fetched;
            while SUCCEEDED(enumItems->Next(1, &shellItem, &fetched))
            {
                shellItems.push_back(shellItem);
                shellItem = nullptr; 
            }
        }
    }

    return hr;
}
int main() {
  Write("Creating test locks and CVs, should be successful\n", 50, ConsoleOutput);
  lock1 = CreateLock("Lock1", 5, 0);
	lock2 = CreateLock("Lock2", 5, 0);
	cond1 = CreateCondition("Condition1", 10, 0);
	cond2 = CreateCondition("Condition2", 10, 0);
  lock3 = CreateLock("Lock3", 5, 0);
  lock4 = CreateLock("Lock4", 5, 0);
  cond3 = CreateCondition("Condition3", 10, 0);
  cond4 = CreateCondition("Condition4", 10, 0);
	condToBeDestroyed = CreateCondition("condToBeDestroyed", 17, 0);

  theLockThatDoesntExist = lock1+10;
  theCondThatDoesntExist = cond1+10;

  PrintNl();
	Write("Testing invalid actions for conds\n", 34, ConsoleOutput);
	Write("Waiting with invalid lock and valid condition, should give error\n", 65, ConsoleOutput);
	Wait(theLockThatDoesntExist, cond1);
  Write("Waiting with valid lock and invalid condition, should give error\n", 65, ConsoleOutput);
	Wait(lock1, theCondThatDoesntExist);
	Write("Signaling theCondThatDoesntExist, should give error\n", 52, ConsoleOutput);
	Signal(lock1, theCondThatDoesntExist);
	Write("Destroying theCondThatDoesntExist, should give error\n", 53, ConsoleOutput);
	DestroyCondition(theCondThatDoesntExist);
	Write("Destroying condToBeDestroyed, should be successful\n", 51, ConsoleOutput);
	DestroyCondition(condToBeDestroyed);
  Write("Signaling condToBeDestroyed, should give error\n", 47, ConsoleOutput);
	Signal(lock1, condToBeDestroyed);
  Write("Broadcasting condToBeDestroyed, should give error\n", 50, ConsoleOutput);
  Broadcast(lock1, condToBeDestroyed);
  Write("Destroying condToBeDestroyed, should give error\n", 48, ConsoleOutput);
	DestroyCondition(condToBeDestroyed);
  Write("Waiting before acquring, should give error\n", 43, ConsoleOutput);
  Wait(lock1, cond1);
  Write("Signaling before acquring, should give error\n", 45, ConsoleOutput);
  Signal(lock1, cond1);
  Write("Broadcasting before acquring, should give error\n", 48, ConsoleOutput);
  Broadcast(lock1, cond1);


	Write("Finshing condServerInitTest\n", 28, ConsoleOutput);
	Exit(0);
}
Example #13
0
void main()
{
  unsigned int i;
  int conditionNum;

  conditionNum=CreateCondition("condition",9);
  DestroyCondition(conditionNum);
	
  Exit(0);
}
void negativecase4()
{
    int n1,c1;

    /*n1=CreateLock("n1",2);*/
    c1=CreateCondition("c1",2);
    Signal(c1,n1);/*signalling without owning the lock n2*/
    Wait(c1,n1);/*going on wait without acquring n1*/

}
void lockcvdestroytest()
{
   int lockd,cvd;
   
  lockd=CreateLock("lockd",5);
  cvd=CreateCondition("cvd",3);
  DestroyLock(lockd);
  DestroyCondition(cvd);
  
}
Example #16
0
void main()
{
  unsigned int i;
  int lock,cond;
  lock = CreateLock("lock",4);
  AcquireLock(lock);
  cond=CreateCondition("condition",9);
  WaitCondition(cond,lock);
  ReleaseLock(lock);
  Exit(0);
}
Example #17
0
int
main() {

    /*Create lock, CV*/
    int i,j,total;
    int lockID, cvID;
    lockID = CreateLock("testLock",8);
    cvID = CreateCondition("testCV",6);


    /*Get into critical section*/
    Acquire(lockID);

    Write("Sector 1...\n",12,ConsoleOutput);

    /*Do some work*/
    for(i = 0;i<LEN;i++){
        for(j = 0;j<LEN;j++){
            total += i*j; /*Just to keep the thread occupied*/
        }
    }

    /*Signal and then wait for another signal*/
    Signal(cvID,lockID);
    Wait(cvID,lockID);

    Write("Sector 2...\n",12,ConsoleOutput);

    /*Do some work*/
    for(i = 0;i<LEN;i++){
        for(j = 0;j<LEN;j++){
            total += i*j; /*Just to keep the thread occupied*/
        }
    }

    /*Signal. Even though the last thread will be signalling no one, this is part of the test
     * to allow all threads to finish*/
    Signal(cvID,lockID);

    /*Release*/
    Release(lockID);

    Write("Out of critical section\n",24,ConsoleOutput);

    /*Destroy the lock, cv (really, set its toBeDestroyed bit to true)*/
    DestroyLock(lockID);
    DestroyCondition(cvID);

    /*Send a result to print*/
    Exit(total);



}
void client3()
{
  int Lock1,CV1;

  Lock1=CreateLock("USERLOCK",8);
  CV1=CreateCondition("USERCV",6);
  
  Acquire(Lock1);
  Wait(CV1,Lock1);
  
 }
Example #19
0
int main () {

	lock = CreateLock("Lock", 4);
	cv = CreateCondition("CV", 3);
	
	Fork((void*)dummy, "increment", 9, 1);
	Fork((void*)dummy, "increment", 9, 2);
	Fork((void*)dummy, "increment", 9, 3);
	Exit(0);


}
Example #20
0
int main()
{


  Print("Create lock, create cv, create monitor, start monitor val at 1", 100,"","");
  
  CreateLock("Al",2);
  CreateCondition("Acv", 3);
  monitor = CreateMonitor(0, "test", 4);
  SetMonitor(monitor,0, 1);

}
Example #21
0
void main()
{
    unsigned int i;
    int lock,cond;
    Write("\nTest Create lock\n", 18,1 );
    lock = CreateLock("lock",4);
    AcquireLock(lock);
    cond=CreateCondition("condition",9);
    SignalCondition(cond,lock);
    ReleaseLock(lock);
    Exit(0);
}
Example #22
0
int main()
{
	Write("\nTESTING: TRYING TO DESTROY A CONDITION VARUIABLE WHEN STILL THREADS ARE WAIITNG IN THE WAIT QUEUE",98,1);
	l1=CreateLock();
	cv1=CreateCondition();
	Fork(fun1);
	Yield();
	Yield();
	Yield();
	DestroyCondition(cv1);
	Exit(0);
}
Example #23
0
int main() {
	
	lock1 = CreateLock("Lock1", 5, 0);
	cond1 = CreateCondition("Condition1", 10, 0);
  Write("Waiting cond1 with lock1, should be successful\n", 47, ConsoleOutput);
  Acquire(lock1);
  Wait(lock1,cond1);
  Release(lock1);

  Write("Finshing signalTest\n", 20, ConsoleOutput);
  Exit(0);
}
void positivetestcase1()
{
    int L1,cv1;

    L1=CreateLock("USERLOCK",8);/*LOCK is created*/
    cv1=CreateCondition("USERCV",6);/*CV is created*/
    DestroyLock(L1);/*Lock is destroyed*/
    DestroyCondition(cv1);/*CV is destroyed*/



}
Example #25
0
int main()
{
	unsigned int i=0;
	Write("\nTESTING WAIT AND BROADCAST",27,1);
	l1=CreateLock();
	c1=CreateCondition();
	c2=CreateCondition();
	Fork(clt1);
	Fork(clt2);
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	Yield();
	/*for(i=0;i<100000;i++){}*/
	AcquireLock(l1);
	counter=counter+3;
	BroadcastCondition(c1,l1);
	ReleaseLock(l1);
	Exit(0);
}
void client2()
{ 
 int Lock1,CV1;
 
 Lock1=CreateLock("USERLOCK",8);
 CV1=CreateCondition("USERCV",6);
 

 
  Acquire(Lock1);
  Signal(CV1,Lock1);
  Release(Lock1);
 
}
void lockcvdestroytest()
{
    int lockd,cvd;

    lockd=CreateLock("lockd",5);
    cvd=CreateCondition("cvd",3);

    Print("Please press any number after you run client 2, for successfull deletion of the lock and cv\n");
    Scan("%d");
    DestroyLock(lockd);
    DestroyCondition(cvd);


}
Example #28
0
int
main(){
	lockid = CreateLock("LOCK1", 5);
	initlock = CreateLock("LOCK2", 5);
	condid = CreateCondition("COND1", 5);
	initcond = CreateCondition("COND2", 5);

	Write( "test4\n", 6, ConsoleOutput );
	Acquire(initlock);
	Fork(waiter);
	Wait(initcond, initlock);

	Fork(signaller);
	while(i != 2){
		Wait(initcond, initlock);
	}
	Release(initlock);

	DestroyLock(lockid);
	DestroyLock(initlock);
	DestroyCondition(condid);
	DestroyCondition(initcond);
	Exit(0);
}
Example #29
0
void main()
{
    Print("\nTest2 is for waiting and signaling condition variable.\n", sizeof("\nTest2 is for waiting and signaling condition variable.\n")/sizeof(char), 0, 0);
     l1 = CreateLock("l1", 2);
     c1 = CreateCondition("c1", 2);
     m1 = CreateMV("m1", 2, 3);
    
    AcquireLock(l1);
    Print("client2 of Test2 has acquired lock1.\n", sizeof("client2 of Test2 has acquired lock1.\n")/sizeof(char), 0, 0);
    SetMV(m1, 1, 10);
    SignalCondition(c1, l1);
    Print("client2 of Test2 signals client1.\n", sizeof("client2 of Test2 signals client1.\n")/sizeof(char), 0, 0);
    ReleaseLock(l1);
    Print("client2 of Test2 has released lock1.\n", sizeof("client2 of Test2 has released lock1.\n")/sizeof(char), 0, 0);
    Exit(0);
}
Example #30
0
int main(){
	lk1 = CreateLock("lk1", sizeof("lk1"));
	cv1 = CreateCondition("cv1", sizeof("cv1"));
	
	Acquire(lk1);
	
	Write("Test 2:Acquired lk1 \n", sizeof("Test 2:Acquired lk1 \n"), ConsoleOutput);

	Signal(lk1, cv1);
	Write("Test 2:Signalled lk1 \n", sizeof("Test 2:Signalled lk1 \n"), ConsoleOutput);

	Wait(lk1, cv1);
	Write("Test 2:I was signalled lk1 \n", sizeof("Test 2:I was signalled lk1 \n"), ConsoleOutput);

	Release(lk1);
	Write("Test 2:Released lk1 \n", sizeof("Test 2:Released lk1 \n"), ConsoleOutput);
}