Hi!
> hugeshmat01 test use fixed addr for its 2nd testcase, however it does
> not work on some architectures, like powerpc. I took some codes from
> syscalls/shmat01, which fetches the baseaddr by running shmat first at
> setup(), and use it for 2nd testcase.

I would be happier to have the code generating the address in one place
rather than copying the code around.

> Signed-off-by: Caspar Zhang <[email protected]>
> ---
> +void *base_addr;
>  
>  struct test_case_t {
>       int *shmid;
>       void *addr;
>       int flags;
> -} TC[] = {
> -     /* a straight forward read/write attach */
> -     {&shm_id_1, 0, 0},
> -
> -       /* an attach using non aligned memory */
> -     {&shm_id_1, (void *)UNALIGNED, SHM_RND},
> -
> -     /* a read only attach */
> -     {&shm_id_1, 0, SHM_RDONLY}
>  };

There is no need to remove the static declaration for the structure,
just set the UNALIGNED to NULL and intialize only what is needed on
runtime.

Also the addr should be initalized with NULL rather than 0.

> +struct test_case_t TC[3];
> +
>  int main(int ac, char **av)
>  {
>       int lc;                         /* loop counter */
> @@ -259,6 +247,35 @@ setup(void)
>               tst_brkm(TBROK, cleanup, "Failed to create shared memory "
>                        "resource 1 in setup()");
>       }
> +
> +     /* Probe an available linear address for attachment */
> +     base_addr = shmat(shm_id_1, NULL, 0);
> +     if (base_addr == (void *)-1)
> +             tst_brkm(TBROK|TERRNO, cleanup,
> +                             "Couldn't attach shared memory");
> +     if (shmdt((const void *)base_addr) == -1)
> +             tst_brkm(TBROK|TERRNO, cleanup,
> +                             "Couldn't detach shared memory");

Cast from void* to const void* is not needed here.

-- 
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
EMC VNX: the world's simplest storage, starting under $10K
The only unified storage solution that offers unified management 
Up to 160% more powerful than alternatives and 25% more efficient. 
Guaranteed. http://p.sf.net/sfu/emc-vnx-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to