public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/4] getcwd03.c: cleanup && convert to new API
Date: Tue, 17 Jan 2017 13:19:47 +0100	[thread overview]
Message-ID: <20170117121912.GE10880@rei> (raw)
In-Reply-To: <1483949756-8685-3-git-send-email-yangx.jy@cn.fujitsu.com>

Hi!
> +	char buf1[BUFSIZ], buf2[BUFSIZ];
> +	char link[BUFSIZ];
> +	char *res1;
> +	char *res2;
> +
> +	SAFE_CHDIR(dir1);
> +
> +	errno = 0;
> +	res1 = getcwd(buf1, sizeof(buf1));
> +	TEST_ERRNO = errno;
> +	if (res1 == NULL) {
> +		tst_res(TFAIL | TTERRNO, "getcwd() failed to "
> +			"get working directory of a directory");
> +		return;
>  	}
> -	cleanup();
>  
> -	tst_exit();
> -}
> +	SAFE_CHDIR("..");
> +	SAFE_CHDIR(dir2);
>  
> -void setup(void)
> -{
> -	/* FORK is set here because of the popen() call below */
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> +	errno = 0;
> +	res2 = getcwd(buf2, sizeof(buf2));
> +	TEST_ERRNO = errno;
> +	if (res2 == NULL) {
> +		tst_res(TFAIL | TTERRNO, "getcwd() failed to get "
> +			"working directory of a symbolic link");
> +		return;
> +	}
> +
> +	SAFE_CHDIR("..");
> +	SAFE_READLINK(dir2, link, sizeof(link));
> +
> +	if (strcmp(res1, res2)) {
> +		tst_res(TFAIL, "getcwd() got mismatched strings containing "
> +			"the pathname of the current working directory");
> +		return;
> +	}
>  
> -	TEST_PAUSE;
> +	if (strcmp(buf1, buf2)) {
> +		tst_res(TFAIL, "getcwd() got mismatched working directories");
> +		return;
> +	}
>  
> -	/* create a test directory and cd into it */
> -	tst_tmpdir();
> +	if (strcmp(link, SAFE_BASENAME(buf1))) {
> +		tst_res(TFAIL,
> +			"link information didn't match the working directory");
> +		return;
> +	}
> +
> +	tst_res(TPASS, "getcwd() succeeded");
>  }
>  
> -void cleanup(void)
> +static void setup(void)
>  {
> -	/* remove the test directory */
> -	tst_rmdir();
> +	SAFE_CHDIR("/tmp");

The test must use the test temporary directory to create files and/or
directories no exceptions. If you are afraid that the buffers for
strings will be too small why can't we just let the getcwd() allocate
the buffers dynamically?

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2017-01-17 12:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-09  8:15 [LTP] [PATCH 1/4] getcwd01.c: cleanup && convert to new API Xiao Yang
2017-01-09  8:15 ` [LTP] [PATCH 2/4] getcwd02.c: " Xiao Yang
2017-01-17 11:47   ` Cyril Hrubis
2017-01-09  8:15 ` [LTP] [PATCH 3/4] getcwd03.c: " Xiao Yang
2017-01-17 12:19   ` Cyril Hrubis [this message]
2017-01-09  8:15 ` [LTP] [PATCH 4/4] getcwd04.c: " Xiao Yang
2017-01-17 11:38 ` [LTP] [PATCH 1/4] getcwd01.c: " Cyril Hrubis
2017-01-17 11:43   ` Cyril Hrubis
2017-01-17 14:11 ` Cyril Hrubis
2017-01-18  6:03   ` [LTP] [PATCH v2 1/3] syscalls/getcwd02.c: " Xiao Yang
2017-01-18  6:03     ` [LTP] [PATCH v2 2/3] syscalls/getcwd03.c: " Xiao Yang
2017-01-18 14:24       ` Cyril Hrubis
2017-01-18  6:03     ` [LTP] [PATCH v2 3/3] syscalls/getcwd04.c: " Xiao Yang
2017-01-18 14:28       ` Cyril Hrubis
2017-01-18 13:32     ` [LTP] [PATCH v2 1/3] syscalls/getcwd02.c: " 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=20170117121912.GE10880@rei \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox