Skip to contentSkip to conversation

getcwd01.c: cleanup && convert to new API

PATCH Superseded Xiao Yang 2 participants 15 messages Jan 9, 2017 – Jan 18, 2017

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/4 getcwd01.c: cleanup && convert to new API

add one test for ERANGE

---
 testcases/kernel/syscalls/getcwd/getcwd01.c | 181 +++++++++-------------------
 1 file changed, 59 insertions(+), 122 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd01.c +59 -122
index 0d0ecdb..701823b 100644
@@ -1,152 +1,89 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
  */
 
 /*
- * NAME
- *	getcwd01
- *
  * DESCRIPTION
- *	Testcase to test that getcwd(2) sets errno correctly.
- *
- * ALGORITHM
- *	Test 1: Call getcwd(2) with a buf pointing outside the address space of
- *		 process, and a valid size, and expect EFAULT to be
- *		 set in errno.
- *	Test 2: Call getcwd(2) with buf = NULL, size = -1, and expect ENOMEM
- *		 to be set in errno.
- *	Test 3: Call getcwd(2) with a valid buf, and size = 0, and expect
- *		 EINVAL to be set in errno.
- *	Test 4: Call getcwd(2) on the root directory, and set size to 1, expect
- *		 ERANGE to be set in errno.
+ * Testcase to test that getcwd(2) sets errno correctly.
+ * 1) getcwd(2) fails if buf points to a bad address.
+ * 2) getcwd(2) fails if the size is invalid.
+ * 3) getcwd(2) fails if the size is set to 0.
+ * 4) getcwd(2) fails if the size is set to 1.
+ * 5) getcwd(2) fails if buf points to NULL and the size is set to 1.
  *
- * USAGE:  <for command-line>
- *  getcwd01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * Expected Result:
+ * 1) getcwd(2) should return NULL and set errno to EFAULT.
+ * 2) getcwd(2) should return NULL and set errno to ENOMEM.
+ * 3) getcwd(2) should return NULL and set errno to EINVAL.
+ * 4) getcwd(2) should return NULL and set errno to ERANGE.
+ * 5) getcwd(2) should return NULL and set errno to ERANGE.
  *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
  */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "test.h"
 
-char *TCID = "getcwd01";
-char buf[100];
+#include <errno.h>
+#include <unistd.h>
+#include "tst_test.h"
 
-void cleanup(void);
-void setup(void);
-void setup_test4(void);
+static char buffer[5];
 
