($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Yang Xu via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2] gethostname: Add negative test for gethostname
Date: Fri, 19 Apr 2024 04:25:49 -0400	[thread overview]
Message-ID: <20240419082549.25476-1-xuyang2018.jy@fujitsu.com> (raw)

Add negative cases for gethostname(), when errno is ENAMETOOLONG

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 runtest/syscalls                              |  1 +
 .../kernel/syscalls/gethostname/.gitignore    |  1 +
 .../syscalls/gethostname/gethostname02.c      | 31 +++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100644 testcases/kernel/syscalls/gethostname/gethostname02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index de4f5a633..cc1e39c05 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -477,6 +477,7 @@ gethostbyname_r01 gethostbyname_r01
 gethostid01 gethostid01
 
 gethostname01 gethostname01
+gethostname02 gethostname02
 
 getitimer01 getitimer01
 getitimer02 getitimer02
diff --git a/testcases/kernel/syscalls/gethostname/.gitignore b/testcases/kernel/syscalls/gethostname/.gitignore
index d09d5d288..d6e4cffcb 100644
--- a/testcases/kernel/syscalls/gethostname/.gitignore
+++ b/testcases/kernel/syscalls/gethostname/.gitignore
@@ -1 +1,2 @@
 /gethostname01
+/gethostname02
diff --git a/testcases/kernel/syscalls/gethostname/gethostname02.c b/testcases/kernel/syscalls/gethostname/gethostname02.c
new file mode 100644
index 000000000..250e5f2fd
--- /dev/null
+++ b/testcases/kernel/syscalls/gethostname/gethostname02.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that gethostname(2) fails with
+ *
+ * - ENAMETOOLONG when len is smaller than the actual size
+ */
+
+#include "tst_test.h"
+
+static void verify_gethostname(void)
+{
+	char hostname[HOST_NAME_MAX];
+	int real_length;
+
+	SAFE_GETHOSTNAME(hostname, sizeof(hostname));
+	real_length = strlen(hostname);
+
+	TST_EXP_FAIL(gethostname(hostname, real_length - 1), ENAMETOOLONG,
+		"len is smaller than the actual size");
+}
+
+static struct tst_test test = {
+	.test_all = verify_gethostname,
+};
-- 
2.39.3


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2024-04-19  9:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-19  8:25 Yang Xu via ltp [this message]
2024-04-19 14:04 ` [LTP] [PATCH v2] gethostname: Add negative test for gethostname Avinesh Kumar
2024-04-22  7:37   ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240419082549.25476-1-xuyang2018.jy@fujitsu.com \
    --to=ltp@lists.linux.it \
    --cc=xuyang2018.jy@fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).