public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] Usage about LTP_BIG_DEV exported by runltp
@ 2014-03-21 11:43 Xiaoguang Wang
  2014-03-21 11:43 ` [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space Xiaoguang Wang
  2014-03-21 11:44 ` [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function Xiaoguang Wang
  0 siblings, 2 replies; 6+ messages in thread
From: Xiaoguang Wang @ 2014-03-21 11:43 UTC (permalink / raw)
  To: ltp-list

Some tests may need a big block device to complete test. When having
this demand, users may run runltp script with "-z" option to specify
such a big block device.

When a big block device is specified, related test cases will run. But
these tests may need different requirement about the size of the block
device. If testA needs 500MB and testB needs 1GB, and if one user
has interest in testA and he also doesn't know the existence of testB,
when he specifies a block device size of 600MB, then testB will fail.

So when user needs a big block device, he may first need to determine
the mounted block device's free space. If the specified device does not
have enouth free space, the test should also return TCONF.

Maybe this also need to be updated to doc/test-writing-guidelines.txt.

Thanks.


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space
  2014-03-21 11:43 [LTP] Usage about LTP_BIG_DEV exported by runltp Xiaoguang Wang
@ 2014-03-21 11:43 ` Xiaoguang Wang
  2014-04-10 11:11   ` chrubis
  2014-03-21 11:44 ` [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function Xiaoguang Wang
  1 sibling, 1 reply; 6+ messages in thread
From: Xiaoguang Wang @ 2014-03-21 11:43 UTC (permalink / raw)
  To: ltp-list

The existing lib/tst_cwd_has_free.c only determines the filesystem, which
the current directory is in. And I think tst_cwd_has_free() is not entirely
correct. See this code in tst_cwd_has_free():
	return ((float)sf.f_bfree) / (1024 / sf.f_bsize) >=
		 required_kib ? 1 : 0;
if sf.f_bsize is greater than 1024, this code is wrong.

I choose to remove tst_cwd_has_free.c and add lib/tst_fs_has_free.c.
The prototype is below:
	int tst_fs_has_free(void (*cleanup)(void), const char *path,
			    int required_kib)
User can specify the path to determine the corresponding filesystem.

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 include/test.h                                |  8 ++++--
 lib/tst_cwd_has_free.c                        | 22 ----------------
 lib/tst_fs_has_free.c                         | 37 +++++++++++++++++++++++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c |  2 +-
 testcases/kernel/syscalls/swapoff/swapoff02.c |  2 +-
 testcases/kernel/syscalls/swapon/libswapon.c  |  2 +-
 6 files changed, 46 insertions(+), 27 deletions(-)
 delete mode 100644 lib/tst_cwd_has_free.c
 create mode 100644 lib/tst_fs_has_free.c

diff --git a/include/test.h b/include/test.h
index 32b9680..ce7e0a6 100644
--- a/include/test.h
+++ b/include/test.h
@@ -204,8 +204,12 @@ struct tst_kern_exv {
 
 int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers);
 
-/* lib/tst_cwd_has_free.c */
-int tst_cwd_has_free(int required_kib);
+/* lib/tst_fs_has_free.c
+ *
+ * @path: path is the pathname of any file within the mounted file system
+ * @required_kib: the required free space(count in KB)
+ */
+int tst_fs_has_free(void (*cleanup)(void), const char *path, int required_kib);
 
 int tst_is_virt(int virt_type);
 
diff --git a/lib/tst_cwd_has_free.c b/lib/tst_cwd_has_free.c
deleted file mode 100644
index e44c31f..0000000
--- a/lib/tst_cwd_has_free.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- *    AUTHOR
- *    	Ricky Ng-Adam <rngadam@yahoo.com>, 2005-01-01
- *
- *    DESCRIPTION
- * 	Check if there is enough blocks to fill number of KiB specified
- * 	If current directory has enough blocks, return 1
- * 	If current directory has NOT enough blocks, return 0
- *
- *
- */
-#include <sys/vfs.h>
-
-int tst_cwd_has_free(int required_kib)
-{
-	struct statfs sf;
-	statfs(".", &sf);
-
-	/* check that we have enough blocks to create swap file */
-	return ((float)sf.f_bfree) / (1024 / sf.f_bsize) >=
-	    required_kib ? 1 : 0;
-}
diff --git a/lib/tst_fs_has_free.c b/lib/tst_fs_has_free.c
new file mode 100644
index 0000000..ba14912
--- /dev/null
+++ b/lib/tst_fs_has_free.c
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * DESCRIPTION
+ * 	Check if the mounted file system has enough free space,
+ * 	if it is, tst_fs_has_free() returns 1, otherwise 0.
+ */
+
+#include <sys/vfs.h>
+#include "test.h"
+
+int tst_fs_has_free(void (*cleanup)(void), const char *path, int required_kib)
+{
+	struct statfs sf;
+
+	if (statfs(path, &sf)) {
+		tst_brkm(TBROK | TERRNO, cleanup,
+			 "tst_fs_has_free: failed to statfs(%s)", path);
+	}
+
+	return (sf.f_bfree * sf.f_bsize / 1024) >= required_kib ? 1 : 0;
+}
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index b4d19de..8d1c435 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -99,7 +99,7 @@ static void setup(void)
 	break;
 	}
 
-	if (!tst_cwd_has_free(65536)) {
+	if (!tst_fs_has_free(NULL, ".", 65536)) {
 		tst_brkm(TBROK, cleanup,
 			 "Insufficient disk space to create swap file");
 	}
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index 978dc01..fb1f6f8 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -157,7 +157,7 @@ static void setup(void)
 	break;
 	}
 
-	if (!tst_cwd_has_free(1)) {
+	if (!tst_fs_has_free(NULL, ".", 1)) {
 		tst_brkm(TBROK, cleanup,
 			 "Insufficient disk space to create swap file");
 	}
diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
index 8eca7dc..ffb23a8 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.c
+++ b/testcases/kernel/syscalls/swapon/libswapon.c
@@ -27,7 +27,7 @@
  */
 void make_swapfile(void (cleanup)(void), const char *swapfile)
 {
-	if (!tst_cwd_has_free(sysconf(_SC_PAGESIZE)*10)) {
+	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE)*10)) {
 		tst_brkm(TBROK, cleanup,
 			"Insufficient disk space to create swap file");
 	}
-- 
1.8.2.1


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function
  2014-03-21 11:43 [LTP] Usage about LTP_BIG_DEV exported by runltp Xiaoguang Wang
  2014-03-21 11:43 ` [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space Xiaoguang Wang
@ 2014-03-21 11:44 ` Xiaoguang Wang
       [not found]   ` <5344F4E5.2050600@cn.fujitsu.com>
  2014-04-10 11:13   ` chrubis
  1 sibling, 2 replies; 6+ messages in thread
From: Xiaoguang Wang @ 2014-03-21 11:44 UTC (permalink / raw)
  To: ltp-list

Create misc.sh to place miscellaneous functions, which will be
useful for tests written in shell but do not have a proper place
to place.

Currenly add tst_fs_has_free(), which will check if the mounted
file system has enough free space.

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 testcases/lib/misc.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 testcases/lib/misc.sh

diff --git a/testcases/lib/misc.sh b/testcases/lib/misc.sh
new file mode 100644
index 0000000..f6b97ba
--- /dev/null
+++ b/testcases/lib/misc.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+#
+# Copyright (c) Linux Test Project, 2014
+#
+# 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.
+#
+# 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.
+#
+# This is a LTP shell test library for miscellaneous functions.
+#
+
+. test.sh
+
+# check if the mounted file system has enough free space,
+# if it is, tst_fs_has_free() returns 1, otherwise 0.
+# NOTE: filesystem free space counts in KB
+tst_fs_has_free()
+{
+	local free_space=0
+	local abs_mntpoint=$(cd $1; pwd)
+	local required_space=$2
+
+	if [ -z "$abs_mntpoint" ]; then
+		tst_brkm TBROK "$1: not a valid path"
+	fi
+
+	free_space=$(df | grep $abs_mntpoint | awk '{print $4}')
+
+	if [ -z "$free_space" ]; then
+		tst_brkm TBROK "$1: not a valid mount point"
+	fi
+
+	if [ $free_space -ge $required_space ]; then
+		return 1;
+	else
+		return 0;
+	fi
+}
-- 
1.8.2.1


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function
       [not found]   ` <5344F4E5.2050600@cn.fujitsu.com>
@ 2014-04-09 17:06     ` chrubis
  0 siblings, 0 replies; 6+ messages in thread
From: chrubis @ 2014-04-09 17:06 UTC (permalink / raw)
  To: Xiaoguang Wang; +Cc: LTP

Hi!
> Ping :-)

You are in the queue :). I will have a look tomorrow, but I cannot
promise that the patch will get merged before next release which should
happen anytime soon.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space
  2014-03-21 11:43 ` [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space Xiaoguang Wang
@ 2014-04-10 11:11   ` chrubis
  0 siblings, 0 replies; 6+ messages in thread
From: chrubis @ 2014-04-10 11:11 UTC (permalink / raw)
  To: Xiaoguang Wang; +Cc: ltp-list

Hi!
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it would be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, write the Free Software Foundation, Inc.,
> + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> + */
> +
> +/*
> + * DESCRIPTION
> + * 	Check if the mounted file system has enough free space,
> + * 	if it is, tst_fs_has_free() returns 1, otherwise 0.
> + */
> +
> +#include <sys/vfs.h>
> +#include "test.h"
> +
> +int tst_fs_has_free(void (*cleanup)(void), const char *path, int required_kib)
> +{
> +	struct statfs sf;
> +
> +	if (statfs(path, &sf)) {
> +		tst_brkm(TBROK | TERRNO, cleanup,
> +			 "tst_fs_has_free: failed to statfs(%s)", path);
> +	}
> +
> +	return (sf.f_bfree * sf.f_bsize / 1024) >= required_kib ? 1 : 0;

The f_bfree is unsigned long (via typedef to the fsblkcnt_t) so if I'm
counting right on 32bit system the multiplication will overflow on > 4TB
filesystem.

If we do the multiplication first we should cast the b_free to 64 bit
unsigned integer.

The rest looks fine.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function
  2014-03-21 11:44 ` [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function Xiaoguang Wang
       [not found]   ` <5344F4E5.2050600@cn.fujitsu.com>
@ 2014-04-10 11:13   ` chrubis
  1 sibling, 0 replies; 6+ messages in thread
From: chrubis @ 2014-04-10 11:13 UTC (permalink / raw)
  To: Xiaoguang Wang; +Cc: ltp-list

Hi!
> Create misc.sh to place miscellaneous functions, which will be
> useful for tests written in shell but do not have a proper place
> to place.
> 
> Currenly add tst_fs_has_free(), which will check if the mounted
> file system has enough free space.
> 
> Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>

Wouldn't this be easier to implement by adding a few lines that calls
the C variant into the ltpapicmd.c?

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment 
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-04-10 11:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-21 11:43 [LTP] Usage about LTP_BIG_DEV exported by runltp Xiaoguang Wang
2014-03-21 11:43 ` [LTP] [PATCH 1/2] lib/tst_fs_has_free.c: add tst_fs_has_free() to determine filesystem's free space Xiaoguang Wang
2014-04-10 11:11   ` chrubis
2014-03-21 11:44 ` [LTP] [PATCH 2/2] testcases/lib/misc.sh: add tst_fs_has_free function Xiaoguang Wang
     [not found]   ` <5344F4E5.2050600@cn.fujitsu.com>
2014-04-09 17:06     ` chrubis
2014-04-10 11:13   ` chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox