Author: bonefish Date: 2010-04-08 19:15:49 +0200 (Thu, 08 Apr 2010) New Revision: 36089 Changeset: http://dev.haiku-os.org/changeset/36089/haiku Modified: haiku/trunk/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/shm_open/23-1.c Log: * More generous buffer sizes for the semaphore and shared memory object names. * The result shared memory was mapped PROT_WRITE only, but since the variable in it is used with the increment operator, it needs PROT_READ, too. Modified: haiku/trunk/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/shm_open/23-1.c =================================================================== --- haiku/trunk/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/shm_open/23-1.c 2010-04-08 17:09:56 UTC (rev 36088) +++ haiku/trunk/src/tests/system/libroot/posix/posixtestsuite/conformance/interfaces/shm_open/23-1.c 2010-04-08 17:15:49 UTC (rev 36089) @@ -18,13 +18,13 @@ */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to - avoid warning if the implementation does not program ftruncate as a base + avoid warning if the implementation does not program ftruncate as a base interface */ /* adam.li: 2004-04-30: Rewrite the test case. The idea is that with O_CREAT and O_EXCL specified, to shm_open() a object can only success - once, although multiple processes might open with the same name at the - same time. + once, although multiple processes might open with the same name at the + same time. */ #define _XOPEN_SOURCE 600 @@ -40,7 +40,7 @@ #include <unistd.h> #include "posixtest.h" -#define NAME_SIZE 20 +#define NAME_SIZE 50 #define SHM_NAME "/posixtest_23-1_%d" /* The processes communicate by a shared memory object */ @@ -57,10 +57,10 @@ { int i, fd; struct timespec ts = {.tv_sec = 0, .tv_nsec = 0}; - int msec = 0; - + int msec = 0; + sleep(1); - srand(time(NULL)); + srand(time(NULL)); for(i=0; i<NLOOP; i++){ sprintf(name, SHM_NAME, i); fd = shm_open(name, O_RDONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); @@ -81,9 +81,9 @@ int main() { int i, pid, result_fd; - char semname[20]; + char semname[50]; - snprintf(semname, 20, "/sem23-1_%ld", (long)getpid()); + snprintf(semname, sizeof(semname), "/sem23-1_%ld", (long)getpid()); sem = sem_open(semname, O_CREAT, 0777, 1); if( sem == SEM_FAILED || sem == NULL ) { perror("error at sem_open"); @@ -91,8 +91,8 @@ } sem_unlink(semname); - result_fd = shm_open(SHM_RESULT_NAME, - O_RDWR|O_CREAT, + result_fd = shm_open(SHM_RESULT_NAME, + O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(result_fd == -1){ perror("An error occurs when calling shm_open()"); @@ -102,16 +102,16 @@ if(ftruncate(result_fd, sizeof(*create_cnt)) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_RESULT_NAME); - return PTS_UNRESOLVED; + return PTS_UNRESOLVED; } - create_cnt = mmap(NULL, sizeof(*create_cnt), PROT_WRITE, + create_cnt = mmap(NULL, sizeof(*create_cnt), PROT_READ | PROT_WRITE, MAP_SHARED, result_fd, 0); if( create_cnt == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_RESULT_NAME); - return PTS_UNRESOLVED; - } + return PTS_UNRESOLVED; + } *create_cnt = 0; @@ -127,11 +127,11 @@ } while (wait(NULL) > 0); - + for(i=0; i<NLOOP; i++){ sprintf(name, SHM_NAME, i); shm_unlink(name); - } + } fprintf(stderr, "create_cnt: %d\n", *create_cnt); if(*create_cnt != NLOOP){