xref: /titanic_51/usr/src/lib/libshell/common/tests/sun_solaris_builtin_sum.sh (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26#
27# Test whether the ksh93/libcmd sum builtin is compatible to
28# Solaris/SystemV /usr/bin/sum
29#
30
31# test setup
32function err_exit
33{
34	print -u2 -n "\t"
35	print -u2 -r ${Command}[$1]: "${@:2}"
36	(( Errors < 127 && Errors++ ))
37}
38alias err_exit='err_exit $LINENO'
39
40set -o nounset
41Command=${0##*/}
42integer Errors=0
43
44
45typeset x
46
47builtin sum || err_exit "sum builtin not found"
48
49# Basic tests
50x="$(print 'hello' | /usr/bin/sum)" || err_exit "/usr/bin/sum pipe failed."
51[[ "$x" == "542 1" ]] || err_exit "print 'hello' | /usr/bin/sum did not return 542 1, got $x"
52x="$(print 'hello' | sum)" || err_exit "sum builtin pipe failed."
53[[ "$x" == "542 1" ]] || err_exit "print 'hello' | sum builtin did not return 542 1, got $x"
54x="$(print 'hello' | sum -x md5)" || err_exit "sum md5 builtin pipe failed."
55[[ "$x" == "b1946ac92492d2347c6235b4d2611184" ]] || err_exit "print 'hello' | sum md5 builtin did not return b1946ac92492d2347c6235b4d2611184, got $x"
56x="$(print 'hello' | sum -x sha1)" || err_exit "sum sha1 builtin pipe failed."
57[[ "$x" == "f572d396fae9206628714fb2ce00f72e94f2258f" ]] || err_exit "print 'hello' | sum sha1 builtin did not return f572d396fae9206628714fb2ce00f72e94f2258f, got $x"
58x="$(print 'hello' | sum -x sha256)" || err_exit "sum sha256 builtin pipe failed."
59[[ "$x" == "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03" ]] || err_exit "print 'hello' | sum sha256 builtin did not return 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03, got $x"
60x="$(print 'hello' | sum -x sha512)" || err_exit "sum sha512 builtin pipe failed."
61[[ "$x" == "e7c22b994c59d9cf2b48e549b1e24666636045930d3da7c1acb299d1c3b7f931f94aae41edda2c2b207a36e10f8bcb8d45223e54878f5b316e7ce3b6bc019629" ]] || err_exit "print 'hello' | sum sha512 builtin did not return e7c22b994c59d9cf2b48e549b1e24666636045930d3da7c1acb299d1c3b7f931f94aae41edda2c2b207a36e10f8bcb8d45223e54878f5b316e7ce3b6bc019629, got $x"
62# note that Solaris /usr/bin/cksum outputs $'3015617425\t6' (which may be a bug in Solaris /usr/bin/cksum)
63x="$(print 'hello' | sum -x cksum)" || err_exit "sum cksum builtin pipe failed."
64[[ "$x" == $'3015617425 6' ]] || err_exit "print 'hello' | sum cksum builtin did not return \$'3015617425 6', got $(printf "%q\n" "$x")"
65
66[[ "$(print 'hello'	| /usr/bin/sum)" == "$(print 'hello'	 | sum)" ]] || err_exit "sum hello != /usr/bin/sum hello"
67[[ "$(print 'fish' 	| /usr/bin/sum)" == "$(print 'fish'	 | sum)" ]] || err_exit "sum fish != /usr/bin/sum fish"
68[[ "$(print '12345'	| /usr/bin/sum)" == "$(print '12345'	 | sum)" ]] || err_exit "sum 12345 != /usr/bin/sum 12345"
69[[ "$(print '\n\r\n \v'	| /usr/bin/sum)" == "$(print '\n\r\n \v' | sum)" ]] || err_exit "sum spaces != /usr/bin/sum spaces"
70
71# Test some binary files...
72x="/usr/bin/ls"
73[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
74[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
75
76x="/usr/bin/chmod"
77[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
78[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
79
80x="/usr/bin/tee"
81[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
82[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
83
84x="/usr/bin/grep"
85[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
86[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
87
88x="/usr/bin/egrep"
89[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
90[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
91
92x="/usr/bin/awk"
93[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
94[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
95
96x="/usr/bin/nawk"
97[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
98[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
99
100x="/usr/bin/ksh"
101[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
102[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
103
104x="/usr/bin/sh"
105[[ "$(cat "$x" | /usr/bin/sum)" == "$(cat "$x" | sum)" ]]	|| err_exit "pipe: /usr/bin/sum $x != sum $x"
106[[ "$(/usr/bin/sum "$x")" == "$(sum "$x")" ]]			|| err_exit "file: /usr/bin/sum $x != sum $x"
107
108
109# tests done
110exit $((Errors))
111