xref: /illumos-gate/usr/src/test/smbclient-tests/tests/smbfs/mmap/tp_mmap_009.ksh (revision c559157643fef9f9afb0414e00a3579407ba3052)
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_009
31#
32# DESCRIPTION:
33#        Verify smbfs will help sync the dirty pages to the file and close it, including otW close, if the userland does not explicitly do it.
34#
35# STRATEGY:
36#       1. run "mount -F smbfs //server/public /export/mnt"
37#       2. mkfile in smbfs
38#	3. open, mmap the file, then write some data into the mapped addr
39#	4. exit without close the file
40#	5. verify the data successfully written back to smb server
41# KEYWORDS:
42#
43# TESTABILITY: explicit
44#
45# __stc_assertion_end
46#
47
48. $STF_SUITE/include/libtest.ksh
49
50tc_id="mmap009"
51tc_desc=" Verify smbfs will sync the dirty pages to the file and close it,
52 including otW close, if the userland does not explicitly do it."
53print_test_case $tc_id - $tc_desc
54
55if [[ $STC_CIFS_CLIENT_DEBUG == 1 ]] || \
56	[[ *:${STC_CIFS_CLIENT_DEBUG}:* == *:$tc_id:* ]]; then
57    set -x
58fi
59
60server=$(server_name) || return
61
62testdir=$TDIR
63mnt_point=$TMNT
64
65testdir_init $testdir
66smbmount_clean $mnt_point
67smbmount_init $mnt_point
68
69test_file="tmp009"
70
71cmd="mount -F smbfs //$TUSER:$TPASS@$server/public $mnt_point"
72cti_execute -i '' FAIL $cmd
73if (($?!=0)); then
74	cti_fail "FAIL: $cmd"
75	return
76else
77	cti_report "PASS: $cmd"
78fi
79
80# open, mmap a file in smbfs, then write something into it,
81# exit without msync/munmap/close
82cti_execute FAIL "no_close ${mnt_point}/${test_file}"
83if (($?!=0)); then
84	cti_fail "FAIL: $cmd"
85	return
86else
87	cti_report "PASS: $cmd"
88fi
89
90# do the same thing in local file, for comparison
91cti_execute FAIL "no_close ${testdir}/${test_file}"
92if (($?!=0)); then
93	cti_fail "FAIL: $cmd"
94	return
95else
96	cti_report "PASS: $cmd"
97fi
98
99# diff the local file & smbfs file
100
101cti_execute_cmd "sum ${testdir}/${test_file}"
102read sum1 cnt1 junk < cti_stdout
103cti_report "local sum $sum1 $cnt1"
104
105cti_execute_cmd "sum ${mnt_point}/${test_file}"
106read sum2 cnt2 junk < cti_stdout
107cti_report "smbfs sum $sum2 $cnt2"
108
109if [[ $sum1 != $sum2 ]] ; then
110        cti_fail "FAIL: the files are different"
111        return
112else
113        cti_report "PASS: the files are the same"
114fi
115
116cti_execute_cmd "rm -rf $testdir/*"
117cti_execute_cmd "rm -f ${mnt_point}/${test_file}"
118
119smbmount_clean $mnt_point
120
121cti_pass "${tc_id}: PASS"
122