-struct test_case_t {
-	char *desc;
-	void (*setupfunc) ();
+static struct t_case {
 	char *buf;
 	int size;
-	int exp_errno;
-	char *exp_retval;
-} testcases[] = {
+	int exp_err;
+} tcases[] = {
 #ifndef UCLINUX
 	/* Skip since uClinux does not implement memory protection */
-	{
-	"Test for EFAULT", NULL, (void *)-1, BUFSIZ, EFAULT, NULL},
+	{(void *)-1, sizeof(buffer), EFAULT},
 #endif
-	{
-	"Test for ENOMEM", NULL, NULL, -1, ENOMEM, NULL}, {
-	"Test for EINVAL", NULL, buf, 0, EINVAL, NULL}, {
-	"Test for ERANGE", (void *)setup_test4, buf, 1, ERANGE, NULL}
+	{NULL, -1, ENOMEM},
+	{buffer, 0, EINVAL},
+	{buffer, 1, ERANGE},
+	{NULL, 1, ERANGE}
 };
 
-int TST_TOTAL = ARRAY_SIZE(testcases);
-
-int main(int ac, char **av)
+static void verify_getcwd(unsigned int n)
 {
-	int i;
-	int lc;
-	char *test_erg;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-	setup();
-
-	/*
-	 * The following loop checks looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-			tst_resm(TINFO, "%s", testcases[i].desc);
-
-			if (testcases[i].setupfunc != NULL) {
-				testcases[i].setupfunc();
-			}
-
-			errno = 0;
-			test_erg = getcwd(testcases[i].buf, testcases[i].size);
-			TEST_ERRNO = errno;
-
-			if (test_erg != testcases[i].exp_retval) {
-				tst_resm(TFAIL, "getcwd(2) failed to return"
-					 "expected value, expected: %p, "
-					 "got: %p", testcases[i].exp_retval,
-					 test_erg);
-				continue;
-			}
-			if (TEST_ERRNO != testcases[i].exp_errno) {
-				tst_resm(TFAIL, "getcwd returned unexpected "
-					 "errno, expected: %d, got: %d",
-					 testcases[i].exp_errno, TEST_ERRNO);
-				continue;
-			}
-			tst_resm(TPASS, "Test case %d PASSED", i + 1);
-		}
+	struct t_case *tc = &tcases[n];
+	char *res;
+
+	errno = 0;
+	res = getcwd(tc->buf, tc->size);
+	TEST_ERRNO = errno;
+	if (res != NULL) {
+		tst_res(TFAIL, "getcwd() succeeded unexpectedly");
+		return;
 	}
-	cleanup();
 
-	tst_exit();
-}
+	if (TEST_ERRNO != tc->exp_err) {
+		tst_res(TFAIL | TTERRNO, "getcwd() failed unexpectedly, expected %s",
+			tst_strerrno(tc->exp_err));
+		return;
+	}
 
-void setup_test4(void)
-{
-	chdir("/");
+	tst_res(TPASS | TTERRNO, "getcwd() failed as expected");
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* create a test directory and cd into it */
-	tst_tmpdir();
+	SAFE_CHDIR("/tmp");
 }
 
-void cleanup(void)
-{
-	/* remove the test directory */
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tid = "getcwd01",
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_getcwd
+};
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/4 getcwd02.c: cleanup && convert to new API

remove some duplicated tests

---
 testcases/kernel/syscalls/getcwd/getcwd02.c | 318 ++++++----------------------
 1 file changed, 59 insertions(+), 259 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd02.c +59 -259
index 030474c..c0f4c6a 100644
@@ -1,286 +1,86 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
  */
 
 /*
- * NAME
- *	getcwd02
- *
  * DESCRIPTION
- *	Testcase to check the basic functionality of the getcwd(2) system call.
- *
- * ALGORITHM
- *	Get the path name of the current working directory from the current
- *	shell through a pipe, and compare it with what is returned by
- *	getcwd(2) system call.
- *
- *  Blocks 1-4 are with char[], #4 is special case where address is -1
- *
- *	Block 1: Call getcwd(2) with valid cwd[]:
- *              Should work fine
- *	Block 2: Call getcwd(2) with valid cwd[], size = 0:
- *              Should return NULL, errno = EINVAL
- *	Block 3: Call getcwd(2) with valid cwd[], size <= strlen(path):
- *              i.e. size = 1, Should return NULL, errno = ERANGE
- *      Block 4: Call getcwd(2) with cwd address = -1, size > strlen(path):
- *              Should return NULL, errno = EFAULT
- *
- *  Blocks 5-7 are with char*
- *
- *	Block 5: Call getcwd(2) with *buffer = NULL, size = 0:
- * 		Should allocate buffer, and work fine
- *	Block 6: Call getcwd(2) with *buffer = NULL, size <= strlen(path):
- * 		i.e. size = 1, Should return NULL, errno = ERANGE
- *      Block 7: Call getcwd(2) with *buffer = NULL, size > strlen(path):
- *              Should work fine and allocate buffer
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *      02/2002 Added more testcases, cleaned up by wjh
- *
- * RESTRICTIONS
- *	NONE
+ * Testcase to check the basic functionality of the getcwd(2) system call.
+ * 1) getcwd(2) works fine if buf and size are valid.
+ * 2) getcwd(2) works fine if buf points to NULL and size is set to 0.
+ * 3) getcwd(2) works fine if buf points to NULL and size is greater than strlen(path).
  */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "test.h"
-#define FAILED 1
-
-char *pwd = "/bin/pwd";
-int flag;
-char *TCID = "getcwd02";
-int TST_TOTAL = 7;
-
-void cleanup(void);
-void setup(void);
-void do_block1(void);
-void do_block2(void);
-void do_block3(void);
-void do_block4(void);
-void do_block5(void);
-void do_block6(void);
-void do_block7(void);
-
-char pwd_buf[BUFSIZ];		//holds results of pwd pipe
-char cwd[BUFSIZ];		//used as our valid buffer
-char *buffer = NULL;		//catches the return value from getcwd when passing NULL
-char *cwd_ptr = NULL;		//catches the return value from getcwd() when passing cwd[]
-
-int main(int ac, char **av)
-{
-	FILE *fin;
-	char *cp;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-	setup();
-
-	/*
-	 * The following loop checks looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if ((fin = popen(pwd, "r")) == NULL) {
-			tst_resm(TINFO, "%s: can't run %s", TCID, pwd);
-			tst_brkm(TBROK, cleanup, "%s FAILED", TCID);
-		}
-		while (fgets(pwd_buf, sizeof(pwd_buf), fin) != NULL) {
-			if ((cp = strchr(pwd_buf, '\n')) == NULL) {
-				tst_brkm(TBROK, cleanup, "pwd output too long");
-			}
-			*cp = 0;
-		}
-		pclose(fin);
 
-		do_block1();
-		do_block2();
-		do_block3();
-		do_block4();
-		do_block5();
-		do_block6();
-		do_block7();
-	}
-	cleanup();
-	tst_exit();
-}
-
-void do_block1(void)		//valid cwd[]: -> Should work fine
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 1");
-
-	if ((cwd_ptr = getcwd(cwd, sizeof(cwd))) == NULL) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-		flag = FAILED;
-	}
-	if ((flag != FAILED) && (strcmp(pwd_buf, cwd) != 0)) {
-		tst_resm(TFAIL, "getcwd() returned unexpected working "
-			 "directory: expected: %s, got: %s\n", pwd_buf, cwd);
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 1");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 1 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 1 PASSED");
-	}
-}
-
-void do_block2(void)		//valid cwd[], size = 0: -> Should return NULL, errno = EINVAL
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 2");
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tst_test.h"
 
-	if (((cwd_ptr = getcwd(cwd, 0)) == NULL)
-	    && (errno != EINVAL)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted EINVAL)");
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 2");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 2 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 2 PASSED");
-	}
-}
+static char exp_buf[5] = "/tmp";
+static char buffer[5];
 
-void do_block3(void)		//valid cwd[], size = 1 -> Should return NULL, errno = ERANGE
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 3");
+static struct t_case {
+	char *buf;
+	int size;
+} tcases[] = {
+	{buffer, sizeof(buffer)},
+	{NULL, 0},
+	{NULL, sizeof(buffer)}
+};
 
-	if (((cwd_ptr = getcwd(cwd, 1)) != NULL)
-	    || (errno != ERANGE)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted ERANGE)");
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 3");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 3 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 3 PASSED");
-	}
-}
-
-void do_block4(void)		//invalid cwd[] = -1, size = BUFSIZ: -> return NULL, errno = FAULT
+static void verify_getcwd(unsigned int n)
 {
-/* Skip since uClinux does not implement memory protection */
-#ifndef UCLINUX
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 4");
+	struct t_case *tc = &tcases[n];
+	char *res;
 
-	if (((cwd_ptr = getcwd((char *)-1, sizeof(cwd))) != NULL)
-	    || (errno != EFAULT)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted EFAULT)");
-		flag = FAILED;
+	errno = 0;
+	res  = getcwd(tc->buf, tc->size);
+	TEST_ERRNO = errno;
+	if (res == NULL) {
+		tst_res(TFAIL | TTERRNO, "getcwd() failed");
+		return;
 	}
-	tst_resm(TINFO, "Exit Block 4");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 4 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 4 PASSED");
-	}
-#else
-	tst_resm(TINFO, "Skipping Block 4 on uClinux");
-#endif
-}
 
-void do_block5(void)		//buffer = NULL, and size = 0, should succeed
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 5");
-
-	if ((buffer = getcwd(NULL, 0)) == NULL) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-		flag = FAILED;
-	}
-	if ((flag != FAILED) && (strcmp(pwd_buf, buffer) != 0)) {
-		tst_resm(TFAIL, "getcwd() returned unexpected working "
-			 "directory: expected: %s, got: %s\n", pwd_buf, buffer);
-		flag = FAILED;
+	if (tc->buf != NULL && strcmp(exp_buf, tc->buf)) {
+		tst_res(TFAIL, "getcwd() returned unexpected directory: %s, "
+			"expected: %s", tc->buf, exp_buf);
+		goto end;
 	}
-	tst_resm(TINFO, "Exit Block 5");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 5 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 5 PASSED");
-	}
-	free(buffer);
-	buffer = NULL;
-}
-
-void do_block6(void)		//buffer = NULL, size = 1: -> return NULL, errno = ERANGE
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 6");
 
