Log Message:
-----------
* {default,thor}.conf (ALL_TESTS): include mmap test.

* progs/Makefile: invoke mmap test.

* t-mmap.sh: new script to execute mmap test.

* progs/mapper.c: simple new program to test mmap reading and
writing with copyup.

Tags:
----
LKML-branch

Modified Files:
--------------
    unionfs/regression-2.0:
        ChangeLog (r1.1.2.15 -> r1.1.2.16)
        default.conf (r1.1.2.3 -> r1.1.2.4)
        thor.conf (r1.1.2.4 -> r1.1.2.5)
    unionfs/regression-2.0/progs:
        .cvsignore (r1.1.2.1 -> r1.1.2.2)
        Makefile (r1.1.2.2 -> r1.1.2.3)

Added Files:
-----------
    unionfs/regression-2.0:
        t-mmap.sh (r1.1.2.1)
    unionfs/regression-2.0/progs:
        mapper.c (r1.1.2.1)

Revision Data
-------------
Index: default.conf
===================================================================
RCS file: /home/cvs/unionfs/unionfs/regression-2.0/Attic/default.conf,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -Lregression-2.0/default.conf -Lregression-2.0/default.conf -u -d -b -B -p 
-r1.1.2.3 -r1.1.2.4
--- regression-2.0/default.conf
+++ regression-2.0/default.conf
@@ -14,6 +14,7 @@ ALL_TESTS="
        t-lookup.sh
        t-mkdir.sh
        t-mknod.sh
+       t-mmap.sh
        t-open-unlink.sh
        t-open.sh
        t-readdir.sh
Index: ChangeLog
===================================================================
RCS file: /home/cvs/unionfs/unionfs/regression-2.0/Attic/ChangeLog,v
retrieving revision 1.1.2.15
retrieving revision 1.1.2.16
diff -Lregression-2.0/ChangeLog -Lregression-2.0/ChangeLog -u -d -b -B -p 
-r1.1.2.15 -r1.1.2.16
--- regression-2.0/ChangeLog
+++ regression-2.0/ChangeLog
@@ -1,3 +1,14 @@
+2007-05-19  Erez Zadok  <[EMAIL PROTECTED]>
+
+       * {default,thor}.conf (ALL_TESTS): include mmap test.
+
+       * progs/Makefile: invoke mmap test.
+
+       * t-mmap.sh: new script to execute mmap test.
+
+       * progs/mapper.c: simple new program to test mmap reading and
+       writing with copyup.
+
 2007-05-17  Erez Zadok  <[EMAIL PROTECTED]>
 
        * t-open-unlink.sh, t-creat-open.sh, t-branchman.sh: minor
Index: thor.conf
===================================================================
RCS file: /home/cvs/unionfs/unionfs/regression-2.0/Attic/thor.conf,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -Lregression-2.0/thor.conf -Lregression-2.0/thor.conf -u -d -b -B -p 
-r1.1.2.4 -r1.1.2.5
--- regression-2.0/thor.conf
+++ regression-2.0/thor.conf
@@ -14,6 +14,7 @@ ALL_TESTS="
        t-lookup.sh
        t-mkdir.sh
        t-mknod.sh
+       t-mmap.sh
        t-open-unlink.sh
        t-open.sh
        t-readdir.sh
--- /dev/null
+++ regression-2.0/t-mmap.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# TEST: Branches: b0,b1=ro and b0,b1
+# TEST: open(a), mmap) for reading, read, unmap, close
+# TEST: open(b), mmap for writing/copyup, read, rewrite, unmap, close
+
+source scaffold
+
+function files {
+cat <<FILES
+d $TOP_LOWER_DIR
+d $LOWER_DIR0
+d $LOWER_DIR1
+f $LOWER_DIR1/a
+f $LOWER_DIR1/b
+d $LOWER_DIR2
+d $LOWER_DIR3
+FILES
+}
+
+function afterfiles_ro {
+cat <<FILES
+d $TOP_LOWER_DIR
+d $LOWER_DIR0
+d $LOWER_DIR1
+f $LOWER_DIR1/a
+f $LOWER_DIR1/b
+d $LOWER_DIR2
+d $LOWER_DIR3
+FILES
+}
+
+function afterfiles_rw {
+cat <<FILES
+d $TOP_LOWER_DIR
+d $LOWER_DIR0
+f $LOWER_DIR0/b
+d $LOWER_DIR1
+f $LOWER_DIR1/a
+f $LOWER_DIR1/b
+d $LOWER_DIR2
+d $LOWER_DIR3
+FILES
+}
+
+# read-only mmap test
+( files ) | create_hierarchy
+mount_union "" $LOWER_DIR0 $LOWER_DIR1=ro
+./progs/mapper -r $MOUNTPOINT/a > /dev/null
+unmount_union
+echo -n "[ro] "
+( afterfiles_ro ) | check_hierarchy $TOP_LOWER_DIR
+
+# read-write mmap test
+( files ) | create_hierarchy
+mount_union "" $LOWER_DIR0 $LOWER_DIR1=ro
+./progs/mapper -w $MOUNTPOINT/b > /dev/null
+echo -n "[rw] "
+exit 123
+unmount_union
+( afterfiles_rw ) | check_hierarchy $TOP_LOWER_DIR
+
+complete_test
Index: .cvsignore
===================================================================
RCS file: /home/cvs/unionfs/unionfs/regression-2.0/progs/Attic/.cvsignore,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -Lregression-2.0/progs/.cvsignore -Lregression-2.0/progs/.cvsignore -u -d 
-b -B -p -r1.1.2.1 -r1.1.2.2
--- regression-2.0/progs/.cvsignore
+++ regression-2.0/progs/.cvsignore
@@ -6,3 +6,4 @@ truncate
 bug418
 rmdircheckinode
 rename
