/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Test that the check for the existence of the shared memory object and the * creation of the object if it does not exist is atomic with respect to other * processes executing shm_open() naming the same shared memory object with * O_EXCL and O_CREAT set. * * This test launch NPROCESS processes which all try to open NLOOP shared * memory objects. If an unexpected error occurs or if the number of created * objects is not NLOOP, the test failed. In other case the test is unresolved. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to 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. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAME_SIZE 20 #define SHM_NAME "/posixtest_23-1_%d" /* The processes communicate by a shared memory object */ #define SHM_RESULT_NAME "/result_23-1" #define NPROCESS 1000 /* Number of concurrent processes */ #define NLOOP 1000 /* Number of shared memory object */ char name[NAME_SIZE]; int *create_cnt; sem_t *sem; int child_func(void) { int i, fd; struct timespec ts = {.tv_sec = 0, .tv_nsec = 0}; int msec = 0; sleep(1); srand(time(NULL)); for(i=0; i 0); for(i=0; i