-	if (((buffer = getcwd(NULL, 1)) != NULL)
-	    || (errno != ERANGE)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted ERANGE)");
-		flag = FAILED;
+	if (strcmp(exp_buf, res)) {
+		tst_res(TFAIL, "getcwd() returned unexpected directory: %s, "
+			"expected: %s", res, exp_buf);
+		goto end;
 	}
-	tst_resm(TINFO, "Exit Block 6");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 6 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 6 PASSED");
-	}
-}
 
-void do_block7(void)		//buffer = NULL, size = BUFSIZ: -> work fine, allocate buffer
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 7");
+	tst_res(TPASS, "getcwd() returned expected directory: %s", res);
 
-	if ((buffer = getcwd(NULL, sizeof(cwd))) == NULL) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-		flag = FAILED;
-	}
-	if ((flag != FAILED) && (strcmp(pwd_buf, buffer) != 0)) {
-		tst_resm(TFAIL, "getcwd() returned unexpected working "
-			 "directory: expected: %s, got: %s\n", pwd_buf, buffer);
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 7");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 7 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 7 PASSED");
-	}
-	free(buffer);
-	buffer = NULL;
+end:
+	if (tc->buf == NULL)
+		free(res);
 }
 
-void setup(void)
+static void setup(void)
 {
-	/* FORK is set here because of the popen() call above */
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* create a test directory and cd into it */
-	tst_tmpdir();
+	SAFE_CHDIR("/tmp");
 }
 
-void cleanup(void)
-{
-	/* remove the test directory */
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tid = "getcwd02",
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_getcwd
+};
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/4 getcwd02.c: cleanup && convert to new API

Hi!
Hmm, this test has been testing the extension with NULL buffer pointer and allocations for ages, so it looks like it's widely implemented extension and we can safely use it.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

PATCH 3/4 getcwd03.c: cleanup && convert to new API

In reply to Xiao Yang

take use of some SAFE Marcos

---
 testcases/kernel/syscalls/getcwd/getcwd03.c | 291 +++++++++-------------------
 1 file changed, 87 insertions(+), 204 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd03.c +87 -204
index af74608..b34b6f9 100644
@@ -1,237 +1,120 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
  */
 
 /*
- * NAME
- *	getcwd03
- *
  * DESCRIPTION
- *	Testcase to check the basic functionality of the getcwd(2) system call
- *	for symbolically linked directories.
+ * Testcase to check the basic functionality of the getcwd(2)
+ * system call on a symbolic link.
  *
  * ALGORITHM
- *	This testcase checks for the functionality of the getcwd(2) system call
- *	on a symbolic link. First create a directory (dir1), and create a
- *	symbolic link (dir2) to it at the same directory level. Then, chdir()
- *	to dir1, and get the working directory (cwd1), and its pathname (pwd1).
- *	Then, chdir() to dir2, and get the working directory (cwd2), its
- *	pathname (pwd2), and its readlink info (link2).
- *	Testcase succeeds if:
- *	i.	pwd1 == pwd2
- *	ii.	cwd1 == cwd2
- *	iii.	link2 == basename(cwd1)
- *
- * USAGE:  <for command-line>
- *  getcwd03 [-c n] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
+ * 1) create a directory, and create a symbolic link to it at the
+ *    same directory level.
+ * 2) get the working directory of a directory, and its pathname.
+ * 3) get the working directory of a symbolic link, and its pathname,
+ *    and its readlink info.
+ * 4) compare the working directories, pathnames and link information.
  */
+
 #define _GNU_SOURCE 1
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
-#include <errno.h>
-#include "test.h"
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <stdlib.h>
-#define FAILED 1
-
-int flag;
-char *TCID = "getcwd03";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-void cleanup(void);
-void setup(void);
-char *getpwd(void);
+static char dir1[BUFSIZ], dir2[BUFSIZ];
 
-int main(int ac, char **av)
+static void verify_getcwd(void)
 {
-	char dir1[BUFSIZ], dir2[BUFSIZ];
-	char cwd1[BUFSIZ], cwd2[BUFSIZ];
-	char *pwd1, *pwd2;
-	char link2[BUFSIZ];
-	int n;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/*
-	 * The following loop checks looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		flag = 0;
-
-		/*
-		 * Create dir1, then chdir to dir1, and get the pwd,
-		 * and cwd informations
-		 */
-		sprintf(dir1, "getcwd1.%d", getpid());
-		if (mkdir(dir1, 00755) < 0) {
-			tst_brkm(TBROK, cleanup, "mkdir(2) failed");
-		}
-		if (chdir(dir1) != 0) {
-			tst_brkm(TBROK, cleanup, "chdir(2) failed");
-		}
-
-		pwd1 = getpwd();
-		if (getcwd(cwd1, sizeof cwd1) == NULL) {
-			tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-			flag = FAILED;
-		}
-		if ((flag != FAILED) && (strcmp(pwd1, cwd1) != 0)) {
-			tst_brkm(TFAIL, cleanup, "getcwd() returned unexpected "
-				 "working directory: expected: %s, got: %s\n",
-				 pwd1, cwd1);
-		}
-
-		tst_resm(TINFO, "getcwd(2) succeeded in returning correct path "
-			 "for dir1");
-
-		/*
-		 * Now create dir2, then chdir to dir2, and get the pwd,
-		 * cwd, and link informations
-		 */
-		chdir("..");
-		flag = 0;
-
-		sprintf(dir2, "getcwd2.%d", getpid());
-		if (symlink(dir1, dir2) < 0) {
-			tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d",
-				 errno);
-		}
-
-		if (chdir(dir2) != 0) {
-			tst_brkm(TBROK, cleanup, "chdir(2) failed: errno: %d",
-				 errno);
-		}
-
-		pwd2 = getpwd();
-		if (getcwd(cwd2, sizeof cwd2) == NULL) {
-			tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-			flag = FAILED;
-		}
-
-		chdir("..");
-		if ((flag != FAILED) &&
-		    ((n = readlink(dir2, link2, sizeof(link2))) < 0)) {
-			tst_brkm(TBROK, cleanup, "readlink(2) failed: errno:%d",
-				 errno);
-		}
-
-		/*
-		 * Finally compare the pwd, cwd, link informations:
-		 * The test should pass iff all the following are true:
-		 * a.   pwd1 == pwd2
-		 * b.   cwd1 == cwd2
-		 * c.   link2 == basename(cwd1)
-		 */
-		if (flag != FAILED) {
-			if (strcmp(pwd1, pwd2) != 0) {
-				tst_resm(TFAIL, "pwd1: %s, pwd2: %s",
-					 pwd1, pwd2);
-				flag = FAILED;
-			}
-			if (strcmp(cwd1, cwd2) != 0) {
-				tst_resm(TFAIL, "cwd1: %s, cwd2: %s",
-					 cwd1, cwd2);
-				flag = FAILED;
-			}
-			if (memcmp(link2, (char *)basename(cwd1), n) != 0) {
-				tst_resm(TFAIL, "link2: %s, cwd1: %s",
-					 link2, cwd1);
-				flag = FAILED;
-			}
-			if (flag != FAILED) {
-				tst_resm(TINFO, "getcwd(2) succeeded in "
-					 "returning correct path for symbolic "
-					 "link dir2 -> dir1");
-			}
-		}
-
-		if (flag == FAILED) {
-			tst_resm(TFAIL, "Test FAILED");
-		} else {
-			tst_resm(TPASS, "Test PASSED");
-		}
-
-		/* clean up things in case we are looping */
-		if (unlink(dir2) == -1) {
-			tst_brkm(TBROK, cleanup, "couldnt remove dir2");
-		}
-		if (rmdir(dir1) == -1) {
-			tst_brkm(TBROK, cleanup, "couldnt remove dir1");
-		}
+	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");
+	sprintf(dir1, "getcwd1.%d", getpid());
+	sprintf(dir2, "getcwd2.%d", getpid());
+	SAFE_MKDIR(dir1, 0755);
+	SAFE_SYMLINK(dir1, dir2);
 }
 