+mapper
Index: Makefile
===================================================================
RCS file: /home/cvs/unionfs/unionfs/regression-2.0/progs/Attic/Makefile,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -Lregression-2.0/progs/Makefile -Lregression-2.0/progs/Makefile -u -d -b 
-B -p -r1.1.2.2 -r1.1.2.3
--- regression-2.0/progs/Makefile
+++ regression-2.0/progs/Makefile
@@ -18,7 +18,8 @@
 
 CFLAGS=-g -Wall -Werror # -lefence
 MOUNTPOINT=.
-BINS=open-unlink flock-copyup fsync truncate bug418 rmdircheckinode creat-open 
rename
+BINS=open-unlink flock-copyup fsync truncate bug418 rmdircheckinode \
+       creat-open rename mapper
 
 all: $(BINS)
 
--- /dev/null
+++ regression-2.0/progs/mapper.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 1997-2007 Erez Zadok <[EMAIL PROTECTED]>
+ * Copyright (c) 2001-2007 Stony Brook University
+ *
+ * For specific licensing information, see the COPYING file distributed with
+ * this package, or get one from
+ * ftp://ftp.filesystems.org/pub/fistgen/COPYING.
+ *
+ * This Copyright notice must be kept intact and distributed with all
+ * fistgen sources INCLUDING sources generated by fistgen.
+ *
+ *
+ * File: mapper.c
+ *
+ * Usage: mapper -r file
+ * Usage: mapper -w file
+ *     -r will open file for reading only
+ *     -w will open file for reading anf writing, and will change the file
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define BASE 0
+#define SIZE 10
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((void *)-1)
+#endif
+
+void usage(void)
+{
+  fprintf(stderr, "Usage: mapper -r filename\n");
+  fprintf(stderr, "       mapper -w filename\n");
+  exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+  int fd;
+  caddr_t pa;
+  int rw_flag = -1;            /* 0=read, 1=read+write */
+  char *filename, byte;
+
+  /* check input args */
+  if (argc != 3)
+    usage();
+  if (strcmp(argv[1], "-w") == 0)
+    rw_flag = 1;
+  else if (strcmp(argv[1], "-r") == 0)
+    rw_flag = 0;
+  else
+    usage();
+
+  filename = argv[2];
+
+  /* open input file */
+  if (rw_flag)
+    fd = open(filename, O_RDWR);
+  else
+    fd = open(filename, O_RDONLY);
+  if (fd < 0) {
+    perror(filename);
+    exit(1);
+  }
+  printf("opened file %s\n", filename);
+
+  /* mmap the input file */
+  pa = mmap((caddr_t) 0,
+           SIZE,
+           (rw_flag ? (PROT_READ | PROT_WRITE) : PROT_READ),
+           MAP_SHARED,
+           fd,
+           BASE);
+  if (pa == MAP_FAILED) {
+    perror("mmap");
+    exit(1);
+  }
+  printf("file is mapped with address 0x%x\n", (u_int) pa);
+
+  /* now read the first byte of that file */
+  byte = pa[0];
+  printf("byte 0 is decimal %03d (\'%c\')\n",
+        byte, isprint(byte) ? byte : '.');
+
+  /* for a read-write test, modify the first byte */
+  if (rw_flag)
+    pa[0] += 1;
+
+  /* msync the file */
+  if (msync(pa, SIZE, MS_SYNC) < 0) {
+    perror("msync");
+    exit(1);
+  }
+  printf("file is msynchronized\n");
+
+  /* unmap the file */
+  if (munmap(pa, SIZE) < 0) {
+    perror("munmap");
+    exit(1);
+  }
+  printf("file is unmapped\n");
+
+  close(fd);
+  printf("closed file %s\n", filename);
+
+  /*
+   * Now, if we need to do a read-write test, then we reopen the file and
+   * check if the file's content (first bytes) is what we expect it to be.
+   */
+  if (!rw_flag)
+    goto out;
+  /* re-open file (readonly now) */
+  fd = open(filename, O_RDONLY);
+  if (fd < 0) {
+    perror(filename);
+    exit(1);
+  }
+  printf("re-opened file %s\n", filename);
+
+  /* re-mmap the input file */
+  pa = mmap((caddr_t) 0,
+           SIZE,
+           PROT_READ,
+           MAP_SHARED,
+           fd,
+           BASE);
+  if (pa == MAP_FAILED) {
+    perror("mmap");
+    exit(1);
+  }
+  printf("file is re-mapped with address 0x%x\n", (u_int) pa);
+  /* check if bytes match */
+  if (pa[0] != (byte+1)) {
+    fprintf(stderr,
+           "bytes mismatched in re-mapped file, old=%03d new=%03d!\n",
+           byte+1, pa[0]);
+    exit(1);
+  }
+  /* unmap the file */
+  if (munmap(pa, SIZE) < 0) {
+    perror("munmap");
+    exit(1);
+  }
+  printf("file is unmapped again\n");
+
+  close(fd);
+  printf("closed file %s again\n", filename);
+
+out:
+  exit(0);
+}
_______________________________________________
unionfs-cvs mailing list: http://unionfs.filesystems.org/
[email protected]
http://www.fsl.cs.sunysb.edu/mailman/listinfo/unionfs-cvs

Reply via email to