os/ossrv/genericopenlibs/posixrealtimeextensions/test/testsharedmemory/src/tsharedmemoryblocks.cpp
Update contrib.
     1 // Copyright (c) 2008-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".
 
     8 // Initial Contributors:
 
     9 // Nokia Corporation - initial contribution.
 
    14 // Name        : tsharedmemoryblocks.cpp
 
    15 // Test cases for blocking signal api's
 
    20 #include "tsharedmemory.h"
 
    22 static int closenunlink(int fd,char *name )
 
    24 	int ret, ret1 = KErrGeneral;
 
    30 	ret = shm_unlink(name);
 
    41 // -----------------------------------------------------------------------------
 
    42 // CTestsharedmemory::Testsharedmemory1
 
    43 // Test Case ID: OPENENV-LIBC-CIT-5946
 
    44 // API tested: shm_open(), shm_unlink()
 
    45 // Description: Test case added to open the shared memory object using shm_open() and unlinking the same using shm_unlink()
 
    46 // -----------------------------------------------------------------------------
 
    48 TInt CTestsharedmemory::Testsharedmemory1 (  )
 
    51 	int ret, ret1 = KErrGeneral, fd;
 
    54 	ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
    55 	shmname.Copy(Shmname) ; 
 
    56 	char *file = (char *) shmname.Ptr() ;
 
    59 		ERR_PRINTF1(_L("Failed to read input file name") );
 
    62     file[shmname.Length()] = '\0' ;
 
    63 	strcpy(filename , file) ;
 
    64 	fd = shm_open(filename, O_CREAT, 0777);
 
    67 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
    70 	ret = closenunlink(fd,filename);
 
    71 	if(ret == KErrGeneral)
 
    73 		ERR_PRINTF1(_L("Error in deleting the file"));
 
    76 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));	
 
    83 // -----------------------------------------------------------------------------
 
    84 // CTestsharedmemory::Testsharedmemory2
 
    85 // Test Case ID: OPENENV-LIBC-CIT-5946
 
    86 // API tested: shm_open(), shm_unlink()
 
    87 // Description: Trying to open a file which is closed and unlinked
 
    88 // -----------------------------------------------------------------------------
 
    90 TInt CTestsharedmemory::Testsharedmemory2 (  )
 
    93 	int ret, ret1 = KErrGeneral, fd;
 
    96     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
    97     shmname.Copy(Shmname) ; 
 
    98 	char *file = (char *) shmname.Ptr() ;
 
   101 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   104 	file[shmname.Length()] = '\0' ;
 
   105 	strcpy(filename , file) ;
 
   106 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
   109 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   112 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   113 	ret = closenunlink(fd,filename);
 
   114 	if(ret == KErrGeneral)
 
   116 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   119 	INFO_PRINTF1(_L("Successfully able to delete a shared memory"));
 
   120 	fd = shm_open(filename,O_RDWR,0777);
 
   121 	if((fd != -1) || (errno != ENOENT))
 
   123 		ERR_PRINTF2(_L("shm_open() failed on negative test and errno is %d"),errno);
 
   126 	INFO_PRINTF1(_L("shm_open() successfully returned ENOENT on negative test"));
 
   133 // -----------------------------------------------------------------------------
 
   134 // CTestsharedmemory::Testsharedmemory3
 
   135 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   136 // API tested: shm_open(), shm_unlink()
 
   137 // Description: Trying to open a file which is already present using O_EXCL
 
   138 // -----------------------------------------------------------------------------
 
   140 TInt CTestsharedmemory::Testsharedmemory3 (  )
 
   143 	int ret, ret1 = KErrGeneral, fd;
 
   146     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   147     shmname.Copy(Shmname) ; 
 
   148 	char *file = (char *) shmname.Ptr() ;
 
   151 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   154 	file[shmname.Length()] = '\0' ;
 
   155 	strcpy(filename , file) ;
 
   156 	fd = shm_open(filename,O_CREAT,0777);
 
   159 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   162 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   166 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   169 	fd = shm_open(filename,O_CREAT|O_EXCL,0777);
 
   170 	if((fd != -1) || (errno != EEXIST))
 
   172 		ERR_PRINTF1(_L("shm_open() failed on negative test"));
 
   175 	INFO_PRINTF1(_L("shm_open() successfully returned EEXIST on negative test"));
 
   176 	ret = shm_unlink(filename);
 
   179 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   188 // -----------------------------------------------------------------------------
 
   189 // CTestsharedmemory::Testsharedmemory4
 
   190 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   191 // API tested: shm_open(), shm_unlink()
 
   192 // Description: Trying to create a shared memory using O_CREAT|O_EXCL|O_RDWR flag
 
   193 // -----------------------------------------------------------------------------
 
   195 TInt CTestsharedmemory::Testsharedmemory4 (  )
 
   198 	int ret, ret1 = KErrGeneral, fd;
 
   201     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   202     shmname.Copy(Shmname) ; 
 
   203 	char *file = (char *) shmname.Ptr() ;
 
   206 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   209 	file[shmname.Length()] = '\0' ;
 
   210 	strcpy(filename , file) ;
 
   211 	fd = shm_open(filename,O_CREAT|O_EXCL|O_RDWR,0777);
 
   214 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   217 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   218 	ret =  closenunlink(fd,filename);
 
   219 	if(ret == KErrGeneral)
 
   221 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   230 // -----------------------------------------------------------------------------
 
   231 // CTestsharedmemory::Testsharedmemory5
 
   232 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   233 // API tested: shm_open(), shm_unlink()
 
   234 // Description: To validate that the lowest numbered file descriptor not currently opened for that process is returned by shm_open()
 
   235 // -----------------------------------------------------------------------------
 
   237 TInt CTestsharedmemory::Testsharedmemory5 (  )
 
   240 	int ret, ret1 = KErrGeneral, fd, fd1, fd2, fd3;
 
   243     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   244     shmname.Copy(Shmname) ; 
 
   245 	char *file = (char *) shmname.Ptr() ;
 
   248 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   251 	file[shmname.Length()] = '\0' ;
 
   252 	strcpy(filename , file) ;
 
   253 	fd1 = shm_open(filename,O_CREAT,0777);
 
   256 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   259 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   260 	fd2 = shm_open(filename,O_CREAT,0777);
 
   263 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   266 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   271 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   274 	fd3 = shm_open(filename,O_CREAT,0777);
 
   277 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   280 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   283 		ERR_PRINTF1(_L("Error in returning the lowest fd value"));
 
   286 	INFO_PRINTF1(_L("Successfully returned the lowest fd value"));
 
   290 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   293 	ret = closenunlink(fd3,filename);
 
   294 	if(ret == KErrGeneral)
 
   296 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   305 // -----------------------------------------------------------------------------
 
   306 // CTestsharedmemory::Testsharedmemory6
 
   307 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   308 // API tested: shm_open()
 
   309 // Description: Trying to open a shared memory with only O_WRONLY flag set
 
   310 // -----------------------------------------------------------------------------
 
   312 TInt CTestsharedmemory::Testsharedmemory6 (  )
 
   315 	int ret, ret1 = KErrGeneral, fd;
 
   318     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   319     shmname.Copy(Shmname) ; 
 
   320 	char *file = (char *) shmname.Ptr() ;
 
   323 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   326 	file[shmname.Length()] = '\0' ;
 
   327 	strcpy(filename , file) ;
 
   328 	fd = shm_open(filename,O_CREAT,0777);
 
   332 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   335 	fd = shm_open(filename,O_WRONLY,0777);
 
   336 	if ((fd != -1) || (errno != EINVAL))
 
   338 		ERR_PRINTF2(_L("shm_unlink() failed on negative test and errno is %d"),errno);
 
   341 	INFO_PRINTF1(_L("shm_unlink() successfully returned EINVAL on negative test"));
 
   345 	shm_unlink(filename);
 
   349 // -----------------------------------------------------------------------------
 
   350 // CTestsharedmemory::Testsharedmemory7
 
   351 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   352 // API tested: shm_open()
 
   353 // Description: Trying to open a shared memory with NULL as the input
 
   354 // -----------------------------------------------------------------------------
 
   356 TInt CTestsharedmemory::Testsharedmemory7 (  )
 
   358 	int ret1 = KErrGeneral, fd;
 
   359 	fd = shm_open(NULL,O_CREAT|O_RDWR,0777);
 
   360 	if ((fd != -1) || (errno != EFAULT))
 
   362 		ERR_PRINTF1(_L("shm_unlink() failed on negative test"));
 
   365 	INFO_PRINTF1(_L("Successfully shm_unlink() returned EFAULT on negative test"));
 
   372 // -----------------------------------------------------------------------------
 
   373 // CTestsharedmemory::Testsharedmemory8
 
   374 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   375 // API tested: shm_open()
 
   376 // Description: Trying to open a shared memory name as an empty string
 
   377 // -----------------------------------------------------------------------------
 
   379 TInt CTestsharedmemory::Testsharedmemory8 (  )
 
   381 	int fd, ret1 = KErrGeneral;
 
   382 	fd = shm_open("",O_CREAT,0777);
 
   383 	if ((fd != -1) || (errno != EINVAL))
 
   385 		ERR_PRINTF1(_L("shm_unlink() failed on negative test"));
 
   388 	INFO_PRINTF1(_L("Successfully shm_unlink() returned EINVAL on negative test"));
 
   395 // -----------------------------------------------------------------------------
 
   396 // CTestsharedmemory::Testsharedmemory9
 
   397 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   398 // API tested: shm_open(), shm_unlink()
 
   399 // Description: Trying to open a shared memory with a name less than maximum bytes
 
   400 // -----------------------------------------------------------------------------
 
   402 TInt CTestsharedmemory::Testsharedmemory9 (  )
 
   404 	int len, fd, ret1 = KErrGeneral, ret;
 
   406 	for (len=0; len<219; len++)
 
   411 	fd = shm_open(path,O_CREAT,0777);
 
   414 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   417 	ret = closenunlink(fd,path);
 
   418 	if(ret == KErrGeneral)
 
   420 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   423 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   430 // -----------------------------------------------------------------------------
 
   431 // CTestsharedmemory::Testsharedmemory10
 
   432 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   433 // API tested: shm_open()
 
   434 // Description: Negative test to return ENAMETOOLONG for shm_open()
 
   435 // -----------------------------------------------------------------------------
 
   437 TInt CTestsharedmemory::Testsharedmemory10 (  )
 
   439 	int len, fd, ret1 = KErrGeneral;
 
   441 	for (len=0; len<258; len++)
 
   446 	fd = shm_open(path,O_CREAT,0777);
 
   447 	if((fd != -1) || (errno != ENAMETOOLONG))
 
   449 		ERR_PRINTF1(_L("shm_open() failed on negative test"));
 
   452 	INFO_PRINTF1(_L("shm_open() successfully returned ENAMETOOLONG on negative test"));
 
   459 // -----------------------------------------------------------------------------
 
   460 // CTestsharedmemory::Testsharedmemory11
 
   461 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   462 // API tested: shm_open(), shm_unlink()
 
   463 // Description: Opening an existing shared memory in the different process using posix_spawn()
 
   464 // -----------------------------------------------------------------------------
 
   466 TInt CTestsharedmemory::Testsharedmemory11 (  )
 
   469 	int ret, ret1 = KErrGeneral, fd, status;
 
   471 	char **argv = (char**)malloc(2*sizeof(char*));
 
   472 	argv[0] = (char*)malloc(30*sizeof(char));
 
   474 	fd = shm_open("shmemtest", O_CREAT, 0777);
 
   477 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   480 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));	
 
   481 	strcpy(argv[0], "z:\\sys\\bin\\openshmem.exe");
 
   482 	ret = posix_spawn(&pid, "z:\\sys\\bin\\openshmem.exe", NULL, NULL, argv, (char**)NULL);
 
   485 		ERR_PRINTF2(_L("Error in posix spawn and errno is set to %d"),errno);
 
   488 	pid1 = waitpid(pid, &status, WUNTRACED);
 
   491 		ERR_PRINTF1(_L("waitpid failed..."));	
 
   494 	if(!(WEXITSTATUS(status)))
 
   496 		ERR_PRINTF1(_L("Failed to open the shared memory in the child process"));	
 
   499 	INFO_PRINTF1(_L("Successfully able to open the shared memory in the child process"));
 
   500 	ret = closenunlink(fd,"shmemtest");
 
   501 	if(ret == KErrGeneral)
 
   503 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   509 	free((void*)argv[0]);
 
   514 // -----------------------------------------------------------------------------
 
   515 // CTestsharedmemory::Testsharedmemory12
 
   516 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   517 // API tested: shm_open(), shm_unlink()
 
   518 // Description: Opening an existing shared memory in the different process using popen()
 
   519 // -----------------------------------------------------------------------------
 
   521 TInt CTestsharedmemory::Testsharedmemory12 (  )
 
   523 	int ret, ret1 = KErrGeneral, fd, status, fds[3], pid, pid1;
 
   525 	fd = shm_open("shmemtest_popen", O_CREAT|O_RDWR , 0666);
 
   528 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   531 	INFO_PRINTF2(_L("Successfully able to create a shared memory with fd  = %d"),fd);	
 
   532 	ret = write(fd, "helloworldss", 6);
 
   535 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
   538 	INFO_PRINTF1(_L("Successfully able to write in a shared memory for the first time"));
 
   539 	ret = write(fd, "gimmick", 6);
 
   542 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
   545 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
   546 	ret = lseek(fd, 3, SEEK_SET);
 
   547 	INFO_PRINTF2(_L("lseek returns = %d"),ret);
 
   550 		INFO_PRINTF2(_L("Failed to move the offset using lseek() and  errno is %d"),errno);
 
   553 	ret = write(fd, "symbianis", 9);
 
   556 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
   559 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
   560 	ret = lseek(fd, -12, SEEK_END);
 
   561 	INFO_PRINTF2(_L("lseek returns = %d"),ret);
 
   564 		INFO_PRINTF2(_L("Failed to move the offset using lseek() and  errno is %d"),errno);
 
   567 	ret = read(fd, (void*)buf, 21);
 
   568 	INFO_PRINTF2(_L("read returns = %d"),ret);
 
   571 		INFO_PRINTF2(_L("Error in reading from file and  errno is %d"),errno);
 
   574 	INFO_PRINTF1(_L("Successfully able to read from shared memory"));
 
   575 	pid = popen3("openshmem_popen.exe", NULL, NULL, fds);
 
   578 		ERR_PRINTF2(_L("Error in popen() and errno is set to %d"),errno);
 
   581 	pid1 = waitpid(pid, &status, WUNTRACED);
 
   584 		ERR_PRINTF1(_L("waitpid failed..."));	
 
   587 	if(!(WEXITSTATUS(status)))
 
   589 		ERR_PRINTF1(_L("Failed to open the shared memory in the child process"));	
 
   592 	ret = strncmp(buf, "helsymbianis",12);
 
   595 		ERR_PRINTF2(_L("Error in reading and writing and errno is %d"),errno);
 
   601 	closenunlink(fd,"shmemtest_popen");
 
   605 // -----------------------------------------------------------------------------
 
   606 // CTestsharedmemory::Testsharedmemory13
 
   607 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   608 // API tested: shm_unlink()
 
   609 // Description: To delete the shared memory which does not exists with an argument name been less than PATH_MAX/NAME_MAX
 
   610 // -----------------------------------------------------------------------------
 
   612 TInt CTestsharedmemory::Testsharedmemory13 (  )
 
   614 	int len, fd, ret1 = KErrGeneral;
 
   616 	for (len=0; len<219; len++)
 
   621 	fd = shm_unlink(path);
 
   622 	if((fd != -1) || (errno != ENOENT) )
 
   624 		ERR_PRINTF1(_L("shm_unlink() failed on negative test"));
 
   627 	INFO_PRINTF1(_L("shm_unlink() successfully returned ENOENT on negative test"));
 
   634 // -----------------------------------------------------------------------------
 
   635 // CTestsharedmemory::Testsharedmemory14
 
   636 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   637 // API tested: shm_unlink()
 
   638 // Description: To delete the shared memory with the name of  an argument been greater than 256.
 
   639 // -----------------------------------------------------------------------------
 
   641 TInt CTestsharedmemory::Testsharedmemory14 (  )
 
   643 	int i, ret, ret1 = KErrGeneral;
 
   645 	for (i=0; i<258; i++)
 
   650 	ret = shm_unlink(path);
 
   651 	if((ret != -1) || (errno != ENAMETOOLONG) )
 
   653 		ERR_PRINTF1(_L("shm_unlink() failed on negative test"));
 
   656 	INFO_PRINTF1(_L("shm_unlink() successfully returned ENAMETOOLONG on negative test"));
 
   663 // -----------------------------------------------------------------------------
 
   664 // CTestsharedmemory::Testsharedmemory15
 
   665 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   666 // API tested: shm_unlink()
 
   667 // Description: To delete the shared memory with NULL as the input
 
   668 // -----------------------------------------------------------------------------
 
   670 TInt CTestsharedmemory::Testsharedmemory15 (  )
 
   672 	int ret, ret1 = KErrGeneral;
 
   673 	ret = shm_unlink(NULL);
 
   674 	if((ret != -1) || (errno != EFAULT) )
 
   676 		ERR_PRINTF1(_L("shm_unlink() failed on negative test"));
 
   679 	INFO_PRINTF1(_L("shm_unlink() successfully returned EFAULT on negative test"));
 
   686 // -----------------------------------------------------------------------------
 
   687 // CTestsharedmemory::Testsharedmemory16
 
   688 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   689 // API tested: shm_unlink()
 
   690 // Description: Trying to delete an empty string shared memory
 
   691 // -----------------------------------------------------------------------------
 
   693 TInt CTestsharedmemory::Testsharedmemory16 (  )
 
   695 	int ret, ret1 = KErrGeneral;
 
   696 	ret = shm_unlink("");
 
   697 	if((ret != -1) || (errno != ENOENT) )
 
   699 		ERR_PRINTF1(_L("shm_unlink() failed on negative test"));
 
   702 	INFO_PRINTF1(_L("shm_unlink() successfully returned ENOENT on negative test"));
 
   709 // -----------------------------------------------------------------------------
 
   710 // CTestsharedmemory::Testsharedmemory17
 
   711 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   712 // API tested: shm_open(), shm_unlink()
 
   713 // Description: Writing into a shared memory and reading it
 
   714 // -----------------------------------------------------------------------------
 
   716 TInt CTestsharedmemory::Testsharedmemory17 (  )
 
   719 	int ret, ret1 = KErrGeneral, fd;
 
   721 	char buf1[15] = "Sharedmemory", buf2[15], filename[50];
 
   722     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   723     shmname.Copy(Shmname) ; 
 
   724 	char *file = (char *) shmname.Ptr() ;
 
   727 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   730 	file[shmname.Length()] = '\0' ;
 
   731 	strcpy(filename , file) ;
 
   732 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
   735 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   738 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   739 	ret = write(fd,buf1,13);
 
   742 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
   745 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
   749 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   752 	fd = shm_open(filename,O_RDWR,0777);
 
   755 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   758 	INFO_PRINTF1(_L("Successfully able to open a shared memory"));
 
   759 	ret = read(fd,buf2,13);
 
   762 		ERR_PRINTF2(_L("Error in reading into a file and errno is %d"),errno);
 
   765 	ret = strncmp(buf1,buf2,12);
 
   768 		ERR_PRINTF1(_L("Input and output buffer are not same"));
 
   771 	ret = closenunlink(fd,filename);
 
   772 	if(ret == KErrGeneral)
 
   774 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   783 // -----------------------------------------------------------------------------
 
   784 // CTestsharedmemory::Testsharedmemory18
 
   785 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   786 // API tested: shm_open(), shm_unlink()
 
   787 // Description: Checking the size of shared memory when opened using O_CREAT and O_TRUNC
 
   788 // -----------------------------------------------------------------------------
 
   790 TInt CTestsharedmemory::Testsharedmemory18 (  )
 
   793 	int ret, ret1 = KErrGeneral, fd;
 
   797     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   798     shmname.Copy(Shmname) ; 
 
   799 	char *file = (char *) shmname.Ptr() ;
 
   802 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   805 	file[shmname.Length()] = '\0' ;
 
   806 	strcpy(filename , file) ;
 
   807 	fd = shm_open(filename,O_CREAT|O_TRUNC,0777);
 
   810 		ERR_PRINTF2(_L("Error in opening the shared memory and errno is %d"),errno);
 
   813 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   814 	ret = fstat(fd,&statbuf);
 
   815 	if(statbuf.st_size != 0)
 
   817 		ERR_PRINTF2(_L("shared memory not truncated when created and errno is %d"),errno);
 
   819 		shm_unlink(filename);
 
   822 	INFO_PRINTF1(_L("shm_open() successfully truncated shared memory to size zero with O_CREAT and O_TRUNC flag"));
 
   825 	shm_unlink(filename);
 
   830 // -----------------------------------------------------------------------------
 
   831 // CTestsharedmemory::Testsharedmemory19
 
   832 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   833 // API tested: shm_open(), shm_unlink()
 
   834 // Description: To truncate the shared memory object by setting O_TRUNC flag.
 
   835 // -----------------------------------------------------------------------------
 
   837 TInt CTestsharedmemory::Testsharedmemory19 (  )
 
   840 	int ret, ret1 = KErrGeneral, fd;
 
   842 	char buf1[15] = "Sharedmemory", buf2[15], filename[50];
 
   843     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   844     shmname.Copy(Shmname) ; 
 
   845 	char *file = (char *) shmname.Ptr() ;
 
   848 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   851 	file[shmname.Length()] = '\0' ;
 
   852 	strcpy(filename , file) ;
 
   853 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
   856 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   859 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   860 	ret = write(fd,buf1,12);
 
   863 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
   866 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
   870 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   873 	fd = shm_open(filename,O_TRUNC,0777);
 
   876 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   879 	INFO_PRINTF1(_L("Successfully able to open the shared memory with O_TRUNC flag"));
 
   880 	ret = read(fd,buf2,12);
 
   883 		ERR_PRINTF2(_L("file not trsuncated and errno is %d"),errno);
 
   884 		closenunlink(fd,filename);
 
   887 	INFO_PRINTF1(_L("Successfully able to truncate"));
 
   888 	ret = closenunlink(fd,filename);
 
   889 	if(ret == KErrGeneral)
 
   891 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   900 // -----------------------------------------------------------------------------
 
   901 // CTestsharedmemory::Testsharedmemory20
 
   902 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   903 // API tested: shm_open(), shm_unlink()
 
   904 // Description: Trying to write into the shared memory with O_RDONLY flag
 
   905 //				write() should fail with EBADF
 
   906 // -----------------------------------------------------------------------------
 
   908 TInt CTestsharedmemory::Testsharedmemory20 (  )
 
   911 	int ret, ret1 = KErrGeneral, fd;
 
   913 	char buf[15] = "Sharedmemory", filename[50];
 
   914     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   915     shmname.Copy(Shmname) ; 
 
   916 	char *file = (char *) shmname.Ptr() ;
 
   919 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   922 	file[shmname.Length()] = '\0' ;
 
   923 	strcpy(filename , file) ;
 
   924 	fd = shm_open(filename,O_CREAT|O_RDONLY,0777);
 
   927 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   930 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   931 	ret = write(fd,buf,7);
 
   934 		ERR_PRINTF2(_L("shm_open() failed on negative test and errno is %d"),errno);
 
   935 		closenunlink(fd,filename);
 
   938 	if ((ret == -1) && (errno == EBADF))
 
   940 		INFO_PRINTF3(_L("Shm_open() successfully passed on negative test with return = %d and errno = %d"), ret, errno);
 
   942 	ret = closenunlink(fd,filename);
 
   943 	if(ret == KErrGeneral)
 
   945 		ERR_PRINTF1(_L("Error in deleting the file"));
 
   954 // -----------------------------------------------------------------------------
 
   955 // CTestsharedmemory::Testsharedmemory21
 
   956 // Test Case ID: OPENENV-LIBC-CIT-5946
 
   957 // API tested: shm_open(), shm_unlink()
 
   958 // Description: Trying to write to a file with O_TRUNC and O_RDWR
 
   959 // -----------------------------------------------------------------------------
 
   961 TInt CTestsharedmemory::Testsharedmemory21 (  )
 
   964 	int ret, ret1 = KErrGeneral, fd;
 
   966 	char buf1[15] = "Sharedmemory", buf2[15], filename[50];
 
   967     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
   968     shmname.Copy(Shmname) ; 
 
   969     char *file = (char *) shmname.Ptr() ;
 
   972 		ERR_PRINTF1(_L("Failed to read input file name") );
 
   976 	file[shmname.Length()] = '\0' ;
 
   977 	strcpy(filename , file) ;
 
   978 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
   981 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   984 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
   988 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
   991 	fd = shm_open(filename,O_TRUNC|O_RDWR,0777);
 
   994 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
   997 	INFO_PRINTF1(_L("Successfully able to open a shared memory with an O_TRUNC flag"));
 
   998 	ret = write(fd,buf1,12);
 
  1001 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
  1004 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
  1008 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
  1011 	fd = shm_open(filename,O_RDWR,0777);
 
  1014 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
  1017 	INFO_PRINTF1(_L("Successfully able to open a shared memory with an O_TRUNC flag"));
 
  1018 	ret = read(fd,buf2,12);
 
  1021 		ERR_PRINTF2(_L("error in reading from a file and errno is %d"),errno);
 
  1024 	ret = strncmp(buf1,buf2,12);
 
  1027 		ERR_PRINTF1(_L("Input and output buffer are not same"));
 
  1030 	INFO_PRINTF1(_L("Successfully able to read the contents of shared memory"));
 
  1031 	ret = closenunlink(fd,filename);
 
  1032 	if(ret == KErrGeneral)
 
  1034 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1043 // -----------------------------------------------------------------------------
 
  1044 // CTestsharedmemory::Testsharedmemory22
 
  1045 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1046 // API tested: shm_open(), shm_unlink()
 
  1047 // Description: Trying to write to a file with only O_TRUNC flag set
 
  1048 //				write() should fail with EBADF
 
  1049 // -----------------------------------------------------------------------------
 
  1051 TInt CTestsharedmemory::Testsharedmemory22 (  )
 
  1054 	int ret, ret1 = KErrGeneral, fd;
 
  1056 	char buf1[15] = "Sharedmemory", buf2[12] = "symbianpips", filename[50];
 
  1057     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1058     shmname.Copy(Shmname) ; 
 
  1059 	char *file = (char *) shmname.Ptr() ;
 
  1062 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1065 	file[shmname.Length()] = '\0' ;
 
  1066 	strcpy(filename , file) ;
 
  1067 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
  1070 		ERR_PRINTF2(_L("Error in creating shared memory and errno is %d"),errno);
 
  1073 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
  1074 	ret = write(fd,buf1,12);
 
  1077 		ERR_PRINTF2(_L("Error in writing into shared memory and errno is %d"),errno);
 
  1083 		ERR_PRINTF2(_L("Error in closing shared memory and errno is %d"),errno);
 
  1086 	INFO_PRINTF1(_L("Successfully able to write to shared memory"));
 
  1087 	fd = shm_open(filename,O_TRUNC,0777);
 
  1090 		ERR_PRINTF2(_L("Error in opening shared memory with O_TRUNC and errno is %d"),errno);
 
  1092 		shm_unlink(filename);
 
  1095 	INFO_PRINTF1(_L("Successfully able to open a shared memory with O_TRUNC"));
 
  1096 	ret = write(fd,buf2,12);
 
  1097 	if ((ret != -1) && (errno != EBADF))
 
  1099 		ERR_PRINTF2(_L("Error in writing into shared memory and errno is %d"),errno);
 
  1100 		ERR_PRINTF1(_L("shm_open() negative test failed"));
 
  1103 	INFO_PRINTF1(_L("shm_open() negative test successful"));
 
  1107 		ERR_PRINTF2(_L("Error in closing shared memory and errno is %d"),errno);
 
  1110 	ret = shm_unlink(filename);
 
  1111 	if(ret == KErrGeneral)
 
  1113 		ERR_PRINTF1(_L("Error in removing shared memory"));
 
  1122 // -----------------------------------------------------------------------------
 
  1123 // CTestsharedmemory::Testsharedmemory23
 
  1124 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1125 // API tested: shm_open(), shm_unlink()
 
  1126 // Description: Trying to open a shared memory using O_CREAT|O_EXCL|O_TRUNC|O_RDWR flag
 
  1127 // -----------------------------------------------------------------------------
 
  1129 TInt CTestsharedmemory::Testsharedmemory23 (  )
 
  1132 	int ret, ret1 = KErrGeneral, fd;
 
  1135     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1136     shmname.Copy(Shmname) ; 
 
  1137 	char *file = (char *) shmname.Ptr() ;
 
  1140 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1143 	file[shmname.Length()] = '\0' ;
 
  1144 	strcpy(filename , file) ;
 
  1145 	fd = shm_open(filename,O_CREAT|O_EXCL|O_TRUNC|O_RDWR,0777);
 
  1148 		ERR_PRINTF2(_L("Error in opening the file and errno is %d"),errno);
 
  1151 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
  1155 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
  1158 	fd = shm_open(filename,O_CREAT|O_EXCL|O_TRUNC,0777);
 
  1159 	if ((fd != -1) || (errno != EEXIST))
 
  1161 		ERR_PRINTF2(_L("shm_open() failed on negative test and errno is %d\n"),errno);
 
  1163 		shm_unlink(filename);
 
  1166 	INFO_PRINTF1(_L("shm_open() is success on negative test"));
 
  1167 	ret = shm_unlink(filename);
 
  1168 	if(ret == KErrGeneral)
 
  1170 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1179 // -----------------------------------------------------------------------------
 
  1180 // CTestsharedmemory::Testsharedmemory24
 
  1181 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1182 // API tested: shm_open(), shm_unlink()
 
  1183 // Description: To seek the contents of shared memory using lseek() using SEEK_SET
 
  1184 // -----------------------------------------------------------------------------
 
  1186 TInt CTestsharedmemory::Testsharedmemory24 (  )
 
  1189 	int ret, ret1 = KErrGeneral, fd;
 
  1191 	char buf1[15] = "Sharedmemory";
 
  1192 	char buf2[15], buf3[15], filename[50];
 
  1193     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1194     shmname.Copy(Shmname) ; 
 
  1195 	char *file = (char *) shmname.Ptr() ;
 
  1198 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1201 	file[shmname.Length()] = '\0' ;
 
  1202 	strcpy(filename , file) ;
 
  1203 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
  1204 	INFO_PRINTF2(_L("shm_open() returns = %d"),fd);
 
  1207 		INFO_PRINTF2(_L("error in shm_open and errno is %d"),errno);
 
  1210 	ret = write(fd,buf1,7);
 
  1211 	INFO_PRINTF2(_L("write returns = %d"),ret);
 
  1214 		INFO_PRINTF2(_L("error in writing into a file and errno is %d"),errno);
 
  1216 		shm_unlink(filename);
 
  1222 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);		
 
  1225 	fd = shm_open(filename,O_RDWR,0777);
 
  1226 	INFO_PRINTF2(_L("shm_open() returns = %d "),fd);
 
  1229 		INFO_PRINTF2(_L("error in shm_open and errno is %d"),errno);
 
  1232 	ret = read(fd,buf2,10);
 
  1233 	INFO_PRINTF2(_L("read returns = %d"),ret);
 
  1236 		INFO_PRINTF2(_L("not able to read from a shmem and  errno is %d"),errno);
 
  1238 		shm_unlink(filename);
 
  1241 	ret = lseek(fd,0,SEEK_SET);
 
  1242 	INFO_PRINTF2(_L("lseek returns = %d"),ret);
 
  1245 		INFO_PRINTF2(_L("Failed to move the offset using lseek() and  errno is %d"),errno);
 
  1247 		shm_unlink(filename);
 
  1250 	ret = read(fd,buf3,10);
 
  1251 	INFO_PRINTF2(_L("read returns = %d"),ret);
 
  1254 		ERR_PRINTF2(_L("error in reading from a file and errno is %d"),errno);
 
  1256 		shm_unlink(filename);
 
  1259 	ret = strncmp(buf3,buf2,7);
 
  1262 		ERR_PRINTF1(_L("Input and output buffer are not same"));
 
  1263 	ret = closenunlink(fd,filename);
 
  1264 	if(ret == KErrGeneral)
 
  1266 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1271 	INFO_PRINTF1(_L("Successfully able to read the contents of a shared memory using SEEK_SET"));
 
  1272 	ret = closenunlink(fd,filename);
 
  1273 	if(ret == KErrGeneral)
 
  1275 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1284 // -----------------------------------------------------------------------------
 
  1285 // CTestsharedmemory::Testsharedmemory25
 
  1286 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1287 // API tested: shm_open(), shm_unlink()
 
  1288 // Description: Description: To seek the contents of shared memory using lseek() using SEEK_CUR
 
  1289 // -----------------------------------------------------------------------------
 
  1291 TInt CTestsharedmemory::Testsharedmemory25 (  )
 
  1294 	int ret, ret1 = KErrGeneral, fd;
 
  1296 	char buf1[15] = "symbian", buf2[15], buf3[15], filename[50];
 
  1297     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1298     shmname.Copy(Shmname) ; 
 
  1299 	char *file = (char *) shmname.Ptr() ;
 
  1302 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1305 	file[shmname.Length()] = '\0' ;
 
  1306 	strcpy(filename , file) ;
 
  1307 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
  1308 	INFO_PRINTF2(_L("shm_open() returns = %d"),fd);
 
  1311 		INFO_PRINTF2(_L("error in shm_open and errno is %d"),errno);
 
  1314 	ret = write(fd,buf1,7);
 
  1315 	INFO_PRINTF2(_L("write() returns = %d"),ret);
 
  1318 		INFO_PRINTF2(_L("error in writing into a file and errno is %d"),errno);
 
  1324 		ERR_PRINTF2(_L("Error in closing the file and errno is %d"),errno);
 
  1327 	fd = shm_open(filename,O_RDWR,0777);
 
  1328 	INFO_PRINTF2(_L("shm_open() returns = %d"),fd);
 
  1331 		INFO_PRINTF2(_L("error in shm_open and errno is %d"),errno);
 
  1334 	ret = read(fd,buf2,7);
 
  1335 	INFO_PRINTF2(_L("read() returns = %d"),ret);
 
  1338 		ERR_PRINTF2(_L("error in reading from a file and errno is %d"),errno);
 
  1341 	ret = lseek(fd,-7,SEEK_CUR);
 
  1342 	INFO_PRINTF2(_L("lseek() returns = %d"),ret);
 
  1345 		INFO_PRINTF2(_L("Failed to move the offset using lseek() and  errno is %d"),errno);
 
  1348 	ret = read(fd,buf3,7);
 
  1349 	INFO_PRINTF2(_L("read() returns = %d"),ret);
 
  1352 		ERR_PRINTF2(_L("error in reading from a file and errno is %d"),errno);
 
  1355 	ret = strncmp(buf3,buf2,7);
 
  1358 		ERR_PRINTF1(_L("Input and output buffer are not same"));
 
  1361 	INFO_PRINTF1(_L("Successfully able to read the contents of a shared memory using SEEK_CUR"));
 
  1362 	ret = closenunlink(fd,filename);
 
  1363 	if(ret == KErrGeneral)
 
  1365 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1374 // -----------------------------------------------------------------------------
 
  1375 // CTestsharedmemory::Testsharedmemory26
 
  1376 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1377 // API tested: shm_open(), shm_unlink()
 
  1378 // Description: Description: Combined test for file related operations(read,write,lseek) on shared memory
 
  1379 // -----------------------------------------------------------------------------
 
  1381 TInt CTestsharedmemory::Testsharedmemory26 (  )
 
  1384 	int ret, ret1 = KErrGeneral, fd;
 
  1388     ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1389     shmname.Copy(Shmname) ; 
 
  1390 	char *file = (char *) shmname.Ptr() ;
 
  1393 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1396 	file[shmname.Length()] = '\0' ;
 
  1397 	strcpy(filename , file) ;
 
  1398 	fd = shm_open(filename, O_CREAT|O_RDWR , 0666);
 
  1401 		INFO_PRINTF2(_L("error in shm_open and errno is %d\n"),errno);
 
  1404 	ret = write(fd, "helloworldss", 6);
 
  1407 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
  1410 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
  1411 	ret = write(fd, "gimmick", 6);
 
  1414 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
  1417 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
  1418 	ret = lseek(fd, 3, SEEK_CUR);
 
  1421 		ERR_PRINTF2(_L("Error in lseek() into a file and errno is %d"),errno);
 
  1424 	INFO_PRINTF1(_L("Successfully able use lseek on a shared memory"));
 
  1425 	ret = write(fd, "biswajeet", 9);
 
  1428 		ERR_PRINTF2(_L("Error in writing into a file and errno is %d"),errno);
 
  1431 	INFO_PRINTF1(_L("Successfully able to write in a shared memory"));
 
  1432 	ret = lseek(fd, -18, SEEK_END);
 
  1435 		ERR_PRINTF2(_L("Error in lseek() into a file and errno is %d"),errno);
 
  1438 	INFO_PRINTF1(_L("Successfully able use lseek on a shared memory"));
 
  1439 	ret = read(fd, (void*)buf, 21);
 
  1442 		ERR_PRINTF2(_L("Error in reading into a file and errno is %d"),errno);
 
  1445 	ret = strncmp(buf, "gimmic", 6);
 
  1448 		ERR_PRINTF1(_L("Input and output buffer are not same"));
 
  1451 	ret = closenunlink(fd,filename);
 
  1452 	if(ret == KErrGeneral)
 
  1454 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1463 // -----------------------------------------------------------------------------
 
  1464 // CTestsharedmemory::Testsharedmemory27
 
  1465 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1466 // API tested: shm_open(), shm_unlink()
 
  1467 // Description: To perform lseek operation on an invalid shared memory 
 
  1468 // -----------------------------------------------------------------------------
 
  1470 TInt CTestsharedmemory::Testsharedmemory27 ( )
 
  1473 	int ret, ret1 = KErrGeneral, fd;
 
  1476 	ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1477 	shmname.Copy(Shmname) ; 
 
  1478 	char *file = (char *) shmname.Ptr() ;
 
  1481 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1484 	file[shmname.Length()] = '\0' ;
 
  1485 	strcpy(filename , file) ;
 
  1486 	fd = shm_open(filename, O_CREAT|O_RDWR , 0666);
 
  1489 		ERR_PRINTF2(_L("error in shm_open and errno is %d\n"),errno);
 
  1492 	INFO_PRINTF1(_L("shm_open() successful"));
 
  1496 		ERR_PRINTF1(_L("Error in closing fd"));
 
  1499 	INFO_PRINTF1(_L("close() successful"));
 
  1500 	ret = lseek(fd, 0, SEEK_SET);
 
  1501 	if((ret != -1) || (errno != EBADF))
 
  1503 		ERR_PRINTF2(_L("lseek() failed on negative test for a shared memory and errno is %d"),errno);
 
  1506 	INFO_PRINTF1(_L("lseek() successfully returned EBADF on negative test"));
 
  1507 	ret = shm_unlink(filename);
 
  1510 		ERR_PRINTF1(_L("shm_unlink() unsuccessful"));
 
  1513 	INFO_PRINTF1(_L("shm_unlink() successful"));
 
  1520 // -----------------------------------------------------------------------------
 
  1521 // CTestsharedmemory::Testsharedmemory28
 
  1522 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1523 // API tested: shm_open(), shm_unlink()
 
  1524 // Description: To perform lseek operation on shared memory when whence option is an invalid value 
 
  1525 // -----------------------------------------------------------------------------
 
  1527 TInt CTestsharedmemory::Testsharedmemory28 ( )
 
  1530 	int ret, ret1 = KErrGeneral, fd;
 
  1533 	ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1534 	shmname.Copy(Shmname) ; 
 
  1535 	char *file = (char *) shmname.Ptr() ;
 
  1538 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1541 	file[shmname.Length()] = '\0' ;
 
  1542 	strcpy(filename , file) ;
 
  1543 	fd = shm_open(filename, O_CREAT|O_RDWR , 0666);
 
  1546 		INFO_PRINTF2(_L("error in shm_open and errno is %d\n"),errno);
 
  1549 	ret = lseek(fd, 0, 6);
 
  1550 	if((ret != -1) || (errno != EINVAL))
 
  1552 		ERR_PRINTF2(_L("lseek() failed on negative test for a shared memory and errno is %d"),errno);
 
  1555 	INFO_PRINTF1(_L("lseek() successfully returned EINVAL on negative test"));
 
  1556 	ret = closenunlink(fd,filename);
 
  1557 	if(ret == KErrGeneral)
 
  1559 		ERR_PRINTF1(_L("Error in deleting the file"));
 
  1568 // -----------------------------------------------------------------------------
 
  1569 // CTestsharedmemory::Testsharedmemory29
 
  1570 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1571 // API tested: shm_open(), shm_unlink()
 
  1572 // Description: To open a shared memory using O_RDONLY flag and then try to write 
 
  1573 //				into it. write() should fail with EBADF 
 
  1574 // -----------------------------------------------------------------------------
 
  1576 TInt CTestsharedmemory::Testsharedmemory29 ( )
 
  1579 	int ret, ret1 = KErrGeneral, fd;
 
  1581 	char buf1[15] = "Sharedmemory", buf2[12] = "symbianpips", filename[50], buf3[12];
 
  1582 	ret = GetStringFromConfig(ConfigSection(), _L("Shmname"), Shmname );
 
  1583 	shmname.Copy(Shmname) ; 
 
  1584 	char *file = (char *) shmname.Ptr() ;
 
  1587 		ERR_PRINTF1(_L("Failed to read input file name") );
 
  1590 	file[shmname.Length()] = '\0' ;
 
  1591 	strcpy(filename , file) ;
 
  1592 	fd = shm_open(filename,O_CREAT|O_RDWR,0777);
 
  1595 		ERR_PRINTF2(_L("Error in creating shared memory and errno is %d"),errno);
 
  1598 	INFO_PRINTF1(_L("Successfully able to create a shared memory"));
 
  1599 	ret = write(fd,buf1,12);
 
  1602 		ERR_PRINTF2(_L("Error in writing into shared memory and errno is %d"),errno);
 
  1608 		ERR_PRINTF2(_L("Error in closing shared memory and errno is %d"),errno);
 
  1611 	INFO_PRINTF1(_L("Successfully able to write to shared memory"));
 
  1612 	fd = shm_open(filename,O_RDONLY,0777);
 
  1615 		ERR_PRINTF2(_L("Error in opening shared memory with O_RDONLY and errno is %d"),errno);
 
  1618 	INFO_PRINTF1(_L("Successfully able to open a shared memory with O_RDONLY"));
 
  1619 	ret = read(fd,buf3,12);
 
  1622 		ERR_PRINTF2(_L("Error in reading from shared memory and errno is %d"),errno);
 
  1625 	if (strncmp(buf1, buf2, 12) != 0)
 
  1627 		ERR_PRINTF1(_L("Error in reading from shared memory"));
 
  1629 	INFO_PRINTF1(_L("Successfully able to read from a shared memory"));
 
  1630 	ret = write(fd,buf2,12);
 
  1631 	if ((ret != -1) && (errno != EBADF))
 
  1633 		ERR_PRINTF2(_L("Error in writing into shared memory and errno is %d"),errno);
 
  1634 		ERR_PRINTF1(_L("shm_open() negative test failed"));
 
  1637 	INFO_PRINTF1(_L("shm_open() negative test successful"));
 
  1641 		ERR_PRINTF2(_L("Error in closing shared memory and errno is %d"),errno);
 
  1644 	ret = shm_unlink(filename);
 
  1645 	if(ret == KErrGeneral)
 
  1647 		ERR_PRINTF1(_L("Error in removing shared memory"));
 
  1656 // -----------------------------------------------------------------------------
 
  1657 // CTestsharedmemory::Testsharedmemory30
 
  1658 // Test Case ID: OPENENV-LIBC-CIT-5946
 
  1659 // API tested: shm_open(), read(), write(), lseek()
 
  1660 // Description: negative test case for shm_open(), read(), write() , lseek(), fcntl()
 
  1661 // Purpose : Coverage
 
  1662 // -----------------------------------------------------------------------------
 
  1663 TInt CTestsharedmemory::Testsharedmemory30 (  )
 
  1666 	char buf1[15] = "helloworldss", buf2[21];
 
  1667 	char filename[50] = "page";
 
  1668 	INFO_PRINTF1(_L("negative test case for coverage"));
 
  1669 	fd = shm_open(filename,O_CREAT|O_RDWR,0666);
 
  1670 	INFO_PRINTF2(_L("shm_open() returns = %d"),fd);
 
  1673 		ERR_PRINTF2(_L("error in shm_open and errno is %d"),errno);
 
  1675 	ret = write(fd,buf1,6);
 
  1676 	INFO_PRINTF2(_L("write returns = %d"),ret);
 
  1679 		ERR_PRINTF2(_L("error in writing into a file and errno is %d"),errno);
 
  1681 	ret = write(fd,"gimmick",6);
 
  1682 	INFO_PRINTF2(_L("write returns = %d"),ret);
 
  1685 		ERR_PRINTF2(_L("error in writing into a file and errno is %d"),errno);
 
  1687 	ret = lseek(fd,-30,SEEK_END);
 
  1688 	INFO_PRINTF2(_L("lseek returns = %d"),ret);
 
  1691 		INFO_PRINTF2(_L("Failed to move the offset using lseek() and  errno is %d"),errno);
 
  1694 	INFO_PRINTF2(_L("close returns = %d"),ret);
 
  1697 		ERR_PRINTF2(_L("Failed to close shared memory object using close() and  errno is %d"),errno);
 
  1699 	fd = shm_open(filename,O_RDWR,0666);
 
  1700 	INFO_PRINTF2(_L("shm_open() returns = %d"),fd);
 
  1703 		ERR_PRINTF2(_L("error in shm_open and errno is %d"),errno);
 
  1705 	ret = read(fd,buf2,6);
 
  1706 	INFO_PRINTF2(_L("read returns = %d"),ret);
 
  1709 		ERR_PRINTF2(_L("error in reading from shared memory and errno is %d"),errno);
 
  1711 	ret = fcntl(fd, F_GETFD);
 
  1712 	INFO_PRINTF2(_L("fcntl() with cmd F_GETFD returns = %d"),ret);
 
  1715 		ERR_PRINTF1(_L("fcntl() with cmd F_GETFD failed"));
 
  1717 	ret = fcntl(fd, F_SETFL, O_NONBLOCK);
 
  1718 	INFO_PRINTF2(_L("fcntl() with cmd F_GETFD and arg O_NONBLOCK returns = %d"),ret);
 
  1721 		ERR_PRINTF1(_L("fcntl() with cmd F_GETFD and arg O_NONBLOCK failed"));
 
  1723 	ret = fcntl(fd, F_SETFD, 1);
 
  1724 	INFO_PRINTF2(_L("fcntl() with cmd F_SETFD and arg 1 returns = %d"),ret);
 
  1727 		ERR_PRINTF1(_L("fcntl() with cmd F_SETFD and arg 1 failed"));
 
  1729 	ret = fcntl(fd, F_GETFD);
 
  1730 	INFO_PRINTF2(_L("fcntl() with cmd F_GETFD returns = %d"),ret);
 
  1733 		ERR_PRINTF1(_L("fcntl() with cmd F_GETFD failed"));
 
  1735 	ret = fcntl(fd, F_SETFD, 0);
 
  1736 	INFO_PRINTF2(_L("fcntl() with cmd F_SETFD and arg 0 returns = %d"),ret);
 
  1739 		ERR_PRINTF1(_L("fcntl() with cmd F_SETFD and arg 0 failed"));
 
  1741 	ret = fcntl(fd, F_SETFD, 2);
 
  1742 	INFO_PRINTF2(_L("fcntl() with cmd F_SETFD and arg 2 returns = %d"),ret);
 
  1745 		ERR_PRINTF1(_L("fcntl() with cmd F_SETFD and arg 2 failed"));
 
  1747 	ret = fcntl(fd, F_GETLK);
 
  1748 	INFO_PRINTF2(_L("fcntl() with cmd F_GETLK returns = %d"),ret);
 
  1749 	if(ret != KErrNotSupported)
 
  1751 		ERR_PRINTF1(_L("fcntl() with cmd F_GETLK failed"));
 
  1754 	INFO_PRINTF2(_L("close returns = %d"),ret);
 
  1757 		ERR_PRINTF2(_L("Failed to close shared memory object using close() and  errno is %d"),errno);
 
  1759 	ret = shm_unlink(filename);
 
  1760 	INFO_PRINTF2(_L("shm_unlink returns = %d"),ret);
 
  1763 		ERR_PRINTF2(_L("Failed to remove shared memory using shm_unlink() and  errno is %d"),errno);