-char *getpwd(void)
+static void cleanup(void)
 {
-	FILE *fin;
-	char *pwd = "/bin/pwd";
-	char *cp;
-	char *buf;
-
-	buf = malloc(BUFSIZ);
-	if ((fin = popen(pwd, "r")) == NULL) {
-		tst_resm(TINFO, "%s: can't run %s", TCID, pwd);
-		tst_brkm(TBROK, cleanup, "%s FAILED", TCID);
-	}
-	while (fgets(buf, BUFSIZ, fin) != NULL) {
-		if ((cp = strchr(buf, '\n')) == NULL) {
-			tst_brkm(TBROK, cleanup, "pwd output too long");
-		}
-		*cp = 0;
-	}
-	pclose(fin);
-	return buf;
+	if (unlink(dir2) == -1)
+		tst_res(TWARN | TERRNO, "could not remove %s", dir2);
+
+	if (rmdir(dir1) == -1)
+		tst_res(TWARN | TERRNO, "could not remove %s", dir1);
 }
+
+static struct tst_test test = {
+	.tid = "getcwd03",
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_getcwd
+};
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 3/4 getcwd03.c: cleanup && convert to new API

Hi!

Quoted 57 lines
testcases/kernel/syscalls/getcwd/getcwd03.c +42 -10
+	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;
+	}

testcases/kernel/syscalls/getcwd/getcwd03.c line 99

Quoted 10 lines
testcases/kernel/syscalls/getcwd/getcwd03.c +4 -3
+
+	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?

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#5 lore raw

PATCH 4/4 getcwd04.c: cleanup && convert to new API

In reply to Xiao Yang
---
 testcases/kernel/syscalls/getcwd/getcwd04.c | 81 +++++++++++------------------
 1 file changed, 30 insertions(+), 51 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd04.c +30 -51
index 1a5461c..7e2ca23 100644
@@ -1,16 +1,16 @@
 /*
- *   Copyright (c) 2014 Fujitsu Ltd.
- *   Author: Xiaoguang Wang <[email protected]>
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <[email protected]>
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
 
 /*
@@ -30,7 +30,6 @@
  *
  * This test is to check whether this bug exists in the running kernel,
  * or whether this bug has been fixed.
- *
  */
 
 #include <stdio.h>
@@ -38,77 +37,54 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define TIMEOUT	5
 
-static void setup(void);
-static void cleanup(void);
 static void do_child(void);
 static void sigproc(int sig);
 static volatile sig_atomic_t end;
 static char init_cwd[PATH_MAX];
 
