12fae26bdSAlan Somers# vim: filetype=sh 22fae26bdSAlan Somers# 32fae26bdSAlan Somers# CDDL HEADER START 42fae26bdSAlan Somers# 52fae26bdSAlan Somers# The contents of this file are subject to the terms of the 62fae26bdSAlan Somers# Common Development and Distribution License (the "License"). 72fae26bdSAlan Somers# You may not use this file except in compliance with the License. 82fae26bdSAlan Somers# 92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing. 112fae26bdSAlan Somers# See the License for the specific language governing permissions 122fae26bdSAlan Somers# and limitations under the License. 132fae26bdSAlan Somers# 142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each 152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the 172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying 182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner] 192fae26bdSAlan Somers# 202fae26bdSAlan Somers# CDDL HEADER END 212fae26bdSAlan Somers# 222fae26bdSAlan Somers 232fae26bdSAlan Somers# 242fae26bdSAlan Somers# Copyright 2008 Sun Microsystems, Inc. All rights reserved. 252fae26bdSAlan Somers# Use is subject to license terms. 262fae26bdSAlan Somers 272fae26bdSAlan Somers. $STF_SUITE/include/libtest.kshlib 282fae26bdSAlan Somers 292fae26bdSAlan Somers# a function that takes a file, then creates and verifies 302fae26bdSAlan Somers# an xattr on that file. The xattr_contents is the file 312fae26bdSAlan Somers# that should appear in the xattr namespace. 322fae26bdSAlan Somersfunction create_xattr { # filename xattr_name xattr_contents 332fae26bdSAlan Somers typeset FILE=$1 342fae26bdSAlan Somers typeset XATTR_NAME=$2 352fae26bdSAlan Somers typeset XATTR_CONTENTS=$3 362fae26bdSAlan Somers 372fae26bdSAlan Somers # read any empty xattr on that file 382fae26bdSAlan Somers log_must $RUNAT $FILE $LS 392fae26bdSAlan Somers # create the xattr 402fae26bdSAlan Somers log_must $RUNAT $FILE $CP $XATTR_CONTENTS $XATTR_NAME 412fae26bdSAlan Somers 422fae26bdSAlan Somers verify_xattr $FILE $XATTR_NAME $XATTR_CONTENTS 432fae26bdSAlan Somers} 442fae26bdSAlan Somers 452fae26bdSAlan Somers# a function that compares the a single xattr between two files 462fae26bdSAlan Somers# and checks to see if their contents are identical 472fae26bdSAlan Somersfunction compare_xattrs { # filename1 filename2 xattr_name 482fae26bdSAlan Somers typeset FILE1=$1 492fae26bdSAlan Somers typeset FILE2=$2 502fae26bdSAlan Somers typeset XATTR_NAME=$3 512fae26bdSAlan Somers 522fae26bdSAlan Somers $RUNAT $FILE1 $CAT $XATTR_NAME > $TMPDIR/file1.${TESTCASE_ID} 532fae26bdSAlan Somers $RUNAT $FILE2 $CAT $XATTR_NAME > $TMPDIR/file2.${TESTCASE_ID} 542fae26bdSAlan Somers 552fae26bdSAlan Somers log_must $DIFF $TMPDIR/file1.${TESTCASE_ID} $TMPDIR/file2.${TESTCASE_ID} 562fae26bdSAlan Somers log_must $RM $TMPDIR/file1.${TESTCASE_ID} $TMPDIR/file2.${TESTCASE_ID} 572fae26bdSAlan Somers} 582fae26bdSAlan Somers 592fae26bdSAlan Somersfunction verify_xattr { # filename xattr_name xattr_contents 602fae26bdSAlan Somers typeset FILE=$1 612fae26bdSAlan Somers typeset XATTR_NAME=$2 622fae26bdSAlan Somers typeset XATTR_CONTENTS=$3 632fae26bdSAlan Somers 642fae26bdSAlan Somers # read the xattr, writing it to a temp file 652fae26bdSAlan Somers log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 2>&1" 662fae26bdSAlan Somers log_must $DIFF $XATTR_CONTENTS $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 672fae26bdSAlan Somers $RM $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 682fae26bdSAlan Somers} 692fae26bdSAlan Somers 702fae26bdSAlan Somersfunction delete_xattr { # filename xattr_name 712fae26bdSAlan Somers typeset FILE=$1 722fae26bdSAlan Somers typeset XATTR_NAME=$2 732fae26bdSAlan Somers 742fae26bdSAlan Somers # delete the xattr 752fae26bdSAlan Somers log_must $RUNAT $FILE $RM $XATTR_NAME 762fae26bdSAlan Somers log_mustnot eval "$RUNAT $FILE $LS $XATTR_NAME > /dev/null 2>&1" 772fae26bdSAlan Somers} 782fae26bdSAlan Somers 792fae26bdSAlan Somers# not sure about this : really this should be testing write/append 802fae26bdSAlan Somersfunction verify_write_xattr { # filename xattr_name 812fae26bdSAlan Somers typeset FILE=$1 822fae26bdSAlan Somers typeset XATTR_NAME=$2 832fae26bdSAlan Somers 842fae26bdSAlan Somers log_must eval "$RUNAT $FILE $DD if=/etc/passwd of=$XATTR_NAME" 852fae26bdSAlan Somers log_must eval "$RUNAT $FILE $CAT $XATTR_NAME > $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 2>&1" 862fae26bdSAlan Somers log_must $DD if=/etc/passwd of=$TMPDIR/passwd_dd.${TESTCASE_ID} 872fae26bdSAlan Somers log_must $DIFF $TMPDIR/passwd_dd.${TESTCASE_ID} $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 882fae26bdSAlan Somers log_must $RM $TMPDIR/passwd_dd.${TESTCASE_ID} $TMPDIR/$XATTR_NAME.${TESTCASE_ID} 892fae26bdSAlan Somers} 902fae26bdSAlan Somers 912fae26bdSAlan Somers# this function is to create the expected output 922fae26bdSAlan Somersfunction create_expected_output { # expected_output_file contents_of_the_output 932fae26bdSAlan Somers typeset FILE=$1 942fae26bdSAlan Somers shift 952fae26bdSAlan Somers if [[ -f $FILE ]]; then 962fae26bdSAlan Somers log_must $RM $FILE 972fae26bdSAlan Somers fi 982fae26bdSAlan Somers 992fae26bdSAlan Somers for line in $@ 1002fae26bdSAlan Somers do 1012fae26bdSAlan Somers log_must eval "$ECHO $line >> $FILE" 1022fae26bdSAlan Somers done 1032fae26bdSAlan Somers } 104