[PATCH 1/2] Use libsupport for tst-spawn.c
Florian Weimer
fweimer@redhat.com
Thu Sep 20 05:19:00 GMT 2018
* 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
More information about the Libc-alpha
mailing list