-char *TCID = "getcwd04";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_getcwd(void)
 {
 	int status;
 	char cur_cwd[PATH_MAX];
 	pid_t child;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	child = tst_fork();
-	if (child < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
-
+	child = SAFE_FORK();
 	if (child == 0)
 		do_child();
 
 	 while (1) {
-		SAFE_GETCWD(cleanup, cur_cwd, PATH_MAX);
+		SAFE_GETCWD(cur_cwd, PATH_MAX);
 		if (strncmp(init_cwd, cur_cwd, PATH_MAX)) {
-			tst_resm(TFAIL, "initial current work directory is "
+			tst_res(TFAIL, "initial current work directory is "
 				 "%s, now is %s. Bug is reproduced!",
 				 init_cwd, cur_cwd);
 			break;
 		}
 
 		if (end) {
-			tst_resm(TPASS, "Bug is not reproduced!");
+			tst_res(TPASS, "Bug is not reproduced!");
 			break;
 		}
 	}
 
-	SAFE_KILL(cleanup, child, SIGKILL);
-	SAFE_WAITPID(cleanup, child, &status, 0);
-
-	cleanup();
-	tst_exit();
+	SAFE_KILL(child, SIGKILL);
+	SAFE_WAITPID(child, &status, 0);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
 	if (tst_ncpus() == 1)
-		tst_brkm(TCONF, NULL, "This test needs two cpus at least");
-
-	tst_tmpdir();
+		tst_brk(TCONF, "This test needs two cpus@least");
 
-	if (signal(SIGALRM, sigproc) == SIG_ERR)
-		tst_brkm(TBROK | TERRNO, cleanup, "signal(SIGALRM) failed");
+	SAFE_SIGNAL(SIGALRM, sigproc);
 
 	alarm(TIMEOUT);
 
-	SAFE_GETCWD(cleanup, init_cwd, PATH_MAX);
+	SAFE_GETCWD(init_cwd, PATH_MAX);
 }
 
 static void sigproc(int sig)
@@ -121,16 +97,19 @@ static void do_child(void)
 	unsigned int i = 0;
 	char c_name[PATH_MAX] = "testfile", n_name[PATH_MAX];
 
-	SAFE_TOUCH(NULL, c_name, 0644, NULL);
+	SAFE_TOUCH(c_name, 0644, NULL);
 
 	while (1) {
 		snprintf(n_name, PATH_MAX, "testfile%u", i++);
-		SAFE_RENAME(NULL, c_name, n_name);
+		SAFE_RENAME(c_name, n_name);
 		strncpy(c_name, n_name, PATH_MAX);
 	}
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tid = "getcwd04",
+	.setup = setup,
+	.test_all = verify_getcwd,
+	.needs_tmpdir = 1,
+	.forks_child = 1
+};
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 1/4 getcwd01.c: cleanup && convert to new API

In reply to Xiao Yang

Hi!

Quoted 1 line

add one test for ERANGE

I'm not sure if the newly added check for ERANGE is good idea, since depending on ordering of the checks in kernel it may either reutrn ERANGE, if size is checked first, or EFAULT if the buffer pointer is checked first. It may start to fail for no good reason if the order of kernel chesk ends up reversed.

Otherwise it looks fine.

Signature · 2 lines
Cyril Hrubis
[email protected]
#7 lore raw

PATCH 1/4 getcwd01.c: cleanup && convert to new API

Hi!

Quoted 5 lines

I'm not sure if the newly added check for ERANGE is good idea, since depending on ordering of the checks in kernel it may either reutrn ERANGE, if size is checked first, or EFAULT if the buffer pointer is checked first. It may start to fail for no good reason if the order of kernel chesk ends up reversed.

And looks like glibc has non-standard extension to allocate the buffer if NULL pointer is passed. The we should ifdef the case with

#ifdef __GLIBC__

#endif

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#9 lore raw

PATCH v2 1/3 syscalls/getcwd02.c: cleanup && convert to new API

remove some duplicated tests

---
 testcases/kernel/syscalls/getcwd/getcwd02.c | 318 ++++++----------------------
 1 file changed, 59 insertions(+), 259 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd02.c +59 -259
index 030474c..7785bb6 100644
@@ -1,286 +1,86 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
  */
 
 /*
- * NAME
- *	getcwd02
- *
  * DESCRIPTION
- *	Testcase to check the basic functionality of the getcwd(2) system call.
- *
- * ALGORITHM
- *	Get the path name of the current working directory from the current
- *	shell through a pipe, and compare it with what is returned by
- *	getcwd(2) system call.
- *
- *  Blocks 1-4 are with char[], #4 is special case where address is -1
- *
- *	Block 1: Call getcwd(2) with valid cwd[]:
- *              Should work fine
- *	Block 2: Call getcwd(2) with valid cwd[], size = 0:
- *              Should return NULL, errno = EINVAL
- *	Block 3: Call getcwd(2) with valid cwd[], size <= strlen(path):
- *              i.e. size = 1, Should return NULL, errno = ERANGE
- *      Block 4: Call getcwd(2) with cwd address = -1, size > strlen(path):
- *              Should return NULL, errno = EFAULT
- *
- *  Blocks 5-7 are with char*
- *
- *	Block 5: Call getcwd(2) with *buffer = NULL, size = 0:
- * 		Should allocate buffer, and work fine
- *	Block 6: Call getcwd(2) with *buffer = NULL, size <= strlen(path):
- * 		i.e. size = 1, Should return NULL, errno = ERANGE
- *      Block 7: Call getcwd(2) with *buffer = NULL, size > strlen(path):
- *              Should work fine and allocate buffer
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *      02/2002 Added more testcases, cleaned up by wjh
- *
- * RESTRICTIONS
- *	NONE
+ * Testcase to check the basic functionality of the getcwd(2) system call.
+ * 1) getcwd(2) works fine if buf and size are valid.
+ * 2) getcwd(2) works fine if buf points to NULL and size is set to 0.
+ * 3) getcwd(2) works fine if buf points to NULL and size is greater than strlen(path).
  */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include "test.h"
-#define FAILED 1
-
-char *pwd = "/bin/pwd";
-int flag;
-char *TCID = "getcwd02";
-int TST_TOTAL = 7;
-
-void cleanup(void);
-void setup(void);
-void do_block1(void);
-void do_block2(void);
-void do_block3(void);
-void do_block4(void);
-void do_block5(void);
-void do_block6(void);
-void do_block7(void);
-
-char pwd_buf[BUFSIZ];		//holds results of pwd pipe
-char cwd[BUFSIZ];		//used as our valid buffer
-char *buffer = NULL;		//catches the return value from getcwd when passing NULL
-char *cwd_ptr = NULL;		//catches the return value from getcwd() when passing cwd[]
-
-int main(int ac, char **av)
-{
-	FILE *fin;
-	char *cp;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-	setup();
-
-	/*
-	 * The following loop checks looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if ((fin = popen(pwd, "r")) == NULL) {
-			tst_resm(TINFO, "%s: can't run %s", TCID, pwd);
-			tst_brkm(TBROK, cleanup, "%s FAILED", TCID);
-		}
-		while (fgets(pwd_buf, sizeof(pwd_buf), fin) != NULL) {
-			if ((cp = strchr(pwd_buf, '\n')) == NULL) {
-				tst_brkm(TBROK, cleanup, "pwd output too long");
-			}
-			*cp = 0;
-		}
-		pclose(fin);
 
-		do_block1();
-		do_block2();
-		do_block3();
-		do_block4();
-		do_block5();
-		do_block6();
-		do_block7();
-	}
-	cleanup();
-	tst_exit();
-}
-
-void do_block1(void)		//valid cwd[]: -> Should work fine
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 1");
-
-	if ((cwd_ptr = getcwd(cwd, sizeof(cwd))) == NULL) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-		flag = FAILED;
-	}
-	if ((flag != FAILED) && (strcmp(pwd_buf, cwd) != 0)) {
-		tst_resm(TFAIL, "getcwd() returned unexpected working "
-			 "directory: expected: %s, got: %s\n", pwd_buf, cwd);
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 1");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 1 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 1 PASSED");
-	}
-}
-
-void do_block2(void)		//valid cwd[], size = 0: -> Should return NULL, errno = EINVAL
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 2");
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tst_test.h"
 
-	if (((cwd_ptr = getcwd(cwd, 0)) == NULL)
-	    && (errno != EINVAL)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted EINVAL)");
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 2");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 2 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 2 PASSED");
-	}
-}
+static char exp_buf[5] = "/tmp";
+static char buffer[5];
 
-void do_block3(void)		//valid cwd[], size = 1 -> Should return NULL, errno = ERANGE
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 3");
+static struct t_case {
+	char *buf;
+	size_t size;
+} tcases[] = {
+	{buffer, sizeof(buffer)},
+	{NULL, 0},
+	{NULL, sizeof(buffer)}
+};
 
-	if (((cwd_ptr = getcwd(cwd, 1)) != NULL)
-	    || (errno != ERANGE)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted ERANGE)");
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 3");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 3 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 3 PASSED");
-	}
-}
-
-void do_block4(void)		//invalid cwd[] = -1, size = BUFSIZ: -> return NULL, errno = FAULT
+static void verify_getcwd(unsigned int n)
 {
-/* Skip since uClinux does not implement memory protection */
-#ifndef UCLINUX
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 4");
+	struct t_case *tc = &tcases[n];
+	char *res = NULL;
 
-	if (((cwd_ptr = getcwd((char *)-1, sizeof(cwd))) != NULL)
-	    || (errno != EFAULT)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted EFAULT)");
-		flag = FAILED;
+	errno = 0;
+	res  = getcwd(tc->buf, tc->size);
+	TEST_ERRNO = errno;
+	if (!res) {
+		tst_res(TFAIL | TTERRNO, "getcwd() failed");
+		goto end;
 	}
-	tst_resm(TINFO, "Exit Block 4");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 4 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 4 PASSED");
-	}
-#else
-	tst_resm(TINFO, "Skipping Block 4 on uClinux");
-#endif
-}
 
