genericopenlibs/openenvcore/libc/test/testlocalsocket/src/tlocalsocketblocks.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : tlocalsocketblocks.cpp
       
    15 //
       
    16 
       
    17 #include "tlocalsocket.h"
       
    18 #include <sys/un.h>
       
    19 #include <sys/stat.h>
       
    20 #include <pthread.h>
       
    21 #include <semaphore.h>
       
    22 
       
    23 #include <sys/select.h>
       
    24 
       
    25 #define SERVPATH "c:\\tmp22.a" 
       
    26 #define SOCK_PATH "c:\\negsocket.txt"
       
    27 #define SOCK_PATH1 "c:\\negsocket1.txt"
       
    28 #define DATA "Hello World"
       
    29 const TUint KMaxLine = 27;
       
    30 const TUint KDataLength = sizeof(DATA);
       
    31 
       
    32 // Util function to read from a socket
       
    33 TInt read1(int newsock_fd,char *line)
       
    34     {    
       
    35     int ret;    
       
    36     int left = KMaxLine;   
       
    37     
       
    38     while (1)
       
    39         {
       
    40         
       
    41         ret = read(newsock_fd,line,left);
       
    42         
       
    43         if (ret < 0)
       
    44             {
       
    45             return -1;
       
    46             }
       
    47         else if (ret == 0)
       
    48             {
       
    49             break;
       
    50             }
       
    51         left -= ret;
       
    52         line += ret;
       
    53         if (left <= 0)
       
    54             {
       
    55             break;
       
    56             }
       
    57         }
       
    58     return 0;
       
    59     }
       
    60     
       
    61 // Util function to write to a socket
       
    62 TInt write1(int sock_fd)
       
    63     {
       
    64     char line[KMaxLine];    
       
    65     int x;
       
    66     char character = 'A';
       
    67     unsigned int cnt = 0;
       
    68     for(; cnt < KMaxLine - 1; cnt++)
       
    69         {
       
    70         line[cnt] = character;
       
    71         character++;
       
    72         if (character > 'Z')
       
    73             {
       
    74             character = 'A';
       
    75             }
       
    76         }
       
    77     line[cnt] = '\0';
       
    78     x=write(sock_fd,line,KMaxLine);
       
    79     if (x < 0)
       
    80         {
       
    81         return -1;
       
    82         }
       
    83         
       
    84     return 0;
       
    85     }
       
    86     
       
    87 
       
    88 static TInt Recv1(int newsock_fd,char *line)
       
    89     {    
       
    90     int ret;    
       
    91     int left = KMaxLine;   
       
    92     
       
    93     while (1)
       
    94         {
       
    95         
       
    96         ret = recv(newsock_fd,line,left,0);
       
    97         
       
    98         if (ret < 0)
       
    99             {
       
   100             return -1;
       
   101             }
       
   102         else if (ret == 0)
       
   103             {
       
   104             break;
       
   105             }
       
   106         left -= ret;
       
   107         line += ret;
       
   108         if (left <= 0)
       
   109             {
       
   110             break;
       
   111             }
       
   112         }
       
   113     return 0;
       
   114     }
       
   115     
       
   116 // Util function to write to a socket
       
   117 static TInt Send1(int sock_fd)
       
   118     {
       
   119     char line[KMaxLine];    
       
   120     int x;
       
   121     char character = 'A';
       
   122     unsigned int cnt = 0;
       
   123     for(; cnt < KMaxLine - 1; cnt++)
       
   124         {
       
   125         line[cnt] = character;
       
   126         character++;
       
   127         if (character > 'Z')
       
   128             {
       
   129             character = 'A';
       
   130             }
       
   131         }
       
   132     line[cnt] = '\0';
       
   133     x=send(sock_fd,line,KMaxLine,0);
       
   134     if (x < 0)
       
   135         {
       
   136         return -1;
       
   137         }
       
   138         
       
   139     return 0;
       
   140     }
       
   141 
       
   142 
       
   143 // Util function 
       
   144 static void* TCPThreadWrite(TAny* aPath)
       
   145 	{
       
   146 	int sock_fd,len;
       
   147 		
       
   148 	struct sockaddr_un remote;
       
   149 	int tmp;
       
   150 	memset(&remote, 0x00, sizeof(struct sockaddr_un));    
       
   151 	remote.sun_family=AF_UNIX;    
       
   152 	strcpy((char*)&remote.sun_path, (const char *)aPath);
       
   153 	
       
   154     sock_fd = socket(AF_UNIX,SOCK_STREAM,0);
       
   155     if (sock_fd < 0)
       
   156 		{
       
   157 		goto close;
       
   158 		}
       
   159 	len = sizeof(sockaddr_un);
       
   160 	tmp = connect(sock_fd,(struct sockaddr *)&remote,len);
       
   161 	if (tmp < 0)
       
   162 		{
       
   163 		goto close;
       
   164 		}
       
   165 	if (write1(sock_fd) < 0)
       
   166 		{
       
   167 		goto close;
       
   168 		}
       
   169 close:
       
   170 	close(sock_fd);
       
   171 	unlink((const char *)aPath);
       
   172 	return (void*)NULL;
       
   173 	}
       
   174 	
       
   175 // Util function	
       
   176 static void* TCPThreadRead(TAny* aPath)
       
   177 	{
       
   178 	int sock_fd,len;
       
   179 	char line[KMaxLine ];
       
   180 	
       
   181 	struct sockaddr_un remote;
       
   182 	int tmp;
       
   183 	memset(&remote, 0x00, sizeof(struct sockaddr_un));    
       
   184 	remote.sun_family=AF_UNIX;    
       
   185     strcpy((char*)&remote.sun_path, (const char *)aPath);
       
   186     sock_fd = socket(AF_UNIX,SOCK_STREAM,0);
       
   187     if (sock_fd < 0)
       
   188 		{
       
   189 		goto close;
       
   190 		}
       
   191 	len = strlen(remote.sun_path) + sizeof(remote.sun_family);
       
   192 	tmp = connect(sock_fd,(struct sockaddr *)&remote,len);
       
   193 	if (tmp < 0)
       
   194 		{
       
   195 		goto close;
       
   196 		}
       
   197 	if (read1(sock_fd,line) < 0)
       
   198 		{
       
   199 		goto close;
       
   200 		}
       
   201 close:
       
   202 	close(sock_fd);
       
   203 	unlink((const char *)aPath);
       
   204 	return (void*)NULL;
       
   205 	}	
       
   206 	
       
   207 //Util function to connect to the calling thread
       
   208 void* ThreadConnect(void*)	
       
   209 {
       
   210 	int sockfd = -1;
       
   211 
       
   212 	struct sockaddr_un dest;
       
   213 	unlink(SOCK_PATH);
       
   214 	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
       
   215 	if(sockfd < 0)
       
   216 		{
       
   217 		return (void*)NULL;
       
   218 		}
       
   219 	memset(&dest, 0x00, sizeof(struct sockaddr_un));
       
   220 	dest.sun_family=AF_UNIX; 
       
   221 	strcpy((char*)&dest.sun_path, SOCK_PATH);   
       
   222 	unlink(SOCK_PATH);
       
   223 	if ( bind(sockfd,(struct sockaddr *)&dest,sizeof(dest))  < 0)
       
   224 		{
       
   225 		if(sockfd)
       
   226 			close(sockfd);
       
   227 		return (void*)NULL;
       
   228 		}
       
   229 
       
   230 	strcpy((char*)&dest.sun_path, SERVPATH);
       
   231 	if(connect(sockfd, (struct sockaddr *)&dest, sizeof(dest)) < 0)
       
   232 		{
       
   233 		close(sockfd);
       
   234 		return (void*)NULL;
       
   235 		}
       
   236 	sleep(1);
       
   237 	if(sockfd)
       
   238 		close(sockfd);
       
   239 	return (void*)NULL;
       
   240 }
       
   241 
       
   242 //Util function to sendto() a datagram socket
       
   243 void *ThreadSendto(void *)
       
   244 {
       
   245 	int sockfd = -1;
       
   246     struct sockaddr_un dest;
       
   247     sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
       
   248     if(sockfd < 0)
       
   249     	return (void*)NULL;
       
   250 	memset(&dest, 0x00, sizeof(struct sockaddr_un));    
       
   251 	dest.sun_family=AF_UNIX;    
       
   252 	strcpy((char*)&dest.sun_path, SERVPATH);
       
   253 	socklen_t length = sizeof(struct sockaddr);
       
   254 	sendto(sockfd, DATA, KDataLength, 0, (struct sockaddr*)&dest, length);
       
   255 	if(sockfd)
       
   256 		close(sockfd);
       
   257 	return (void*)NULL;
       
   258 }
       
   259 
       
   260 //Util function to recvfrom() a datagram socket
       
   261 void *ThreadRecvfrom(void *)
       
   262 	{
       
   263 	int sockfd = -1;
       
   264 	char buf[KDataLength];
       
   265 	struct sockaddr_un dest,from;
       
   266     sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
       
   267     if(sockfd < 0)
       
   268     	return (void*)NULL;
       
   269     unlink(SERVPATH);
       
   270 	memset(&dest, 0x00, sizeof(struct sockaddr_un));    
       
   271 	dest.sun_family=AF_UNIX;    
       
   272 	strcpy((char*)&dest.sun_path, SERVPATH);
       
   273 	if ( bind(sockfd,(struct sockaddr *)&dest,sizeof(dest))  < 0)
       
   274 		{
       
   275 		if(sockfd)
       
   276 			close(sockfd);
       
   277 		unlink(SERVPATH);
       
   278 		return (void*)NULL;
       
   279 		}
       
   280 
       
   281 	socklen_t length = sizeof(from);
       
   282 	recvfrom(sockfd, buf, KDataLength, 0, (struct sockaddr*)&from, &length);
       
   283 	if(sockfd)
       
   284 		close(sockfd);
       
   285 	unlink(SERVPATH);
       
   286 	return (void*)NULL;
       
   287 	}
       
   288 
       
   289 /**
       
   290 * Function Name		: TestBind
       
   291 * Description		: bind a local socket
       
   292 * Return Value		: Test case should return KErrNone
       
   293 */
       
   294 TVerdict CTestLocalSocket::TestBind( )
       
   295     {
       
   296     INFO_PRINTF1(_L("TestBind"));
       
   297     int fd = -1;
       
   298     int rslt = -1;
       
   299     int sz = 0,err;
       
   300     const char path[] = "C:\\TestBind";
       
   301     struct sockaddr_un server;
       
   302         
       
   303     server.sun_family = PF_LOCAL;
       
   304     strncpy(server.sun_path, path, strlen(path)+1);
       
   305     sz = SUN_LEN(&server);
       
   306     
       
   307     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
   308     if (fd < 0)
       
   309     	{
       
   310     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
   311     	return TestStepResult();
       
   312     	}
       
   313 
       
   314     rslt = bind(fd, (struct sockaddr*)&server, sz);
       
   315     
       
   316     if (rslt < 0)
       
   317        {
       
   318        INFO_PRINTF2(_L("socket binding error: %d"), errno);
       
   319        close(fd);
       
   320        unlink(path);
       
   321        return TestStepResult();
       
   322        }
       
   323     err=fcntl(fd, F_SETFL, O_NONBLOCK);
       
   324     if(err==-1)
       
   325     	{
       
   326     	INFO_PRINTF1(_L("fcntl failure"));
       
   327     	}
       
   328     close(fd);
       
   329     unlink(path);
       
   330 	
       
   331     SetTestStepResult(EPass);
       
   332     return TestStepResult();
       
   333     }
       
   334 
       
   335 /**
       
   336 * Function Name		: TestLseek
       
   337 * Description		: Perform LSeek on a local socket
       
   338 * Return Value		: Test case should return KErrNone
       
   339 */
       
   340 TVerdict CTestLocalSocket::TestLseek()
       
   341 	{
       
   342 	int sock_fd;
       
   343 	const char path[] = "C:\\TestLSeek";
       
   344 	struct sockaddr_un serveraddr;
       
   345     
       
   346     serveraddr.sun_family = PF_LOCAL;
       
   347     strncpy(serveraddr.sun_path, path, strlen(path)+1);
       
   348 	sock_fd=socket(AF_UNIX, SOCK_STREAM, 0);  
       
   349     if (sock_fd < 0)
       
   350     	{
       
   351     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
   352     	return TestStepResult();
       
   353         }
       
   354 
       
   355     if (lseek(sock_fd,0,SEEK_CUR)<0)
       
   356     	{
       
   357 		INFO_PRINTF1(_L("Lseek on socket success"));
       
   358 		close(sock_fd);
       
   359 		unlink(SERVPATH);
       
   360 		SetTestStepResult(EPass);
       
   361     	}
       
   362     else
       
   363     	{
       
   364     	close(sock_fd);
       
   365     	unlink(SERVPATH);
       
   366     	INFO_PRINTF2(_L("Lseek fails with errno no: %d"), errno);
       
   367     	}
       
   368     return TestStepResult();
       
   369 	}
       
   370 
       
   371 /**
       
   372 * Function Name		: TestFstat
       
   373 * Description		: Perform FStat on a local socket
       
   374 * Return Value		: Test case should return KErrNone
       
   375 */	
       
   376 TVerdict CTestLocalSocket::TestFstat()
       
   377 	{
       
   378 	int sock_fd;
       
   379 	const char path[] = "C:\\TestFStat";
       
   380 	struct sockaddr_un serveraddr;
       
   381     
       
   382     serveraddr.sun_family = PF_LOCAL;
       
   383     strncpy(serveraddr.sun_path, path, strlen(path)+1);
       
   384 	sock_fd=socket(AF_UNIX, SOCK_STREAM, 0);  
       
   385     if (sock_fd < 0)
       
   386     	{
       
   387     	INFO_PRINTF2(_L("Socket open failed with errno: %d"), errno);
       
   388     	return TestStepResult();
       
   389         }
       
   390 
       
   391     struct stat buf;
       
   392     if(fstat(sock_fd , &buf ) < 0 ) 
       
   393     	{
       
   394     	INFO_PRINTF1(_L("fstat on socket failure"));
       
   395 		close(sock_fd);
       
   396 		unlink(SERVPATH);
       
   397     	}
       
   398     else
       
   399     	{
       
   400     	close(sock_fd);
       
   401     	unlink(SERVPATH);
       
   402     	SetTestStepResult(EPass);
       
   403     	}
       
   404     return TestStepResult();
       
   405 	}
       
   406 	
       
   407 /**
       
   408 * Function Name		: TestThreadSocketRead
       
   409 * Description		: Perform read on a local socket
       
   410 * Return Value		: Test case should return KErrNone
       
   411 */	
       
   412 TVerdict CTestLocalSocket::TestThreadSocketRead()
       
   413 	{
       
   414 	int sock_fd,newsock_fd;	
       
   415 	int error;            
       
   416 	unsigned int t;
       
   417 	struct sockaddr_un serveraddr,remote;
       
   418 	char line[KMaxLine ];
       
   419 	sock_fd = socket(AF_UNIX,SOCK_STREAM,0);
       
   420 	if (sock_fd < 0)
       
   421         {
       
   422         INFO_PRINTF2(_L("Socket open failed with errno: %d"), errno);
       
   423     	return TestStepResult();
       
   424         }
       
   425 
       
   426 	pthread_t testThread;
       
   427 	int threadRetVal;
       
   428 	void *threadRetValPtr = (void*)&threadRetVal;
       
   429 	
       
   430 	memset(&serveraddr, 0x00, sizeof(struct sockaddr_un));    
       
   431 	serveraddr.sun_family=AF_UNIX;    
       
   432 	strcpy((char*)&serveraddr.sun_path, SERVPATH);    
       
   433 	if ( bind(sock_fd,(struct sockaddr *)&serveraddr,sizeof(serveraddr))  < 0)
       
   434 		{		
       
   435 		INFO_PRINTF2(_L("Socket bind failed with errno: %d"), errno);
       
   436 		goto close;
       
   437 		}
       
   438 		
       
   439 	if(listen(sock_fd,3) < 0)
       
   440 		{
       
   441 		ERR_PRINTF2(_L("Listen failed with errno: %d\n"),errno);
       
   442 		goto close;
       
   443 		}
       
   444 	t=sizeof(remote);
       
   445 	// Create the thread and thread is client code 
       
   446 	pthread_create(&testThread, NULL, &TCPThreadWrite, (void*)(serveraddr.sun_path));
       
   447 	
       
   448 	newsock_fd = accept(sock_fd,(sockaddr*)&remote,&t); 
       
   449 	if(newsock_fd < 0)
       
   450 		{
       
   451 		ERR_PRINTF2(_L("Accept failed %d\n"),errno);
       
   452 		goto close;
       
   453 		}
       
   454 	error = read1(newsock_fd,line);
       
   455 	if (error < 0)
       
   456 		{		
       
   457 		INFO_PRINTF2(_L("read failed with error %d"), error);
       
   458 		goto close;
       
   459 		}
       
   460 	SetTestStepResult(EPass);
       
   461 close:
       
   462 	pthread_join(testThread, &threadRetValPtr);
       
   463 	shutdown(sock_fd,SHUT_RDWR);
       
   464 	close(sock_fd);
       
   465 	unlink(SERVPATH);
       
   466 	return TestStepResult();	
       
   467 	}
       
   468 
       
   469 
       
   470 /**
       
   471 * Function Name		: TestThreadSocketRead
       
   472 * Description		: Perform read on a local socket
       
   473 * Return Value		: Test case should return KErrNone
       
   474 */	
       
   475 TVerdict CTestLocalSocket::TestThreadSocketRecv()
       
   476 	{
       
   477 	int sock_fd,newsock_fd;	
       
   478 	int error;            
       
   479 	unsigned int t;
       
   480 	struct sockaddr_un serveraddr,remote;
       
   481 	char line[KMaxLine ];
       
   482 	sock_fd = socket(AF_LOCAL,SOCK_STREAM,0);
       
   483 	if (sock_fd < 0)
       
   484         {
       
   485         INFO_PRINTF2(_L("Socket open failed with errno: %d"), errno);
       
   486     	return TestStepResult();
       
   487         }
       
   488 
       
   489 	memset(&serveraddr, 0x00, sizeof(struct sockaddr_un));    
       
   490 	serveraddr.sun_family=AF_LOCAL;    
       
   491 	strcpy((char*)&serveraddr.sun_path, SERVPATH);    
       
   492 	
       
   493 	pthread_t testThread;
       
   494 	int threadRetVal;
       
   495 	void *threadRetValPtr = (void*)&threadRetVal;
       
   496 		
       
   497 	if ( bind(sock_fd,(struct sockaddr *)&serveraddr,sizeof(serveraddr))  < 0)
       
   498 		{		
       
   499 		INFO_PRINTF2(_L("Socket bind failed with errno: %d"), errno);
       
   500 		goto close;
       
   501 		}
       
   502 		
       
   503 	if(listen(sock_fd,3) < 0)
       
   504 		{
       
   505 		ERR_PRINTF2(_L("Listen failed with errno: %d\n"),errno);
       
   506 		goto close;
       
   507 		}
       
   508 	
       
   509 	t=sizeof(remote);
       
   510 	// Create the thread and thread is client code 
       
   511 	pthread_create(&testThread, NULL, &TCPThreadWrite, (void*)(serveraddr.sun_path));
       
   512 
       
   513 	newsock_fd = accept(sock_fd,(sockaddr*)&remote,&t); 
       
   514 	if(newsock_fd < 0)
       
   515 		{
       
   516 		INFO_PRINTF2(_L("accept bind failed with errno: %d"), errno);
       
   517 		goto close;
       
   518 		}
       
   519 	error = Recv1(newsock_fd,line);
       
   520 	if (error < 0)
       
   521 		{		
       
   522 		INFO_PRINTF2(_L("read failed with error %d"), error);
       
   523 		goto close;
       
   524 		}
       
   525 	SetTestStepResult(EPass);
       
   526 close:
       
   527 	pthread_join(testThread, &threadRetValPtr);
       
   528 	shutdown(sock_fd,SHUT_RDWR);
       
   529 	close(sock_fd);
       
   530 	unlink(SERVPATH);
       
   531 	return TestStepResult();	
       
   532 	}
       
   533 	
       
   534 /**
       
   535 * Function Name		: TestThreadSocketWrite
       
   536 * Description		: Perform write on a local socket
       
   537 * Return Value		: Test case should return KErrNone
       
   538 */	
       
   539 TVerdict CTestLocalSocket::TestThreadSocketWrite()
       
   540 	{
       
   541 	int sock_fd,newsock_fd;	
       
   542 	int error;            
       
   543 	unsigned int t;
       
   544 	struct sockaddr_un serveraddr,remote;
       
   545 	sock_fd = socket(AF_UNIX,SOCK_STREAM,0);
       
   546 	if (sock_fd < 0)
       
   547         {
       
   548         INFO_PRINTF2(_L("Socket open failed with errno: %d"), errno);
       
   549     	return TestStepResult();
       
   550         }
       
   551 
       
   552 	memset(&serveraddr, 0x00, sizeof(struct sockaddr_un));    
       
   553 	serveraddr.sun_family=AF_UNIX;    
       
   554 	strcpy((char*)&serveraddr.sun_path, SERVPATH);    
       
   555 
       
   556 	pthread_t testThread;
       
   557 	int threadRetVal;
       
   558 	void *threadRetValPtr = (void*)&threadRetVal;
       
   559 	
       
   560 	if ( bind(sock_fd,(struct sockaddr *)&serveraddr,sizeof(serveraddr))  < 0)
       
   561 		{		
       
   562 		INFO_PRINTF2(_L("BIND failed with errno: %d"), errno);
       
   563 		goto close;
       
   564 		}
       
   565 		
       
   566 	if(listen(sock_fd,3) < 0)
       
   567 		{
       
   568 		ERR_PRINTF2(_L("Listen failed with errno: %d\n"),errno);
       
   569 		goto close;
       
   570 		}
       
   571 	
       
   572 	t=sizeof(remote);
       
   573 	// Create the thread and thread is client code 
       
   574 	pthread_create(&testThread, NULL, &TCPThreadRead, (void*)(serveraddr.sun_path));
       
   575 
       
   576 	newsock_fd = accept(sock_fd,(sockaddr*)&remote,&t); 
       
   577 	error = write1(newsock_fd);
       
   578 	if (error < 0)
       
   579 		{		
       
   580 		goto close;
       
   581 		}
       
   582 	SetTestStepResult(EPass);
       
   583 close:
       
   584 	pthread_join(testThread, &threadRetValPtr);
       
   585 	shutdown(sock_fd,SHUT_RDWR);
       
   586 	close(sock_fd);
       
   587 	unlink(SERVPATH);
       
   588 	return TestStepResult();	
       
   589 
       
   590 	}
       
   591 
       
   592 /**
       
   593 * Function Name		: TestThreadSocketSend
       
   594 * Description		: Perform Send on a local socket
       
   595 * Return Value		: Test case should return KErrNone
       
   596 */	
       
   597 TVerdict CTestLocalSocket::TestThreadSocketSend()
       
   598 	{
       
   599 	int sock_fd,newsock_fd;	
       
   600 	int error;            
       
   601 	unsigned int t;
       
   602 	struct sockaddr_un serveraddr,remote;
       
   603 	sock_fd = socket(AF_LOCAL,SOCK_STREAM,0);
       
   604 	if (sock_fd < 0)
       
   605         {
       
   606         INFO_PRINTF2(_L("Socket open failed with errno: %d"), errno);
       
   607     	return TestStepResult();
       
   608         }
       
   609 
       
   610 	memset(&serveraddr, 0x00, sizeof(struct sockaddr_un));    
       
   611 	serveraddr.sun_family=AF_LOCAL;    
       
   612 	strcpy((char*)&serveraddr.sun_path, SERVPATH);
       
   613 	
       
   614 	pthread_t testThread;
       
   615 	int threadRetVal;
       
   616 	void *threadRetValPtr = (void*)&threadRetVal;
       
   617 		
       
   618 	if ( bind(sock_fd,(struct sockaddr *)&serveraddr,sizeof(serveraddr))  < 0)
       
   619 		{		
       
   620 		INFO_PRINTF2(_L("socket bind failed with errno: %d"), errno);
       
   621 		goto close;
       
   622 		}
       
   623 		
       
   624 	if(listen(sock_fd,3) < 0)
       
   625 		{
       
   626 		ERR_PRINTF2(_L("Listen failed with errno: %d\n"),errno);
       
   627 		goto close;
       
   628 		}
       
   629 	
       
   630 	t=sizeof(remote);
       
   631 	// Create the thread and thread is client code 
       
   632 	pthread_create(&testThread, NULL, &TCPThreadRead, (void*)(serveraddr.sun_path));
       
   633 
       
   634 	newsock_fd = accept(sock_fd,(sockaddr*)&remote,&t);
       
   635 	if(newsock_fd < 0)
       
   636 		{
       
   637 		INFO_PRINTF2(_L("accept failed with errno: %d"), errno);
       
   638 		goto close;
       
   639 		}
       
   640 	error = Send1(newsock_fd);
       
   641 	if (error < 0)
       
   642 		{		
       
   643 		INFO_PRINTF2(_L("Send failed with errno: %d"), errno);
       
   644 		goto close;
       
   645 		}
       
   646 	
       
   647 	SetTestStepResult(EPass);
       
   648 close:
       
   649 	pthread_join(testThread, &threadRetValPtr);
       
   650 	shutdown(sock_fd,SHUT_RDWR);
       
   651 	close(sock_fd);
       
   652 	unlink(SERVPATH);
       
   653 	return TestStepResult();	
       
   654 
       
   655 	}
       
   656 
       
   657 
       
   658 /**
       
   659 * Function Name		: TestMultProc
       
   660 * Description		: Perform read and write on a local socket across processes
       
   661 * Return Value		: Test case should return KErrNone
       
   662 */
       
   663 TVerdict CTestLocalSocket::TestMultProc()
       
   664 	{
       
   665 	char *cmd="Z:\\sys\\bin\\tsample.exe";
       
   666 	int fp,n=0;
       
   667 	int sock_fd,len;
       
   668 	char line[KMaxLine ];
       
   669     struct sockaddr_un remote;
       
   670 	
       
   671 	memset(&remote, 0x00, sizeof(struct sockaddr_un));    
       
   672 	remote.sun_family=AF_UNIX;    
       
   673 	strcpy((char*)&remote.sun_path, "c:\\tmp.pipe");
       
   674 	
       
   675     sock_fd = socket(AF_UNIX,SOCK_STREAM,0);
       
   676     INFO_PRINTF1(_L("socket in client called"));
       
   677     
       
   678     
       
   679     int fds[3]; 
       
   680     int tmp;
       
   681     int val;
       
   682     fp = popen3(cmd,NULL, NULL, fds);
       
   683     if(fp < 0)
       
   684     	{
       
   685     	INFO_PRINTF2(_L("popen3 failed with errno: %d"), errno);
       
   686     	goto close;
       
   687     	}
       
   688     sleep(1);
       
   689     len = strlen(remote.sun_path) + sizeof(remote.sun_family);
       
   690 	tmp = connect(sock_fd,(struct sockaddr *)&remote,len);
       
   691 	if (tmp < 0)
       
   692 		{
       
   693 		INFO_PRINTF2(_L("connect failed with errno: %d"), errno);
       
   694 		goto close;
       
   695 		}   
       
   696 	
       
   697 	if (read1(sock_fd,line) < 0)
       
   698 		{
       
   699 		INFO_PRINTF2(_L("read failed with errno: %d"), errno);
       
   700 		goto close;
       
   701 		}
       
   702 	
       
   703 	val=strcmp(line, "ABCDEFGHIJKLMNOPQRSTUVWXYZ");	
       
   704 	if(val)
       
   705 		{
       
   706 		INFO_PRINTF1(_L("string compare failed"));
       
   707 		}
       
   708 	else
       
   709 		{
       
   710 		SetTestStepResult(EPass);
       
   711 		}
       
   712     INFO_PRINTF2(_L("n=%d"),n);    
       
   713 	n=errno;
       
   714 close:
       
   715     close(sock_fd);
       
   716 	unlink(SERVPATH);
       
   717     return TestStepResult();	
       
   718 	}
       
   719 	
       
   720 struct TThreadParam
       
   721 	{
       
   722 	TInt iDataCount;
       
   723 	sem_t iSemaphore;
       
   724 	};
       
   725 
       
   726 //Util function
       
   727 void* SocketReadThreadEntryPoint(void* aParam)
       
   728 	{
       
   729 	TInt retVal = 0;
       
   730 	TInt count = 5;
       
   731     TThreadParam* pThreadParam = ( TThreadParam* ) aParam;
       
   732 
       
   733 	TInt portNum = 0;
       
   734 	int serverFd = 0;
       
   735 	int newFd = 0;
       
   736 	size_t addrSize;
       
   737 	struct sockaddr_in servAddr;
       
   738 	struct sockaddr_in sockAddr;
       
   739 	const char* buff = "Server --> Sending Data Item : ";
       
   740 	char sendBuff[50];
       
   741 	char recvBuff[100];
       
   742 	const unsigned int maxRecv = 100;
       
   743 
       
   744 	serverFd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
   745 	if( serverFd == -1 )
       
   746 		{
       
   747 		retVal = -1;
       
   748 		}
       
   749 
       
   750 	(&servAddr)->sin_addr.s_addr  = 0x0100007F;
       
   751 	(&servAddr)->sin_family = PF_LOCAL;
       
   752 
       
   753 	servAddr.sin_port = htons( (TUint16) portNum );
       
   754 	retVal |= bind( serverFd, (struct sockaddr*)&servAddr, sizeof(servAddr) );
       
   755 	if( retVal != 0 )
       
   756 		{
       
   757 		close( serverFd );
       
   758 		retVal = -1;
       
   759 		}
       
   760 
       
   761 	
       
   762 
       
   763 	addrSize = sizeof( sockAddr );
       
   764 
       
   765 	//Tell the other thread that data is ready for reading
       
   766 	retVal = sem_post(&pThreadParam->iSemaphore);
       
   767 	if( retVal != 0 )
       
   768 		{
       
   769 		close( serverFd );
       
   770 		retVal = -1;
       
   771 		}
       
   772 
       
   773 	newFd = accept( serverFd, (struct sockaddr*)&sockAddr, &addrSize);
       
   774 	if( newFd == -1 )
       
   775 		{
       
   776 		close( serverFd );
       
   777 		retVal = -1;
       
   778 	    return (void*)retVal;
       
   779 		}
       
   780 
       
   781 	if( 0 == retVal )
       
   782 		{
       
   783 		//Now Receive and Send some Data
       
   784 		for(TUint i=1; i<=count; i++)
       
   785 			{
       
   786 			TInt ret = recv(newFd, recvBuff, maxRecv, 0);
       
   787 			if( ret == -1 )
       
   788 				{
       
   789 				close( newFd );
       
   790 				close( serverFd );
       
   791 				retVal = -1;
       
   792 				break;
       
   793 				}
       
   794 			sprintf(sendBuff, "%s %d", buff, i);
       
   795 			ret = send(newFd, sendBuff, sizeof(sendBuff), 0);
       
   796 			if( ret == -1 )
       
   797 				{
       
   798 				close( newFd );
       
   799 				close( serverFd );
       
   800 				retVal = -1;
       
   801 				break;
       
   802 				}
       
   803 			}
       
   804 		}
       
   805 
       
   806 	if( 0 == retVal )
       
   807 		{
       
   808 		close( newFd );
       
   809 		close( serverFd );
       
   810 		}
       
   811 	return (void*)retVal;
       
   812 	}
       
   813 
       
   814 //Util function
       
   815 void* SocketWriteThreadEntryPoint(void* aParam)
       
   816 	{
       
   817 	TInt retVal = 0;
       
   818 	TInt count = 5;
       
   819     TThreadParam* pThreadParam = ( TThreadParam* ) aParam;
       
   820 
       
   821 	TInt portNum = 0;
       
   822 	int clientFd;
       
   823 	size_t addrSize;
       
   824 	struct sockaddr_in servAddr;
       
   825 	const char* buff = "Client --> Sending Data Item : ";
       
   826 	char sendBuff[50];
       
   827 	char recvBuff[100];
       
   828 	const unsigned int maxRecv = 100;
       
   829 
       
   830 	(&servAddr)->sin_addr.s_addr  = 0x0100007F;
       
   831 	(&servAddr)->sin_family = PF_LOCAL;
       
   832 
       
   833 	servAddr.sin_port = htons( portNum );
       
   834 
       
   835 	clientFd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
   836 	if( clientFd == -1 )
       
   837 		{
       
   838 		retVal = -1;
       
   839 		}
       
   840 
       
   841     //Wait for the other thread to write some data to file
       
   842     retVal = sem_wait(&pThreadParam->iSemaphore);
       
   843     if( retVal != 0 )
       
   844     	{
       
   845     	close(clientFd);
       
   846     	retVal = -1;
       
   847 	    return (void*)retVal;
       
   848     	}
       
   849 
       
   850 	addrSize = sizeof(servAddr);
       
   851 	retVal = connect(clientFd, (struct sockaddr*)&servAddr, addrSize);
       
   852 	if( retVal == -1 )
       
   853 		{
       
   854 		close(clientFd);
       
   855 		retVal = -1;
       
   856 		}
       
   857 
       
   858 	if( 0 == retVal )
       
   859 		{
       
   860 		//Now Send and Receive some Data
       
   861 		for(TUint i=1; i<=count; i++)
       
   862 			{
       
   863 			sprintf(sendBuff, "%s %d", buff, i);
       
   864 			TInt ret = send(clientFd, sendBuff, sizeof(sendBuff), 0);
       
   865 			if(ret == -1)
       
   866 				{
       
   867 				close( clientFd );
       
   868 				retVal = -1;
       
   869 				break;
       
   870 				}
       
   871 			ret = recv(clientFd, recvBuff, maxRecv, 0);
       
   872 			if(ret == -1)
       
   873 				{
       
   874 				close( clientFd );
       
   875 				retVal = -1;
       
   876 				break;
       
   877 				}
       
   878 			}
       
   879 		}
       
   880 
       
   881 	if (0 == retVal )
       
   882 		{
       
   883 		close( clientFd );
       
   884 		}
       
   885 
       
   886 	return (void*)retVal;
       
   887 	}
       
   888 
       
   889 /**
       
   890 * Function Name		: TestMultThread
       
   891 * Description		: Perform read and write on a local socket across threads
       
   892 * Return Value		: Test case should return KErrNone
       
   893 */
       
   894 TVerdict CTestLocalSocket::TestMultThread()
       
   895 	{
       
   896 	int retVal = 0;
       
   897 	
       
   898 	
       
   899     TThreadParam threadParam;
       
   900 
       
   901 	if( sem_init( &threadParam.iSemaphore, 0, 0 ) != 0 )
       
   902     	{
       
   903     	
       
   904     	//return -1;
       
   905     	return TestStepResult();
       
   906     	}
       
   907 
       
   908 	pthread_t threadID1 = 0;
       
   909 	pthread_t threadID2 = 0;
       
   910 	pthread_attr_t threadAttr;
       
   911 	pthread_attr_init( &threadAttr );
       
   912 	pthread_attr_setdetachstate( &threadAttr, PTHREAD_CREATE_JOINABLE );
       
   913 
       
   914 	//Create a Read thread now
       
   915 	retVal = pthread_create( &threadID1, &threadAttr, SocketReadThreadEntryPoint,
       
   916 		(void*)&threadParam );
       
   917 	
       
   918 	if( retVal == 0)
       
   919 		{
       
   920 		//Create Write thread
       
   921 		retVal = pthread_create( &threadID2, &threadAttr,
       
   922 			SocketWriteThreadEntryPoint, (void*)&threadParam );
       
   923 		
       
   924 		//If its joinable thread and waitFlag id set
       
   925 		if( 0 == retVal )
       
   926 			{
       
   927 			TInt exitReason = 0;
       
   928 			retVal = pthread_join(threadID1, (void**)&exitReason );
       
   929 			
       
   930 			retVal = pthread_join(threadID2, (void**)&exitReason );
       
   931 			
       
   932 			}
       
   933 		}
       
   934 
       
   935 	if( sem_destroy( &threadParam.iSemaphore ) != 0 )
       
   936 		{
       
   937 		return TestStepResult();
       
   938 		//retVal = -1;
       
   939 		}
       
   940 
       
   941 	SetTestStepResult(EPass);
       
   942 	return TestStepResult();
       
   943 	}
       
   944 
       
   945 		
       
   946 
       
   947 /*
       
   948 * Testcase		: TestSetGetSockOpt
       
   949 * Description	: Test setsockopt for different values of option_name
       
   950 *					1. SO_SNDBUF
       
   951 *					2. SO_RCVBUF
       
   952 *					3. SO_DEBUG
       
   953 *				  and upon succes of setsockopt, test getsockopt for the same
       
   954 * Result		: KErrNone
       
   955 */ 
       
   956 TVerdict CTestLocalSocket::TestSetGetSockOpt()
       
   957 	{
       
   958 	INFO_PRINTF1(_L("TestSetGetSockOpt"));
       
   959 	int fd;
       
   960 	int sz = 0, optionName = 0;
       
   961 	int rslt;
       
   962 	const char path[] = "C:\\TestSetGetSockOpt";
       
   963 	struct sockaddr_un server;
       
   964         
       
   965     server.sun_family = PF_LOCAL;
       
   966     strncpy(server.sun_path, path, strlen(path)+1);
       
   967     sz = SUN_LEN(&server);
       
   968     
       
   969     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
   970     if (fd < 0)
       
   971     	{
       
   972     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
   973     	return TestStepResult();
       
   974     	}
       
   975    	   	
       
   976    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
   977     
       
   978     if (rslt)
       
   979        	{
       
   980        	INFO_PRINTF2(_L("socket binding error: %d"), errno);
       
   981        	unlink(path);
       
   982 		close(fd);
       
   983        	return TestStepResult();
       
   984        	}
       
   985        
       
   986     int optionValue = KMaxLine;
       
   987     _LIT( KOptionName, "OptionName" );
       
   988 	rslt = GetIntFromConfig(ConfigSection(), KOptionName, optionName);
       
   989 	if(!rslt)
       
   990 		{
       
   991 	 	INFO_PRINTF1(_L("Could not read option name from ini file"));
       
   992 	 	close(fd);
       
   993 		unlink(path);
       
   994 	 	return TestStepResult();
       
   995 		}    
       
   996     
       
   997     rslt = setsockopt(fd, SOL_SOCKET, optionName, &optionValue, sizeof(optionValue));
       
   998 	if(rslt < 0)
       
   999 		{
       
  1000 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1001 		}
       
  1002 	else
       
  1003 		{
       
  1004 		INFO_PRINTF1(_L("Setsockopt successful"));
       
  1005 		
       
  1006 		unsigned int optionLen = sizeof(optionValue);
       
  1007   		int readOptionValue = 0;
       
  1008     	rslt = getsockopt(fd, SOL_SOCKET, optionName, (void *)&readOptionValue, &optionLen);
       
  1009     
       
  1010     	if(rslt < 0)
       
  1011 			{
       
  1012 			INFO_PRINTF2(_L("Getsockopt fails with error no: %d"), errno);
       
  1013 			}
       
  1014 		else
       
  1015 			{
       
  1016 			INFO_PRINTF1(_L("Getsockopt successful"));
       
  1017 			SetTestStepResult(EPass);
       
  1018 			}
       
  1019 		}
       
  1020 	
       
  1021 	close(fd);
       
  1022 	unlink(path);
       
  1023 	return TestStepResult();
       
  1024 	}
       
  1025 
       
  1026 /*
       
  1027 * Testcase		: TestSetSockOptNegative1
       
  1028 * Description	: Test setsockopt for an invalid value of option_name
       
  1029 * Result		: setsockopt returns setting errno to EINVAL, 
       
  1030 *				  Test case returns KErrNone
       
  1031 */
       
  1032 TVerdict CTestLocalSocket::TestSetSockOptNegative1()
       
  1033 	{
       
  1034 	INFO_PRINTF1(_L("TestSetSockOptNegative1"));
       
  1035 	int fd;
       
  1036 	int sz = 0, optionName = 0;
       
  1037 	int rslt;
       
  1038 	const char path[] = "C:\\TestSetSockOptNegative1";
       
  1039 	struct sockaddr_un server;
       
  1040         
       
  1041     server.sun_family = PF_LOCAL;
       
  1042     strncpy(server.sun_path, path, strlen(path)+1);
       
  1043     sz = SUN_LEN(&server);
       
  1044     
       
  1045     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1046     if (fd < 0)
       
  1047     	{
       
  1048     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1049     	return TestStepResult();
       
  1050     	}
       
  1051    	   	
       
  1052    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1053     
       
  1054     if (rslt)
       
  1055        {
       
  1056        INFO_PRINTF1(_L("socket binding error"));
       
  1057        return TestStepResult(); 
       
  1058        }
       
  1059        
       
  1060     int optionValue = KMaxLine;
       
  1061     _LIT( KOptionName, "OptionName" );
       
  1062 	rslt = GetIntFromConfig(ConfigSection(), KOptionName, optionName);
       
  1063 	if(!rslt)
       
  1064 		{
       
  1065 	 	INFO_PRINTF1(_L("Could not read option name from ini file"));
       
  1066 	 	close(fd);
       
  1067 		unlink(path);
       
  1068 	 	return TestStepResult();
       
  1069 		}    
       
  1070     
       
  1071     rslt = setsockopt(fd, SOL_SOCKET, optionName, &optionValue, sizeof(optionValue));
       
  1072 	if(rslt < 0 && errno == ENOPROTOOPT)
       
  1073 		{
       
  1074 		INFO_PRINTF1(_L("setsockopt fails with right error value"));
       
  1075 		SetTestStepResult(EPass);
       
  1076 		}
       
  1077 	else
       
  1078 		{
       
  1079 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1080 		}
       
  1081 	
       
  1082 	close(fd);
       
  1083 	unlink(path);
       
  1084 	return TestStepResult();
       
  1085 	}
       
  1086 /*
       
  1087 * Testcase		: TestSetSockOptNegative2
       
  1088 * Description	: Test setsockopt for invalid value of socklen_t
       
  1089 * Result		: setsockopt returns -1 setting errno to EINVAL 
       
  1090 *				  Test case returns KErrNone
       
  1091 */	
       
  1092 TVerdict CTestLocalSocket::TestSetSockOptNegative2()
       
  1093 	{
       
  1094 	INFO_PRINTF1(_L("TestSetSockOptNegative2"));
       
  1095 	int fd;
       
  1096 	int sz = 0;
       
  1097 	int rslt;
       
  1098 	const char path[] = "C:\\TestSetSockOptNegative2";
       
  1099 	struct sockaddr_un server;
       
  1100         
       
  1101     server.sun_family = PF_LOCAL;
       
  1102     strncpy(server.sun_path, path, strlen(path)+1);
       
  1103     sz = SUN_LEN(&server);
       
  1104     
       
  1105     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1106     if (fd < 0)
       
  1107     	{
       
  1108     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1109     	return TestStepResult();
       
  1110     	}
       
  1111    	   	
       
  1112    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1113     
       
  1114     if (rslt)
       
  1115        {
       
  1116        INFO_PRINTF1(_L("socket binding error"));
       
  1117        return TestStepResult();
       
  1118        }
       
  1119        
       
  1120     int optionValue = KMaxLine;
       
  1121     int sockLen=0;
       
  1122     
       
  1123     _LIT( KSocketLen, "SocketLen" );
       
  1124 	rslt = GetIntFromConfig(ConfigSection(), KSocketLen, sockLen);
       
  1125 	if(!rslt)
       
  1126 		{
       
  1127 	 	INFO_PRINTF1(_L("Could not read option name from ini file"));
       
  1128 	 	close(fd);
       
  1129 		unlink(path);
       
  1130 	 	return TestStepResult();
       
  1131 		}    
       
  1132     rslt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optionValue, sockLen);
       
  1133     if(rslt < 0 && errno == EINVAL)
       
  1134 		{
       
  1135 		INFO_PRINTF1(_L("Setsockopt fails with right error value"));
       
  1136 		SetTestStepResult(EPass);
       
  1137 		}
       
  1138 	else
       
  1139 		{
       
  1140 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1141 		}
       
  1142 	
       
  1143 	close(fd);
       
  1144 	unlink(path);
       
  1145 	return TestStepResult();
       
  1146 	}
       
  1147 
       
  1148 /*
       
  1149 * Testcase		: TestSetSockOptNegative3
       
  1150 * Description	: Test setsockopt for value of level other than SOL_SOCKET
       
  1151 * Result		: setsockopt returns EINVAL, test case returns KErrNone
       
  1152 */	
       
  1153 TVerdict CTestLocalSocket::TestSetSockOptNegative3()
       
  1154 	{
       
  1155 	INFO_PRINTF1(_L("TestSetSockOptNegative3"));
       
  1156 	int fd;
       
  1157 	int sz = 0;
       
  1158 	int rslt;
       
  1159 	const char path[] = "C:\\TestSetSockOptNegative3";
       
  1160 	struct sockaddr_un server;
       
  1161         
       
  1162     server.sun_family = PF_LOCAL;
       
  1163     strncpy(server.sun_path, path, strlen(path)+1);
       
  1164     sz = SUN_LEN(&server);
       
  1165     
       
  1166     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1167     if (fd < 0)
       
  1168     	{
       
  1169     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1170     	return TestStepResult();
       
  1171     	}
       
  1172    	   	
       
  1173    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1174     
       
  1175     if (rslt)
       
  1176        {
       
  1177        INFO_PRINTF1(_L("socket binding error"));
       
  1178        return TestStepResult();
       
  1179        }
       
  1180        
       
  1181     int optionValue = KMaxLine;
       
  1182       
       
  1183     // pass invalid level = 3
       
  1184     rslt = setsockopt(fd, 3, SO_SNDBUF, &optionValue, sizeof(optionValue));
       
  1185         
       
  1186     if(rslt < 0 && errno == ENOPROTOOPT)
       
  1187 		{
       
  1188 		INFO_PRINTF1(_L("Setsockopt fails with right error value"));
       
  1189 		SetTestStepResult(EPass);
       
  1190 		}
       
  1191 	else
       
  1192 		{
       
  1193 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1194 		}
       
  1195 	
       
  1196 	close(fd);
       
  1197 	unlink(path);
       
  1198 	return TestStepResult();
       
  1199 	}
       
  1200 
       
  1201 /*
       
  1202 * Testcase		: TestSetSockOptNegative4
       
  1203 * Description	: Test setsockopt for option_value=NULL
       
  1204 * Result		: setsockopt returns EFAULT, test case returns KErrNone
       
  1205 */	
       
  1206 TVerdict CTestLocalSocket::TestSetSockOptNegative4()
       
  1207 	{
       
  1208 	INFO_PRINTF1(_L("TestSetSockOptNegative4"));
       
  1209 	int fd;
       
  1210 	int sz = 0;
       
  1211 	int rslt;
       
  1212 	const char path[] = "C:\\TestSetSockOptNegative4";
       
  1213 	struct sockaddr_un server;
       
  1214         
       
  1215     server.sun_family = PF_LOCAL;
       
  1216     strncpy(server.sun_path, path, strlen(path)+1);
       
  1217     sz = SUN_LEN(&server);
       
  1218     
       
  1219     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1220     if (fd < 0)
       
  1221     	{
       
  1222     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1223     	return TestStepResult();
       
  1224     	}
       
  1225    	   	
       
  1226    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1227     
       
  1228     if (rslt)
       
  1229        {
       
  1230        INFO_PRINTF1(_L("socket binding error"));
       
  1231        return TestStepResult();
       
  1232        }
       
  1233        
       
  1234     rslt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, NULL, NULL);
       
  1235         
       
  1236     if(rslt < 0 && errno == EFAULT)
       
  1237 		{
       
  1238 		INFO_PRINTF1(_L("Setsockopt fails with right error value"));
       
  1239 		SetTestStepResult(EPass);
       
  1240 		}
       
  1241 	else
       
  1242 		{
       
  1243 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1244 		}
       
  1245 	
       
  1246 	close(fd);
       
  1247 	unlink(path);
       
  1248 	return TestStepResult();
       
  1249 	}
       
  1250 
       
  1251 /*
       
  1252 * Testcase		: TestGetSockOptNegative1
       
  1253 * Description	: Test getsockopt for an invalid value of option_name
       
  1254 * Result		: getsockopt returns EINVAL, test case returns KErrNone
       
  1255 */	
       
  1256 TVerdict CTestLocalSocket::TestGetSockOptNegative1()
       
  1257 	{
       
  1258 	INFO_PRINTF1(_L("TestGetSockOptNegative1"));
       
  1259 	int fd;
       
  1260 	int sz = 0;
       
  1261 	int rslt;
       
  1262 	const char path[] = "C:\\TestGetSockOptNegative1";
       
  1263 	struct sockaddr_un server;
       
  1264         
       
  1265     server.sun_family = PF_LOCAL;
       
  1266     strncpy(server.sun_path, path, strlen(path)+1);
       
  1267     sz = SUN_LEN(&server);
       
  1268     
       
  1269     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1270     if (fd < 0)
       
  1271     	{
       
  1272     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1273     	return TestStepResult();
       
  1274     	}
       
  1275    	   	
       
  1276    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1277     
       
  1278     if (rslt)
       
  1279        {
       
  1280        INFO_PRINTF1(_L("socket binding error"));
       
  1281        return TestStepResult();
       
  1282        }
       
  1283        
       
  1284     int optionValue = KMaxLine;
       
  1285     rslt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optionValue, sizeof(optionValue));
       
  1286 	if(rslt < 0)
       
  1287 		{
       
  1288 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1289 		}
       
  1290 	else
       
  1291 		{
       
  1292 		INFO_PRINTF1(_L("Setsockopt successful"));
       
  1293 		
       
  1294 		unsigned int optionLen = sizeof(optionValue);
       
  1295   		int readOptionValue = 0;
       
  1296   		int invalidOptName = 0;
       
  1297   		 _LIT( KOptionName, "OptionName" );
       
  1298 		rslt = GetIntFromConfig(ConfigSection(), KOptionName, invalidOptName);
       
  1299 		if(!rslt)
       
  1300 			{
       
  1301 	 		INFO_PRINTF1(_L("Could not read option name from ini file"));
       
  1302 	 		close(fd);
       
  1303 			unlink(path);
       
  1304 	 		return TestStepResult();
       
  1305 			}  
       
  1306     	rslt = getsockopt(fd, SOL_SOCKET, invalidOptName, (void *)&readOptionValue, &optionLen);
       
  1307     
       
  1308     	if(rslt < 0 && errno == ENOPROTOOPT)
       
  1309 			{
       
  1310 			INFO_PRINTF1(_L("getsockopt fails with right error value"));
       
  1311 			SetTestStepResult(EPass);
       
  1312 			}
       
  1313 		else
       
  1314 			{
       
  1315 			INFO_PRINTF2(_L("getsockopt fails with error no: %d"), errno);
       
  1316 			}
       
  1317 		}
       
  1318 	
       
  1319 	close(fd);
       
  1320 	unlink(path);
       
  1321 	return TestStepResult();
       
  1322 	}
       
  1323 
       
  1324 /*
       
  1325 * Testcase		: TestGetSockOptNegative2
       
  1326 * Description	: Test getsockopt for option_value=NULL
       
  1327 * Result		: getsockopt returns EFAULT, test case returns KErrNone
       
  1328 */	
       
  1329 TVerdict CTestLocalSocket::TestGetSockOptNegative2()
       
  1330 	{
       
  1331 	INFO_PRINTF1(_L("TestGetSockOptNegative2"));
       
  1332 	int fd;
       
  1333 	int sz = 0;
       
  1334 	int rslt;
       
  1335 	const char path[] = "C:\\TestGetSockOptNegative2";
       
  1336 	struct sockaddr_un server;
       
  1337         
       
  1338     server.sun_family = PF_LOCAL;
       
  1339     strncpy(server.sun_path, path, strlen(path)+1);
       
  1340     sz = SUN_LEN(&server);
       
  1341     
       
  1342     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1343     if (fd < 0)
       
  1344     	{
       
  1345     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1346     	return TestStepResult();
       
  1347     	}
       
  1348    	   	
       
  1349    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1350     
       
  1351     if (rslt)
       
  1352        {
       
  1353        INFO_PRINTF1(_L("socket binding error"));
       
  1354        return TestStepResult();
       
  1355        }
       
  1356        
       
  1357     int optionValue = KMaxLine;
       
  1358     rslt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optionValue, sizeof(optionValue));
       
  1359 	if(rslt < 0)
       
  1360 		{
       
  1361 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1362 		}
       
  1363 	else
       
  1364 		{
       
  1365 		INFO_PRINTF1(_L("Setsockopt successful"));
       
  1366 		
       
  1367 		unsigned int optionLen = sizeof(optionValue);
       
  1368   		  		 		
       
  1369     	rslt = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, NULL, &optionLen);
       
  1370     
       
  1371     	if(rslt < 0 && errno == EFAULT)
       
  1372 			{
       
  1373 			INFO_PRINTF1(_L("getsockopt fails with right error value"));
       
  1374 			SetTestStepResult(EPass);
       
  1375 			}
       
  1376 		else
       
  1377 			{
       
  1378 			INFO_PRINTF2(_L("getsockopt fails with error no: %d"), errno);
       
  1379 			}
       
  1380 		}
       
  1381 	
       
  1382 	close(fd);
       
  1383 	unlink(path);
       
  1384 	return TestStepResult();
       
  1385 	}
       
  1386 
       
  1387 /*
       
  1388 * Testcase		: TestGetSockOptNegative3
       
  1389 * Description	: Test getsockopt for invalid value of socklen_t
       
  1390 * Result		: getsockopt returns EINVAL, test case returns KErrNone
       
  1391 */	
       
  1392 TVerdict CTestLocalSocket::TestGetSockOptNegative3()
       
  1393 	{
       
  1394 	INFO_PRINTF1(_L("TestGetSockOptNegative3"));
       
  1395 	int fd;
       
  1396 	int sz = 0;
       
  1397 	int rslt;
       
  1398 	const char path[] = "C:\\TestGetSockOptNegative3";
       
  1399 	struct sockaddr_un server;
       
  1400         
       
  1401     server.sun_family = PF_LOCAL;
       
  1402     strncpy(server.sun_path, path, strlen(path)+1);
       
  1403     sz = SUN_LEN(&server);
       
  1404     
       
  1405     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1406     if (fd < 0)
       
  1407     	{
       
  1408     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1409     	return TestStepResult();
       
  1410     	}
       
  1411    	   	
       
  1412    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1413     
       
  1414     if (rslt)
       
  1415        {
       
  1416        INFO_PRINTF1(_L("socket binding error"));
       
  1417        return TestStepResult();
       
  1418        }
       
  1419        
       
  1420     int optionValue = KMaxLine;
       
  1421     rslt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optionValue, sizeof(optionValue));
       
  1422 	if(rslt < 0)
       
  1423 		{
       
  1424 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1425 		}
       
  1426 	else
       
  1427 		{
       
  1428 		INFO_PRINTF1(_L("Setsockopt successful"));
       
  1429 		
       
  1430 		int readOptionValue = 0;
       
  1431 		unsigned int sockLen = 0;
       
  1432   		
       
  1433   	   	rslt = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (void *)&readOptionValue, &sockLen);
       
  1434     
       
  1435 	    if(rslt < 0 && errno == EINVAL)
       
  1436 			{
       
  1437 			INFO_PRINTF1(_L("getsockopt fails with right error value"));
       
  1438 			SetTestStepResult(EPass);
       
  1439 			}
       
  1440 		else
       
  1441 			{
       
  1442 			INFO_PRINTF2(_L("getsockopt fails with error no: %d"), errno);
       
  1443 			}
       
  1444 		}
       
  1445 	
       
  1446 	close(fd);
       
  1447 	unlink(path);
       
  1448 	return TestStepResult();
       
  1449 	}
       
  1450 
       
  1451 /*
       
  1452 * Testcase		: TestGetSockOptNegative4
       
  1453 * Description	: Test setsockopt for value of level other than SOL_SOCKET
       
  1454 * Result		: setsockopt returns EINVAL, test case returns KErrNone
       
  1455 */	
       
  1456 TVerdict CTestLocalSocket::TestGetSockOptNegative4()
       
  1457 	{
       
  1458 	INFO_PRINTF1(_L("TestGetSockOptNegative4"));
       
  1459 	int fd;
       
  1460 	int sz = 0;
       
  1461 	int rslt;
       
  1462 	const char path[] = "C:\\TestGetSockOptNegative4";
       
  1463 	struct sockaddr_un server;
       
  1464         
       
  1465     server.sun_family = PF_LOCAL;
       
  1466     strncpy(server.sun_path, path, strlen(path)+1);
       
  1467     sz = SUN_LEN(&server);
       
  1468     
       
  1469     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1470     if (fd < 0)
       
  1471     	{
       
  1472     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1473     	return TestStepResult();
       
  1474     	}
       
  1475 
       
  1476    	rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1477     
       
  1478     if (rslt)
       
  1479        {
       
  1480        INFO_PRINTF1(_L("socket binding error"));
       
  1481        return TestStepResult();
       
  1482        }
       
  1483        
       
  1484     int optionValue = KMaxLine;
       
  1485     rslt = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optionValue, sizeof(optionValue));
       
  1486 	if(rslt < 0)
       
  1487 		{
       
  1488 		INFO_PRINTF2(_L("Setsockopt fails with error no: %d"), errno);
       
  1489 		}
       
  1490 	else
       
  1491 		{
       
  1492 		INFO_PRINTF1(_L("Setsockopt successful"));
       
  1493 		
       
  1494 		unsigned int optionLen = sizeof(optionValue);
       
  1495 		int readOptionValue = 0;
       
  1496 				  		
       
  1497   		// pass invalid level = 3
       
  1498   	   	rslt = getsockopt(fd, 3, SO_SNDBUF, (void *)&readOptionValue, &optionLen);
       
  1499     
       
  1500 	    if(rslt < 0 && errno == ENOPROTOOPT)
       
  1501 			{
       
  1502 			INFO_PRINTF1(_L("getsockopt fails with right error value"));
       
  1503 			SetTestStepResult(EPass);
       
  1504 			}
       
  1505 		else
       
  1506 			{
       
  1507 			INFO_PRINTF2(_L("getsockopt fails with error no: %d"), errno);
       
  1508 			}
       
  1509 		}
       
  1510 	
       
  1511 	close(fd);
       
  1512 	unlink(path);
       
  1513 	return TestStepResult();
       
  1514 	}
       
  1515 /*
       
  1516 * Testcase		: TestLocalSockIoctl
       
  1517 * Description	: Test ioctl for localsocket
       
  1518 * Result		: ioctl retuns -1 settign errno to ENOSYS
       
  1519 *				  Test case returns KErrNone
       
  1520 **/
       
  1521 TVerdict CTestLocalSocket::TestLocalSockIoctl()
       
  1522 	{
       
  1523 	INFO_PRINTF1(_L("TestLocalSockIoctl"));
       
  1524 	int fd;
       
  1525 	int rslt=0;
       
  1526 	const char path[] = "C:\\TestLocalSockIoctl";
       
  1527 	struct sockaddr_un server;
       
  1528 	TRequestStatus status;
       
  1529         
       
  1530     server.sun_family = PF_LOCAL;
       
  1531     strncpy(server.sun_path, path, strlen(path)+1);
       
  1532     SUN_LEN(&server);
       
  1533     
       
  1534     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1535     if (fd < 0)
       
  1536     	{
       
  1537     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1538     	return TestStepResult();
       
  1539     	}
       
  1540 	
       
  1541 	rslt = ioctl(fd, SIOCSIFNAME, &status);
       
  1542 	
       
  1543 	if (rslt < 0 && errno == ENOSYS)
       
  1544 		{
       
  1545 		INFO_PRINTF1(_L("ioctl successful"));
       
  1546 		SetTestStepResult(EPass);
       
  1547 		}
       
  1548 	else
       
  1549 		{
       
  1550 		INFO_PRINTF2(_L("ioctl fails with error number: %d"), errno);
       
  1551 		}
       
  1552 		
       
  1553 	close(fd);
       
  1554 	unlink(path);
       
  1555 	return TestStepResult();
       
  1556 	}
       
  1557 	
       
  1558 /*
       
  1559 * Testcase		: TestLocalSockFcntl
       
  1560 * Description	: Test fcntl for localsocket
       
  1561 * Result		: fcntl retuns 0, test case returns KErrNone
       
  1562 **/
       
  1563 TVerdict CTestLocalSocket::TestLocalSockFcntl()
       
  1564 	{
       
  1565 	INFO_PRINTF1(_L("TestLocalSockFcntl"));
       
  1566     int fd = -1;
       
  1567     int rslt = -1;
       
  1568     int sz,err = 0;
       
  1569     const char path[] = "C:\\TestLocalSockFcntl";
       
  1570     struct sockaddr_un server;
       
  1571         
       
  1572     server.sun_family = PF_LOCAL;
       
  1573     strncpy(server.sun_path, path, strlen(path)+1);
       
  1574     sz = SUN_LEN(&server);
       
  1575     
       
  1576     fd = socket(PF_LOCAL, SOCK_STREAM, 0);
       
  1577    
       
  1578     if (fd < 0)
       
  1579     	{
       
  1580     	INFO_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  1581     	return TestStepResult();
       
  1582     	}
       
  1583 
       
  1584     rslt = bind(fd, (struct sockaddr*)&server, sz);
       
  1585     
       
  1586     if (rslt)
       
  1587        {
       
  1588        INFO_PRINTF1(_L("socket binding error"));
       
  1589        return TestStepResult();
       
  1590        }
       
  1591     
       
  1592     int fcntlGetFlag=0;
       
  1593     _LIT(KFcntlGetFlag, "FcntlGetFlag");
       
  1594     
       
  1595     rslt = GetIntFromConfig(ConfigSection(), KFcntlGetFlag, fcntlGetFlag);
       
  1596     if(!rslt)
       
  1597 		{
       
  1598 	 	INFO_PRINTF1(_L("Could not read from ini file"));
       
  1599 	 	close(fd);
       
  1600 		unlink(path);
       
  1601 	 	return TestStepResult();
       
  1602 		}
       
  1603     
       
  1604     int fcntlSetFlag = 0;
       
  1605     _LIT(KFcntlSetFlag, "FcntlSetFlag");
       
  1606 
       
  1607     rslt = GetIntFromConfig(ConfigSection(), KFcntlSetFlag, fcntlSetFlag);
       
  1608     if(!rslt)
       
  1609     	{
       
  1610     	INFO_PRINTF1(_L("Could not read from ini file"));
       
  1611     	close(fd);
       
  1612     	unlink(path);
       
  1613     	return TestStepResult();
       
  1614     	}
       
  1615     
       
  1616     int fcntlArg=0;
       
  1617     _LIT(KFcntlArg, "FcntlArg");
       
  1618     
       
  1619     rslt = GetIntFromConfig(ConfigSection(), KFcntlArg, fcntlArg);
       
  1620     if(!rslt)
       
  1621     	{
       
  1622     	INFO_PRINTF1(_L("Could not read FcntlArg from ini file"));
       
  1623     	close(fd);
       
  1624     	unlink(path);
       
  1625     	return TestStepResult();
       
  1626     	}
       
  1627    
       
  1628     int currentFlag = 0;
       
  1629     currentFlag=fcntl(fd, fcntlGetFlag, 0);
       
  1630     if(currentFlag == -1)
       
  1631     	{
       
  1632     	INFO_PRINTF2(_L("fcntl fails with %d"), errno);
       
  1633     	close(fd);
       
  1634     	unlink(path);
       
  1635     	return TestStepResult();
       
  1636     	}
       
  1637         
       
  1638     err=fcntl(fd, fcntlSetFlag, fcntlArg);
       
  1639     if(err == -1)
       
  1640     	{
       
  1641     	INFO_PRINTF2(_L("fcntl fails with %d"), errno);
       
  1642     	close(fd);
       
  1643     	unlink(path);
       
  1644     	return TestStepResult();
       
  1645     	}
       
  1646     currentFlag=fcntl(fd, fcntlGetFlag, 0);
       
  1647     if(currentFlag == -1)
       
  1648     	{
       
  1649     	INFO_PRINTF2(_L("fcntl fails with %d"), errno);
       
  1650     	close(fd);
       
  1651     	unlink(path);
       
  1652     	return TestStepResult();
       
  1653     	}
       
  1654    
       
  1655     int result=0;
       
  1656     _LIT(KResult, "Result");
       
  1657 
       
  1658     rslt = GetIntFromConfig(ConfigSection(), KResult, result);
       
  1659     if(!rslt)
       
  1660     	{
       
  1661     	INFO_PRINTF1(_L("Could not read Result from ini file"));
       
  1662     	close(fd);
       
  1663     	unlink(path);
       
  1664     	return TestStepResult();
       
  1665     	}
       
  1666     
       
  1667     if(currentFlag & fcntlArg != result)
       
  1668     	{
       
  1669     	INFO_PRINTF1(_L("fcntl set failed "));
       
  1670     	close(fd);
       
  1671     	unlink(path);
       
  1672     	return TestStepResult();
       
  1673     	}
       
  1674     close(fd);
       
  1675     unlink(path);
       
  1676     SetTestStepResult(EPass);
       
  1677     return TestStepResult(); 
       
  1678 	}
       
  1679 	
       
  1680 
       
  1681 /**
       
  1682 * Function Name		: TestNegativeBind1
       
  1683 * Description		: Negative test on UNIX sockets, with this combination unlink(),bind(),unlink(),bind()
       
  1684 * Return Value		: First bind() should be success and second bind() should fail with EINVAL, since it is already bound
       
  1685 * API Tested		: bind() 
       
  1686 */	
       
  1687 
       
  1688 TVerdict CTestLocalSocket::TestNegativeBind1( )
       
  1689     { 
       
  1690     int SocketFamily, ret, fd, s = -1, len;
       
  1691     struct sockaddr_un local;
       
  1692 	ret = GetIntFromConfig(ConfigSection(), _L("SocketFamily"), SocketFamily);
       
  1693 	if(ret != 1)
       
  1694 		{
       
  1695 	 	ERR_PRINTF1(_L("Could not read the socket family name from ini file"));
       
  1696 	 	goto close;
       
  1697 		} 
       
  1698     local.sun_family = SocketFamily;
       
  1699     if(sizeof(local.sun_path) < strlen(SOCK_PATH))
       
  1700     	{
       
  1701     	ERR_PRINTF1(_L("The length of the path given exceeds the maximum limit"));
       
  1702     	goto close;
       
  1703     	}
       
  1704 	s = socket(SocketFamily, SOCK_STREAM, 0);
       
  1705     if (s == -1) 
       
  1706     	{
       
  1707     	ERR_PRINTF2(_L("Error in creating the socket and errno is %d"),errno);
       
  1708     	goto close;
       
  1709     	}
       
  1710 
       
  1711     strcpy(local.sun_path, SOCK_PATH);
       
  1712     unlink(SOCK_PATH);
       
  1713     fd = open(SOCK_PATH, O_CREAT | O_RDWR, 0666);
       
  1714     if (fd < 0)
       
  1715 		{
       
  1716 		ERR_PRINTF2(_L("Error in creating the file and errno is %d"),errno);
       
  1717 		goto close;
       
  1718 		}
       
  1719     close(fd);
       
  1720     unlink(SOCK_PATH);
       
  1721     len = sizeof(struct sockaddr_un);
       
  1722     ret = bind(s, (struct sockaddr *)&local, len);
       
  1723     if (ret != 0) 
       
  1724     	{
       
  1725     	ERR_PRINTF2(_L("Bind1 failed and errno is set to %d"),errno);
       
  1726     	goto close;
       
  1727     	}
       
  1728     INFO_PRINTF1(_L("Successfully able to bind for the first"));
       
  1729     unlink(SOCK_PATH);
       
  1730     ret = bind(s, (struct sockaddr *)&local, len);
       
  1731     if ((ret != -1) || (errno != EINVAL)) 
       
  1732      	{
       
  1733      	ERR_PRINTF2(_L("Bind2 failed to return EINVAL and errno is set to %d"),errno);
       
  1734      	goto close;
       
  1735      	}
       
  1736     INFO_PRINTF1(_L("bind() successfully returned EINVAL when called for the second time"));
       
  1737     
       
  1738     SetTestStepResult(EPass);
       
  1739     close:
       
  1740     if(s != -1)
       
  1741     	{
       
  1742     	close(s);
       
  1743     	}
       
  1744     unlink(SOCK_PATH);
       
  1745     return TestStepResult();
       
  1746     }
       
  1747 
       
  1748 /**
       
  1749 * Function Name		: TestNegativeBind2
       
  1750 * Description		: Negative test on UNIX sockets, with this combination unlink(),bind(),bind()
       
  1751 * Return Value		: First bind() should be success and second bind() should fail with EINVAL, since it is already bound
       
  1752 * API Tested		: bind() 
       
  1753 */	
       
  1754 
       
  1755 TVerdict CTestLocalSocket::TestNegativeBind2( )
       
  1756     { 
       
  1757     int SocketFamily, ret, fd, s = -1, len;
       
  1758     struct sockaddr_un local;
       
  1759 	ret = GetIntFromConfig(ConfigSection(), _L("SocketFamily"), SocketFamily);
       
  1760 	if(ret != 1)
       
  1761 		{
       
  1762 	 	ERR_PRINTF1(_L("Could not read the socket family name from ini file"));
       
  1763 	 	goto close;
       
  1764 		} 
       
  1765     local.sun_family = SocketFamily;
       
  1766     if(sizeof(local.sun_path) < strlen(SOCK_PATH))
       
  1767     	{
       
  1768     	ERR_PRINTF1(_L("The length of the path given exceeds the maximum limit"));
       
  1769     	goto close;
       
  1770     	}
       
  1771 	s = socket(SocketFamily, SOCK_STREAM, 0);
       
  1772     if (s == -1) 
       
  1773     	{
       
  1774     	ERR_PRINTF2(_L("Error in creating the socket and errno is %d"),errno);
       
  1775     	goto close;
       
  1776     	}
       
  1777 
       
  1778     strcpy(local.sun_path, SOCK_PATH);
       
  1779     unlink(SOCK_PATH);
       
  1780     fd = open(SOCK_PATH, O_CREAT | O_RDWR, 0666);
       
  1781     if (fd < 0)
       
  1782 		{
       
  1783 		ERR_PRINTF2(_L("Error in creating the file and errno is %d"),errno);
       
  1784 		goto close;
       
  1785 		}
       
  1786     close(fd);
       
  1787     unlink(SOCK_PATH);
       
  1788     len = sizeof(struct sockaddr_un);
       
  1789     ret = bind(s, (struct sockaddr *)&local, len);
       
  1790     if (ret != 0) 
       
  1791     	{
       
  1792     	ERR_PRINTF2(_L("Bind1 failed and errno is set to %d"),errno);
       
  1793     	goto close;
       
  1794     	}
       
  1795     INFO_PRINTF1(_L("Successfully able to bind for the first"));
       
  1796     ret = bind(s, (struct sockaddr *)&local, len);
       
  1797     if ((ret != -1) || (errno != EINVAL)) 
       
  1798      	{
       
  1799      	ERR_PRINTF2(_L("Bind2 failed to return EINVAL and errno is set to %d"),errno);
       
  1800      	goto close;
       
  1801      	}
       
  1802     INFO_PRINTF1(_L("bind() successfully returned EINVAL when called for the second time"));
       
  1803     
       
  1804     SetTestStepResult(EPass);
       
  1805     close:
       
  1806     if(s != -1)
       
  1807     	{
       
  1808     	close(s);
       
  1809     	}
       
  1810     unlink(SOCK_PATH);
       
  1811     return TestStepResult();
       
  1812     }
       
  1813 
       
  1814 /**
       
  1815 * Function Name		: TestNegativeBind3
       
  1816 * Description		: Negative test on UNIX sockets, with this combination bind(),unlink(),bind()
       
  1817 * Return Value		: First bind() should fail with EADDRINUSE and second bind() should be success
       
  1818 * API Tested		: bind() 
       
  1819 */	
       
  1820 
       
  1821 TVerdict CTestLocalSocket::TestNegativeBind3( )
       
  1822     { 
       
  1823     int SocketFamily, ret, fd, s = -1, len;
       
  1824     struct sockaddr_un local;
       
  1825 	ret = GetIntFromConfig(ConfigSection(), _L("SocketFamily"), SocketFamily);
       
  1826 	if(ret != 1)
       
  1827 		{
       
  1828 	 	ERR_PRINTF1(_L("Could not read the socket family name from ini file"));
       
  1829 	 	goto close;
       
  1830 		} 
       
  1831     local.sun_family = SocketFamily;
       
  1832     if(sizeof(local.sun_path) < strlen(SOCK_PATH))
       
  1833     	{
       
  1834     	ERR_PRINTF1(_L("The length of the path given exceeds the maximum limit"));
       
  1835     	goto close;
       
  1836     	}
       
  1837 	s = socket(SocketFamily, SOCK_STREAM, 0);
       
  1838     if (s == -1) 
       
  1839     	{
       
  1840     	ERR_PRINTF2(_L("Error in creating the socket and errno is %d"),errno);
       
  1841     	goto close;
       
  1842     	}
       
  1843 
       
  1844     strcpy(local.sun_path, SOCK_PATH);
       
  1845     unlink(SOCK_PATH);
       
  1846     fd = open(SOCK_PATH, O_CREAT | O_RDWR, 0666);
       
  1847     if (fd < 0)
       
  1848 		{
       
  1849 		ERR_PRINTF2(_L("Error in creating the file and errno is %d"),errno);
       
  1850 		goto close;
       
  1851 		}
       
  1852     close(fd);
       
  1853     len = sizeof(struct sockaddr_un);
       
  1854     ret = bind(s, (struct sockaddr *)&local, len);
       
  1855     if ((ret != -1) || (errno != EADDRINUSE)) 
       
  1856     	{
       
  1857     	ERR_PRINTF2(_L("Bind1 failed to return EADDRINUSE and errno is set to %d"),errno);
       
  1858     	goto close;
       
  1859     	}
       
  1860     INFO_PRINTF1(_L("Bind1 successfully returned EADDRINUSE when called for the first time"));
       
  1861     unlink(SOCK_PATH);
       
  1862     ret = bind(s, (struct sockaddr *)&local, len);
       
  1863     if (ret != 0) 
       
  1864      	{
       
  1865      	ERR_PRINTF2(_L("Bind2 failed and errno is set to %d"),errno);
       
  1866      	goto close;
       
  1867      	}
       
  1868     INFO_PRINTF1(_L("Successfully able to bind for the second time"));
       
  1869     
       
  1870     SetTestStepResult(EPass);
       
  1871     close:
       
  1872     if(s != -1)
       
  1873     	{
       
  1874     	close(s);
       
  1875     	}
       
  1876     unlink(SOCK_PATH);
       
  1877     return TestStepResult();
       
  1878     }
       
  1879 
       
  1880 /**
       
  1881 * Function Name		: TestNegativeBind4
       
  1882 * Description		: Negative test on UNIX sockets, with this combination only bind(),bind()
       
  1883 * Return Value		: First bind() should fail with EADDRINUSE and second bind() should fail with EADDRINUSE
       
  1884 * API Tested		: bind() 
       
  1885 */	
       
  1886 
       
  1887 TVerdict CTestLocalSocket::TestNegativeBind4( )
       
  1888     { 
       
  1889     int SocketFamily, ret, fd, s = -1, len;
       
  1890     struct sockaddr_un local;
       
  1891 	ret = GetIntFromConfig(ConfigSection(), _L("SocketFamily"), SocketFamily);
       
  1892 	if(ret != 1)
       
  1893 		{
       
  1894 	 	ERR_PRINTF1(_L("Could not read the socket family name from ini file"));
       
  1895 	 	goto close;
       
  1896 		} 
       
  1897     local.sun_family = SocketFamily;
       
  1898     if(sizeof(local.sun_path) < strlen(SOCK_PATH))
       
  1899     	{
       
  1900     	ERR_PRINTF1(_L("The length of the path given exceeds the maximum limit"));
       
  1901     	goto close;
       
  1902     	}
       
  1903 	s = socket(SocketFamily, SOCK_STREAM, 0);
       
  1904     if (s == -1) 
       
  1905     	{
       
  1906     	ERR_PRINTF2(_L("Error in creating the socket and errno is %d"),errno);
       
  1907     	goto close;
       
  1908     	}
       
  1909 
       
  1910     strcpy(local.sun_path, SOCK_PATH);
       
  1911     unlink(SOCK_PATH);
       
  1912     fd = open(SOCK_PATH, O_CREAT | O_RDWR, 0666);
       
  1913     if (fd < 0)
       
  1914 		{
       
  1915 		ERR_PRINTF2(_L("Error in creating the file and errno is %d"),errno);
       
  1916 		goto close;
       
  1917 		}
       
  1918     close(fd);
       
  1919     len = sizeof(struct sockaddr_un);
       
  1920     ret = bind(s, (struct sockaddr *)&local, len);
       
  1921     if ((ret != -1) || (errno != EADDRINUSE)) 
       
  1922      	{
       
  1923      	ERR_PRINTF2(_L("Bind1 failed to return EADDRINUSE and errno is set to %d"),errno);
       
  1924      	goto close;
       
  1925      	}
       
  1926     INFO_PRINTF1(_L("Bind1 successfully returned EADDRINUSE when called for the first time"));
       
  1927     ret = bind(s, (struct sockaddr *)&local, len);
       
  1928     if ((ret != -1) || (errno != EADDRINUSE)) 
       
  1929      	{
       
  1930      	ERR_PRINTF2(_L("Bind2 failed to return EADDRINUSE and errno is set to %d"),errno);
       
  1931      	goto close;
       
  1932      	}
       
  1933     INFO_PRINTF1(_L("Bind1 successfully returned EADDRINUSE when called for the second time"));
       
  1934 
       
  1935     SetTestStepResult(EPass);
       
  1936     close:
       
  1937     if(s != -1)
       
  1938     	{
       
  1939     	close(s);
       
  1940     	}
       
  1941     unlink(SOCK_PATH);
       
  1942     return TestStepResult();
       
  1943     }
       
  1944 
       
  1945 /**
       
  1946 * Function Name		: TestNegativeBind5
       
  1947 * Description		: Negative test on UNIX sockets, with this combination unlink(x),bind(),unlink(y),bind()
       
  1948 * Return Value		: First bind() should be success and second bind() should fail with EINVAL
       
  1949 * API Tested		: bind() 
       
  1950 */	
       
  1951 
       
  1952 TVerdict CTestLocalSocket::TestNegativeBind5( )
       
  1953     { 
       
  1954     int SocketFamily, ret, fd, s = -1, len;
       
  1955     struct sockaddr_un local;
       
  1956 	ret = GetIntFromConfig(ConfigSection(), _L("SocketFamily"), SocketFamily);
       
  1957 	if(ret != 1)
       
  1958 		{
       
  1959 	 	ERR_PRINTF1(_L("Could not read the socket family name from ini file"));
       
  1960 	 	goto close;
       
  1961 		} 
       
  1962     local.sun_family = SocketFamily;
       
  1963     if(sizeof(local.sun_path) < strlen(SOCK_PATH))
       
  1964     	{
       
  1965     	ERR_PRINTF1(_L("The length of the path given exceeds the maximum limit"));
       
  1966     	goto close;
       
  1967     	}
       
  1968 	s = socket(SocketFamily, SOCK_STREAM, 0);
       
  1969     if (s == -1) 
       
  1970     	{
       
  1971     	ERR_PRINTF2(_L("Error in creating the socket and errno is %d"),errno);
       
  1972     	goto close;
       
  1973     	}
       
  1974 
       
  1975     strcpy(local.sun_path, SOCK_PATH);
       
  1976     unlink(SOCK_PATH);
       
  1977     fd = open(SOCK_PATH, O_CREAT | O_RDWR, 0666);
       
  1978     if (fd < 0)
       
  1979 		{
       
  1980 		ERR_PRINTF2(_L("Error in creating the file and errno is %d"),errno);
       
  1981 		goto close;
       
  1982 		}
       
  1983     close(fd);
       
  1984     unlink(SOCK_PATH);
       
  1985     len = sizeof(struct sockaddr_un);
       
  1986     ret = bind(s, (struct sockaddr *)&local, len);
       
  1987     if (ret != 0) 
       
  1988     	{
       
  1989     	ERR_PRINTF2(_L("Bind1 failed and errno is set to %d"),errno);
       
  1990     	goto close;
       
  1991     	}
       
  1992     INFO_PRINTF1(_L("Successfully able to bind for the first"));
       
  1993     strcpy(local.sun_path, SOCK_PATH1);
       
  1994     ret = bind(s, (struct sockaddr *)&local, len);
       
  1995     if ((ret != -1) || (errno != EINVAL)) 
       
  1996      	{
       
  1997      	ERR_PRINTF2(_L("Bind2 failed to return EINVAL and errno is set to %d"),errno);
       
  1998      	goto close;
       
  1999      	}
       
  2000     INFO_PRINTF1(_L("bind() successfully returned EINVAL when called for the second time"));
       
  2001 
       
  2002     SetTestStepResult(EPass);
       
  2003     close:
       
  2004     if(s != -1)
       
  2005     	{
       
  2006     	close(s);
       
  2007     	}
       
  2008     unlink(SOCK_PATH);
       
  2009     return TestStepResult();
       
  2010     }
       
  2011 
       
  2012 /**
       
  2013 * Function Name		: TestListenonUnixsoc
       
  2014 * Description		: Listen on UNIX socket
       
  2015 * Return Value		: listen() should just return 0.
       
  2016 */	
       
  2017 
       
  2018 TVerdict CTestLocalSocket::TestListenonUnixsoc( )
       
  2019     {
       
  2020     int ret, SocketFamily, s = -1, len;
       
  2021     struct sockaddr_un local;
       
  2022 	ret = GetIntFromConfig(ConfigSection(), _L("SocketFamily"), SocketFamily);
       
  2023 	if(ret != 1)
       
  2024 		{
       
  2025 	 	ERR_PRINTF1(_L("Could not read the socket family name from ini file"));
       
  2026 	 	goto close;
       
  2027 		}         
       
  2028     local.sun_family = SocketFamily;
       
  2029     if(sizeof(local.sun_path) < strlen(SOCK_PATH))
       
  2030     	{
       
  2031     	ERR_PRINTF1(_L("The length of the path given exceeds the maximum limit"));
       
  2032     	goto close;
       
  2033     	}
       
  2034     strcpy(local.sun_path, SOCK_PATH);
       
  2035     unlink(SOCK_PATH);
       
  2036     
       
  2037     s = socket(SocketFamily, SOCK_STREAM, 0);
       
  2038     if (s < 0)
       
  2039     	{
       
  2040     	ERR_PRINTF2(_L("protocol not supported. Errno is %d"), errno);
       
  2041     	goto close;
       
  2042     	}
       
  2043     len = sizeof(struct sockaddr_un);
       
  2044     ret = bind(s, (struct sockaddr*)&local, len);
       
  2045     if (ret < 0)
       
  2046        	{
       
  2047         ERR_PRINTF2(_L("socket binding error: %d"), errno);
       
  2048        	goto close;
       
  2049        	}
       
  2050     
       
  2051     ret = listen(s, 5);
       
  2052     if (ret != 0)
       
  2053 		{
       
  2054 		ERR_PRINTF2(_L("Listen fails with error no: %d"), errno);
       
  2055 		goto close;
       
  2056 		}
       
  2057     INFO_PRINTF1(_L("Listen successful"));
       
  2058 	
       
  2059 	SetTestStepResult(EPass);
       
  2060 	close:
       
  2061     if(s != -1)
       
  2062     	{
       
  2063     	close(s);
       
  2064     	}
       
  2065     unlink(SOCK_PATH);
       
  2066     return TestStepResult();
       
  2067     }
       
  2068 
       
  2069 
       
  2070 
       
  2071 /**
       
  2072 * Function Name		: TestNonblockAcceptSetfl
       
  2073 * Description		: Nonblocking accept() by setting setfl flag
       
  2074 * Return Value		: accept() should not block and should succeed after multiple tries.
       
  2075 */
       
  2076 TVerdict CTestLocalSocket::TestNonblockAcceptSetfl( )
       
  2077 	{
       
  2078 	int sockfd = -1, newsockfd = -1;
       
  2079 	pthread_t thread;
       
  2080 	int t1= 0, iof = -1;
       
  2081 	struct sockaddr_un src,cliaddr;
       
  2082 	unlink(SERVPATH);
       
  2083 	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
       
  2084 	if(sockfd < 0)
       
  2085 		{
       
  2086 		ERR_PRINTF2(_L("Socket Creation failed %d\n"), errno);
       
  2087 		return TestStepResult();
       
  2088 		}
       
  2089 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2090 	src.sun_family=AF_UNIX;    
       
  2091 	strcpy((char*)&src.sun_path, SERVPATH);    
       
  2092 	if ( bind(sockfd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2093 		{
       
  2094 		ERR_PRINTF2(_L("Bind error = %d\n"), errno);
       
  2095 		if(sockfd)
       
  2096 			close(sockfd);
       
  2097 		unlink(SERVPATH);
       
  2098 		return TestStepResult();
       
  2099 		}
       
  2100 	if(listen(sockfd,5) < 0)
       
  2101 		{
       
  2102 		ERR_PRINTF2(_L("listen() fails with errno %d\n"), errno);
       
  2103 		if(sockfd)
       
  2104 			close(sockfd);
       
  2105 		unlink(SERVPATH);
       
  2106 		return TestStepResult();
       
  2107 		}
       
  2108 	if(pthread_create(&thread, NULL, ThreadConnect, (void*)t1) != 0)
       
  2109 		{
       
  2110 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2111 		if(sockfd)
       
  2112 			close(sockfd);
       
  2113 		unlink(SERVPATH);
       
  2114 		return TestStepResult();
       
  2115 		}
       
  2116 	socklen_t clilen = sizeof(cliaddr);
       
  2117 	if((iof = fcntl(sockfd, F_GETFL, 0)) != -1){
       
  2118 		if(fcntl(sockfd,F_SETFL,iof | O_NONBLOCK) < 0)
       
  2119 			{
       
  2120 			ERR_PRINTF2(_L("Setting non-blocking mode failed with errno %d\n"), errno);
       
  2121 			if(sockfd)
       
  2122 				close(sockfd);
       
  2123 			unlink(SERVPATH);
       
  2124 			return TestStepResult();
       
  2125 			}
       
  2126 	}
       
  2127 	else
       
  2128 		{
       
  2129 		ERR_PRINTF2(_L("fcntl failed with errno %d\n"), errno);
       
  2130 		if(sockfd)
       
  2131 			close(sockfd);
       
  2132 		unlink(SERVPATH);
       
  2133 		return TestStepResult();
       
  2134 		}
       
  2135 	do
       
  2136 		{
       
  2137 		newsockfd = accept(sockfd, (struct sockaddr *)&cliaddr, &clilen);
       
  2138 		if(newsockfd<0)
       
  2139 			INFO_PRINTF1(_L("Waiting on accept()...\n"));
       
  2140 		}while((newsockfd == -1) && (errno == EAGAIN));
       
  2141 	if(newsockfd < 0)
       
  2142 		{
       
  2143 		ERR_PRINTF2(_L("Accept failed with errno %d"),errno);
       
  2144 		if(sockfd)
       
  2145 			close(sockfd);
       
  2146 		unlink(SERVPATH);
       
  2147 		return TestStepResult();
       
  2148 		}
       
  2149 	pthread_join(thread,NULL);
       
  2150 	SetTestStepResult(EPass);
       
  2151 	if(sockfd)
       
  2152 		close(sockfd);
       
  2153 	unlink(SERVPATH);
       
  2154 	return TestStepResult();
       
  2155 	}
       
  2156 
       
  2157 
       
  2158 /**
       
  2159 * Function Name		: TestNonblockAcceptSelect
       
  2160 * Description		: Nonblocking accept() using select()
       
  2161 * Return Value		: accept() succeeds, testcase returns KErrNone
       
  2162 */
       
  2163 TVerdict CTestLocalSocket::TestNonblockAcceptSelect()
       
  2164 	{
       
  2165 	int sockfd = -1, newsockfd = -1;
       
  2166 	fd_set readfds;
       
  2167 	int fdmax, t1 = 0;
       
  2168 	pthread_t thread;
       
  2169 	struct sockaddr_un src,cliaddr;
       
  2170 	unlink(SERVPATH);
       
  2171 	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
       
  2172 	if(sockfd < 0)
       
  2173 		{
       
  2174 		ERR_PRINTF2(_L("Socket Creation failed %d\n"), errno);
       
  2175 		return TestStepResult();
       
  2176 		}
       
  2177 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2178 	src.sun_family=AF_UNIX;    
       
  2179 	strcpy((char*)&src.sun_path, SERVPATH);    
       
  2180 	if ( bind(sockfd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2181 		{
       
  2182 		ERR_PRINTF2(_L("Bind fails %d\n"),errno);
       
  2183 		if(sockfd)
       
  2184 			close(sockfd);
       
  2185 		unlink(SERVPATH);
       
  2186 		return TestStepResult();
       
  2187 		}
       
  2188 	if( listen(sockfd,5) < 0)
       
  2189 		{
       
  2190 		ERR_PRINTF2(_L("Listen fails %d\n"),errno);
       
  2191 		if(sockfd)
       
  2192 			close(sockfd);
       
  2193 		unlink(SERVPATH);
       
  2194 		return TestStepResult();
       
  2195 		}
       
  2196 	if(pthread_create(&thread, NULL, ThreadConnect, (void*)t1) != 0)
       
  2197 		{
       
  2198 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2199 		if(sockfd)
       
  2200 			close(sockfd);
       
  2201 		unlink(SERVPATH);
       
  2202 		return TestStepResult();
       
  2203 		}
       
  2204 	socklen_t clilen = sizeof(cliaddr);
       
  2205 	fdmax = sockfd;
       
  2206 	struct timeval tv;
       
  2207 	tv.tv_sec = 1;
       
  2208 	tv.tv_usec = 0;
       
  2209 	int result;
       
  2210 	do
       
  2211 		{
       
  2212 		FD_ZERO(&readfds);
       
  2213 		FD_SET(sockfd,&readfds);
       
  2214 		result = select(fdmax+1,&readfds,NULL,NULL,&tv);
       
  2215 		}while(result == -1 && errno == EINTR);
       
  2216 	
       
  2217 	if(result == -1)
       
  2218 		{
       
  2219 		ERR_PRINTF2(_L("Select failed with errno %d\n"), errno);
       
  2220 		if(sockfd)
       
  2221 			close(sockfd);
       
  2222 		unlink(SERVPATH);
       
  2223 		return TestStepResult();
       
  2224 		}
       
  2225 	
       
  2226 	if(result == 0)
       
  2227 		{
       
  2228 		ERR_PRINTF1(_L("Select timed out\n"));
       
  2229 		if(sockfd)
       
  2230 			close(sockfd);
       
  2231 		unlink(SERVPATH);
       
  2232 		return TestStepResult();
       
  2233 		}
       
  2234 	if(result>0)
       
  2235 		if(FD_ISSET(sockfd,&readfds))
       
  2236 			{
       
  2237 			newsockfd = accept(sockfd, (struct sockaddr *)&cliaddr, &clilen);
       
  2238 			if(newsockfd < 0)
       
  2239 				{
       
  2240 				ERR_PRINTF2(_L("Accept fails %d\n"), errno);
       
  2241 				if(sockfd)
       
  2242 					close(sockfd);
       
  2243 				unlink(SERVPATH);
       
  2244 				return TestStepResult();
       
  2245 				}
       
  2246 			}
       
  2247 	SetTestStepResult(EPass);
       
  2248 	pthread_join(thread,NULL);
       
  2249 	if(sockfd)
       
  2250 		close(sockfd);
       
  2251 	unlink(SERVPATH);
       
  2252 	return TestStepResult();
       
  2253 	}
       
  2254 
       
  2255 /**
       
  2256 * Function Name		: TestNonblockingRead
       
  2257 * Description		: Nonblocking read() using select()
       
  2258 * Return Value		: read() succeeds, testcase returns KErrNone
       
  2259 */
       
  2260 TVerdict CTestLocalSocket::TestNonblockingRead()
       
  2261 	{
       
  2262 	int sockfd = -1, newsockfd = -1;
       
  2263 	int fdmax;
       
  2264 	char buffer[KMaxLine];
       
  2265 	fd_set readfds;
       
  2266 	pthread_t thread;
       
  2267 	struct sockaddr_un src,cliaddr;
       
  2268 	unlink(SERVPATH);
       
  2269 	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
       
  2270 	if(sockfd < 0)
       
  2271 		{
       
  2272 		ERR_PRINTF2(_L("Socket creation failed %d\n"),errno);
       
  2273 		return TestStepResult();
       
  2274 		}
       
  2275 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2276 	src.sun_family=AF_UNIX;    
       
  2277 	strcpy((char*)&src.sun_path, SERVPATH);  
       
  2278 	if ( bind(sockfd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2279 		{
       
  2280 		ERR_PRINTF2(_L("Bind failed %d\n"), errno);
       
  2281 		if(sockfd)
       
  2282 			close(sockfd);
       
  2283 		unlink(SERVPATH);
       
  2284 		return TestStepResult();
       
  2285 		}
       
  2286 	if(listen(sockfd,5) < 0)
       
  2287 		{
       
  2288 		ERR_PRINTF2(_L("Listen failed %d\n"), errno);
       
  2289 		if(sockfd)
       
  2290 			close(sockfd);
       
  2291 		unlink(SERVPATH);
       
  2292 		return TestStepResult();
       
  2293 		}
       
  2294 	if(pthread_create(&thread, NULL, TCPThreadWrite, (void*)(src.sun_path)) != 0)
       
  2295 		{
       
  2296 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2297 		if(sockfd)
       
  2298 			close(sockfd);
       
  2299 		unlink(SERVPATH);
       
  2300 		return TestStepResult();
       
  2301 		}
       
  2302 	socklen_t clilen = sizeof(cliaddr);
       
  2303 	newsockfd = accept(sockfd, (struct sockaddr *)&cliaddr, &clilen);
       
  2304 	if(newsockfd < 0)
       
  2305 		{
       
  2306 		ERR_PRINTF2(_L("Accept failed %d\n"), errno);
       
  2307 		if(sockfd)
       
  2308 			close(sockfd);
       
  2309 		unlink(SERVPATH);
       
  2310 		return TestStepResult();
       
  2311 		}
       
  2312 	fdmax = newsockfd;
       
  2313 	int result;
       
  2314 	struct timeval tv;
       
  2315 	tv.tv_sec = 0;
       
  2316 	tv.tv_usec = 2 * 1000;
       
  2317 	do
       
  2318 		{
       
  2319 		FD_ZERO(&readfds);
       
  2320 		FD_SET(newsockfd,&readfds);
       
  2321 		result = select(fdmax+1,&readfds,NULL,NULL,&tv);
       
  2322 		}while(result == -1 && errno == EINTR);
       
  2323 	
       
  2324 	if(result == -1)
       
  2325 		{
       
  2326 		INFO_PRINTF2(_L("Select failed with errno %d"),errno);
       
  2327 		if(sockfd)
       
  2328 			close(sockfd);
       
  2329 		unlink(SERVPATH);
       
  2330 		return TestStepResult();
       
  2331 		}
       
  2332 	
       
  2333 	if(result == 0)
       
  2334 		{
       
  2335 		INFO_PRINTF1(_L("Select() timed out\n"));
       
  2336 		if(sockfd)
       
  2337 			close(sockfd);
       
  2338 		unlink(SERVPATH);
       
  2339 		return TestStepResult();
       
  2340 		}
       
  2341 	
       
  2342 	if(result > 0)
       
  2343 		{
       
  2344 		int res2;
       
  2345 		if(FD_ISSET(newsockfd,&readfds))
       
  2346 			{
       
  2347 			res2 = read(newsockfd,buffer,KMaxLine);
       
  2348 			if(res2 != KMaxLine)
       
  2349 				{
       
  2350 				ERR_PRINTF2(_L("Read failed %d\n"),errno);
       
  2351 				if(sockfd)
       
  2352 					close(sockfd);
       
  2353 				unlink(SERVPATH);
       
  2354 				return TestStepResult();
       
  2355 				}
       
  2356 			}
       
  2357 		}
       
  2358 	pthread_join(thread,NULL);
       
  2359 	SetTestStepResult(EPass);
       
  2360 	if(sockfd)
       
  2361 		close(sockfd);
       
  2362 	unlink(SERVPATH);
       
  2363 	return TestStepResult();
       
  2364 	}
       
  2365 
       
  2366 /**
       
  2367 * Function Name		: TestNonblockingRecv
       
  2368 * Description		: Nonblocking recv() using select()
       
  2369 * Return Value		: recv() succeeds, testcase returns KErrNone
       
  2370 */
       
  2371 TVerdict CTestLocalSocket::TestNonblockingRecv()
       
  2372 	{
       
  2373 	int sockfd = -1, newsockfd = -1;
       
  2374 	int fdmax;
       
  2375 	char buffer[KMaxLine];
       
  2376 	fd_set readfds;
       
  2377 	pthread_t thread;
       
  2378 	struct sockaddr_un src,cliaddr;
       
  2379 	unlink(SERVPATH);
       
  2380 	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
       
  2381 	if(sockfd < 0)
       
  2382 		{
       
  2383 		ERR_PRINTF2(_L("Socket creation failed %d\n"),errno);
       
  2384 		return TestStepResult();
       
  2385 		}
       
  2386 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2387 	src.sun_family=AF_UNIX;    
       
  2388 	strcpy((char*)&src.sun_path, SERVPATH);  
       
  2389 	if ( bind(sockfd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2390 		{
       
  2391 		ERR_PRINTF2(_L("Bind failed %d\n"), errno);
       
  2392 		if(sockfd)
       
  2393 			close(sockfd);
       
  2394 		unlink(SERVPATH);
       
  2395 		return TestStepResult();
       
  2396 		}
       
  2397 	if(listen(sockfd,5) < 0)
       
  2398 		{
       
  2399 		ERR_PRINTF2(_L("Listen failed %d\n"), errno);
       
  2400 		if(sockfd)
       
  2401 			close(sockfd);
       
  2402 		unlink(SERVPATH);
       
  2403 		return TestStepResult();
       
  2404 		}
       
  2405 	if(pthread_create(&thread, NULL, TCPThreadWrite, (void*)(src.sun_path)) != 0)
       
  2406 		{
       
  2407 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2408 		if(sockfd)
       
  2409 			close(sockfd);
       
  2410 		unlink(SERVPATH);
       
  2411 		return TestStepResult();
       
  2412 		}
       
  2413 	socklen_t clilen = sizeof(cliaddr);
       
  2414 	newsockfd = accept(sockfd, (struct sockaddr *)&cliaddr, &clilen);
       
  2415 	if(newsockfd < 0)
       
  2416 		{
       
  2417 		ERR_PRINTF2(_L("Accept failed %d\n"), errno);
       
  2418 		if(sockfd)
       
  2419 			close(sockfd);
       
  2420 		unlink(SERVPATH);
       
  2421 		return TestStepResult();
       
  2422 		}
       
  2423 	fdmax = newsockfd;
       
  2424 	struct timeval tv;
       
  2425 	tv.tv_sec = 0;
       
  2426 	tv.tv_usec = 2 * 1000;
       
  2427 	int result;
       
  2428 	do
       
  2429 		{
       
  2430 		FD_ZERO(&readfds);
       
  2431 		FD_SET(newsockfd,&readfds);
       
  2432 		result = select(fdmax+1,&readfds,NULL,NULL,&tv);
       
  2433 		}while(result == -1 && errno == EINTR);
       
  2434 	if(result == -1)
       
  2435 		{
       
  2436 		INFO_PRINTF2(_L("Select failed with errno %d"),errno);
       
  2437 		if(sockfd)
       
  2438 			close(sockfd);
       
  2439 		unlink(SERVPATH);
       
  2440 		return TestStepResult();
       
  2441 		}
       
  2442 	
       
  2443 	if(result == 0)
       
  2444 		{
       
  2445 		INFO_PRINTF1(_L("Select() timed out\n"));
       
  2446 		if(sockfd)
       
  2447 			close(sockfd);
       
  2448 		unlink(SERVPATH);
       
  2449 		return TestStepResult();
       
  2450 		}
       
  2451 	
       
  2452 	if(result > 0)
       
  2453 		{
       
  2454 		int res2;
       
  2455 		if(FD_ISSET(newsockfd,&readfds))
       
  2456 			{
       
  2457 			res2 = recv(newsockfd,buffer,KMaxLine,NULL);
       
  2458 			if(res2 != KMaxLine)
       
  2459 				{
       
  2460 				ERR_PRINTF2(_L("Recv failed %d\n"),errno);
       
  2461 				if(sockfd)
       
  2462 					close(sockfd);
       
  2463 				unlink(SERVPATH);
       
  2464 				return TestStepResult();
       
  2465 				}
       
  2466 			}
       
  2467 		}
       
  2468 	pthread_join(thread,NULL);
       
  2469 	SetTestStepResult(EPass);
       
  2470 	if(sockfd)
       
  2471 		close(sockfd);
       
  2472 	unlink(SERVPATH);
       
  2473 	return TestStepResult();
       
  2474 	}
       
  2475 
       
  2476 /**
       
  2477 * Function Name		: TestGetSockName
       
  2478 * Description		: Retrieve the address of the sockaddr structure and the length of this structure, bound to the specified socket
       
  2479 * Return Value		: getsockname() succeeds, testcase returns KErrNone
       
  2480 */
       
  2481 TVerdict CTestLocalSocket::TestGetSockName()
       
  2482 	{
       
  2483 	int sockfd = -1;
       
  2484 	struct sockaddr_un src,cliaddr;
       
  2485 	unlink(SERVPATH);
       
  2486 	sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
       
  2487 	if(sockfd < 0)
       
  2488 		{
       
  2489 		ERR_PRINTF2(_L("Socket creation failed %d\n"),errno);
       
  2490 		return TestStepResult();
       
  2491 		}
       
  2492 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2493 	memset(&cliaddr, 0x00, sizeof(struct sockaddr_un));
       
  2494 	src.sun_family=AF_UNIX; 
       
  2495 	strcpy((char*)&src.sun_path, SERVPATH);    
       
  2496 	if ( bind(sockfd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2497 		{
       
  2498 		ERR_PRINTF2(_L("Bind error = %d\n"), errno);
       
  2499 		if(sockfd)
       
  2500 			close(sockfd);
       
  2501 		unlink(SERVPATH);
       
  2502 		return TestStepResult();
       
  2503 		}
       
  2504 	socklen_t clilen = sizeof(cliaddr);
       
  2505 	if(getsockname(sockfd,(struct sockaddr*)&cliaddr,&clilen) < 0)
       
  2506 		{
       
  2507 		ERR_PRINTF2(_L("Getsockname failed %d\n"),errno);
       
  2508 		if(sockfd)
       
  2509 			close(sockfd);
       
  2510 		unlink(SERVPATH);
       
  2511 		return TestStepResult();
       
  2512 		}
       
  2513 	if((cliaddr.sun_family == AF_UNIX)&&
       
  2514 	   (strcasecmp(cliaddr.sun_path,src.sun_path)==0)&&
       
  2515 	   (clilen == (sizeof(SERVPATH)+ sizeof(src.sun_family))))
       
  2516 			{
       
  2517 			INFO_PRINTF1(_L("Getsockname() succeeds\n"));
       
  2518 			SetTestStepResult(EPass);
       
  2519 			}
       
  2520 	else
       
  2521 		ERR_PRINTF2(_L("Getsockname: cleintlen is improper\n"),errno);
       
  2522 	if(sockfd)
       
  2523 		close(sockfd);
       
  2524 	unlink(SERVPATH);
       
  2525 	return TestStepResult();
       
  2526 	}
       
  2527 
       
  2528 
       
  2529 /**
       
  2530 * Function Name		: TestGetPeerName
       
  2531 * Description		: Retrieve the address of the sockaddr structure and the length of this structure, bound to the specified peer socket
       
  2532 * Return Value		: getpeername() succeeds, testcase returns KErrNone
       
  2533 */
       
  2534 TVerdict CTestLocalSocket::TestGetPeerName()
       
  2535 	{
       
  2536 	int new_fd = -1, newsockfd = -1;
       
  2537 	pthread_t thread;
       
  2538 	socklen_t clilen2 = 0;
       
  2539 
       
  2540 	unlink(SERVPATH);
       
  2541     struct sockaddr_un src,cliaddr2;
       
  2542     new_fd = socket(AF_UNIX, SOCK_STREAM, 0);
       
  2543     if(new_fd < 0)
       
  2544     	{
       
  2545     	ERR_PRINTF2(_L("Socket Creation failed %d\n"),errno);
       
  2546     	return TestStepResult();
       
  2547     	}
       
  2548 	memset(&cliaddr2, 0x00, sizeof(struct sockaddr_un));
       
  2549 	memset(&src, 0x00, sizeof(struct sockaddr_un));  
       
  2550 	src.sun_family=AF_UNIX; 
       
  2551 	strcpy((char*)&src.sun_path, SERVPATH);    
       
  2552 	if ( bind(new_fd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2553 		{
       
  2554 		ERR_PRINTF2(_L("Bind failed = %d\n"),errno);
       
  2555 	 	if(new_fd)
       
  2556 			close(new_fd);
       
  2557 		unlink(SERVPATH);
       
  2558 		return TestStepResult();
       
  2559 		}
       
  2560 	if(listen(new_fd,2) < 0)
       
  2561 		{
       
  2562 		ERR_PRINTF2(_L("Listen failed %d\n"),errno);
       
  2563 	 	if(new_fd)
       
  2564 			close(new_fd);
       
  2565 		unlink(SERVPATH);
       
  2566 		return TestStepResult();
       
  2567 		}
       
  2568 	if(pthread_create(&thread, NULL, ThreadConnect, NULL) != 0)
       
  2569 		{
       
  2570 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2571 		if(new_fd)
       
  2572 			close(new_fd);
       
  2573 		unlink(SERVPATH);
       
  2574 		return TestStepResult();
       
  2575 		}
       
  2576 
       
  2577 	newsockfd = accept(new_fd, (struct sockaddr*)&src, &clilen2);
       
  2578 	if(newsockfd < 0)
       
  2579 		{
       
  2580 		ERR_PRINTF2(_L("Accept failed %d\n"),errno);
       
  2581 	 	if(new_fd)
       
  2582 			close(new_fd);
       
  2583 		unlink(SERVPATH);
       
  2584 		return TestStepResult();
       
  2585 		}
       
  2586 	clilen2 = sizeof(struct sockaddr_un);
       
  2587 
       
  2588     if(getpeername(newsockfd,(struct sockaddr*)&cliaddr2,&clilen2) < 0)
       
  2589     	{
       
  2590     	ERR_PRINTF2(_L("Getpeername failed %d\n"),errno);
       
  2591      	if(new_fd)
       
  2592     		close(new_fd);
       
  2593     	unlink(SERVPATH);
       
  2594     	return TestStepResult();
       
  2595     	}
       
  2596     if((cliaddr2.sun_family == AF_UNIX)&&
       
  2597        (strcasecmp(cliaddr2.sun_path,SOCK_PATH) == 0)&& 
       
  2598        (clilen2 == (sizeof(SOCK_PATH)+ sizeof(src.sun_family))))
       
  2599 			{
       
  2600 			SetTestStepResult(EPass);
       
  2601 			}
       
  2602 
       
  2603  	if(new_fd)
       
  2604 		close(new_fd);
       
  2605 	unlink(SERVPATH);
       
  2606 
       
  2607 	pthread_join(thread,NULL);
       
  2608 	ERR_PRINTF1(_L("Coming at end3 %d\n"));
       
  2609 	return TestStepResult();
       
  2610 	}
       
  2611 
       
  2612 
       
  2613 /**
       
  2614 * Function Name		: TestThreadRecvfrom
       
  2615 * Description		: recvfrom from a datagram socket
       
  2616 * Return Value		: recvfrom() succeeds, testcase returns KErrNone
       
  2617 */
       
  2618 TVerdict CTestLocalSocket::TestThreadRecvfrom()
       
  2619 	{
       
  2620 	int sockfd = -1;
       
  2621 	char buffer[KDataLength];
       
  2622 	pthread_t thread;
       
  2623 	struct sockaddr_un src,cliaddr;
       
  2624 	sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
       
  2625 	if(sockfd < 0)
       
  2626 		{
       
  2627 		ERR_PRINTF2(_L("Socket Creation failed %d\n"),errno);
       
  2628 		return TestStepResult();
       
  2629 		}
       
  2630 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2631 	src.sun_family=AF_UNIX;    
       
  2632 	strcpy((char*)&src.sun_path, SERVPATH);   
       
  2633 	unlink(SERVPATH);
       
  2634 	if ( bind(sockfd,(struct sockaddr *)&src,sizeof(src))  < 0)
       
  2635 		{
       
  2636 		ERR_PRINTF2(_L("Bind failed = %d\n"),errno);
       
  2637 		if(sockfd)
       
  2638 			close(sockfd);
       
  2639 		unlink(SERVPATH);
       
  2640 		return TestStepResult();
       
  2641 		}
       
  2642 	if(pthread_create(&thread, NULL, ThreadSendto, NULL) != 0)
       
  2643 		{
       
  2644 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2645 		if(sockfd)
       
  2646 			close(sockfd);
       
  2647 		unlink(SERVPATH);
       
  2648 		return TestStepResult();
       
  2649 		}
       
  2650 	socklen_t clilen = sizeof(cliaddr);
       
  2651 	pthread_join(thread,NULL);
       
  2652 	if(recvfrom(sockfd, buffer, KDataLength, 0, (struct sockaddr*)&cliaddr, &clilen) < KDataLength)
       
  2653 		{
       
  2654 		ERR_PRINTF2(_L("Recvfrom failed %d\n"),errno);
       
  2655 		if(sockfd)
       
  2656 			close(sockfd);
       
  2657 		unlink(SERVPATH);
       
  2658 		return TestStepResult();
       
  2659 		}
       
  2660 	SetTestStepResult(EPass);
       
  2661 	if(sockfd)
       
  2662 		close(sockfd);
       
  2663 	unlink(SERVPATH);
       
  2664 	return TestStepResult();
       
  2665 	}
       
  2666 
       
  2667 
       
  2668 /**
       
  2669 * Function Name		: TestThreadSendto
       
  2670 * Description		: sendto a datagram socket
       
  2671 * Return Value		: sendto() succeeds, testcase returns KErrNone
       
  2672 */
       
  2673 TVerdict CTestLocalSocket::TestThreadSendto()
       
  2674 	{
       
  2675 
       
  2676 	int sockfd = -1;
       
  2677 	pthread_t thread;
       
  2678 	struct sockaddr_un src;
       
  2679 	sockfd = socket(AF_UNIX, SOCK_DGRAM, 0);
       
  2680 	if(sockfd < 0)
       
  2681 		{
       
  2682 		ERR_PRINTF2(_L("Socket creation failed %d\n"),errno);
       
  2683 		return TestStepResult();
       
  2684 		}
       
  2685 	memset(&src, 0x00, sizeof(struct sockaddr_un));
       
  2686 	src.sun_family=AF_UNIX;    
       
  2687 	strcpy((char*)&src.sun_path, SERVPATH);   
       
  2688 	if(pthread_create(&thread, NULL, ThreadRecvfrom, NULL) != 0)
       
  2689 		{
       
  2690 		ERR_PRINTF2(_L("pthread_create() fails with errno %d\n"), errno);
       
  2691 		if(sockfd)
       
  2692 			close(sockfd);
       
  2693 		unlink(SERVPATH);
       
  2694 		return TestStepResult();
       
  2695 		}
       
  2696 	sleep(1);
       
  2697 
       
  2698 	if(sendto(sockfd, DATA, KDataLength, 0, (struct sockaddr*)&src, sizeof(src)) < KDataLength)
       
  2699 		{
       
  2700 		ERR_PRINTF2(_L("Sendto failed %d\n"),errno);
       
  2701 		if(sockfd)
       
  2702 			close(sockfd);
       
  2703 		unlink(SERVPATH);
       
  2704 		return TestStepResult();
       
  2705 		}
       
  2706 	SetTestStepResult(EPass);
       
  2707 	pthread_join(thread,NULL);
       
  2708 	if(sockfd)
       
  2709 		close(sockfd);
       
  2710 	unlink(SERVPATH);
       
  2711 	return TestStepResult();
       
  2712     }
       
  2713 
       
  2714 
       
  2715 /*
       
  2716 * Testcase		: TestLocalSockMultipleBind
       
  2717 * Description	: Test multiple binds for localsocket
       
  2718 * Result		: bind retuns 0, test case returns KErrNone
       
  2719 **/
       
  2720 TVerdict CTestLocalSocket::TestLocalSockMultipleBind()
       
  2721 	{
       
  2722     int len = 0;
       
  2723     int listenSocket1 = -1;
       
  2724     int listenSocket2 = -1;
       
  2725     struct sockaddr_un local;
       
  2726     
       
  2727     INFO_PRINTF1(_L("   ...Setting sockaddr_un for bind and listen"));
       
  2728     local.sun_family = AF_UNIX;
       
  2729     strcpy(local.sun_path, "c:\\some_local_socket");
       
  2730     len = strlen(local.sun_path) + sizeof(local.sun_family) + 1;    
       
  2731     
       
  2732     INFO_PRINTF1(_L("   ...Ensuring that the file does not exist (unlink)")); 
       
  2733     unlink(local.sun_path);
       
  2734     
       
  2735     INFO_PRINTF1(_L( "   ...Creating 1st listening UNIX domain socket (AF_UNIX)" ));    
       
  2736     
       
  2737     //===============================================================
       
  2738     // Socket 1
       
  2739     //===============================================================
       
  2740     
       
  2741     // create listening server socket
       
  2742     if ((listenSocket1 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
       
  2743     	{
       
  2744         ERR_PRINTF2(_L( "Socket creation failed, errno: %d"), errno);
       
  2745         goto close;
       
  2746     	}
       
  2747     
       
  2748     INFO_PRINTF1(_L( "...Binding"));    
       
  2749     if (bind(listenSocket1, (struct sockaddr *)&local, len) == -1)
       
  2750     	{
       
  2751         ERR_PRINTF2(_L("..Bind error :%d"), errno);
       
  2752         goto close;
       
  2753     	}
       
  2754 
       
  2755     INFO_PRINTF1(_L("...Listening"));  
       
  2756     if (listen(listenSocket1, 5) == -1) 
       
  2757     	{
       
  2758         ERR_PRINTF2(_L("...Listen error is :%d"), errno);    
       
  2759         goto close;
       
  2760     	}
       
  2761     
       
  2762     //===============================================================
       
  2763     // Forced unlink
       
  2764     //===============================================================       
       
  2765     INFO_PRINTF1(_L("...force unlink the file"));
       
  2766     if (unlink(local.sun_path) == -1)
       
  2767     	{    	
       
  2768     	ERR_PRINTF2(_L("...forced unlink failed and errno :%d"), errno);
       
  2769     	}
       
  2770     else
       
  2771     	{
       
  2772     	INFO_PRINTF1(_L("...forced unlink() succeeded"));
       
  2773     	}
       
  2774          
       
  2775     //===============================================================
       
  2776     // Socket 2
       
  2777     //===============================================================        
       
  2778     INFO_PRINTF1(_L("...Creating 2nd listening UNIX domain socket (AF_UNIX)"));         
       
  2779          
       
  2780     // create listening server socket
       
  2781     if ((listenSocket2 = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) 
       
  2782     	{
       
  2783         ERR_PRINTF2(_L("...Error in UNIX domain socket (AF_UNIX) creation, errno: %d"), errno);
       
  2784         goto close;
       
  2785     	}
       
  2786     
       
  2787     INFO_PRINTF1(_L("...Binding"));    
       
  2788     if (bind(listenSocket2, (struct sockaddr *)&local, len) == -1) 
       
  2789     	{
       
  2790         ERR_PRINTF2(_L("...Bind error :%d"), errno);
       
  2791     	goto close;
       
  2792     	}
       
  2793 
       
  2794     INFO_PRINTF1(_L("...Listening\n"));  
       
  2795     if (listen(listenSocket2, 5) == -1) 
       
  2796     	{
       
  2797         ERR_PRINTF2(_L("...Listen error is :%d"), errno);    
       
  2798         goto close;
       
  2799     	}
       
  2800     	
       
  2801   	SetTestStepResult(EPass);
       
  2802   	close:
       
  2803   	if(listenSocket1 > 0)
       
  2804 		close(listenSocket1);
       
  2805   	if(listenSocket2 > 0)
       
  2806 		close(listenSocket2);
       
  2807   	unlink(local.sun_path);	    
       
  2808 	return TestStepResult();
       
  2809 	}
       
  2810 //  End of File