int main()
{
	int Choice = -1;
	
	  Print((int)"*************************************client 2****************************************\n");

        
		
		Print("Choice#1:\n");
		Print("TestCase#1: Shows that signal only wakes up one thread, this therad goes on wait\n\n");
		
		Print("Choice#2:\n");
		Print("TestCase#2:shows that broadcast wakes up all the threads,this therad goes on wait\n\n");
		
		Print("Choice#3:\n");
		Print("TestCase#3:Tests the proper functioning of signal and wait \n\n");
		
		Print("Choice#4:\n");
		Print("TestCase#4:Subsequent clients cannot acquire the lock until the previous clients release them \n\n");
		
		Print("Choice#5:\n");
		Print("TestCase#5: To show that a lock or a CV cannot be destroyed by other client if this client is using it\n\n");
		
		Print("Choice#6:\n");
		Print("TestCase#6: To show that a lock or a condition variable can only be destoyed if all clients using it call destroy\n\n");
		
		
		
		Choice=Scan("%d");
		 switch (Choice)
			{
                    case 1: 
							client3();
							break;
							
					case 2: 
							client3();
							break;
							
					case 3: Print("This test case checks the proper functioning of wait and signal RPC\n");
					        client2();
                            break;
							
					case 4: Print("Susequent clients can acquire the lock only when this client releases\n");
					        Lockacquiretest();
                            break;
							
					case 5: Print("To show that a lock or a CV cannot be destroyed by other client if this client is using it\n");
					        Lockdestroytest();
                            break;
							
							
					case 6:	Print("To show that a lock or a condition variable can only be destoyed if all clients using it call destroy\n");
					        lockcvdestroytest();
							break;
			}
}
Beispiel #2
0
int main(void) {
    char buf[16];

    /* Test simple data exchange, with explicit handshake. */
    int u[2];
    int rc = ipc_pair(u);
    errno_assert(rc == 0);
    int cr = go(client1(u[1]));
    errno_assert(cr >= 0);
    int s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1);
    errno_assert(s >= 0);
    rc = brecv(s, buf, 3, -1);
    errno_assert(rc == 0);
    assert(buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C');
    rc = brecv(s, buf, 3, -1);
    errno_assert(rc == -1 && errno == EPIPE);
    rc = bsend(s, "DEF", 3, -1);
    errno_assert(rc == 0);
    rc = tls_done(s, -1);
    errno_assert(rc == 0);
    u[0] = tls_detach(s, -1);
    errno_assert(u[0] >= 0);
    rc = hclose(u[0]);
    errno_assert(rc == 0);
    rc = bundle_wait(cr, -1);
    errno_assert(rc == 0);
    rc = hclose(cr);
    errno_assert(rc == 0);

    /* Test simple data transfer, terminated by tls_detach().
       Then send some data over undelying IPC connection. */
    rc = ipc_pair(u);
    errno_assert(rc == 0);
    cr = go(client2(u[1]));
    errno_assert(cr >= 0);
    s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1);
    errno_assert(s >= 0);
    rc = brecv(s, buf, 3, -1);
    errno_assert(rc == 0);
    assert(buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C');
    u[0] = tls_detach(s, -1);
    errno_assert(u[0] >= 0);
    rc = brecv(u[0], buf, 3, -1);
    errno_assert(rc == 0);
    assert(buf[0] == 'D' && buf[1] == 'E' && buf[2] == 'F');
    rc = ipc_close(u[0], -1);
    errno_assert(rc == 0);
    rc = bundle_wait(cr, -1);
    errno_assert(rc == 0);
    rc = hclose(cr);
    errno_assert(rc == 0);

    /* Transfer large amount of data. */
    rc = ipc_pair(u);
    errno_assert(rc == 0);
    cr = go(client3(u[1]));
    errno_assert(cr >= 0);
    s = tls_attach_server(u[0], "tests/cert.pem", "tests/key.pem", -1);
    errno_assert(s >= 0);
    uint8_t c = 0;
    int i;
    for(i = 0; i != 2777; ++i) {
        uint8_t b[257];
        rc = brecv(s, b, sizeof(b), -1);
        errno_assert(rc == 0);
        int j;
        for(j = 0; j != sizeof(b); ++j) {
            assert(b[j] == c);
            c++;
        }
    }
    u[0] = tls_detach(s, -1);
    errno_assert(u[0] >= 0);
    rc = bundle_wait(cr, -1);
    errno_assert(rc == 0);
    rc = hclose(cr);
    errno_assert(rc == 0);
    rc = hclose(u[0]);
    errno_assert(rc == 0);
    
    return 0;
}
int main()
{
    int Choice = -1;

    Print((int)"*************************************client 1**************************************** \n");

    Print("enter the test case choice \n");


    /*Print("TestCase#1:  Shows that signal only wakes up one thread,this thread goes on wait\n\n");


    Print("TestCase#2:  shows that broadcast wakes up all the threads,this thread goes on wait\n\n");


    Print("TestCase#3:  Tests the proper functioning of signal and wait \n\n");


    Print("TestCase#4:  Negative Test cases for Createlock and Createcv\n\n");

    Print("TestCase#5:  Negative Test cases for Destroylock and Destroycv\n\n");


    Print("TestCase#6:  Proper functioning of Create and Destroy Lock and condition\n\n");

    Print("TestCase#7:  Proper functioning of Acquire and Release \n\n");


    Print("TestCase#8:  Negative test cases for acquire and release \n\n");


    Print("TestCase#9:  Negative test cases for signal and wait \n\n");

    Print("TestCase#10: Subsequent clients cannot acquire the lock until the previous clients release them \n\n");

    Print("TestCase#11: To show that a lock or a CV cannot be destroyed by other client if this client is using it \n\n");

    Print("TestCase#12: To show that a lock or a condition variable can only be destoyed if all clients using it call destroy \n\n"); */



    Choice=Scan("%d");
    switch (Choice)
    {
    case 1:
        client3();
        break;

    case 2:
        client3();
        break;

    case 3:
        Print("This test case checks the proper functioning of wait and signal RPC\n");
        client1();

        break;

    case 4:
        Print("The following are the negative test cases which will return error messages\n\n");
        negativecase1();
        break;

    case 5:
        Print("The following are the negative test cases which will return error messages\n\n\\");
        negativecase2();
        break;

    case 6:
        Print("Lock and CV are suceesfully created and deleted\n\n");
        positivetestcase1();
        break;

    case 7:
        Print("Locks are suceefully acquired and released\n\n");
        positivetestcase2();
        break;

    case 8:
        Print("We get error messages\n\n\n");
        negativecase3();
        break;

    case 9:
        Print("We get error messages\n\n\n");
        negativecase4();
        break;

    case 10:
        Print("Susequent clients can acquire the lock only when this client releases\n");
        Lockacquiretest();
        break;

    case 11:
        Print("To show that a lock or a CV cannot be destroyed by other client if this client is using it\n");
        Lockdestroytest();
        break;

    case 12:
        Print("To show that a lock or a condition variable can only be destoyed if all clients using it call destroy\n");
        lockcvdestroytest();
        break;
    }
}
void ServerFuncD(int port)
{
	struct result b;

	try{
		//Initialization
		int i=0;
	
		communication::ServerTCP server(port);
		
		cout<<">>\nTest 1 ..."<<endl;
		communication::Socket_ sock_;
		server.acceptConnection(sock_);
		communication::ClientTCP client(sock_);		
		i=client.receive(b.intval);
		
	
		cout<<">>\nTest 2 ..."<<endl;
		communication::Socket_ sock_2;
		server.acceptConnection(sock_2);
		communication::ClientTCP client2(sock_2);
		i=client2.receive(b.long64);
		i=client2.send(b.long64);

		cout<<">>\nTest 3 ..."<<endl;
		communication::Socket_ sock_3;
		server.acceptConnection(sock_3);
		communication::ClientTCP client3(sock_3);
		i=client3.receive(b.intval);
		
		cout<<">>\nTest 4 ..."<<endl;
		communication::Socket_ sock_4;
		server.acceptConnection(sock_4);
		communication::ClientTCP client4(sock_4);
		i=client4.receive(b.longarr,20);
		i=client4.send(b.longarr,20);

		cout<<">>\nTest 5 ..."<<endl;
		//timer was shutdown before, so timer sould work properly again
		i=client4.receive(b.longarr,20);
		




	
		
		
		//Do not answer , deadline should passed and shutdown communication

	}catch(communication::ServerTCPException e)
	{
		cout<<"Error in Server2:"<<e.getMessage()<<endl;
	}catch(...)
	{
		cout<<"Error in Server2:"<<":Unknown Failure"<<endl;
	}

	cout<<"ServerFunc disabled."<<endl;

}