-void do_block5(void)		//buffer = NULL, and size = 0, should succeed
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 5");
-
-	if ((buffer = getcwd(NULL, 0)) == NULL) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-		flag = FAILED;
-	}
-	if ((flag != FAILED) && (strcmp(pwd_buf, buffer) != 0)) {
-		tst_resm(TFAIL, "getcwd() returned unexpected working "
-			 "directory: expected: %s, got: %s\n", pwd_buf, buffer);
-		flag = FAILED;
+	if (tc->buf != NULL && strcmp(exp_buf, tc->buf)) {
+		tst_res(TFAIL, "getcwd() returned unexpected directory: %s, "
+			"expected: %s", tc->buf, exp_buf);
+		goto end;
 	}
-	tst_resm(TINFO, "Exit Block 5");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 5 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 5 PASSED");
-	}
-	free(buffer);
-	buffer = NULL;
-}
-
-void do_block6(void)		//buffer = NULL, size = 1: -> return NULL, errno = ERANGE
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 6");
 
-	if (((buffer = getcwd(NULL, 1)) != NULL)
-	    || (errno != ERANGE)) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly (wanted ERANGE)");
-		flag = FAILED;
+	if (strcmp(exp_buf, res)) {
+		tst_res(TFAIL, "getcwd() returned unexpected directory: %s, "
+			"expected: %s", res, exp_buf);
+		goto end;
 	}
-	tst_resm(TINFO, "Exit Block 6");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 6 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 6 PASSED");
-	}
-}
 
-void do_block7(void)		//buffer = NULL, size = BUFSIZ: -> work fine, allocate buffer
-{
-	int flag = 0;
-	tst_resm(TINFO, "Enter Block 7");
+	tst_res(TPASS, "getcwd() returned expected directory: %s", res);
 
-	if ((buffer = getcwd(NULL, sizeof(cwd))) == NULL) {
-		tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-		flag = FAILED;
-	}
-	if ((flag != FAILED) && (strcmp(pwd_buf, buffer) != 0)) {
-		tst_resm(TFAIL, "getcwd() returned unexpected working "
-			 "directory: expected: %s, got: %s\n", pwd_buf, buffer);
-		flag = FAILED;
-	}
-	tst_resm(TINFO, "Exit Block 7");
-	if (flag == FAILED) {
-		tst_resm(TFAIL, "Block 7 FAILED");
-	} else {
-		tst_resm(TPASS, "Block 7 PASSED");
-	}
-	free(buffer);
-	buffer = NULL;
+end:
+	if (!tc->buf)
+		free(res);
 }
 
-void setup(void)
+static void setup(void)
 {
-	/* FORK is set here because of the popen() call above */
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* create a test directory and cd into it */
-	tst_tmpdir();
+	SAFE_CHDIR("/tmp");
 }
 
-void cleanup(void)
-{
-	/* remove the test directory */
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tid = "getcwd02",
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_getcwd
+};
Signature · 1 line
1.8.3.1
author
#10 lore raw

PATCH v2 2/3 syscalls/getcwd03.c: cleanup && convert to new API

---
 testcases/kernel/syscalls/getcwd/getcwd03.c | 289 ++++++++--------------------
 1 file changed, 84 insertions(+), 205 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd03.c +84 -205
index 8ba5286..030dd7c 100644
@@ -1,238 +1,117 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program.
  */
 
 /*
- * NAME
- *	getcwd03
- *
  * DESCRIPTION
- *	Testcase to check the basic functionality of the getcwd(2) system call
- *	for symbolically linked directories.
+ * Testcase to check the basic functionality of the getcwd(2)
+ * system call on a symbolic link.
  *
  * ALGORITHM
- *	This testcase checks for the functionality of the getcwd(2) system call
- *	on a symbolic link. First create a directory (dir1), and create a
- *	symbolic link (dir2) to it at the same directory level. Then, chdir()
- *	to dir1, and get the working directory (cwd1), and its pathname (pwd1).
- *	Then, chdir() to dir2, and get the working directory (cwd2), its
- *	pathname (pwd2), and its readlink info (link2).
- *	Testcase succeeds if:
- *	i.	pwd1 == pwd2
- *	ii.	cwd1 == cwd2
- *	iii.	link2 == basename(cwd1)
- *
- * USAGE:  <for command-line>
- *  getcwd03 [-c n] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
+ * 1) create a directory, and create a symbolic link to it at the
+ *    same directory level.
+ * 2) get the working directory of a directory, and its pathname.
+ * 3) get the working directory of a symbolic link, and its pathname,
+ *    and its readlink info.
+ * 4) compare the working directories and link information.
  */
+
 #define _GNU_SOURCE 1
