zram test is broken for the following two issues:
* At the end of test, error message printed:
ERROR: Module zram is in use
this is because the mapped area s is not freed yet. This patch unmaps
s before calling rmmod zram.
* Sometimes `if (access() && errno == ENOENT)' doesn't work due to errno
not correctly captured. I have to split them into 2 if-conditions to
make it work.
Signed-off-by: Caspar Zhang <[email protected]>
---
testcases/kernel/mem/zram/zram01.c | 25 ++++++++++++++++++-------
1 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/testcases/kernel/mem/zram/zram01.c b/testcases/kernel/mem/zram/zram01.c
index e0a0361..644fab6 100644
--- a/testcases/kernel/mem/zram/zram01.c
+++ b/testcases/kernel/mem/zram/zram01.c
@@ -37,6 +37,7 @@
char *TCID = "zram01";
int TST_TOTAL = 1;
int modprobe = 0;
+void *s;
#define PATH_ZRAM "/sys/block/zram0"
#define SIZE (512 * 1024 * 1024)
@@ -52,7 +53,6 @@ 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)
@@ -108,12 +108,18 @@ 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
+ if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1) {
+ if (errno == ENOENT) {
+ system("modprobe zram");
+ modprobe = 1;
+ if (access(PATH_ZRAM, R_OK|W_OK|X_OK) == -1) {
+ if (errno == ENOENT)
+ tst_brkm(TCONF, NULL,
+ "system has no zram device.");
+ else
+ tst_brkm(TBROK|TERRNO, NULL, "access");
+ }
+ } else
tst_brkm(TBROK|TERRNO, NULL, "access");
}
tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -122,6 +128,11 @@ void setup(void)
void cleanup(void)
{
+ if (s != MAP_FAILED && s != NULL) {
+ if (munmap(s, SIZE) != 0)
+ tst_brkm(TBROK|TERRNO, NULL, "munmap");
+ usleep(10000);
+ }
if (modprobe == 1)
system("rmmod zram");
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
http://p.sf.net/sfu/rim-devcon-copy2
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list