示例#1
0
TVerdict CPPPMinMaxMMU::doTestStepL()
	{
	const TInt KMaxMMU = 4000;
	const TInt KMinMMU = 1;

	TBuf8<KMaxMMU> *sendBuf = new(ELeave) TBuf8<KMaxMMU>();
	CleanupStack::PushL(sendBuf);
	
	TBuf8<KMaxMMU> *recvBuf = new(ELeave) TBuf8<KMaxMMU>();
	CleanupStack::PushL(recvBuf);
	
	TBuf8<KMaxMMU> *recvBuf2 = new(ELeave) TBuf8<KMaxMMU>();
	CleanupStack::PushL(recvBuf2);

    //initialize COMM
    //CommInitL(EFalse);
    
	//Start Comms server
// 	_LIT(KPhbkSyncCMI, "phbsync.cmi");
//    (void)StartC32WithCMISuppressions(KPhbkSyncCMI);
	
	SetTestStepResult(EPass);
    INFO_PRINTF1(_L("Starting: Socket Server\n"));
    
    RSocketServ ss;

    // Start the socket server
    TEST(KErrNone == ss.Connect());
    RSocket sock;
    TRequestStatus sta;
	INFO_PRINTF1(_L("Open a socket\n"));
    
    // Get the test address
    TInetAddr RemAddr(7);
    TPtrC testAddr;
	TEST(GetStringFromConfig(_L("AddressInfo"), _L("TestPPPIPAddr"), testAddr));
	
    if(testAddr.Length())
		{
		RemAddr.Input(testAddr); 
		}
    else
		{
		INFO_PRINTF1(_L("Test FAILED\nMissing address information in config file: "));
		return EFail;
		}
    
    // Open a socket
    TEST(KErrNone == sock.Open(ss, KAfInet, KSockStream, KProtocolInetTcp)); 
    INFO_PRINTF1(_L("Connecting Socket to:"));
	
    TBuf<30> printAddr;
    RemAddr.Output(printAddr);
	
    INFO_PRINTF1(printAddr);
	
    // Connect a socket
    sock.Connect(RemAddr,sta);
	
    // Wait for Connect to complete
    User::WaitForRequest(sta);
    TEST(sta.Int() == 0);
    
    TInt iterEnd;
	GetIntFromConfig(_L("MMUInfo"), _L("TestPPPmaxMMU"), iterEnd);
    if (iterEnd > KMaxMMU)
		iterEnd = KMaxMMU;
	
    TInt iterStart;
	GetIntFromConfig(_L("MMUInfo"), _L("TestPPPminMMU"), iterStart);
    if (iterStart < KMinMMU)
		iterStart = KMinMMU;
	
    TInt i,j;
    TSockXfrLength recvLen;
    INFO_PRINTF1(_L("Send/Recv frames"));
    for(j=iterStart;j<=iterEnd;j++)
		{
		sendBuf->Zero();
		
		for (i=0;i<j;i++)
			sendBuf->Append(Math::Random() & 0x7f);
		
		INFO_PRINTF2(_L("Sending Packet of Size: %d"),j);
		// Send data to echo port
		sock.Write(*sendBuf,sta);
		User::WaitForRequest(sta);
		TEST(sta.Int() == 0);
		i=0;
		recvBuf->Zero();
		
		while(i<j)
			{
			// Receive data from echo port
			sock.RecvOneOrMore(*recvBuf2,0,sta,recvLen); 
			User::WaitForRequest(sta);
			TEST(sta.Int() == 0);
			i += recvBuf2->Length();
			recvBuf->Append(*recvBuf2);
			}
		
		TEST(KErrNone == recvBuf->Compare(*sendBuf));
		INFO_PRINTF1(_L("   Received echoed Packet"));
		}
    
    sock.Shutdown(RSocket::EStopOutput,sta);
    User::WaitForRequest(sta);
    TEST(sta.Int() == 0);
    sock.Close();
    ss.Close();

	CleanupStack::PopAndDestroy(3);

	return TestStepResult();
	}
enum TVerdict CTestStepNullAgtLoopbackTest::doTestStepL(void)
{
    __UHEAP_MARK;

    TInt r;                // the result of various operations
    TRequestStatus status; // status of asynchronous ops

    RSocketServ server;    // connection paraphanelia
    RConnection connection;
    RSocket socket;

    TInetAddr dest;
    dest.SetAddress(KDummyNifLocalAddressBase + 4);
    dest.SetPort(KPortNo);

    TBuf8<KBufferLength> buffer;

    // connect to the socket server
    r = server.Connect();
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(server);

    // this is why we needed a socket server...
    r = connection.Open(server, KAfInet);
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(connection);

    // start the connection up (outgoing)
    connection.Start(status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    // open a udp socket
    r = socket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp);
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(socket);
    TESTL(socket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone);
    // set the source port number - otherwise will panic cos it's zero
    r = socket.SetLocalPort(KPortNo);
    TESTEL(r == KErrNone, r);

    // build some data to send on the socket
    // this is an ICMP ping request apparently
    buffer.SetMax();
    buffer.FillZ();
    buffer[0] = (TUint8) 0x8;		// ICMP type = 8
    buffer[1] = (TUint8) 0x0;		// ICMP code = 0
    buffer[2] = (TUint8) 0xF7;		// ICMP checksum high byte
    buffer[3] = (TUint8) 0xFF;		// ICMP checksum low byte
    // NB the rest of the buffer is zero
    // hence the checksum (0xFFFF - 0x800) since 0x8
    // is the only non-zero element of the buffer

    // send the data out over the socket
    socket.SendTo(buffer, dest, 0, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    buffer.Zero();
    // I expect to get the data looped back from the dummy NIF
    socket.RecvFrom(buffer, dest, 0, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    // check that what we sent is what we got back
    if (status.Int() == KErrNone)
    {
        // if the receive times out and we access buffer we get a panic
        TEST(buffer[0] == 0x08);
        TEST(buffer[1] == 0x00);
        TEST(buffer[2] == 0xF7);
        TEST(buffer[3] == 0xFF);
    }

    // close the socket
    socket.Shutdown(RSocket::ENormal, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());
    CleanupStack::Pop();

    // force the destruction of the connection
    r = connection.Stop();
    TESTEL(r == KErrNone, r);
    CleanupStack::Pop();

    // close the socket server
    server.Close();
    CleanupStack::Pop();

    __UHEAP_MARKEND;

    return iTestStepResult;
}