+#include <errno.h>
 #include <stdio.h>
 #include <string.h>
-#include <errno.h>
-#include <libgen.h>
-#include "test.h"
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <stdlib.h>
-#define FAILED 1
-
-int flag;
-char *TCID = "getcwd03";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-void cleanup(void);
-void setup(void);
-char *getpwd(void);
+static char dir1[BUFSIZ], dir2[BUFSIZ];
 
-int main(int ac, char **av)
+static void verify_getcwd(void)
 {
-	char dir1[BUFSIZ], dir2[BUFSIZ];
-	char cwd1[BUFSIZ], cwd2[BUFSIZ];
-	char *pwd1, *pwd2;
-	char link2[BUFSIZ];
-	int n;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/*
-	 * The following loop checks looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		flag = 0;
-
-		/*
-		 * Create dir1, then chdir to dir1, and get the pwd,
-		 * and cwd informations
-		 */
-		sprintf(dir1, "getcwd1.%d", getpid());
-		if (mkdir(dir1, 00755) < 0) {
-			tst_brkm(TBROK, cleanup, "mkdir(2) failed");
-		}
-		if (chdir(dir1) != 0) {
-			tst_brkm(TBROK, cleanup, "chdir(2) failed");
-		}
-
-		pwd1 = getpwd();
-		if (getcwd(cwd1, sizeof cwd1) == NULL) {
-			tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-			flag = FAILED;
-		}
-		if ((flag != FAILED) && (strcmp(pwd1, cwd1) != 0)) {
-			tst_brkm(TFAIL, cleanup, "getcwd() returned unexpected "
-				 "working directory: expected: %s, got: %s\n",
-				 pwd1, cwd1);
-		}
-
-		tst_resm(TINFO, "getcwd(2) succeeded in returning correct path "
-			 "for dir1");
-
-		/*
-		 * Now create dir2, then chdir to dir2, and get the pwd,
-		 * cwd, and link informations
-		 */
-		chdir("..");
-		flag = 0;
-
-		sprintf(dir2, "getcwd2.%d", getpid());
-		if (symlink(dir1, dir2) < 0) {
-			tst_brkm(TBROK, cleanup, "symlink(2) failed: errno: %d",
-				 errno);
-		}
-
-		if (chdir(dir2) != 0) {
-			tst_brkm(TBROK, cleanup, "chdir(2) failed: errno: %d",
-				 errno);
-		}
-
-		pwd2 = getpwd();
-		if (getcwd(cwd2, sizeof cwd2) == NULL) {
-			tst_resm(TFAIL|TERRNO, "getcwd() failed unexpectedly");
-			flag = FAILED;
-		}
-
-		chdir("..");
-		if ((flag != FAILED) &&
-		    ((n = readlink(dir2, link2, sizeof(link2))) < 0)) {
-			tst_brkm(TBROK, cleanup, "readlink(2) failed: errno:%d",
-				 errno);
-		}
-
-		/*
-		 * Finally compare the pwd, cwd, link informations:
-		 * The test should pass iff all the following are true:
-		 * a.   pwd1 == pwd2
-		 * b.   cwd1 == cwd2
-		 * c.   link2 == basename(cwd1)
-		 */
-		if (flag != FAILED) {
-			if (strcmp(pwd1, pwd2) != 0) {
-				tst_resm(TFAIL, "pwd1: %s, pwd2: %s",
-					 pwd1, pwd2);
-				flag = FAILED;
-			}
-			if (strcmp(cwd1, cwd2) != 0) {
-				tst_resm(TFAIL, "cwd1: %s, cwd2: %s",
-					 cwd1, cwd2);
-				flag = FAILED;
-			}
-			if (memcmp(link2, (char *)basename(cwd1), n) != 0) {
-				tst_resm(TFAIL, "link2: %s, cwd1: %s",
-					 link2, cwd1);
-				flag = FAILED;
-			}
-			if (flag != FAILED) {
-				tst_resm(TINFO, "getcwd(2) succeeded in "
-					 "returning correct path for symbolic "
-					 "link dir2 -> dir1");
-			}
-		}
-
-		if (flag == FAILED) {
-			tst_resm(TFAIL, "Test FAILED");
-		} else {
-			tst_resm(TPASS, "Test PASSED");
-		}
-
-		/* clean up things in case we are looping */
-		if (unlink(dir2) == -1) {
-			tst_brkm(TBROK, cleanup, "couldnt remove dir2");
-		}
-		if (rmdir(dir1) == -1) {
-			tst_brkm(TBROK, cleanup, "couldnt remove dir1");
-		}
+	char link[BUFSIZ];
+	char *res1 = NULL;
+	char *res2 = NULL;
+
+	SAFE_CHDIR(dir1);
+
+	errno = 0;
+	res1 = getcwd(NULL, 0);
+	TEST_ERRNO = errno;
+	if (!res1) {
+		tst_res(TFAIL | TTERRNO, "getcwd() failed to "
+			"get working directory of a directory");
+		goto end;
 	}
-	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(NULL, 0);
+	TEST_ERRNO = errno;
+	if (!res2) {
+		tst_res(TFAIL | TTERRNO, "getcwd() failed to get "
+			"working directory of a symbolic link");
+		goto end;
+	}
+
+	if (strcmp(res1, res2)) {
+		tst_res(TFAIL, "getcwd() got mismatched working directories");
+		goto end;
+	}
+
+	SAFE_CHDIR("..");
+	SAFE_READLINK(dir2, link, sizeof(link));
+
+	if (strcmp(link, SAFE_BASENAME(res1))) {
+		tst_res(TFAIL,
+			"link information didn't match the working directory");
+		goto end;
+	}
 
-	TEST_PAUSE;
+	tst_res(TPASS, "getcwd() succeeded on a symbolic link");
 
-	/* create a test directory and cd into it */
-	tst_tmpdir();
+end:
+	free(res1);
+	free(res2);
 }
 
-void cleanup(void)
+static void setup(void)
 {
-	/* remove the test directory */
-	tst_rmdir();
+	sprintf(dir1, "getcwd1.%d", getpid());
+	sprintf(dir2, "getcwd2.%d", getpid());
+	SAFE_MKDIR(dir1, 0755);
+	SAFE_SYMLINK(dir1, dir2);
 }
 
