[LTP] hugetlb/hugeshmget: Add hugeshmget07 to test SHM_HUGETLB with /dev/zero read
Cyril Hrubis
chrubis@suse.cz
Mon Nov 2 17:15:31 CET 2026
Hi!
> >+ zero_fd = SAFE_OPEN("/dev/zero", O_RDONLY);
> >+
> >+ shmid = SAFE_SHMGET(IPC_PRIVATE, size, SHM_HUGETLB | SHM_R | SHM_W);
> >+
> >+ shmaddr = SAFE_SHMAT(shmid, 0, SHM_RND);
> >+ tst_res(TINFO, "shmaddr: %p", shmaddr);
> >+
> >+ for (i = 0; i < size; i += hpage_size) {
> >+ TST_EXP_VAL(read(zero_fd, shmaddr + i, hpage_size),
> >+ (ssize_t)hpage_size);
> >+ }
> >+
> >+ SAFE_CLOSE(zero_fd);
>
> File descriptors must be initialized to -1 and closed in cleanup() with an
> fd != -1 guard. If SAFE_SHMGET() or SAFE_SHMAT() aborts, zero_fd is not
> closed. Define static int zero_fd = -1 at file scope, open it in setup(),
> and close it in cleanup().
>
> >+ SAFE_SHMCTL(shmid, IPC_RMID, NULL);
> >+ shmid = -1;
>
> SAFE_SHMCTL() sets shmid to -1 when called with IPC_RMID. The subsequent
> shmid = -1 assignment is redundant.
These two are valid, the rest of the code looks good.
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list