From: Subrata M. <su...@li...> - 2007-05-18 12:23:58
|
This is also through to CVS. Regards-- Subrata Carmelo AMOROSO wrote: > Nadia Derbey wrote: >> Found some bugs in testcases/kernel/mem/mtest07/shm_test.c: >> >> 1) in main(): >> chld_args is declared as >> long chld_args[3]; >> instead of [4] >> --> chld_args[3] is used to pass the reader / writer status to the >> created thread. >> >> 2) in shmat_rd_wr(): >> shmat() is called as follows: >> shmat(shmkey, (void *)locargs[2], SHM_RND|SHMLBA) >> >> while locargs[2] contains the shm segment size (which may be set to >> big values since it is a random size). >> >> This should be changed to >> shmat(shmkey, (void *)NULL, 0) >> >> Attached a patch including other minor chnages, if interested. >> >> Regards, >> Nadia >> > Hi Nadia, All, > I fully agree with your changes. The attached patch includes Nadia'a > one plus some other bug fixes: > > - pthread_exit / pthread_join handling of exit status (a very common > error into LTP) > - the threads pair (reader/writer) are using the same thread_id > - name conventions changes: I prefer use shm_id as shared memory > identifier instead of shmkey (just to be clearer) > > Regards, > Carmelo > ------------------------------------------------------------------------ > > --- shm_test.c.orig 2003-03-25 00:15:48.000000000 +0100 > +++ shm_test.c 2007-05-14 15:34:22.382556000 +0200 > @@ -69,7 +69,7 @@ > #define PTHREAD_EXIT(val) do {\ > exit_val = val; \ > dprt("pid[%d]: exiting with %d\n", getpid(),exit_val); \ > - pthread_exit((void *)&exit_val); \ > + pthread_exit((void *)exit_val); \ > } while (0) > > #define OPT_MISSING(prog, opt) do{\ > @@ -182,7 +182,7 @@ > int shmndx = 0; /* index to the number of attach and detach */ > int index = 0; /* index to the number of blocks touched */ > int reader = 0; /* this thread is a reader thread if set to 1 */ > - key_t shmkey = 0; /* shared memory id */ > + key_t shm_id = 0; /* shared memory id */ > long *locargs = /* local pointer to arguments */ > (long *)args; > volatile int exit_val = 0; /* exit value of the pthread */ > @@ -199,7 +199,7 @@ > getpid(), (int)locargs[1]); > > /* get shared memory id */ > - if ((shmkey = shmget((int)locargs[1], (int)locargs[2], IPC_CREAT|0666)) > + if ((shm_id = shmget((int)locargs[1], (int)locargs[2], IPC_CREAT|0666)) > == -1) > { > dprt("pid[%d]: shmat_rd_wr(): shmget failed\n", getpid()); > @@ -209,13 +209,12 @@ > > fprintf(stdout, "pid[%d]: shmat_rd_wr(): shmget():" > "success got segment id %d\n", > - getpid(), shmkey); > + getpid(), shm_id); > > /* get shared memory segment */ > - if ((shmat_addr = shmat(shmkey, (void *)locargs[2], SHM_RND|SHMLBA)) > - == (void *)-1) > + if ((shmat_addr = (char *)shmat(shm_id, NULL, 0)) == (void *)-1) > { > - rm_shared_mem(shmkey, shmat_addr, 0); > + rm_shared_mem(shm_id, shmat_addr, 0); > fprintf(stderr, "pid[%d]: do_shmat_shmadt(): shmat_addr = %#lx\n", > getpid(), (long)shmat_addr); > perror("do_shmat_shmadt(): shmat()"); > @@ -236,8 +235,8 @@ > { > dprt("pid[%d]: do_shmat_shmatd(): write_to_mem = %#x\n", > getpid(), write_to_mem); > - strncpy(write_to_mem, "Y", sizeof(char *)); > - index += sizeof(char *); > + *write_to_mem = 'Y'; > + index++; > write_to_mem++; > sched_yield(); > } > @@ -250,7 +249,7 @@ > while (index < (int)locargs[2]) > { > buff = *read_from_mem; > - index += sizeof(char *); > + index++; > read_from_mem++; > sched_yield(); > } > @@ -259,7 +258,7 @@ > sched_yield(); > > /* remove the shared memory */ > - if (rm_shared_mem(shmkey, shmat_addr, 1) == -1) > + if (rm_shared_mem(shm_id, shmat_addr, 1) == -1) > { > fprintf(stderr, > "pid[%d]: do_shmat_shmatd(): rm_shared_mem(): faild to rm id\n", > @@ -296,11 +295,11 @@ > int num_thrd = MAXT;/* number of threads to create */ > int num_reps = MAXR;/* number of repatitions the test is run */ > int thrd_ndx; /* index into the array of thread ids */ > - int *th_status; /* exit status of LWP's */ > + int th_status; /* exit status of LWP's */ > int map_size; /* size of the file mapped. */ > int shmkey = 1969;/* key used to generate shmid by shmget() */ > pthread_t thrdid[30]; /* maxinum of 30 threads allowed */ > - long chld_args[3]; /* arguments to the thread function */ > + long chld_args[4]; /* arguments to the thread function */ > char *map_address=NULL; > /* address in memory of the mapped file */ > extern int optopt; /* options to the program */ > @@ -342,7 +341,7 @@ > > chld_args[0] = num_reps; > > - for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx++) > + for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx+=2) > { > srand(time(NULL)%100); > map_size = (1 + (int)(1000.0*rand()/(RAND_MAX+1.0))) * 4096; > @@ -363,7 +362,7 @@ > > chld_args[3] = READER; > > - if (pthread_create(&thrdid[thrd_ndx], NULL, shmat_rd_wr, chld_args)) > + if (pthread_create(&thrdid[thrd_ndx+1], NULL, shmat_rd_wr, chld_args)) > { > perror("shmat_rd_wr(): pthread_create()"); > exit(-1); > @@ -374,7 +373,7 @@ > > for (thrd_ndx = 0; thrd_ndx < num_thrd; thrd_ndx++) > { > - if (pthread_join(thrdid[thrd_ndx], (void **)&th_status) != 0) > + if (pthread_join(thrdid[thrd_ndx], (void *)&th_status) != 0) > { > perror("shmat_rd_wr(): pthread_join()"); > exit(-1); > @@ -382,7 +381,7 @@ > else > { > dprt("WE ARE HERE %d\n", __LINE__); > - if ((*th_status) == -1) > + if (th_status == -1) > { > fprintf(stderr, > "thread [%ld] - process exited with errors\n", > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > ------------------------------------------------------------------------ > > _______________________________________________ > Ltp-list mailing list > Ltp...@li... > https://lists.sourceforge.net/lists/listinfo/ltp-list > |