-char *getpwd(void)
+static void cleanup(void)
 {
-	FILE *fin;
-	char *pwd = "/bin/pwd";
-	char *cp;
-	char *buf;
-
-	buf = malloc(BUFSIZ);
-	if ((fin = popen(pwd, "r")) == NULL) {
-		tst_resm(TINFO, "%s: can't run %s", TCID, pwd);
-		tst_brkm(TBROK, cleanup, "%s FAILED", TCID);
-	}
-	while (fgets(buf, BUFSIZ, fin) != NULL) {
-		if ((cp = strchr(buf, '\n')) == NULL) {
-			tst_brkm(TBROK, cleanup, "pwd output too long");
-		}
-		*cp = 0;
-	}
-	pclose(fin);
-	return buf;
+	if (unlink(dir2) == -1)
+		tst_res(TWARN | TERRNO, "could not remove %s", dir2);
+
+	if (rmdir(dir1) == -1)
+		tst_res(TWARN | TERRNO, "could not remove %s", dir1);
 }
+
+static struct tst_test test = {
+	.tid = "getcwd03",
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_getcwd
+};
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v2 2/3 syscalls/getcwd03.c: cleanup && convert to new API

Hi!

testcases/kernel/syscalls/getcwd/getcwd03.c line 66

Quoted 3 lines
testcases/kernel/syscalls/getcwd/getcwd03.c +3 -0
+	errno = 0;
+	res2 = getcwd(NULL, 0);
+	TEST_ERRNO = errno;

I've simplified this part not to use the TEST_ERRNO.

testcases/kernel/syscalls/getcwd/getcwd03.c line 72

Quoted 6 lines
testcases/kernel/syscalls/getcwd/getcwd03.c +6 -0
+	if (!res2) {
+		tst_res(TFAIL | TTERRNO, "getcwd() failed to get "
+			"working directory of a symbolic link");
+		goto end;
+	}
+

And also removed the test cleanup() since the temporary directory is removed recursively at the test end.

And pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#12 lore raw

PATCH v2 3/3 syscalls/getcwd04.c: cleanup && convert to new API

In reply to Xiao Yang
---
 testcases/kernel/syscalls/getcwd/getcwd04.c | 81 +++++++++++------------------
 1 file changed, 30 insertions(+), 51 deletions(-)
testcases/kernel/syscalls/getcwd/getcwd04.c +30 -51
index 1a5461c..7e2ca23 100644
@@ -1,16 +1,16 @@
 /*
- *   Copyright (c) 2014 Fujitsu Ltd.
- *   Author: Xiaoguang Wang <[email protected]>
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <[email protected]>
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  */
 
 /*
@@ -30,7 +30,6 @@
  *
  * This test is to check whether this bug exists in the running kernel,
  * or whether this bug has been fixed.
- *
  */
 
 #include <stdio.h>
@@ -38,77 +37,54 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define TIMEOUT	5
 
-static void setup(void);
-static void cleanup(void);
 static void do_child(void);
 static void sigproc(int sig);
 static volatile sig_atomic_t end;
 static char init_cwd[PATH_MAX];
 
-char *TCID = "getcwd04";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_getcwd(void)
 {
 	int status;
 	char cur_cwd[PATH_MAX];
 	pid_t child;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	child = tst_fork();
-	if (child < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
-
+	child = SAFE_FORK();
 	if (child == 0)
 		do_child();
 
 	 while (1) {
-		SAFE_GETCWD(cleanup, cur_cwd, PATH_MAX);
+		SAFE_GETCWD(cur_cwd, PATH_MAX);
 		if (strncmp(init_cwd, cur_cwd, PATH_MAX)) {
-			tst_resm(TFAIL, "initial current work directory is "
+			tst_res(TFAIL, "initial current work directory is "
 				 "%s, now is %s. Bug is reproduced!",
 				 init_cwd, cur_cwd);
 			break;
 		}
 
 		if (end) {
-			tst_resm(TPASS, "Bug is not reproduced!");
+			tst_res(TPASS, "Bug is not reproduced!");
 			break;
 		}
 	}
 
-	SAFE_KILL(cleanup, child, SIGKILL);
-	SAFE_WAITPID(cleanup, child, &status, 0);
-
-	cleanup();
-	tst_exit();
+	SAFE_KILL(child, SIGKILL);
+	SAFE_WAITPID(child, &status, 0);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
 	if (tst_ncpus() == 1)
-		tst_brkm(TCONF, NULL, "This test needs two cpus at least");
-
-	tst_tmpdir();
+		tst_brk(TCONF, "This test needs two cpus@least");
 
-	if (signal(SIGALRM, sigproc) == SIG_ERR)
-		tst_brkm(TBROK | TERRNO, cleanup, "signal(SIGALRM) failed");
+	SAFE_SIGNAL(SIGALRM, sigproc);
 
 	alarm(TIMEOUT);
 
-	SAFE_GETCWD(cleanup, init_cwd, PATH_MAX);
+	SAFE_GETCWD(init_cwd, PATH_MAX);
 }
 
 static void sigproc(int sig)
@@ -121,16 +97,19 @@ static void do_child(void)
 	unsigned int i = 0;
 	char c_name[PATH_MAX] = "testfile", n_name[PATH_MAX];
 
-	SAFE_TOUCH(NULL, c_name, 0644, NULL);
+	SAFE_TOUCH(c_name, 0644, NULL);
 
 	while (1) {
 		snprintf(n_name, PATH_MAX, "testfile%u", i++);
-		SAFE_RENAME(NULL, c_name, n_name);
+		SAFE_RENAME(c_name, n_name);
 		strncpy(c_name, n_name, PATH_MAX);
 	}
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tid = "getcwd04",
+	.setup = setup,
+	.test_all = verify_getcwd,
+	.needs_tmpdir = 1,
+	.forks_child = 1
+};
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH v2 1/3 syscalls/getcwd02.c: cleanup && convert to new API

In reply to Xiao Yang

Hi!

testcases/kernel/syscalls/getcwd/getcwd02.c line 60

Quoted 4 lines
testcases/kernel/syscalls/getcwd/getcwd02.c +4 -0
+	if (tc->buf != NULL && strcmp(exp_buf, tc->buf)) {
+		tst_res(TFAIL, "getcwd() returned unexpected directory: %s, "
+			"expected: %s", tc->buf, exp_buf);
+		goto end;

I've removed this check because it was redundant. Unless tc->buf is NULL the tc->buf is the same as res.

Pushed, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]