This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 1/2] Use libsupport for tst-spawn.c
- From: Florian Weimer <fweimer at redhat dot com>
- To: adhemerval dot zanella at linaro dot org
- Cc: libc-alpha at sourceware dot org
- Date: Thu, 20 Sep 2018 07:18:59 +0200
- Subject: Re: [PATCH 1/2] Use libsupport for tst-spawn.c
- References: <20180919224624.3920-1-adhemerval.zanella@linaro.org>
* adhemerval zanella:
> /* First the easy part: read from the file descriptor which is
> supposed to be open. */
> + TEST_VERIFY_EXIT (lseek (fd2, 0, SEEK_CUR) == strlen (fd2string));
> /* The duped descriptor must have the same position. */
> + TEST_VERIFY_EXIT (lseek (fd4, 0, SEEK_CUR) == strlen (fd2string));
> + TEST_VERIFY_EXIT (lseek (fd2, 0, SEEK_SET) == 0);
> + TEST_VERIFY_EXIT (lseek (fd4, 0, SEEK_CUR) == 0);
> + TEST_VERIFY_EXIT (read (fd2, buf, sizeof buf) == strlen (fd2string));
These can use TEST_COMPARE and xlseek.
> + TEST_VERIFY_EXIT (memcmp (fd2string, buf, strlen (fd2string)) == 0);
Use TEST_COMPARE_BLOB?
> /* Now read from the third file. */
> + TEST_VERIFY_EXIT (read (fd3, buf, sizeof buf) == strlen (fd3string));
> + TEST_VERIFY_EXIT (memcmp (fd3string, buf, strlen (fd3string)) == 0);
> /* Try to write to the file. This should not be allowed. */
> + TEST_VERIFY_EXIT (write (fd3, "boo!", 4) == -1 && errno == EBADF);
>
> /* Now try to read the first file. First make sure it is not opened. */
> + TEST_VERIFY_EXIT (lseek (fd1, 0, SEEK_CUR) == (off_t) -1
> + && errno == EBADF);
Use too TEST_COMPARE calls?
>
> /* Now open the file and read it. */
> + TEST_VERIFY_EXIT ((fd1 = open (name, O_RDONLY)) != -1);
You can use xopen.
> + TEST_VERIFY_EXIT (read (fd1, buf, sizeof buf) == strlen (fd1string));
> + TEST_VERIFY_EXIT (memcmp (fd1string, buf, strlen (fd1string)) == 0);
Likewise TEST_COMPARE.
More instances below, sorry.
Thanks,
Florian