public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/3] llistxattr/llistxattr03.c: add new testcase
Date: Wed, 10 Feb 2016 15:12:19 +0100	[thread overview]
Message-ID: <20160210141219.GA12894@rei.lan> (raw)
In-Reply-To: <1454058489-25625-3-git-send-email-yangx.jy@cn.fujitsu.com>

Hi!
> diff --git a/testcases/kernel/syscalls/llistxattr/llistxattr03.c b/testcases/kernel/syscalls/llistxattr/llistxattr03.c
> new file mode 100644
> index 0000000..dd5ab52
> --- /dev/null
> +++ b/testcases/kernel/syscalls/llistxattr/llistxattr03.c
> @@ -0,0 +1,133 @@
> +/*
> +* Copyright (c) 2016 Fujitsu Ltd.
> +* Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
> +*
> +* This program is free software; you can redistribute it and/or modify it
> +* under the terms of version 2 of the GNU General Public License as
> +* published by the Free Software Foundation.
> +*
> +* This program is distributed in the hope that it would be useful, but
> +* WITHOUT ANY WARRANTY; without even the implied warranty of
> +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> +*
> +* You should have received a copy of the GNU General Public License
> +* alone with this program.
> +*/
> +
> +/*
> +* Test Name: llistxattr03
> +*
> +* Description:
> +* llistxattr(2) with an empty buffer of size zero can return
> +* the current size of the list of extended attribute names.
> +*/
> +
> +#include "config.h"
> +#include <errno.h>
> +#include <sys/types.h>
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#include <attr/xattr.h>
> +#endif
> +
> +#include "test.h"
> +#include "safe_macros.h"
> +#include "safe_file_ops.h"
> +
> +char *TCID = "llistxattr03";
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#define SECURITY_KEY	"security.symtest"
> +#define SECURITY_KEY_INIT	"security.selinux"
> +#define VALUE	"test"
> +#define VALUE_SIZE	4
> +#define KEY_SIZE	17
> +
> +static void verify_llistxattr(void);
> +static void setup(void);
> +static void cleanup(void);
> +
> +int TST_TOTAL = 1;
> +
> +int main(int ac, char **av)
> +{
> +	int lc;
> +
> +	tst_parse_opts(ac, av, NULL, NULL);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		tst_count = 0;
> +
> +		verify_llistxattr();
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void verify_llistxattr(void)
> +{
> +	int se = 1;
> +	int n;
> +
> +	/* check selinux initialized attr */
> +	n = lgetxattr("symlink", SECURITY_KEY_INIT, NULL, 0);
> +	if (n == -1) {
> +		if (errno == ENOATTR) {
> +			se = 0;
> +		} else {
> +			tst_brkm(TFAIL | TERRNO, cleanup,
> +				 "lgetxattr() failed");
> +		}
> +	}
> +
> +	TEST(llistxattr("symlink", NULL, 0));
> +	if (TEST_RETURN == -1) {
> +		tst_resm(TFAIL | TTERRNO, "llistxattr() failed");
> +		return;
> +	}
> +
> +	if (TEST_RETURN == KEY_SIZE*(1 + se))
> +		tst_resm(TPASS, "llistxattr() returned the size successfully");
> +	else
> +		tst_resm(TFAIL, "llistxattr() failed to return the size");

Hmm, why don't we just call llistxattr() with zero size and then check
that it succeds with allocated buffer of a size of the return value and
fails for a buffer that is one byte smaller?

There is no need for special cases like this.

> +}
> +
> +static void setup(void)
> +{
> +	int n;
> +
> +	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +	TEST_PAUSE;
> +
> +	tst_tmpdir();
> +
> +	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
> +
> +	SAFE_SYMLINK(cleanup, "testfile", "symlink");
> +
> +	n = lsetxattr("symlink", SECURITY_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);

Why the symlink here? I understand that in the first test you want to
make sure that the atrribute from symlink is read. (you should probably
add some attributes for the file there, and maybe try with broken
symlink as well)

But here you just check that it returns a size for a suitable buffer.

> +	if (n == -1) {
> +		if (errno == ENOTSUP) {
> +			tst_brkm(TCONF, cleanup, "no xattr support in fs or "
> +				 "mounted without user_xattr option");
> +		} else {
> +			tst_brkm(TFAIL | TERRNO, cleanup, "lsetxattr() failed");
> +		}
> +	}
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2016-02-10 14:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-29  9:08 [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: add new testcase Xiao Yang
2016-01-29  9:08 ` [LTP] [PATCH 2/3] llistxattr/llistxattr02.c: " Xiao Yang
2016-02-10 13:41   ` Cyril Hrubis
2016-01-29  9:08 ` [LTP] [PATCH 3/3] llistxattr/llistxattr03.c: " Xiao Yang
2016-02-10 14:12   ` Cyril Hrubis [this message]
2016-02-10 14:04 ` [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: " Cyril Hrubis
2016-02-18 10:02   ` Xiao Yang
2016-02-18 12:03     ` Cyril Hrubis
2016-02-19  4:55       ` [LTP] [PATCH v2 " Xiao Yang
2016-02-19  4:55         ` [LTP] [PATCH v2 2/3] llistxattr/llistxattr02.c: " Xiao Yang
2016-02-24 13:54           ` Cyril Hrubis
2016-02-19  4:55         ` [LTP] [PATCH v2 3/3] llistxattr/llistxattr03.c: " Xiao Yang
2016-02-24 14:28           ` Cyril Hrubis
2016-02-25  3:55             ` [LTP] [PATCH v3] " Xiao Yang
2016-02-25 11:21               ` Cyril Hrubis
2016-02-24 13:38         ` [LTP] [PATCH v2 1/3] llistxattr/llistxattr01.c: " Cyril Hrubis

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=20160210141219.GA12894@rei.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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