All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] zram01: add a new test for zram feature
       [not found] <1064791416.56186.1295424761697.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
@ 2011-01-19  8:12 ` CAI Qian
  2011-01-19  9:07   ` Garrett Cooper
  0 siblings, 1 reply; 4+ messages in thread
From: CAI Qian @ 2011-01-19  8:12 UTC (permalink / raw)
  To: ltp-list

[-- Attachment #1: Type: text/plain, Size: 6002 bytes --]

zram: generic RAM based compressed R/W block devices
http://lkml.org/lkml/2010/8/9/227

Signed-off-by: CAI Qian <caiqian@redhat.com>
---
 testcases/kernel/mem/zram/Makefile |   22 +++++
 testcases/kernel/mem/zram/zram01.c |  159 ++++++++++++++++++++++++++++++++++++
 2 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/zram/Makefile
 create mode 100644 testcases/kernel/mem/zram/zram01.c

diff --git a/testcases/kernel/mem/zram/Makefile b/testcases/kernel/mem/zram/Makefile
new file mode 100644
index 0000000..3634570
--- /dev/null
+++ b/testcases/kernel/mem/zram/Makefile
@@ -0,0 +1,22 @@
+#
+#  Copyright (C) 2010  Red Hat, Inc.
+#
+#  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/zram/zram01.c b/testcases/kernel/mem/zram/zram01.c
new file mode 100644
index 0000000..e0a0361
--- /dev/null
+++ b/testcases/kernel/mem/zram/zram01.c
@@ -0,0 +1,159 @@
+/*
+ * zram: generic RAM based compressed R/W block devices
+ * http://lkml.org/lkml/2010/8/9/227
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "zram01";
+int TST_TOTAL = 1;
+int modprobe = 0;
+
+#define PATH_ZRAM	"/sys/block/zram0"
+#define SIZE		(512 * 1024 * 1024)
+#define DEVICE		"/dev/zram0"
+
+static void setup(void);
+static void cleanup(void);
+static void print(char *string);
+static void dump_info(void);
+
+int main(int argc, char *argv[])
+{
+	int lc, fd;
+	char *msg;
+	char size[BUFSIZ];
+	void *s;
+
+	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;
+		tst_resm(TINFO, "create a zram device with %d bytes in size.",
+			SIZE);
+		fd = open(PATH_ZRAM "/disksize", O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s",
+				PATH_ZRAM "/disksize");
+		sprintf(size, "%d", SIZE);
+		if (write(fd, size, strlen(size)) != strlen(size))
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s to %s", size,
+				PATH_ZRAM "/disksize");
+		close(fd);
+
+		tst_resm(TINFO, "map it into memory.");
+		fd = open(DEVICE, O_RDWR);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", DEVICE);
+		s = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+		if (s == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+
+		tst_resm(TINFO, "write all the memory.");
+		memset(s, SIZE, 'a');
+		close(fd);
+
+		dump_info();
+
+		tst_resm(TINFO, "reset it.");
+		fd = open(PATH_ZRAM "/reset", O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s",
+				PATH_ZRAM "/reset");
+		if (write(fd, "1", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup, "write 1 to %s",
+				PATH_ZRAM "/reset");
+		close(fd);
+
+		dump_info();
+	}
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)
+{
+	tst_require_root(NULL);
+
+	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT) {
+		system("modprobe zram");
+		modprobe = 1;
+		if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT)
+			tst_brkm(TCONF, NULL, "system has no zram device.");
+		else
+			tst_brkm(TBROK|TERRNO, NULL, "access");
+	}
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+}
+
+void cleanup(void)
+{
+	if (modprobe == 1)
+		system("rmmod zram");
+
+	TEST_CLEANUP;
+}
+
+void print(char *string)
+{
+	FILE *fp;
+	char buf[BUFSIZ], value[BUFSIZ];
+
+	sprintf(buf, "%s/%s", PATH_ZRAM, string);
+	fp = fopen(buf, "r");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen %s", buf);
+
+	if (fgets(value, BUFSIZ, fp) == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fgets %s", buf);
+	value[strlen(value) - 1] = '\0';
+	fclose(fp);
+
+	tst_resm(TINFO, "%s is %s", buf, value);
+}
+
+void dump_info(void)
+{
+	print("initstate");
+	print("compr_data_size");
+	print("orig_data_size");
+	print("disksize");
+	print("mem_used_total");
+	print("num_reads");
+	print("num_writes");
+	print("zero_pages");
+}
-- 
1.7.3.2

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-zram01-add-a-new-test-for-zram-feature.patch --]
[-- Type: text/x-patch; name=0001-zram01-add-a-new-test-for-zram-feature.patch, Size: 6207 bytes --]

From 269b425b5cf8761971ce8dbedf3df70be808059d Mon Sep 17 00:00:00 2001
From: CAI Qian <caiqian@redhat.com>
Date: Wed, 19 Jan 2011 15:58:09 +0800
Subject: [PATCH] zram01: add a new test for zram feature

zram: generic RAM based compressed R/W block devices
http://lkml.org/lkml/2010/8/9/227

Signed-off-by: CAI Qian <caiqian@redhat.com>
---
 testcases/kernel/mem/zram/Makefile |   22 +++++
 testcases/kernel/mem/zram/zram01.c |  159 ++++++++++++++++++++++++++++++++++++
 2 files changed, 181 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/zram/Makefile
 create mode 100644 testcases/kernel/mem/zram/zram01.c

diff --git a/testcases/kernel/mem/zram/Makefile b/testcases/kernel/mem/zram/Makefile
new file mode 100644
index 0000000..3634570
--- /dev/null
+++ b/testcases/kernel/mem/zram/Makefile
@@ -0,0 +1,22 @@
+#
+#  Copyright (C) 2010  Red Hat, Inc.
+#
+#  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/zram/zram01.c b/testcases/kernel/mem/zram/zram01.c
new file mode 100644
index 0000000..e0a0361
--- /dev/null
+++ b/testcases/kernel/mem/zram/zram01.c
@@ -0,0 +1,159 @@
+/*
+ * zram: generic RAM based compressed R/W block devices
+ * http://lkml.org/lkml/2010/8/9/227
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "zram01";
+int TST_TOTAL = 1;
+int modprobe = 0;
+
+#define PATH_ZRAM	"/sys/block/zram0"
+#define SIZE		(512 * 1024 * 1024)
+#define DEVICE		"/dev/zram0"
+
+static void setup(void);
+static void cleanup(void);
+static void print(char *string);
+static void dump_info(void);
+
+int main(int argc, char *argv[])
+{
+	int lc, fd;
+	char *msg;
+	char size[BUFSIZ];
+	void *s;
+
+	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;
+		tst_resm(TINFO, "create a zram device with %d bytes in size.",
+			SIZE);
+		fd = open(PATH_ZRAM "/disksize", O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s",
+				PATH_ZRAM "/disksize");
+		sprintf(size, "%d", SIZE);
+		if (write(fd, size, strlen(size)) != strlen(size))
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s to %s", size,
+				PATH_ZRAM "/disksize");
+		close(fd);
+
+		tst_resm(TINFO, "map it into memory.");
+		fd = open(DEVICE, O_RDWR);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", DEVICE);
+		s = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+		if (s == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+
+		tst_resm(TINFO, "write all the memory.");
+		memset(s, SIZE, 'a');
+		close(fd);
+
+		dump_info();
+
+		tst_resm(TINFO, "reset it.");
+		fd = open(PATH_ZRAM "/reset", O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s",
+				PATH_ZRAM "/reset");
+		if (write(fd, "1", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup, "write 1 to %s",
+				PATH_ZRAM "/reset");
+		close(fd);
+
+		dump_info();
+	}
+	cleanup();
+	tst_exit();
+}
+
+void setup(void)
+{
+	tst_require_root(NULL);
+
+	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT) {
+		system("modprobe zram");
+		modprobe = 1;
+		if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT)
+			tst_brkm(TCONF, NULL, "system has no zram device.");
+		else
+			tst_brkm(TBROK|TERRNO, NULL, "access");
+	}
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+}
+
+void cleanup(void)
+{
+	if (modprobe == 1)
+		system("rmmod zram");
+
+	TEST_CLEANUP;
+}
+
+void print(char *string)
+{
+	FILE *fp;
+	char buf[BUFSIZ], value[BUFSIZ];
+
+	sprintf(buf, "%s/%s", PATH_ZRAM, string);
+	fp = fopen(buf, "r");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen %s", buf);
+
+	if (fgets(value, BUFSIZ, fp) == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fgets %s", buf);
+	value[strlen(value) - 1] = '\0';
+	fclose(fp);
+
+	tst_resm(TINFO, "%s is %s", buf, value);
+}
+
+void dump_info(void)
+{
+	print("initstate");
+	print("compr_data_size");
+	print("orig_data_size");
+	print("disksize");
+	print("mem_used_total");
+	print("num_reads");
+	print("num_writes");
+	print("zero_pages");
+}
-- 
1.7.3.2


[-- Attachment #3: Type: text/plain, Size: 372 bytes --]

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] zram01: add a new test for zram feature
  2011-01-19  8:12 ` [LTP] [PATCH] zram01: add a new test for zram feature CAI Qian
@ 2011-01-19  9:07   ` Garrett Cooper
  0 siblings, 0 replies; 4+ messages in thread
From: Garrett Cooper @ 2011-01-19  9:07 UTC (permalink / raw)
  To: CAI Qian; +Cc: ltp-list

On Wed, Jan 19, 2011 at 12:12 AM, CAI Qian <caiqian@redhat.com> wrote:
> zram: generic RAM based compressed R/W block devices
> http://lkml.org/lkml/2010/8/9/227

Commit pending.
Thanks,
-Garrett

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH] zram01: add a new test for zram feature.
  2010-12-20  8:31 ` CAI Qian
@ 2010-12-30 10:38   ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2010-12-30 10:38 UTC (permalink / raw)
  To: CAI Qian; +Cc: ltp-list

Hi!
> +int main(int argc, char *argv[])
> +{
> +	int lc, fd;
> +	char *msg;
> +	char buf[BUFSIZ], size[BUFSIZ];
> +	void *s;
> +
> +	msg = parse_opts(argc, argv, NULL, NULL);
> +	if (msg != (char *)NULL)
> +		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);

Once again, useless cast here.

> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		Tst_count = 0;
> +		tst_resm(TINFO, "create a zram device with %d bytes in size.",
> +			SIZE);
> +		sprintf(buf, "%s/disksize", PATH_ZRAM);
> +		fd = open(buf, O_WRONLY);

And the sprintf() here.

> +		if (fd == -1)
> +			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
> +		sprintf(size, "%d", SIZE);
> +		if (write(fd, size, strlen(size)) != strlen(size))
> +			tst_brkm(TBROK|TERRNO, cleanup, "write %s to %s", size,
> +				buf);
> +		close(fd);
> +
> +		tst_resm(TINFO, "map it into memory.");
> +		fd = open(DEVICE, O_RDWR);
> +		if (fd == -1)
> +			tst_brkm(TBROK|TERRNO, cleanup, "open %s", DEVICE);
> +		s = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
> +		if (s == MAP_FAILED)
> +			tst_brkm(TBROK|TERRNO, cleanup, "mmap");
> +
> +		tst_resm(TINFO, "write all the memory.");
> +		memset(s, SIZE, 'a');
> +		close(fd);
> +
> +		dump_info();
> +
> +		tst_resm(TINFO, "reset it.");
> +		sprintf(buf, "%s/reset", PATH_ZRAM);

And here.

> +		fd = open(buf, O_WRONLY);
> +		if (fd == -1)
> +			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
> +		if (write(fd, "1", 1) != 1)
> +			tst_brkm(TBROK|TERRNO, cleanup, "write 1 to %s", buf);
> +		close(fd);
> +
> +		dump_info();
> +	}
> +	cleanup();
> +}
> +
> +void setup(void)
> +{
> +	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT) {
> +		system("modprobe zram");
> +		modprobe = 1;
> +		if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT)
> +			tst_brkm(TCONF, tst_exit, "system has no zram device.");
> +		else
> +			tst_brkm(TBROK|TERRNO, tst_exit, "access");
> +	}
> +	tst_sig(FORK, DEF_HANDLER, cleanup);
> +	TEST_PAUSE;
> +}
> +
> +void cleanup(void)
> +{
> +	if (modprobe == 1)
> +		system("rmmod zram");
> +
> +	TEST_CLEANUP;
> +	tst_exit();	
> +}
> +
> +void print(char *string)
> +{
> +	FILE *fp;
> +	char buf[BUFSIZ], value[BUFSIZ];
> +
> +	sprintf(buf, "%s/%s", PATH_ZRAM, string);
> +	fp = fopen(buf, "r");
> +	if (fp == NULL)
> +		tst_brkm(TBROK|TERRNO, cleanup, "fopen %s", buf);
> +
> +	if (fgets(value, BUFSIZ, fp) == NULL)
> +		tst_brkm(TBROK|TERRNO, cleanup, "fgets %s", buf);
> +	value[strlen(value) - 1] = '\0';
> +	fclose(fp);
> +
> +	tst_resm(TINFO, "%s is %s", buf, value);
> +}
> +
> +void dump_info(void)
> +{
> +	print("initstate");
> +	print("compr_data_size");
> +	print("orig_data_size");
> +	print("disksize");
> +	print("mem_used_total");
> +	print("num_reads");
> +	print("num_writes");
> +	print("zero_pages");
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH] zram01: add a new test for zram feature.
       [not found] <82849215.10223.1292833893533.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
@ 2010-12-20  8:31 ` CAI Qian
  2010-12-30 10:38   ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: CAI Qian @ 2010-12-20  8:31 UTC (permalink / raw)
  To: ltp-list

[-- Attachment #1: Type: text/plain, Size: 6023 bytes --]

zram: generic RAM based compressed R/W block devices
http://lkml.org/lkml/2010/8/9/227

Signed-off-by: CAI Qian <caiqian@redhat.com>
---
 testcases/kernel/mem/zram/Makefile |   22 +++++
 testcases/kernel/mem/zram/zram01.c |  157 ++++++++++++++++++++++++++++++++++++
 2 files changed, 179 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/zram/Makefile
 create mode 100644 testcases/kernel/mem/zram/zram01.c

diff --git a/testcases/kernel/mem/zram/Makefile b/testcases/kernel/mem/zram/Makefile
new file mode 100644
index 0000000..3634570
--- /dev/null
+++ b/testcases/kernel/mem/zram/Makefile
@@ -0,0 +1,22 @@
+#
+#  Copyright (C) 2010  Red Hat, Inc.
+#
+#  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/zram/zram01.c b/testcases/kernel/mem/zram/zram01.c
new file mode 100644
index 0000000..aea24de
--- /dev/null
+++ b/testcases/kernel/mem/zram/zram01.c
@@ -0,0 +1,157 @@
+/*
+ * zram: generic RAM based compressed R/W block devices
+ * http://lkml.org/lkml/2010/8/9/227
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "zram01";
+int TST_TOTAL = 1;
+extern int Tst_count;
+int modprobe = 0;
+
+#define PATH_ZRAM	"/sys/block/zram0"
+#define SIZE		(512 * 1024 * 1024)
+#define DEVICE		"/dev/zram0"
+
+static void setup(void);
+static void cleanup(void) LTP_ATTRIBUTE_NORETURN;
+static void print(char *string);
+static void dump_info(void);
+
+int main(int argc, char *argv[])
+{
+	int lc, fd;
+	char *msg;
+	char buf[BUFSIZ], size[BUFSIZ];
+	void *s;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != (char *)NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		tst_resm(TINFO, "create a zram device with %d bytes in size.",
+			SIZE);
+		sprintf(buf, "%s/disksize", PATH_ZRAM);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		sprintf(size, "%d", SIZE);
+		if (write(fd, size, strlen(size)) != strlen(size))
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s to %s", size,
+				buf);
+		close(fd);
+
+		tst_resm(TINFO, "map it into memory.");
+		fd = open(DEVICE, O_RDWR);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", DEVICE);
+		s = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+		if (s == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+
+		tst_resm(TINFO, "write all the memory.");
+		memset(s, SIZE, 'a');
+		close(fd);
+
+		dump_info();
+
+		tst_resm(TINFO, "reset it.");
+		sprintf(buf, "%s/reset", PATH_ZRAM);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		if (write(fd, "1", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup, "write 1 to %s", buf);
+		close(fd);
+
+		dump_info();
+	}
+	cleanup();
+}
+
+void setup(void)
+{
+	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT) {
+		system("modprobe zram");
+		modprobe = 1;
+		if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT)
+			tst_brkm(TCONF, tst_exit, "system has no zram device.");
+		else
+			tst_brkm(TBROK|TERRNO, tst_exit, "access");
+	}
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+}
+
+void cleanup(void)
+{
+	if (modprobe == 1)
+		system("rmmod zram");
+
+	TEST_CLEANUP;
+	tst_exit();	
+}
+
+void print(char *string)
+{
+	FILE *fp;
+	char buf[BUFSIZ], value[BUFSIZ];
+
+	sprintf(buf, "%s/%s", PATH_ZRAM, string);
+	fp = fopen(buf, "r");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen %s", buf);
+
+	if (fgets(value, BUFSIZ, fp) == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fgets %s", buf);
+	value[strlen(value) - 1] = '\0';
+	fclose(fp);
+
+	tst_resm(TINFO, "%s is %s", buf, value);
+}
+
+void dump_info(void)
+{
+	print("initstate");
+	print("compr_data_size");
+	print("orig_data_size");
+	print("disksize");
+	print("mem_used_total");
+	print("num_reads");
+	print("num_writes");
+	print("zero_pages");
+}
-- 
1.7.3.2

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-zram01-add-a-new-test-for-zram-feature.patch --]
[-- Type: text/x-patch; name=0001-zram01-add-a-new-test-for-zram-feature.patch, Size: 6229 bytes --]

From 4a3cf1c988cbda341e752d674e96c36ad810331d Mon Sep 17 00:00:00 2001
From: CAI Qian <caiqian@redhat.com>
Date: Mon, 20 Dec 2010 16:26:46 +0800
Subject: [PATCH] zram01: add a new test for zram feature.

zram: generic RAM based compressed R/W block devices
http://lkml.org/lkml/2010/8/9/227

Signed-off-by: CAI Qian <caiqian@redhat.com>
---
 testcases/kernel/mem/zram/Makefile |   22 +++++
 testcases/kernel/mem/zram/zram01.c |  157 ++++++++++++++++++++++++++++++++++++
 2 files changed, 179 insertions(+), 0 deletions(-)
 create mode 100644 testcases/kernel/mem/zram/Makefile
 create mode 100644 testcases/kernel/mem/zram/zram01.c

diff --git a/testcases/kernel/mem/zram/Makefile b/testcases/kernel/mem/zram/Makefile
new file mode 100644
index 0000000..3634570
--- /dev/null
+++ b/testcases/kernel/mem/zram/Makefile
@@ -0,0 +1,22 @@
+#
+#  Copyright (C) 2010  Red Hat, Inc.
+#
+#  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+top_srcdir              ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/zram/zram01.c b/testcases/kernel/mem/zram/zram01.c
new file mode 100644
index 0000000..aea24de
--- /dev/null
+++ b/testcases/kernel/mem/zram/zram01.c
@@ -0,0 +1,157 @@
+/*
+ * zram: generic RAM based compressed R/W block devices
+ * http://lkml.org/lkml/2010/8/9/227
+ *
+ * Copyright (C) 2010  Red Hat, Inc.
+ * 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.
+ *
+ * Further, this software is distributed without any warranty that it
+ * is free of the rightful claim of any third person regarding
+ * infringement or the like.  Any license provided herein, whether
+ * implied or otherwise, applies only to this software file.  Patent
+ * licenses, if any, provided herein do not apply to combinations of
+ * this program with other software, or any other product whatsoever.
+ *
+ * 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.
+ */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include "test.h"
+#include "usctest.h"
+
+char *TCID = "zram01";
+int TST_TOTAL = 1;
+extern int Tst_count;
+int modprobe = 0;
+
+#define PATH_ZRAM	"/sys/block/zram0"
+#define SIZE		(512 * 1024 * 1024)
+#define DEVICE		"/dev/zram0"
+
+static void setup(void);
+static void cleanup(void) LTP_ATTRIBUTE_NORETURN;
+static void print(char *string);
+static void dump_info(void);
+
+int main(int argc, char *argv[])
+{
+	int lc, fd;
+	char *msg;
+	char buf[BUFSIZ], size[BUFSIZ];
+	void *s;
+
+	msg = parse_opts(argc, argv, NULL, NULL);
+	if (msg != (char *)NULL)
+		tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		Tst_count = 0;
+		tst_resm(TINFO, "create a zram device with %d bytes in size.",
+			SIZE);
+		sprintf(buf, "%s/disksize", PATH_ZRAM);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		sprintf(size, "%d", SIZE);
+		if (write(fd, size, strlen(size)) != strlen(size))
+			tst_brkm(TBROK|TERRNO, cleanup, "write %s to %s", size,
+				buf);
+		close(fd);
+
+		tst_resm(TINFO, "map it into memory.");
+		fd = open(DEVICE, O_RDWR);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", DEVICE);
+		s = mmap(NULL, SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+		if (s == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, cleanup, "mmap");
+
+		tst_resm(TINFO, "write all the memory.");
+		memset(s, SIZE, 'a');
+		close(fd);
+
+		dump_info();
+
+		tst_resm(TINFO, "reset it.");
+		sprintf(buf, "%s/reset", PATH_ZRAM);
+		fd = open(buf, O_WRONLY);
+		if (fd == -1)
+			tst_brkm(TBROK|TERRNO, cleanup, "open %s", buf);
+		if (write(fd, "1", 1) != 1)
+			tst_brkm(TBROK|TERRNO, cleanup, "write 1 to %s", buf);
+		close(fd);
+
+		dump_info();
+	}
+	cleanup();
+}
+
+void setup(void)
+{
+	if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT) {
+		system("modprobe zram");
+		modprobe = 1;
+		if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1 && errno == ENOENT)
+			tst_brkm(TCONF, tst_exit, "system has no zram device.");
+		else
+			tst_brkm(TBROK|TERRNO, tst_exit, "access");
+	}
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+}
+
+void cleanup(void)
+{
+	if (modprobe == 1)
+		system("rmmod zram");
+
+	TEST_CLEANUP;
+	tst_exit();	
+}
+
+void print(char *string)
+{
+	FILE *fp;
+	char buf[BUFSIZ], value[BUFSIZ];
+
+	sprintf(buf, "%s/%s", PATH_ZRAM, string);
+	fp = fopen(buf, "r");
+	if (fp == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fopen %s", buf);
+
+	if (fgets(value, BUFSIZ, fp) == NULL)
+		tst_brkm(TBROK|TERRNO, cleanup, "fgets %s", buf);
+	value[strlen(value) - 1] = '\0';
+	fclose(fp);
+
+	tst_resm(TINFO, "%s is %s", buf, value);
+}
+
+void dump_info(void)
+{
+	print("initstate");
+	print("compr_data_size");
+	print("orig_data_size");
+	print("disksize");
+	print("mem_used_total");
+	print("num_reads");
+	print("num_writes");
+	print("zero_pages");
+}
-- 
1.7.3.2


[-- Attachment #3: Type: text/plain, Size: 290 bytes --]

------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2011-01-19  9:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1064791416.56186.1295424761697.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
2011-01-19  8:12 ` [LTP] [PATCH] zram01: add a new test for zram feature CAI Qian
2011-01-19  9:07   ` Garrett Cooper
     [not found] <82849215.10223.1292833893533.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com>
2010-12-20  8:31 ` CAI Qian
2010-12-30 10:38   ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.