1f38cb554SJohn Wren Kennedy# 2f38cb554SJohn Wren Kennedy# CDDL HEADER START 3f38cb554SJohn Wren Kennedy# 4f38cb554SJohn Wren Kennedy# The contents of this file are subject to the terms of the 5f38cb554SJohn Wren Kennedy# Common Development and Distribution License (the "License"). 6f38cb554SJohn Wren Kennedy# You may not use this file except in compliance with the License. 7f38cb554SJohn Wren Kennedy# 8f38cb554SJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9f38cb554SJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing. 10f38cb554SJohn Wren Kennedy# See the License for the specific language governing permissions 11f38cb554SJohn Wren Kennedy# and limitations under the License. 12f38cb554SJohn Wren Kennedy# 13f38cb554SJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each 14f38cb554SJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15f38cb554SJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the 16f38cb554SJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying 17f38cb554SJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner] 18f38cb554SJohn Wren Kennedy# 19f38cb554SJohn Wren Kennedy# CDDL HEADER END 20f38cb554SJohn Wren Kennedy# 21f38cb554SJohn Wren Kennedy 22f38cb554SJohn Wren Kennedy# 23f38cb554SJohn Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24f38cb554SJohn Wren Kennedy# Use is subject to license terms. 25f38cb554SJohn Wren Kennedy# 26f38cb554SJohn Wren Kennedy 27f38cb554SJohn Wren Kennedy# 28*1d32ba66SJohn Wren Kennedy# Copyright (c) 2013, 2016 by Delphix. All rights reserved. 29f38cb554SJohn Wren Kennedy# 30f38cb554SJohn Wren Kennedy 31f38cb554SJohn Wren Kennedy. $STF_SUITE/include/libtest.shlib 32f38cb554SJohn Wren Kennedy 33f38cb554SJohn Wren Kennedy# a function that takes a file, then creates and verifies 34f38cb554SJohn Wren Kennedy# an xattr on that file. The xattr_contents is the file 35f38cb554SJohn Wren Kennedy# that should appear in the xattr namespace. 36f38cb554SJohn Wren Kennedyfunction create_xattr { # filename xattr_name xattr_contents 37f38cb554SJohn Wren Kennedy typeset FILE=$1 38f38cb554SJohn Wren Kennedy typeset XATTR_NAME=$2 39f38cb554SJohn Wren Kennedy typeset XATTR_CONTENTS=$3 40f38cb554SJohn Wren Kennedy 41f38cb554SJohn Wren Kennedy # read any empty xattr on that file 42*1d32ba66SJohn Wren Kennedy log_must runat $FILE ls 43f38cb554SJohn Wren Kennedy # create the xattr 44*1d32ba66SJohn Wren Kennedy log_must runat $FILE cp $XATTR_CONTENTS $XATTR_NAME 45f38cb554SJohn Wren Kennedy 46f38cb554SJohn Wren Kennedy verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS 47f38cb554SJohn Wren Kennedy} 48f38cb554SJohn Wren Kennedy 49f38cb554SJohn Wren Kennedy# a function that compares the a single xattr between two files 50f38cb554SJohn Wren Kennedy# and checks to see if their contents are identical 51f38cb554SJohn Wren Kennedyfunction compare_xattrs { # filename1 filename2 xattr_name 52f38cb554SJohn Wren Kennedy typeset FILE1=$1 53f38cb554SJohn Wren Kennedy typeset FILE2=$2 54f38cb554SJohn Wren Kennedy typeset XATTR_NAME=$3 55f38cb554SJohn Wren Kennedy 56*1d32ba66SJohn Wren Kennedy runat $FILE1 cat $XATTR_NAME > /tmp/file1.$$ 57*1d32ba66SJohn Wren Kennedy runat $FILE2 cat $XATTR_NAME > /tmp/file2.$$ 58f38cb554SJohn Wren Kennedy 59*1d32ba66SJohn Wren Kennedy log_must diff /tmp/file1.$$ /tmp/file2.$$ 60*1d32ba66SJohn Wren Kennedy log_must rm /tmp/file1.$$ /tmp/file2.$$ 61f38cb554SJohn Wren Kennedy} 62f38cb554SJohn Wren Kennedy 63f38cb554SJohn Wren Kennedyfunction verify_xattr { # filename xattr_name xattr_contents 64f38cb554SJohn Wren Kennedy typeset FILE=$1 65f38cb554SJohn Wren Kennedy typeset XATTR_NAME=$2 66f38cb554SJohn Wren Kennedy typeset XATTR_CONTENTS=$3 67f38cb554SJohn Wren Kennedy 68f38cb554SJohn Wren Kennedy # read the xattr, writing it to a temp file 69*1d32ba66SJohn Wren Kennedy log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1" 70*1d32ba66SJohn Wren Kennedy log_must diff $XATTR_CONTENTS /tmp/$XATTR_NAME.$$ 71*1d32ba66SJohn Wren Kennedy rm /tmp/$XATTR_NAME.$$ 72f38cb554SJohn Wren Kennedy} 73f38cb554SJohn Wren Kennedy 74f38cb554SJohn Wren Kennedyfunction delete_xattr { # filename xattr_name 75f38cb554SJohn Wren Kennedy typeset FILE=$1 76f38cb554SJohn Wren Kennedy typeset XATTR_NAME=$2 77f38cb554SJohn Wren Kennedy 78f38cb554SJohn Wren Kennedy # delete the xattr 79*1d32ba66SJohn Wren Kennedy log_must runat $FILE rm $XATTR_NAME 80*1d32ba66SJohn Wren Kennedy log_mustnot eval "runat $FILE ls $XATTR_NAME > /dev/null 2>&1" 81f38cb554SJohn Wren Kennedy} 82f38cb554SJohn Wren Kennedy 83f38cb554SJohn Wren Kennedy# not sure about this : really this should be testing write/append 84f38cb554SJohn Wren Kennedyfunction verify_write_xattr { # filename xattr_name 85f38cb554SJohn Wren Kennedy typeset FILE=$1 86f38cb554SJohn Wren Kennedy typeset XATTR_NAME=$2 87f38cb554SJohn Wren Kennedy 88*1d32ba66SJohn Wren Kennedy log_must eval "runat $FILE dd if=/etc/passwd of=$XATTR_NAME" 89*1d32ba66SJohn Wren Kennedy log_must eval "runat $FILE cat $XATTR_NAME > /tmp/$XATTR_NAME.$$ 2>&1" 90*1d32ba66SJohn Wren Kennedy log_must dd if=/etc/passwd of=/tmp/passwd_dd.$$ 91*1d32ba66SJohn Wren Kennedy log_must diff /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$ 92*1d32ba66SJohn Wren Kennedy log_must rm /tmp/passwd_dd.$$ /tmp/$XATTR_NAME.$$ 93f38cb554SJohn Wren Kennedy} 94f38cb554SJohn Wren Kennedy 95f38cb554SJohn Wren Kennedy# this function is to create the expected output 96f38cb554SJohn Wren Kennedyfunction create_expected_output { # expected_output_file contents_of_the_output 97f38cb554SJohn Wren Kennedy typeset FILE=$1 98f38cb554SJohn Wren Kennedy shift 99f38cb554SJohn Wren Kennedy if [[ -f $FILE ]]; then 100*1d32ba66SJohn Wren Kennedy log_must rm $FILE 101f38cb554SJohn Wren Kennedy fi 102f38cb554SJohn Wren Kennedy 103f38cb554SJohn Wren Kennedy for line in $@ 104f38cb554SJohn Wren Kennedy do 105*1d32ba66SJohn Wren Kennedy log_must eval "echo $line >> $FILE" 106f38cb554SJohn Wren Kennedy done 107f38cb554SJohn Wren Kennedy } 108