1 #!/bin/ksh -p
   2 #
   3 # CDDL HEADER START
   4 #
   5 # The contents of this file are subject to the terms of the
   6 # Common Development and Distribution License (the "License").
   7 # You may not use this file except in compliance with the License.
   8 #
   9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10 # or http://www.opensolaris.org/os/licensing.
  11 # See the License for the specific language governing permissions
  12 # and limitations under the License.
  13 #
  14 # When distributing Covered Code, include this CDDL HEADER in each
  15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16 # If applicable, add the following below this CDDL HEADER, with the
  17 # fields enclosed by brackets "[]" replaced with your own identifying
  18 # information: Portions Copyright [yyyy] [name of copyright owner]
  19 #
  20 # CDDL HEADER END
  21 #
  22 
  23 # Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  24 
  25 #
  26 # mmap test purpose
  27 #
  28 # __stc_assertion_start
  29 #
  30 # ID: mmap_007
  31 #
  32 # DESCRIPTION:
  33 #       Verify compatibility between open(O_RDWR) &
  34 #         mmap(PROT_READ|PROT_WRITE, MAP_PRIVATE)
  35 #
  36 # STRATEGY:
  37 #       1. run "mount -F smbfs //server/public /export/mnt"
  38 #       2. mkfile in smbfs & local dir, with the same size
  39 #       3. open(O_RDWR) & mmap(PROT_READ|PROT_WRITE, MAP_PRIVATE) the smbfs file
  40 #       4. read data from the local file and write into the smbfs file
  41 #       4. diff the smbfs file before written & after written
  42 # KEYWORDS:
  43 #
  44 # TESTABILITY: explicit
  45 #
  46 # __stc_assertion_end
  47 #
  48 
  49 . $STF_SUITE/include/libtest.ksh
  50 
  51 tc_id="mmap007"
  52 tc_desc=" Verify compatibility between open(O_RDWR) & mmap(rw, p)"
  53 print_test_case $tc_id - $tc_desc
  54 
  55 if [[ $STC_CIFS_CLIENT_DEBUG == 1 ]] || \
  56         [[ *:${STC_CIFS_CLIENT_DEBUG}:* == *:$tc_id:* ]]; then
  57     set -x
  58 fi
  59 
  60 size=1111k
  61 
  62 server=$(server_name) || return
  63 
  64 testdir=$TDIR
  65 mnt_point=$TMNT
  66 
  67 testdir_init $testdir
  68 smbmount_clean $mnt_point
  69 smbmount_init $mnt_point
  70 
  71 test_file="tmp007"
  72 
  73 cmd="mount -F smbfs //$TUSER:$TPASS@$server/public $mnt_point"
  74 cti_execute -i '' FAIL $cmd
  75 if (($?!=0)); then
  76         cti_fail "FAIL: $cmd"
  77         return
  78 else
  79         cti_report "PASS: $cmd"
  80 fi
  81 
  82 # make a smbfs file
  83 cmd="mkfile_mmap -n $size -f ${mnt_point}/${test_file}"
  84 cti_execute FAIL $cmd
  85 if (($?!=0)); then
  86         cti_fail "FAIL: $cmd"
  87         return
  88 else
  89         cti_report "PASS: $cmd"
  90 fi
  91 
  92 # make a local file, with the same size
  93 cmd="mkfile_mmap -n $size -f ${testdir}/${test_file}"
  94 cti_execute FAIL $cmd
  95 if (($?!=0)); then
  96         cti_fail "FAIL: $cmd"
  97         return
  98 else
  99         cti_report "PASS: $cmd"
 100 fi
 101 
 102 # backup the sum before write the smbfs file
 103 cti_execute_cmd "sum ${mnt_point}/${test_file}"
 104 read sum1 cnt1 junk < cti_stdout
 105 cti_report "before sum $sum1 $cnt1"
 106 
 107 # open(O_RDWR) & mmap(PROT_READ|PROT_WRITE, MAP_PRIVATE) the smbfs file,
 108 # verify if can write it
 109 cmd="prot_mmap -o r rw -m rs rwp -f \
 110   ${testdir}/${test_file} ${mnt_point}/${test_file}"
 111 cti_execute FAIL $cmd
 112 if (($?!=0)); then
 113         cti_fail "FAIL: $cmd"
 114         return
 115 else
 116         cti_report "PASS: $cmd"
 117 fi
 118 
 119 # recalc the sum of the smbfs file
 120 cti_execute_cmd "sum ${mnt_point}/${test_file}"
 121 read sum2 cnt2 junk < cti_stdout
 122 cti_report "after sum $sum2 $cnt2"
 123 
 124 # verify the the smbfs file not changed
 125 if [[ $sum1 != $sum2 ]] ; then
 126         cti_fail "FAIL: the smbfs file changed"
 127         return
 128 else
 129         cti_report "PASS: the smbfs file not changed"
 130 fi
 131 
 132 cti_execute_cmd "rm -rf $testdir/*"
 133 cti_execute_cmd "rm -f ${mnt_point}/${test_file}"
 134 
 135 smbmount_clean $mnt_point
 136 
 137 cti_pass "${tc_id}: PASS"