From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/chdir04: Convert to the new API
Date: Wed, 3 Mar 2021 16:26:37 +0100 [thread overview]
Message-ID: <YD+qrfp1cuX96Ftd@yuki.lan> (raw)
In-Reply-To: <20210303022221.1044234-1-ruansy.fnst@fujitsu.com>
Hi!
> +static struct test_case_t {
> + char *dir_name;
> + int expected_error;
> +} testcase_list[] = {
> + {bad_dir, ENAMETOOLONG},
> + {noexist_dir, ENOENT},
> + {(void *)-1, EFAULT}
> +};
This is way to verbose, we can just name these:
struct test_case_t -> struct tcase
testcase_list -> tcases
dir_name -> dir
expected_error -> exp_errno
without loosing any information.
> -void setup(void)
> +static void setup(void)
> {
> -
> - tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> - TEST_PAUSE;
> -
> - tst_tmpdir();
> -
> #ifdef UCLINUX
> bad_addr = mmap(0, 1, PROT_NONE,
> MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> if (bad_addr == MAP_FAILED)
> - tst_brkm(TBROK | TERRNO, cleanup, "mmap() failed");
> - TC[2].dname = bad_addr;
> + tst_brk(TBROK | TERRNO, "mmap() failed");
> + testcase_list[2].dir_name = bad_addr;
> +#endif
> +}
> +
> +static void cleanup(void)
> +{
> +#ifdef UCLINUX
> + munmap(bad_addr, 1);
> #endif
> }
We do not support uClinux anymore, please remove that part as well.
> -void cleanup(void)
> +static void verify_chdir(unsigned int i)
> {
> - tst_rmdir();
> + TEST(chdir(testcase_list[i].dir_name));
> +
> + if (TST_RET != -1) {
> + tst_res(TFAIL, "call succeeded unexpectedly");
> + return;
> + }
>
> + if (TST_ERR == testcase_list[i].expected_error)
> + tst_res(TPASS | TTERRNO, "failed as expected");
> + else {
> + tst_res(TFAIL | TTERRNO,
> + "didn't fail as expected (expected %d)",
> + testcase_list[i].expected_error);
> + }
We do have TST_EXP_FAIL() macro that should replace all of this.
> }
> +
> +static struct tst_test test = {
> + .needs_tmpdir = 1,
> + .test = verify_chdir,
> + .tcnt = ARRAY_SIZE(testcase_list),
> + .setup = setup,
> + .cleanup = cleanup,
> +};
> --
> 2.30.1
>
>
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
prev parent reply other threads:[~2021-03-03 15:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-03 2:22 [LTP] [PATCH] syscalls/chdir04: Convert to the new API Shiyang Ruan
2021-03-03 15:26 ` Cyril Hrubis [this message]
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=YD+qrfp1cuX96Ftd@yuki.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 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.