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 v3 2/5] Add cachestat01 test
Date: Tue, 23 Jul 2024 12:40:03 +0200	[thread overview]
Message-ID: <Zp-Igy54VYXix3eR@yuki> (raw)
In-Reply-To: <20240722-cachestat-v3-2-a0386f7cdaaa@suse.com>

Hi!
Pushed with a two minor changes, thanks.

> +static void test_cached_pages(const unsigned int use_sync, const int num_pages)
> +{
> +	int fd;
> +
> +	tst_res(TINFO, "%s file synchronization", use_sync ? "Enable" : "Disable");
> +	tst_res(TINFO, "Number of pages: %d", num_pages);
> +
> +	memset(cs, 0, sizeof(struct cachestat));
> +
> +	fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, 0600);
> +
> +	for (int i = 0; i < num_pages; i++)
> +		SAFE_WRITE(0, fd, page_data, page_size);
> +
> +	if (use_sync)
> +		fsync(fd);
> +
> +	cs_range->off = 0;
> +	cs_range->len = page_size * num_pages;
> +

I've added memset(cs, 0xff, sizeof(*cs)) here to make sure that the
structure is initialized with bogus data before the syscall. With that
we will make sure that the nr_dirty have been written to (the tst_bufers
are initialized to zero to begin with).

> +	TST_EXP_PASS(cachestat(fd, cs_range, cs, 0));
> +	print_cachestat(cs);
> +
> +	TST_EXP_EQ_LI(cs->nr_cache + cs->nr_evicted, num_pages);
> +
> +	if (use_sync)
> +		TST_EXP_EQ_LI(cs->nr_dirty, 0);
> +
> +	SAFE_CLOSE(fd);
> +	SAFE_UNLINK(FILENAME);
> +}
> +
> +static void run(unsigned int use_sync)
> +{
> +	for (int i = 0; i < 15; i++)
> +		test_cached_pages(use_sync, 1 << i);
> +}
> +
> +static void setup(void)
> +{
> +	page_size = (int)sysconf(_SC_PAGESIZE);
> +
> +	page_data = SAFE_MALLOC(page_size);
> +	memset(page_data, 'a', page_size);
> +}
> +
> +static void cleanup(void)
> +{
> +	if (page_data)
> +		free(page_data);

free(NULL) is no-op so I've removed the if ().

> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.tcnt = 2,
> +	.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)},
> +		{}
> +	},
> +};
> 
> -- 
> 2.43.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

  reply	other threads:[~2024-07-23 10:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22 14:28 [LTP] [PATCH v3 0/5] cachestat testing suite Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 1/5] Add cachestat fallback definitions Andrea Cervesato
2024-07-22 14:28 ` [LTP] [PATCH v3 2/5] Add cachestat01 test Andrea Cervesato
2024-07-23 10:40   ` Cyril Hrubis [this message]
2024-07-22 14:28 ` [LTP] [PATCH v3 3/5] Add cachestat02 test Andrea Cervesato
2024-07-23 10:43   ` Cyril Hrubis
2024-07-22 14:28 ` [LTP] [PATCH v3 4/5] Add cachestat03 test Andrea Cervesato
2024-07-24  9:20   ` Cyril Hrubis
2024-07-22 14:28 ` [LTP] [PATCH v3 5/5] Add cachestat04 test Andrea Cervesato
2024-07-24  9:55   ` 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=Zp-Igy54VYXix3eR@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