* [LTP] [PATCH 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03
@ 2015-05-07 7:35 Xiaoguang Wang
2015-05-07 7:35 ` [LTP] [PATCH 2/2] device-drivers/zram/zram03: cleanup Xiaoguang Wang
0 siblings, 1 reply; 6+ messages in thread
From: Xiaoguang Wang @ 2015-05-07 7:35 UTC (permalink / raw)
To: ltp-list
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
runtest/mm | 2 -
testcases/kernel/device-drivers/zram/zram03.c | 225 ++++++++++++++++++++++++++
testcases/kernel/mem/zram/Makefile | 22 ---
testcases/kernel/mem/zram/zram01.c | 225 --------------------------
4 files changed, 225 insertions(+), 249 deletions(-)
create mode 100644 testcases/kernel/device-drivers/zram/zram03.c
delete mode 100644 testcases/kernel/mem/zram/Makefile
delete mode 100644 testcases/kernel/mem/zram/zram01.c
diff --git a/runtest/mm b/runtest/mm
index 031d766..c7eafa8 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -96,8 +96,6 @@ vma02 vma02
vma03 vma03
vma04 vma04
-zram01 zram01
-
overcommit_memory01 overcommit_memory
overcommit_memory02 overcommit_memory -R 0
overcommit_memory03 overcommit_memory -R 30
diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c
new file mode 100644
index 0000000..a5abb38
--- /dev/null
+++ b/testcases/kernel/device-drivers/zram/zram03.c
@@ -0,0 +1,225 @@
+/*
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "test.h"
+
+char *TCID = "zram01";
+int TST_TOTAL = 1;
+
+#define PATH_ZRAM "/sys/block/zram0"
+#define SIZE (512 * 1024 * 1024L)
+#define DEVICE "/dev/zram0"
+
+static int modprobe;
+
+static void set_disksize(void);
+static void write_device(void);
+static void verify_device(void);
+static void reset(void);
+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;
+
+ tst_parse_opts(argc, argv, NULL, NULL);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ set_disksize();
+
+ write_device();
+ dump_info();
+ verify_device();
+
+ reset();
+ dump_info();
+ }
+ cleanup();
+ tst_exit();
+}
+
+static void set_disksize(void)
+{
+ int fd;
+ char size[BUFSIZ];
+
+ tst_resm(TINFO, "create a zram device with %ld 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, "%ld", SIZE);
+ if (write(fd, size, strlen(size)) != strlen(size))
+ tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
+ PATH_ZRAM "/disksize");
+ close(fd);
+}
+
+static void write_device(void)
+{
+ int fd;
+ char *s;
+
+ 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_SHARED, fd, 0);
+ if (s == MAP_FAILED)
+ tst_brkm(TBROK | TERRNO, cleanup, "mmap");
+
+ tst_resm(TINFO, "write all the memory.");
+ memset(s, 'a', SIZE - 1);
+ s[SIZE - 1] = '\0';
+
+ if (munmap(s, SIZE) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "munmap");
+
+ close(fd);
+}
+
+static void verify_device(void)
+{
+ int fd;
+ long i, fail;
+ char *s;
+
+ tst_resm(TINFO, "verify contents from device.");
+ fd = open(DEVICE, O_RDONLY);
+ if (fd == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
+ s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (s == MAP_FAILED)
+ tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
+
+ i = 0;
+ fail = 0;
+ while (s[i] && i < SIZE - 1) {
+ if (s[i] != 'a')
+ fail++;
+ i++;
+ }
+ if (i != SIZE - 1)
+ tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
+ SIZE - 1, i);
+ else if (s[i] != '\0')
+ tst_resm(TFAIL, "zram device seems not null terminated");
+ if (fail)
+ tst_resm(TFAIL, "%ld failed bytes found.", fail);
+ if (munmap(s, SIZE) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
+
+ close(fd);
+}
+
+static void reset(void)
+{
+ int fd;
+
+ 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);
+}
+
+static void setup(void)
+{
+ int retried = 0;
+
+ tst_require_root(NULL);
+
+retry:
+ if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
+ if (errno == ENOENT) {
+ if (retried)
+ tst_brkm(TCONF, NULL,
+ "system has no zram device.");
+ system("modprobe zram");
+ modprobe = 1;
+ retried = 1;
+ goto retry;
+ } else
+ tst_brkm(TBROK | TERRNO, NULL, "access");
+ }
+
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+ if (modprobe == 1)
+ system("rmmod zram");
+}
+
+static 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);
+}
+
+static 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");
+}
diff --git a/testcases/kernel/mem/zram/Makefile b/testcases/kernel/mem/zram/Makefile
deleted file mode 100644
index fb4818f..0000000
--- a/testcases/kernel/mem/zram/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
deleted file mode 100644
index a5abb38..0000000
--- a/testcases/kernel/mem/zram/zram01.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * 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 <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include "test.h"
-
-char *TCID = "zram01";
-int TST_TOTAL = 1;
-
-#define PATH_ZRAM "/sys/block/zram0"
-#define SIZE (512 * 1024 * 1024L)
-#define DEVICE "/dev/zram0"
-
-static int modprobe;
-
-static void set_disksize(void);
-static void write_device(void);
-static void verify_device(void);
-static void reset(void);
-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;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- set_disksize();
-
- write_device();
- dump_info();
- verify_device();
-
- reset();
- dump_info();
- }
- cleanup();
- tst_exit();
-}
-
-static void set_disksize(void)
-{
- int fd;
- char size[BUFSIZ];
-
- tst_resm(TINFO, "create a zram device with %ld 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, "%ld", SIZE);
- if (write(fd, size, strlen(size)) != strlen(size))
- tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
- PATH_ZRAM "/disksize");
- close(fd);
-}
-
-static void write_device(void)
-{
- int fd;
- char *s;
-
- 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_SHARED, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
-
- tst_resm(TINFO, "write all the memory.");
- memset(s, 'a', SIZE - 1);
- s[SIZE - 1] = '\0';
-
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "munmap");
-
- close(fd);
-}
-
-static void verify_device(void)
-{
- int fd;
- long i, fail;
- char *s;
-
- tst_resm(TINFO, "verify contents from device.");
- fd = open(DEVICE, O_RDONLY);
- if (fd == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
- s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
-
- i = 0;
- fail = 0;
- while (s[i] && i < SIZE - 1) {
- if (s[i] != 'a')
- fail++;
- i++;
- }
- if (i != SIZE - 1)
- tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
- SIZE - 1, i);
- else if (s[i] != '\0')
- tst_resm(TFAIL, "zram device seems not null terminated");
- if (fail)
- tst_resm(TFAIL, "%ld failed bytes found.", fail);
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
-
- close(fd);
-}
-
-static void reset(void)
-{
- int fd;
-
- 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);
-}
-
-static void setup(void)
-{
- int retried = 0;
-
- tst_require_root(NULL);
-
-retry:
- if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
- if (errno == ENOENT) {
- if (retried)
- tst_brkm(TCONF, NULL,
- "system has no zram device.");
- system("modprobe zram");
- modprobe = 1;
- retried = 1;
- goto retry;
- } else
- tst_brkm(TBROK | TERRNO, NULL, "access");
- }
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
- if (modprobe == 1)
- system("rmmod zram");
-}
-
-static 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);
-}
-
-static 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.8.3.1
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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] device-drivers/zram/zram03: cleanup
2015-05-07 7:35 [LTP] [PATCH 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03 Xiaoguang Wang
@ 2015-05-07 7:35 ` Xiaoguang Wang
2015-05-12 11:37 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Xiaoguang Wang @ 2015-05-07 7:35 UTC (permalink / raw)
To: ltp-list
Use SAFE_MACROS to simplify this test case, and add a 'TPASS' notification.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
runtest/kernel_misc | 1 +
testcases/kernel/device-drivers/zram/.gitignore | 1 +
testcases/kernel/device-drivers/zram/Makefile | 2 +-
testcases/kernel/device-drivers/zram/zram03.c | 102 ++++++++++--------------
4 files changed, 44 insertions(+), 62 deletions(-)
create mode 100644 testcases/kernel/device-drivers/zram/.gitignore
diff --git a/runtest/kernel_misc b/runtest/kernel_misc
index 7615c15..a574802 100644
--- a/runtest/kernel_misc
+++ b/runtest/kernel_misc
@@ -11,3 +11,4 @@ rcu_torture rcu_torture.sh
lock_torture lock_torture.sh
zram01 zram01.sh
zram02 zram02.sh
+zram03 zram03
diff --git a/testcases/kernel/device-drivers/zram/.gitignore b/testcases/kernel/device-drivers/zram/.gitignore
new file mode 100644
index 0000000..7d54f60
--- /dev/null
+++ b/testcases/kernel/device-drivers/zram/.gitignore
@@ -0,0 +1 @@
+/zram03
diff --git a/testcases/kernel/device-drivers/zram/Makefile b/testcases/kernel/device-drivers/zram/Makefile
index 0d73f66..5077cf4 100644
--- a/testcases/kernel/device-drivers/zram/Makefile
+++ b/testcases/kernel/device-drivers/zram/Makefile
@@ -17,6 +17,6 @@
top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-INSTALL_TARGETS := *.sh
+INSTALL_TARGETS := *.sh zram03
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c
index a5abb38..8448234 100644
--- a/testcases/kernel/device-drivers/zram/zram03.c
+++ b/testcases/kernel/device-drivers/zram/zram03.c
@@ -23,6 +23,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
+
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -31,7 +32,9 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+
#include "test.h"
+#include "safe_macros.h"
char *TCID = "zram01";
int TST_TOTAL = 1;
@@ -81,15 +84,10 @@ static void set_disksize(void)
char size[BUFSIZ];
tst_resm(TINFO, "create a zram device with %ld bytes in size.", SIZE);
- fd = open(PATH_ZRAM "/disksize", O_WRONLY);
- if (fd == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "open %s",
- PATH_ZRAM "/disksize");
+ fd = SAFE_OPEN(cleanup, PATH_ZRAM "/disksize", O_WRONLY);
sprintf(size, "%ld", SIZE);
- if (write(fd, size, strlen(size)) != strlen(size))
- tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
- PATH_ZRAM "/disksize");
- close(fd);
+ SAFE_WRITE(cleanup, 1, fd, size, strlen(size));
+ SAFE_CLOSE(cleanup, fd);
}
static void write_device(void)
@@ -97,56 +95,48 @@ static void write_device(void)
int fd;
char *s;
- 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_SHARED, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
+ tst_resm(TINFO, "map this zram device into memory.");
+ fd = SAFE_OPEN(cleanup, DEVICE, O_RDWR);
+ s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
tst_resm(TINFO, "write all the memory.");
memset(s, 'a', SIZE - 1);
s[SIZE - 1] = '\0';
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "munmap");
-
- close(fd);
+ SAFE_MUNMAP(cleanup, s, SIZE);
+ SAFE_CLOSE(cleanup, fd);
}
static void verify_device(void)
{
int fd;
- long i, fail;
+ long i = 0, fail = 0;
char *s;
tst_resm(TINFO, "verify contents from device.");
- fd = open(DEVICE, O_RDONLY);
- if (fd == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
- s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
-
- i = 0;
- fail = 0;
+ fd = SAFE_OPEN(cleanup, DEVICE, O_RDONLY);
+ s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+
while (s[i] && i < SIZE - 1) {
if (s[i] != 'a')
fail++;
i++;
}
- if (i != SIZE - 1)
+ if (i != SIZE - 1) {
tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
SIZE - 1, i);
- else if (s[i] != '\0')
+ } else if (s[i] != '\0') {
tst_resm(TFAIL, "zram device seems not null terminated");
- if (fail)
+ } else if (fail) {
tst_resm(TFAIL, "%ld failed bytes found.", fail);
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
+ } else {
+ tst_resm(TPASS, "data read from zram device is consistent "
+ "with those are written");
+ }
- close(fd);
+ SAFE_MUNMAP(cleanup, s, SIZE);
+ SAFE_CLOSE(cleanup, fd);
}
static void reset(void)
@@ -154,14 +144,9 @@ static void reset(void)
int fd;
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);
+ fd = SAFE_OPEN(cleanup, PATH_ZRAM "/reset", O_WRONLY);
+ SAFE_WRITE(cleanup, 1, fd, "1", 1);
+ SAFE_CLOSE(cleanup, fd);
}
static void setup(void)
@@ -171,12 +156,16 @@ static void setup(void)
tst_require_root(NULL);
retry:
- if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
+ if (access(PATH_ZRAM, F_OK) == -1) {
if (errno == ENOENT) {
- if (retried)
+ if (retried) {
tst_brkm(TCONF, NULL,
"system has no zram device.");
- system("modprobe zram");
+ }
+ if (system("modprobe zram") == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "system(modprobe zram) failed");
+ }
modprobe = 1;
retried = 1;
goto retry;
@@ -190,26 +179,17 @@ retry:
static void cleanup(void)
{
- if (modprobe == 1)
- system("rmmod zram");
+ if (modprobe == 1 && system("rmmod zram") == -1)
+ tst_resm(TWARN | TERRNO, "system(rmmod zram) failed");
}
static 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);
+ char filename[BUFSIZ], value[BUFSIZ];
- tst_resm(TINFO, "%s is %s", buf, value);
+ sprintf(filename, "%s/%s", PATH_ZRAM, string);
+ SAFE_FILE_SCANF(cleanup, filename, "%s", value);
+ tst_resm(TINFO, "%s is %s", filename, value);
}
static void dump_info(void)
--
1.8.3.1
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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] device-drivers/zram/zram03: cleanup
2015-05-07 7:35 ` [LTP] [PATCH 2/2] device-drivers/zram/zram03: cleanup Xiaoguang Wang
@ 2015-05-12 11:37 ` Cyril Hrubis
2015-05-15 9:11 ` [LTP] [PATCH v2 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03 Xiaoguang Wang
0 siblings, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2015-05-12 11:37 UTC (permalink / raw)
To: Xiaoguang Wang; +Cc: ltp-list
Hi!
> --- a/runtest/kernel_misc
> +++ b/runtest/kernel_misc
> @@ -11,3 +11,4 @@ rcu_torture rcu_torture.sh
> lock_torture lock_torture.sh
> zram01 zram01.sh
> zram02 zram02.sh
> +zram03 zram03
> diff --git a/testcases/kernel/device-drivers/zram/.gitignore b/testcases/kernel/device-drivers/zram/.gitignore
> new file mode 100644
> index 0000000..7d54f60
> --- /dev/null
> +++ b/testcases/kernel/device-drivers/zram/.gitignore
> @@ -0,0 +1 @@
> +/zram03
> diff --git a/testcases/kernel/device-drivers/zram/Makefile b/testcases/kernel/device-drivers/zram/Makefile
> index 0d73f66..5077cf4 100644
> --- a/testcases/kernel/device-drivers/zram/Makefile
> +++ b/testcases/kernel/device-drivers/zram/Makefile
> @@ -17,6 +17,6 @@
> top_srcdir ?= ../../../..
> include $(top_srcdir)/include/mk/testcases.mk
>
> -INSTALL_TARGETS := *.sh
> +INSTALL_TARGETS := *.sh zram03
Hmm, shouldn't these two changes be rather part of the previous patch?
> include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c
> index a5abb38..8448234 100644
> --- a/testcases/kernel/device-drivers/zram/zram03.c
> +++ b/testcases/kernel/device-drivers/zram/zram03.c
> @@ -23,6 +23,7 @@
> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> * 02110-1301, USA.
> */
> +
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <sys/mman.h>
> @@ -31,7 +32,9 @@
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> +
> #include "test.h"
> +#include "safe_macros.h"
>
> char *TCID = "zram01";
> int TST_TOTAL = 1;
> @@ -81,15 +84,10 @@ static void set_disksize(void)
> char size[BUFSIZ];
>
> tst_resm(TINFO, "create a zram device with %ld bytes in size.", SIZE);
> - fd = open(PATH_ZRAM "/disksize", O_WRONLY);
> - if (fd == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "open %s",
> - PATH_ZRAM "/disksize");
> + fd = SAFE_OPEN(cleanup, PATH_ZRAM "/disksize", O_WRONLY);
> sprintf(size, "%ld", SIZE);
> - if (write(fd, size, strlen(size)) != strlen(size))
> - tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
> - PATH_ZRAM "/disksize");
> - close(fd);
> + SAFE_WRITE(cleanup, 1, fd, size, strlen(size));
> + SAFE_CLOSE(cleanup, fd);
What about:
SAFE_FILE_PRINTF(cleanup, PATH_ZRAM "/disksize", "%ld", SIZE);
> }
>
> static void write_device(void)
> @@ -97,56 +95,48 @@ static void write_device(void)
> int fd;
> char *s;
>
> - 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_SHARED, fd, 0);
> - if (s == MAP_FAILED)
> - tst_brkm(TBROK | TERRNO, cleanup, "mmap");
> + tst_resm(TINFO, "map this zram device into memory.");
> + fd = SAFE_OPEN(cleanup, DEVICE, O_RDWR);
> + s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ | PROT_WRITE,
> + MAP_SHARED, fd, 0);
>
> tst_resm(TINFO, "write all the memory.");
> memset(s, 'a', SIZE - 1);
> s[SIZE - 1] = '\0';
>
> - if (munmap(s, SIZE) == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "munmap");
> -
> - close(fd);
> + SAFE_MUNMAP(cleanup, s, SIZE);
> + SAFE_CLOSE(cleanup, fd);
> }
>
> static void verify_device(void)
> {
> int fd;
> - long i, fail;
> + long i = 0, fail = 0;
> char *s;
>
> tst_resm(TINFO, "verify contents from device.");
> - fd = open(DEVICE, O_RDONLY);
> - if (fd == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
> - s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
> - if (s == MAP_FAILED)
> - tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
> -
> - i = 0;
> - fail = 0;
> + fd = SAFE_OPEN(cleanup, DEVICE, O_RDONLY);
> + s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
> +
> while (s[i] && i < SIZE - 1) {
> if (s[i] != 'a')
> fail++;
> i++;
> }
> - if (i != SIZE - 1)
> + if (i != SIZE - 1) {
> tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
> SIZE - 1, i);
> - else if (s[i] != '\0')
> + } else if (s[i] != '\0') {
> tst_resm(TFAIL, "zram device seems not null terminated");
> - if (fail)
> + } else if (fail) {
> tst_resm(TFAIL, "%ld failed bytes found.", fail);
> - if (munmap(s, SIZE) == -1)
> - tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
> + } else {
> + tst_resm(TPASS, "data read from zram device is consistent "
> + "with those are written");
> + }
>
> - close(fd);
> + SAFE_MUNMAP(cleanup, s, SIZE);
> + SAFE_CLOSE(cleanup, fd);
> }
>
> static void reset(void)
> @@ -154,14 +144,9 @@ static void reset(void)
> int fd;
>
> 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);
> + fd = SAFE_OPEN(cleanup, PATH_ZRAM "/reset", O_WRONLY);
> + SAFE_WRITE(cleanup, 1, fd, "1", 1);
> + SAFE_CLOSE(cleanup, fd);
SAFE_FILE_PRINTF() here as well.
> static void setup(void)
> @@ -171,12 +156,16 @@ static void setup(void)
> tst_require_root(NULL);
>
> retry:
> - if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
> + if (access(PATH_ZRAM, F_OK) == -1) {
> if (errno == ENOENT) {
> - if (retried)
> + if (retried) {
> tst_brkm(TCONF, NULL,
> "system has no zram device.");
> - system("modprobe zram");
> + }
> + if (system("modprobe zram") == -1) {
> + tst_brkm(TBROK | TERRNO, cleanup,
> + "system(modprobe zram) failed");
> + }
> modprobe = 1;
> retried = 1;
> goto retry;
> @@ -190,26 +179,17 @@ retry:
>
> static void cleanup(void)
> {
> - if (modprobe == 1)
> - system("rmmod zram");
> + if (modprobe == 1 && system("rmmod zram") == -1)
> + tst_resm(TWARN | TERRNO, "system(rmmod zram) failed");
> }
>
> static 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);
> + char filename[BUFSIZ], value[BUFSIZ];
>
> - tst_resm(TINFO, "%s is %s", buf, value);
> + sprintf(filename, "%s/%s", PATH_ZRAM, string);
> + SAFE_FILE_SCANF(cleanup, filename, "%s", value);
> + tst_resm(TINFO, "%s is %s", filename, value);
> }
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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 v2 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03
2015-05-12 11:37 ` Cyril Hrubis
@ 2015-05-15 9:11 ` Xiaoguang Wang
2015-05-15 9:12 ` [LTP] [PATCH v2 2/2] device-drivers/zram/zram03: cleanup Xiaoguang Wang
0 siblings, 1 reply; 6+ messages in thread
From: Xiaoguang Wang @ 2015-05-15 9:11 UTC (permalink / raw)
To: ltp-list
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
runtest/kernel_misc | 1 +
runtest/mm | 2 -
testcases/kernel/device-drivers/zram/.gitignore | 1 +
testcases/kernel/device-drivers/zram/Makefile | 2 +-
testcases/kernel/device-drivers/zram/zram03.c | 225 ++++++++++++++++++++++++
testcases/kernel/mem/.gitignore | 1 -
testcases/kernel/mem/zram/Makefile | 22 ---
testcases/kernel/mem/zram/zram01.c | 225 ------------------------
8 files changed, 228 insertions(+), 251 deletions(-)
create mode 100644 testcases/kernel/device-drivers/zram/.gitignore
create mode 100644 testcases/kernel/device-drivers/zram/zram03.c
delete mode 100644 testcases/kernel/mem/zram/Makefile
delete mode 100644 testcases/kernel/mem/zram/zram01.c
diff --git a/runtest/kernel_misc b/runtest/kernel_misc
index 7615c15..a574802 100644
--- a/runtest/kernel_misc
+++ b/runtest/kernel_misc
@@ -11,3 +11,4 @@ rcu_torture rcu_torture.sh
lock_torture lock_torture.sh
zram01 zram01.sh
zram02 zram02.sh
+zram03 zram03
diff --git a/runtest/mm b/runtest/mm
index 031d766..c7eafa8 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -96,8 +96,6 @@ vma02 vma02
vma03 vma03
vma04 vma04
-zram01 zram01
-
overcommit_memory01 overcommit_memory
overcommit_memory02 overcommit_memory -R 0
overcommit_memory03 overcommit_memory -R 30
diff --git a/testcases/kernel/device-drivers/zram/.gitignore b/testcases/kernel/device-drivers/zram/.gitignore
new file mode 100644
index 0000000..7d54f60
--- /dev/null
+++ b/testcases/kernel/device-drivers/zram/.gitignore
@@ -0,0 +1 @@
+/zram03
diff --git a/testcases/kernel/device-drivers/zram/Makefile b/testcases/kernel/device-drivers/zram/Makefile
index 0d73f66..5077cf4 100644
--- a/testcases/kernel/device-drivers/zram/Makefile
+++ b/testcases/kernel/device-drivers/zram/Makefile
@@ -17,6 +17,6 @@
top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-INSTALL_TARGETS := *.sh
+INSTALL_TARGETS := *.sh zram03
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c
new file mode 100644
index 0000000..a5abb38
--- /dev/null
+++ b/testcases/kernel/device-drivers/zram/zram03.c
@@ -0,0 +1,225 @@
+/*
+ * 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 <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include "test.h"
+
+char *TCID = "zram01";
+int TST_TOTAL = 1;
+
+#define PATH_ZRAM "/sys/block/zram0"
+#define SIZE (512 * 1024 * 1024L)
+#define DEVICE "/dev/zram0"
+
+static int modprobe;
+
+static void set_disksize(void);
+static void write_device(void);
+static void verify_device(void);
+static void reset(void);
+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;
+
+ tst_parse_opts(argc, argv, NULL, NULL);
+
+ setup();
+
+ for (lc = 0; TEST_LOOPING(lc); lc++) {
+ tst_count = 0;
+
+ set_disksize();
+
+ write_device();
+ dump_info();
+ verify_device();
+
+ reset();
+ dump_info();
+ }
+ cleanup();
+ tst_exit();
+}
+
+static void set_disksize(void)
+{
+ int fd;
+ char size[BUFSIZ];
+
+ tst_resm(TINFO, "create a zram device with %ld 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, "%ld", SIZE);
+ if (write(fd, size, strlen(size)) != strlen(size))
+ tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
+ PATH_ZRAM "/disksize");
+ close(fd);
+}
+
+static void write_device(void)
+{
+ int fd;
+ char *s;
+
+ 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_SHARED, fd, 0);
+ if (s == MAP_FAILED)
+ tst_brkm(TBROK | TERRNO, cleanup, "mmap");
+
+ tst_resm(TINFO, "write all the memory.");
+ memset(s, 'a', SIZE - 1);
+ s[SIZE - 1] = '\0';
+
+ if (munmap(s, SIZE) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "munmap");
+
+ close(fd);
+}
+
+static void verify_device(void)
+{
+ int fd;
+ long i, fail;
+ char *s;
+
+ tst_resm(TINFO, "verify contents from device.");
+ fd = open(DEVICE, O_RDONLY);
+ if (fd == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
+ s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+ if (s == MAP_FAILED)
+ tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
+
+ i = 0;
+ fail = 0;
+ while (s[i] && i < SIZE - 1) {
+ if (s[i] != 'a')
+ fail++;
+ i++;
+ }
+ if (i != SIZE - 1)
+ tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
+ SIZE - 1, i);
+ else if (s[i] != '\0')
+ tst_resm(TFAIL, "zram device seems not null terminated");
+ if (fail)
+ tst_resm(TFAIL, "%ld failed bytes found.", fail);
+ if (munmap(s, SIZE) == -1)
+ tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
+
+ close(fd);
+}
+
+static void reset(void)
+{
+ int fd;
+
+ 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);
+}
+
+static void setup(void)
+{
+ int retried = 0;
+
+ tst_require_root(NULL);
+
+retry:
+ if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
+ if (errno == ENOENT) {
+ if (retried)
+ tst_brkm(TCONF, NULL,
+ "system has no zram device.");
+ system("modprobe zram");
+ modprobe = 1;
+ retried = 1;
+ goto retry;
+ } else
+ tst_brkm(TBROK | TERRNO, NULL, "access");
+ }
+
+ tst_sig(FORK, DEF_HANDLER, cleanup);
+ TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+ if (modprobe == 1)
+ system("rmmod zram");
+}
+
+static 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);
+}
+
+static 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");
+}
diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore
index c531563..b8888d3 100644
--- a/testcases/kernel/mem/.gitignore
+++ b/testcases/kernel/mem/.gitignore
@@ -74,4 +74,3 @@
/vma/vma04
/vmtests/data_space
/vmtests/stack_space
-/zram/zram01
diff --git a/testcases/kernel/mem/zram/Makefile b/testcases/kernel/mem/zram/Makefile
deleted file mode 100644
index fb4818f..0000000
--- a/testcases/kernel/mem/zram/Makefile
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
deleted file mode 100644
index a5abb38..0000000
--- a/testcases/kernel/mem/zram/zram01.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * 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 <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include "test.h"
-
-char *TCID = "zram01";
-int TST_TOTAL = 1;
-
-#define PATH_ZRAM "/sys/block/zram0"
-#define SIZE (512 * 1024 * 1024L)
-#define DEVICE "/dev/zram0"
-
-static int modprobe;
-
-static void set_disksize(void);
-static void write_device(void);
-static void verify_device(void);
-static void reset(void);
-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;
-
- tst_parse_opts(argc, argv, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- set_disksize();
-
- write_device();
- dump_info();
- verify_device();
-
- reset();
- dump_info();
- }
- cleanup();
- tst_exit();
-}
-
-static void set_disksize(void)
-{
- int fd;
- char size[BUFSIZ];
-
- tst_resm(TINFO, "create a zram device with %ld 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, "%ld", SIZE);
- if (write(fd, size, strlen(size)) != strlen(size))
- tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
- PATH_ZRAM "/disksize");
- close(fd);
-}
-
-static void write_device(void)
-{
- int fd;
- char *s;
-
- 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_SHARED, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
-
- tst_resm(TINFO, "write all the memory.");
- memset(s, 'a', SIZE - 1);
- s[SIZE - 1] = '\0';
-
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "munmap");
-
- close(fd);
-}
-
-static void verify_device(void)
-{
- int fd;
- long i, fail;
- char *s;
-
- tst_resm(TINFO, "verify contents from device.");
- fd = open(DEVICE, O_RDONLY);
- if (fd == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
- s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
-
- i = 0;
- fail = 0;
- while (s[i] && i < SIZE - 1) {
- if (s[i] != 'a')
- fail++;
- i++;
- }
- if (i != SIZE - 1)
- tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
- SIZE - 1, i);
- else if (s[i] != '\0')
- tst_resm(TFAIL, "zram device seems not null terminated");
- if (fail)
- tst_resm(TFAIL, "%ld failed bytes found.", fail);
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
-
- close(fd);
-}
-
-static void reset(void)
-{
- int fd;
-
- 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);
-}
-
-static void setup(void)
-{
- int retried = 0;
-
- tst_require_root(NULL);
-
-retry:
- if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
- if (errno == ENOENT) {
- if (retried)
- tst_brkm(TCONF, NULL,
- "system has no zram device.");
- system("modprobe zram");
- modprobe = 1;
- retried = 1;
- goto retry;
- } else
- tst_brkm(TBROK | TERRNO, NULL, "access");
- }
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
- TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
- if (modprobe == 1)
- system("rmmod zram");
-}
-
-static 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);
-}
-
-static 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.8.2.1
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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 v2 2/2] device-drivers/zram/zram03: cleanup
2015-05-15 9:11 ` [LTP] [PATCH v2 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03 Xiaoguang Wang
@ 2015-05-15 9:12 ` Xiaoguang Wang
2015-06-11 14:12 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Xiaoguang Wang @ 2015-05-15 9:12 UTC (permalink / raw)
To: ltp-list
Use SAFE_MACROS to simplify this test case, and add a 'TPASS' notification.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
testcases/kernel/device-drivers/zram/zram03.c | 104 +++++++++-----------------
1 file changed, 37 insertions(+), 67 deletions(-)
diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c
index a5abb38..9ee77dd 100644
--- a/testcases/kernel/device-drivers/zram/zram03.c
+++ b/testcases/kernel/device-drivers/zram/zram03.c
@@ -23,6 +23,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
+
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -31,7 +32,9 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+
#include "test.h"
+#include "safe_macros.h"
char *TCID = "zram01";
int TST_TOTAL = 1;
@@ -77,19 +80,8 @@ int main(int argc, char *argv[])
static void set_disksize(void)
{
- int fd;
- char size[BUFSIZ];
-
tst_resm(TINFO, "create a zram device with %ld 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, "%ld", SIZE);
- if (write(fd, size, strlen(size)) != strlen(size))
- tst_brkm(TBROK | TERRNO, cleanup, "write %s to %s", size,
- PATH_ZRAM "/disksize");
- close(fd);
+ SAFE_FILE_PRINTF(cleanup, PATH_ZRAM "/disksize", "%ld", SIZE);
}
static void write_device(void)
@@ -97,71 +89,54 @@ static void write_device(void)
int fd;
char *s;
- 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_SHARED, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "mmap");
+ tst_resm(TINFO, "map this zram device into memory.");
+ fd = SAFE_OPEN(cleanup, DEVICE, O_RDWR);
+ s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ | PROT_WRITE,
+ MAP_SHARED, fd, 0);
tst_resm(TINFO, "write all the memory.");
memset(s, 'a', SIZE - 1);
s[SIZE - 1] = '\0';
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "munmap");
-
- close(fd);
+ SAFE_MUNMAP(cleanup, s, SIZE);
+ SAFE_CLOSE(cleanup, fd);
}
static void verify_device(void)
{
int fd;
- long i, fail;
+ long i = 0, fail = 0;
char *s;
tst_resm(TINFO, "verify contents from device.");
- fd = open(DEVICE, O_RDONLY);
- if (fd == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "open %s", DEVICE);
- s = mmap(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
- if (s == MAP_FAILED)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd mmap");
-
- i = 0;
- fail = 0;
+ fd = SAFE_OPEN(cleanup, DEVICE, O_RDONLY);
+ s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+
while (s[i] && i < SIZE - 1) {
if (s[i] != 'a')
fail++;
i++;
}
- if (i != SIZE - 1)
+ if (i != SIZE - 1) {
tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
SIZE - 1, i);
- else if (s[i] != '\0')
+ } else if (s[i] != '\0') {
tst_resm(TFAIL, "zram device seems not null terminated");
- if (fail)
+ } else if (fail) {
tst_resm(TFAIL, "%ld failed bytes found.", fail);
- if (munmap(s, SIZE) == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "2nd munmap");
+ } else {
+ tst_resm(TPASS, "data read from zram device is consistent "
+ "with those are written");
+ }
- close(fd);
+ SAFE_MUNMAP(cleanup, s, SIZE);
+ SAFE_CLOSE(cleanup, fd);
}
static void reset(void)
{
- int fd;
-
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);
+ SAFE_FILE_PRINTF(cleanup, PATH_ZRAM "/reset", "1");
}
static void setup(void)
@@ -171,12 +146,16 @@ static void setup(void)
tst_require_root(NULL);
retry:
- if (access(PATH_ZRAM, R_OK | W_OK | X_OK) == -1) {
+ if (access(PATH_ZRAM, F_OK) == -1) {
if (errno == ENOENT) {
- if (retried)
+ if (retried) {
tst_brkm(TCONF, NULL,
"system has no zram device.");
- system("modprobe zram");
+ }
+ if (system("modprobe zram") == -1) {
+ tst_brkm(TBROK | TERRNO, cleanup,
+ "system(modprobe zram) failed");
+ }
modprobe = 1;
retried = 1;
goto retry;
@@ -190,26 +169,17 @@ retry:
static void cleanup(void)
{
- if (modprobe == 1)
- system("rmmod zram");
+ if (modprobe == 1 && system("rmmod zram") == -1)
+ tst_resm(TWARN | TERRNO, "system(rmmod zram) failed");
}
static 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);
+ char filename[BUFSIZ], value[BUFSIZ];
- tst_resm(TINFO, "%s is %s", buf, value);
+ sprintf(filename, "%s/%s", PATH_ZRAM, string);
+ SAFE_FILE_SCANF(cleanup, filename, "%s", value);
+ tst_resm(TINFO, "%s is %s", filename, value);
}
static void dump_info(void)
--
1.8.2.1
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
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 v2 2/2] device-drivers/zram/zram03: cleanup
2015-05-15 9:12 ` [LTP] [PATCH v2 2/2] device-drivers/zram/zram03: cleanup Xiaoguang Wang
@ 2015-06-11 14:12 ` Cyril Hrubis
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2015-06-11 14:12 UTC (permalink / raw)
To: Xiaoguang Wang; +Cc: ltp-list
Hi!
Both patches pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
_______________________________________________
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:[~2015-06-11 14:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-07 7:35 [LTP] [PATCH 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03 Xiaoguang Wang
2015-05-07 7:35 ` [LTP] [PATCH 2/2] device-drivers/zram/zram03: cleanup Xiaoguang Wang
2015-05-12 11:37 ` Cyril Hrubis
2015-05-15 9:11 ` [LTP] [PATCH v2 1/2] kernel/mem/zram: move zram01 to kernel/device-drivers/zram/ and rename it to zram03 Xiaoguang Wang
2015-05-15 9:12 ` [LTP] [PATCH v2 2/2] device-drivers/zram/zram03: cleanup Xiaoguang Wang
2015-06-11 14:12 ` 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.