• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2#
3# Copyright (c) International Business Machines  Corp., 2005
4#
5# This program is free software;  you can redistribute it and#or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13# for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program;  if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18#
19
20setup()
21{
22	RC=0				# Return code from commands.
23
24	if [ -z "$LTPTMP" ] && [ -z "$TMPBASE" ]
25	then
26		LTPTMP="/tmp"
27	else
28		LTPTMP="$TMPBASE"
29	fi
30
31	export TPM_TMPFILE="$LTPTMP/tst_tpm.err"
32	rm -f $TPM_TMPFILE 2>&1
33
34	# Set known password values
35	if [ -z "$P11_SO_PWD" ]
36	then
37		export P11_SO_PWD="P11 SO PWD"
38	fi
39	if [ -z "$NEW_P11_SO_PWD" ]
40	then
41		export NEW_P11_SO_PWD="NEW P11 SO PWD"
42	fi
43	if [ -z "$P11_USER_PWD" ]
44	then
45		export P11_USER_PWD="P11 USER PWD"
46	fi
47	if [ -z "$NEW_P11_USER_PWD" ]
48	then
49		export NEW_P11_USER_PWD="NEW P11 USER PWD"
50	fi
51
52	tst_resm TINFO "INIT: Inititalizing tests."
53
54	which tpmtoken_setpasswd 1>$TPM_TMPFILE 2>&1 || RC=$?
55	if [ $RC -ne 0 ]
56	then
57		tst_brk TBROK $TPM_TMPFILE NULL \
58			"Setup: tpmtoken_setpasswd command does not exist. Reason:"
59		return $RC
60	fi
61
62	return $RC
63}
64
65test01()
66{
67	RC=0					# Return value from commands
68	export TCID=tpmtoken_setpasswd01	# Test ID
69	export TST_COUNT=1			# Test number
70
71	tpmtoken_setpasswd_tests_exp01.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
72	if [ $RC -eq 0 ]
73	then
74		tst_resm TPASS "'tpmtoken_setpasswd' passed."
75		RC=0
76	else
77		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd' failed."
78		RC=1
79	fi
80	return $RC
81}
82
83test02()
84{
85	RC=0					# Return value from commands
86	export TCID=tpmtoken_setpasswd02	# Test ID
87	export TST_COUNT=2			# Test number
88
89	tpmtoken_setpasswd_tests_exp02.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
90	if [ $RC -eq 0 ]
91	then
92		tst_resm TPASS "'tpmtoken_setpasswd --security-officer' passed."
93		RC=0
94	else
95		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd --security-officer' failed."
96		RC=1
97	fi
98	return $RC
99}
100
101test03()
102{
103	RC=0					# Return value from commands
104	export TCID=tpmtoken_setpasswd03	# Test ID
105	export TST_COUNT=3			# Test number
106
107	tpmtoken_setpasswd_tests_exp03.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
108	if [ $RC -eq 0 ]
109	then
110		tst_resm TPASS "'tpmtoken_setpasswd' passed."
111		RC=0
112	else
113		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd' failed."
114		RC=1
115	fi
116	return $RC
117}
118
119test04()
120{
121	RC=0					# Return value from commands
122	export TCID=tpmtoken_setpasswd04	# Test ID
123	export TST_COUNT=4			# Test number
124
125	tpmtoken_setpasswd_tests_exp04.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
126	if [ $RC -eq 0 ]
127	then
128		tst_resm TPASS "'tpmtoken_setpasswd --security-officer' passed."
129		RC=0
130	else
131		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_setpasswd --security-officer' failed."
132		RC=1
133	fi
134	return $RC
135}
136
137cleanup()
138{
139	rm -f $TPM_TMPFILE 2>&1
140}
141
142# Function:	main
143#
144# Description:	- Execute all tests, report results.
145#
146# Exit:		- zero on success
147# 		- non-zero on failure.
148
149TFAILCNT=0			# Set TFAILCNT to 0, increment on failure.
150RC=0				# Return code from tests.
151
152export TCID=tpmtoken_setpasswd	# Test ID
153export TST_TOTAL=4		# Total numner of tests in this file.
154export TST_COUNT=0		# Initialize identifier
155
156if [ -n "$TPM_NOPKCS11" ]
157then
158	tst_resm TINFO "'tpmtoken_setpasswd' skipped."
159	exit $TFAILCNT
160fi
161
162setup || exit $RC		# Exit if initializing testcases fails.
163
164test01 || TFAILCNT=$(($TFAILCNT+1))
165test02 || TFAILCNT=$(($TFAILCNT+1))
166test03 || TFAILCNT=$(($TFAILCNT+1))
167test04 || TFAILCNT=$(($TFAILCNT+1))
168
169cleanup
170
171exit $TFAILCNT
172