public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: chrubis@suse.cz
To: DAN LI <li.dan@cn.fujitsu.com>
Cc: LTP list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH] mmap/mmap14.c: new case to test MAP_LOCKED of mmap
Date: Thu, 27 Jun 2013 14:56:52 +0200	[thread overview]
Message-ID: <20130627125455.GE5384@rei> (raw)
In-Reply-To: <51CBAFB7.8000508@cn.fujitsu.com>

Hi!
> +int main(int argc, char *argv[])
> +{
> +	int lc;
> +	int ret;
> +	int lock_sz;
> +	char *msg;
> +	char line[LINELEN];
> +	FILE *fstatus = NULL;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +
> +		tst_count = 0;
> +
> +		addr = mmap(NULL, MMAPSIZE, PROT_READ | PROT_WRITE,
> +			    MAP_FILE | MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS,
> +			    -1, 0);
> +
> +		if (addr == MAP_FAILED) {
> +			tst_resm(TFAIL | TERRNO, "mmap of %s failed", TEMPFILE);
> +			continue;
> +		}
> +
> +		if (STD_FUNCTIONAL_TEST) {
> +
> +			fstatus = fopen("/proc/self/status", "r");
> +			if (fstatus == NULL)
> +				tst_brkm(TFAIL | TERRNO, NULL, "Open dev "
> +							       "status failed");
> +
> +			while (fgets(line, LINELEN, fstatus) != NULL)
> +				if (strstr(line, "VmLck") != NULL)
> +					break;
> +
> +			ret = sscanf(line, "%*[^0-9]%d%*[^0-9]", &lock_sz);
> +			if (ret != 1)
> +				tst_brkm(TFAIL | TERRNO, NULL, "Get lock "
> +							       "size failed");
> +
> +			if (lock_sz == MMAPSIZE / 1024)
> +				tst_resm(TPASS, "Functionality of mmap() "
> +						"successful");

I know that it's unlikely that process would have some pages locked
prior the mmap above, but getting the number of locked pages before the
mmap after it and using the difference in the comparsion would be more
robust. And the additional work needed for this is minimal, just move
the part of the code that reads VmLck value into a function and call it
before and after the mmap.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

      parent reply	other threads:[~2013-06-27 12:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27  3:21 [LTP] [PATCH] mmap/mmap14.c: new case to test MAP_LOCKED of mmap DAN LI
2013-06-27  7:38 ` Jan Stancek
2013-06-27 12:56 ` chrubis [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=20130627125455.GE5384@rei \
    --to=chrubis@suse.cz \
    --cc=li.dan@cn.fujitsu.com \
    --cc=ltp-list@lists.sourceforge.net \
    /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