From: Dmitry V. Levin Date: Wed, 6 Jan 2016 16:01:46 +0000 (+0000) Subject: tests/file_handle.c: use libtests X-Git-Tag: v4.12~680 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c83746acf7fd592be84aa1c175068647b19eb57b;p=strace tests/file_handle.c: use libtests * tests/file_handle.c: Use SKIP_MAIN_UNDEFINED. (main): Use assert and perror_msg_and_skip. --- diff --git a/tests/file_handle.c b/tests/file_handle.c index f52b6200..dba48be9 100644 --- a/tests/file_handle.c +++ b/tests/file_handle.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Dmitry V. Levin + * Copyright (c) 2015-2016 Dmitry V. Levin * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,14 +26,15 @@ */ #include "tests.h" -#include -#include -#include #include -#include #ifdef MAX_HANDLE_SZ +# include +# include +# include +# include + int main(void) { @@ -46,26 +47,20 @@ main(void) handle->handle_bytes = 0; - if (name_to_handle_at(dirfd, ".", handle, &mount_id, flags | 1) != -1 - || EINVAL != errno) { - perror("name_to_handle_at"); - return 77; - } + assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags | 1) == -1); + if (EINVAL != errno) + perror_msg_and_skip("name_to_handle_at"); printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=0}, %p" - ", AT_SYMLINK_FOLLOW|0x1) = -1 EINVAL (Invalid argument)\n", - &mount_id); + ", AT_SYMLINK_FOLLOW|0x1) = -1 EINVAL (%m)\n", &mount_id); - if (name_to_handle_at(dirfd, ".", handle, &mount_id, flags) != -1 - || EOVERFLOW != errno) { - perror("name_to_handle_at"); - return 77; - } + assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags) == -1); + if (EOVERFLOW != errno) + perror_msg_and_skip("name_to_handle_at"); printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=0 => %u}" - ", %p, AT_SYMLINK_FOLLOW) = -1 EOVERFLOW" - " (Value too large for defined data type)\n", + ", %p, AT_SYMLINK_FOLLOW) = -1 EOVERFLOW (%m)\n", handle->handle_bytes, &mount_id); - assert(!name_to_handle_at(dirfd, ".", handle, &mount_id, flags)); + assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags) == 0); printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=%u" ", handle_type=%d, f_handle=0x", handle->handle_bytes, handle->handle_type); @@ -73,15 +68,24 @@ main(void) printf("%02x", handle->f_handle[i]); printf("}, [%d], AT_SYMLINK_FOLLOW) = 0\n", mount_id); - assert(open_by_handle_at(-1, handle, O_RDONLY | O_DIRECTORY)); printf("open_by_handle_at(-1, {handle_bytes=%u, handle_type=%d" ", f_handle=0x", handle->handle_bytes, handle->handle_type); for (i = 0; i < handle->handle_bytes; ++i) printf("%02x", handle->f_handle[i]); - printf("}, O_RDONLY|O_DIRECTORY) = -1 %s\n", - EPERM == errno ? "EPERM (Operation not permitted)" : - EINVAL == errno ? "EINVAL (Invalid argument)" : - "EBADF (Bad file descriptor)"); + printf("}, O_RDONLY|O_DIRECTORY) = -1 "); + assert(open_by_handle_at(-1, handle, O_RDONLY | O_DIRECTORY) == -1); + const char *errno_text; + switch (errno) { + case EPERM: + errno_text = "EPERM"; + break; + case EINVAL: + errno_text = "EINVAL"; + break; + default: + errno_text = "EBADF"; + } + printf("%s (%m)\n", errno_text); puts("+++ exited with 0 +++"); return 0; @@ -89,10 +93,6 @@ main(void) #else -int -main(void) -{ - return 77; -} +SKIP_MAIN_UNDEFINED("MAX_HANDLE_SZ") #endif