All of lore.kernel.org
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Yang Xu <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/2] Add error tests for pathconf() system call
Date: Tue, 28 Nov 2023 14:49:12 +0100	[thread overview]
Message-ID: <20231128134912.GB401671@pevik> (raw)
In-Reply-To: <20231102080535.63847-2-xuyang2018.jy@fujitsu.com>

Hi Xu,

> +/*\
> + * [Description]
> + *
> + * Verify that,
> + *
> + * - pathconf() fails with ENOTDIR if A component used as a directory
nit: s/if A/if a/

> + *   in path is not in fact a directory.
> + * - pathconf() fails with ENOENT if path is an empty string.
> + * - pathconf() fails with ENAMETOOLONG if path is too long.
> + * - pathconf() fails with EINVA if name is invalid.
> + * - pathconf() fails with EACCES if search permission is denied for
> + *   one of the directories in the path prefix of path.
> + * - pathconf() fails with ELOOP if too many symbolic links were
> + *   encountered while resolving path.
> + */
> +
> +#define FILEPATH "testfile/testfile_1"
> +#define TESTELOOP "test_eloop1"
> +
> +#include <stdlib.h>
> +#include <pwd.h>
> +#include "tst_test.h"
> +
> +static char *fpath;
> +static char *emptypath;
> +static char path[PATH_MAX + 2];
Maybe define some constant and use it also on other place?
e.g.:

#define PATH_LEN (PATH_MAX + 2)

> +static char *long_path = path;
> +static char *abs_path;
> +static char *testeloop;
> +static struct passwd *user;
> +
> +static struct tcase {
> +	char **path;
> +	int name;
> +	int exp_errno;
> +	char *desc;
> +} tcases[] = {
> +	{&fpath, 0, ENOTDIR, "path prefix is not a directory"},
> +	{&emptypath, 0, ENOENT, "path is an empty string"},
> +	{&long_path, 0, ENAMETOOLONG, "path is too long"},
> +	{&abs_path, -1, EINVAL, "name is invalid"},
> +	{&abs_path, 0, EACCES, "without full permissions of the path prefix"},
> +	{&testeloop, 0, ELOOP, "too many symbolic links"},
> +};
> +
> +static void verify_fpathconf(unsigned int i)
> +{
> +	struct tcase *tc = &tcases[i];
> +
> +	if (tc->exp_errno == EACCES)
> +		SAFE_SETEUID(user->pw_uid);
> +
> +	TST_EXP_FAIL(pathconf(*tc->path, tc->name), tc->exp_errno,
> +		     "pathconf() fail with %s", tc->desc);
> +
> +	if (tc->exp_errno == EACCES)
> +		SAFE_SETEUID(0);
> +}
> +
> +static void setup(void)
> +{
> +	user = SAFE_GETPWNAM("nobody");
> +
> +	SAFE_TOUCH("testfile", 0777, NULL);
> +
> +	char *tmpdir =  tst_get_tmpdir();
> +
> +	abs_path = tst_aprintf("%s/%s", tmpdir, FILEPATH);
> +
> +	SAFE_CHMOD(tmpdir, 0);
> +	free(tmpdir);
> +
> +	memset(path, 'a', PATH_MAX + 2);
> +
> +	SAFE_SYMLINK("test_eloop1", "test_eloop2");
> +	SAFE_SYMLINK("test_eloop2", "test_eloop1");
> +}
> +
> +static struct tst_test test = {
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = verify_fpathconf,
> +	.setup = setup,
> +	.needs_tmpdir = 1,
> +	.bufs = (struct tst_buffers []) {
> +		{&fpath, .str = FILEPATH},
> +		{&emptypath, .str = ""},
> +		{&testeloop, .str = TESTELOOP},
> +		{},
> +	},
> +	.needs_root = 1,
> +};

The rest LGTM.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

  parent reply	other threads:[~2023-11-28 13:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-02  8:05 [LTP] [PATCH 1/2] pathconf01: Convert to new API Yang Xu
2023-11-02  8:05 ` [LTP] [PATCH 2/2] Add error tests for pathconf() system call Yang Xu
2023-11-28  6:03   ` Xiao Yang
2023-11-28 13:49   ` Petr Vorel [this message]
2023-11-28  5:21 ` [LTP] [PATCH 1/2] pathconf01: Convert to new API Xiao Yang
2023-11-28  6:32   ` Xiao Yang
2023-11-29  5:42     ` Yang Xu (Fujitsu)
2023-11-28 13:43   ` Petr Vorel
2023-11-29  5:57     ` Yang Xu (Fujitsu)
2023-11-29  5:36   ` Yang Xu (Fujitsu)

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=20231128134912.GB401671@pevik \
    --to=pvorel@suse.cz \
    --cc=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.