196c8483Yuri Pankov#!/bin/ksh -p
296c8483Yuri Pankov#
396c8483Yuri Pankov# CDDL HEADER START
496c8483Yuri Pankov#
596c8483Yuri Pankov# The contents of this file are subject to the terms of the
696c8483Yuri Pankov# Common Development and Distribution License (the "License").
796c8483Yuri Pankov# You may not use this file except in compliance with the License.
896c8483Yuri Pankov#
996c8483Yuri Pankov# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1096c8483Yuri Pankov# or http://www.opensolaris.org/os/licensing.
1196c8483Yuri Pankov# See the License for the specific language governing permissions
1296c8483Yuri Pankov# and limitations under the License.
1396c8483Yuri Pankov#
1496c8483Yuri Pankov# When distributing Covered Code, include this CDDL HEADER in each
1596c8483Yuri Pankov# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1696c8483Yuri Pankov# If applicable, add the following below this CDDL HEADER, with the
1796c8483Yuri Pankov# fields enclosed by brackets "[]" replaced with your own identifying
1896c8483Yuri Pankov# information: Portions Copyright [yyyy] [name of copyright owner]
1996c8483Yuri Pankov#
2096c8483Yuri Pankov# CDDL HEADER END
2196c8483Yuri Pankov#
2296c8483Yuri Pankov
2396c8483Yuri Pankov# Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
2496c8483Yuri Pankov
2596c8483Yuri Pankov#
2696c8483Yuri Pankov# mmap test purpose
2796c8483Yuri Pankov#
2896c8483Yuri Pankov# __stc_assertion_start
2996c8483Yuri Pankov#
3096c8483Yuri Pankov# ID: mmap_007
3196c8483Yuri Pankov#
3296c8483Yuri Pankov# DESCRIPTION:
3396c8483Yuri Pankov#       Verify compatibility between open(O_RDWR) &
3496c8483Yuri Pankov#	  mmap(PROT_READ|PROT_WRITE, MAP_PRIVATE)
3596c8483Yuri Pankov#
3696c8483Yuri Pankov# STRATEGY:
3796c8483Yuri Pankov#       1. run "mount -F smbfs //server/public /export/mnt"
3896c8483Yuri Pankov#       2. mkfile in smbfs & local dir, with the same size
3996c8483Yuri Pankov#	3. open(O_RDWR) & mmap(PROT_READ|PROT_WRITE, MAP_PRIVATE) the smbfs file
4096c8483Yuri Pankov#	4. read data from the local file and write into the smbfs file
4196c8483Yuri Pankov#	4. diff the smbfs file before written & after written
4296c8483Yuri Pankov# KEYWORDS:
4396c8483Yuri Pankov#
4496c8483Yuri Pankov# TESTABILITY: explicit
4596c8483Yuri Pankov#
4696c8483Yuri Pankov# __stc_assertion_end
4796c8483Yuri Pankov#
4896c8483Yuri Pankov
4996c8483Yuri Pankov. $STF_SUITE/include/libtest.ksh
5096c8483Yuri Pankov
5196c8483Yuri Pankovtc_id="mmap007"
5296c8483Yuri Pankovtc_desc=" Verify compatibility between open(O_RDWR) & mmap(rw, p)"
5396c8483Yuri Pankovprint_test_case $tc_id - $tc_desc
5496c8483Yuri Pankov
5596c8483Yuri Pankovif [[ $STC_CIFS_CLIENT_DEBUG == 1 ]] || \
5696c8483Yuri Pankov	[[ *:${STC_CIFS_CLIENT_DEBUG}:* == *:$tc_id:* ]]; then
5796c8483Yuri Pankov    set -x
5896c8483Yuri Pankovfi
5996c8483Yuri Pankov
6096c8483Yuri Pankovsize=1111k
6196c8483Yuri Pankov
6296c8483Yuri Pankovserver=$(server_name) || return
6396c8483Yuri Pankov
6496c8483Yuri Pankovtestdir=$TDIR
6596c8483Yuri Pankovmnt_point=$TMNT
6696c8483Yuri Pankov
6796c8483Yuri Pankovtestdir_init $testdir
6896c8483Yuri Pankovsmbmount_clean $mnt_point
6996c8483Yuri Pankovsmbmount_init $mnt_point
7096c8483Yuri Pankov
7196c8483Yuri Pankovtest_file="tmp007"
7296c8483Yuri Pankov
7396c8483Yuri Pankovcmd="mount -F smbfs //$TUSER:$TPASS@$server/public $mnt_point"
7496c8483Yuri Pankovcti_execute -i '' FAIL $cmd
7596c8483Yuri Pankovif (($?!=0)); then
7696c8483Yuri Pankov	cti_fail "FAIL: $cmd"
7796c8483Yuri Pankov	return
7896c8483Yuri Pankovelse
7996c8483Yuri Pankov	cti_report "PASS: $cmd"
8096c8483Yuri Pankovfi
8196c8483Yuri Pankov
8296c8483Yuri Pankov# make a smbfs file
8396c8483Yuri Pankovcmd="mkfile_mmap -n $size -f ${mnt_point}/${test_file}"
8496c8483Yuri Pankovcti_execute FAIL $cmd
8596c8483Yuri Pankovif (($?!=0)); then
8696c8483Yuri Pankov	cti_fail "FAIL: $cmd"
8796c8483Yuri Pankov	return
8896c8483Yuri Pankovelse
8996c8483Yuri Pankov	cti_report "PASS: $cmd"
9096c8483Yuri Pankovfi
9196c8483Yuri Pankov
9296c8483Yuri Pankov# make a local file, with the same size
9396c8483Yuri Pankovcmd="mkfile_mmap -n $size -f ${testdir}/${test_file}"
9496c8483Yuri Pankovcti_execute FAIL $cmd
9596c8483Yuri Pankovif (($?!=0)); then
9696c8483Yuri Pankov	cti_fail "FAIL: $cmd"
9796c8483Yuri Pankov	return
9896c8483Yuri Pankovelse
9996c8483Yuri Pankov	cti_report "PASS: $cmd"
10096c8483Yuri Pankovfi
10196c8483Yuri Pankov
10296c8483Yuri Pankov# backup the sum before write the smbfs file
10396c8483Yuri Pankovcti_execute_cmd "sum ${mnt_point}/${test_file}"
10496c8483Yuri Pankovread sum1 cnt1 junk < cti_stdout
10596c8483Yuri Pankovcti_report "before sum $sum1 $cnt1"
10696c8483Yuri Pankov
10796c8483Yuri Pankov# open(O_RDWR) & mmap(PROT_READ|PROT_WRITE, MAP_PRIVATE) the smbfs file,
10896c8483Yuri Pankov# verify if can write it
10996c8483Yuri Pankovcmd="prot_mmap -o r rw -m rs rwp -f \
11096c8483Yuri Pankov  ${testdir}/${test_file} ${mnt_point}/${test_file}"
11196c8483Yuri Pankovcti_execute FAIL $cmd
11296c8483Yuri Pankovif (($?!=0)); then
11396c8483Yuri Pankov	cti_fail "FAIL: $cmd"
11496c8483Yuri Pankov	return
11596c8483Yuri Pankovelse
11696c8483Yuri Pankov	cti_report "PASS: $cmd"
11796c8483Yuri Pankovfi
11896c8483Yuri Pankov
11996c8483Yuri Pankov# recalc the sum of the smbfs file
12096c8483Yuri Pankovcti_execute_cmd "sum ${mnt_point}/${test_file}"
12196c8483Yuri Pankovread sum2 cnt2 junk < cti_stdout
12296c8483Yuri Pankovcti_report "after sum $sum2 $cnt2"
12396c8483Yuri Pankov
12496c8483Yuri Pankov# verify the the smbfs file not changed
12596c8483Yuri Pankovif [[ $sum1 != $sum2 ]] ; then
12696c8483Yuri Pankov        cti_fail "FAIL: the smbfs file changed"
12796c8483Yuri Pankov	return
12896c8483Yuri Pankovelse
12996c8483Yuri Pankov        cti_report "PASS: the smbfs file not changed"
13096c8483Yuri Pankovfi
13196c8483Yuri Pankov
13296c8483Yuri Pankovcti_execute_cmd "rm -rf $testdir/*"
13396c8483Yuri Pankovcti_execute_cmd "rm -f ${mnt_point}/${test_file}"
13496c8483Yuri Pankov
13596c8483Yuri Pankovsmbmount_clean $mnt_point
13696c8483Yuri Pankov
13796c8483Yuri Pankovcti_pass "${tc_id}: PASS"
138