public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests
Date: Mon, 8 Jul 2024 16:29:08 +0200	[thread overview]
Message-ID: <Zov3tFe64kj19dAZ@yuki> (raw)
In-Reply-To: <20240516104227.25381-3-andrea.cervesato@suse.de>

Hi!
> diff --git a/testcases/kernel/syscalls/cachestat/cachestat01.c b/testcases/kernel/syscalls/cachestat/cachestat01.c
> new file mode 100644
> index 000000000..7362a9dcf
> --- /dev/null
> +++ b/testcases/kernel/syscalls/cachestat/cachestat01.c
> @@ -0,0 +1,102 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
> + */
> +
> +/*\
> + * [Description]
> + *
> + * This test verifies that cachestat() syscall is properly counting cached pages
> + * written inside a file. If storage device synchronization is requested, test
> + * will check if the number of dirty pages is zero.
> + *
> + * [Algorithm]
> + *
> + * * create a file with specific amount of pages
> + * ** synchronize storage device, if needed
> + * * monitor file with cachestat()
> + * * check if the right amount of pages have been moved into cache
> + * ** if storage device synchronization is requested, check that dirty pages is
> + *    zero
> + */
> +
> +#include "cachestat.h"
> +
> +#define MNTPOINT "mntpoint"
> +#define FILENAME MNTPOINT "/myfile.bin"
> +#define NUMPAGES 32
> +
> +static char *data;
> +static int file_size;
> +static struct cachestat *cs;
> +static struct cachestat_range *cs_range;
> +static char *run_fsync;
> +
> +static void run(void)
> +{
> +	int fd;
> +
> +	memset(cs, 0, sizeof(struct cachestat));
> +
> +	fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, 0600);
> +	SAFE_WRITE(0, fd, data, file_size);
> +
> +	if (run_fsync)
> +		fsync(fd);
> +
> +	TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
> +	print_cachestat(cs);
> +
> +	TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, NUMPAGES);
> +
> +	if (run_fsync)
> +		TST_EXP_EQ_LI(cs->nr_dirty, 0);
> +
> +	SAFE_CLOSE(fd);
> +	SAFE_UNLINK(FILENAME);
> +}
> +
> +static void setup(void)
> +{
> +	int page_size;
> +
> +	page_size = (int)sysconf(_SC_PAGESIZE);
> +	file_size = page_size * NUMPAGES;
> +
> +	data = SAFE_MALLOC(file_size);
> +	memset(data, 'a', file_size);

I would just allocate a single page and run the write in a loop in the
test. That way we can make the number of pages command line parameter
and try with a bigger mapping as well.

> +	cs_range->off = 0;
> +	cs_range->len = file_size;
> +}
> +
> +static void cleanup(void)
> +{
> +	if (data)
> +		free(data);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_tmpdir = 1,
> +	.min_kver = "6.5",
> +	.mount_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.skip_filesystems = (const char *const []) {
> +		"fuse",
> +		"tmpfs",
> +		NULL
> +	},
> +	.bufs = (struct tst_buffers []) {
> +		{&cs, .size = sizeof(struct cachestat)},
> +		{&cs_range, .size = sizeof(struct cachestat_range)},
> +		{}
> +	},
> +	.options = (struct tst_option[]) {
> +		{"s", &run_fsync, "Synchronize file with storage device"},
> +		{},
> +	},

Can we, rather than adding a command line option, change the test so
that it has two subtests with .tcnt = 2?

I think that it's better that the test runs all testcases by default and
the command like parameters should be used to change parameters of the
test (such as number of pages) rather than to enable/disable tests.

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2024-07-08 14:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-16 10:42 [LTP] [PATCH v1 0/3] cachestat testing suite Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 1/3] Add cachestat fallback definitions Andrea Cervesato
2024-05-16 10:42 ` [LTP] [PATCH v1 2/3] Add cachestat01 and cachestat01A tests Andrea Cervesato
2024-07-08 14:29   ` Cyril Hrubis [this message]
2024-05-16 10:42 ` [LTP] [PATCH v1 3/3] Add cachestat02 test Andrea Cervesato
2024-07-08 14:38 ` [LTP] [PATCH v1 0/3] cachestat testing suite Cyril Hrubis
2024-07-08 14:41   ` Cyril Hrubis
2024-07-15 10:58   ` Andrea Cervesato via ltp
2024-07-15 11:03   ` Andrea Cervesato via ltp
2024-07-15 12:08     ` Cyril Hrubis
2024-07-15 12:14       ` Andrea Cervesato via ltp
2024-07-15 12:30         ` Cyril Hrubis
2024-07-15 16:00           ` Cyril Hrubis
2024-07-16  8:16             ` 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=Zov3tFe64kj19dAZ@yuki \
    --to=chrubis@suse.cz \
    --cc=andrea.cervesato@suse.de \
    --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