• 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 "$OWN_PWD" ]
36	then
37		export OWN_PWD="OWN PWD"
38	fi
39	if [ -z "$SRK_PWD" ]
40	then
41		export SRK_PWD="SRK PWD"
42	fi
43	if [ -z "$P11_SO_PWD" ]
44	then
45		export P11_SO_PWD="P11 SO PWD"
46	fi
47	if [ -z "$P11_USER_PWD" ]
48	then
49		export P11_USER_PWD="P11 USER PWD"
50	fi
51
52	tst_resm TINFO "INIT: Inititalizing tests."
53
54	which tpmtoken_init 1>$TPM_TMPFILE 2>&1 || RC=$?
55	if [ $RC -ne 0 ]
56	then
57		tst_brk TBROK $TPM_TMPFILE NULL \
58			"Setup: tpmtoken_init command does not exist. Reason:"
59		return $RC
60	fi
61
62	tpmtoken_init_tests_exp00.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
63	if [ $RC -ne 0 ]
64	then
65		tst_brk TBROK $TPM_TMPFILE NULL \
66			"Setup: cannot set SRK password. Reason:"
67		return $RC
68	fi
69
70	return $RC
71}
72
73test01()
74{
75	RC=0				# Return value from commands
76	export TCID=tpmtoken_init01	# Test ID
77	export TST_COUNT=1		# Test number
78
79	tpmtoken_init_tests_exp01.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
80	if [ $RC -eq 0 ]
81	then
82		tst_resm TPASS "'tpmtoken_init' passed."
83		RC=0
84	else
85		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_init' failed."
86		RC=1
87	fi
88	return $RC
89}
90
91test02()
92{
93	RC=0				# Return value from commands
94	export TCID=tpmtoken_init02	# Test ID
95	export TST_COUNT=2		# Test number
96
97	tpmtoken_init_tests_exp02.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
98	if [ $RC -eq 0 ]
99	then
100		tst_resm TPASS "'tpmtoken_init' passed."
101		RC=0
102	else
103		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_init' failed."
104		RC=1
105	fi
106	return $RC
107}
108
109test03()
110{
111	RC=0				# Return value from commands
112	export TCID=tpmtoken_init03	# Test ID
113	export TST_COUNT=3		# Test number
114
115	tpmtoken_init_tests_exp03.sh 1>$TPM_TMPFILE 2>&1 || RC=$?
116	if [ $RC -eq 0 ]
117	then
118		tst_resm TPASS "'tpmtoken_init -y' passed."
119		RC=0
120	else
121		tst_res TFAIL $TPM_TMPFILE "'tpmtoken_init -y' failed."
122		RC=1
123	fi
124	return $RC
125}
126
127cleanup()
128{
129	rm -f $TPM_TMPFILE 2>&1
130}
131
132# Function:	main
133#
134# Description:	- Execute all tests, report results.
135#
136# Exit:		- zero on success
137# 		- non-zero on failure.
138
139TFAILCNT=0			# Set TFAILCNT to 0, increment on failure.
140RC=0				# Return code from tests.
141
142export TCID=tpmtoken_init	# Test ID
143export TST_TOTAL=3		# Total numner of tests in this file.
144export TST_COUNT=0		# Initialize identifier
145
146if [ -n "$TPM_NOPKCS11" ]
147then
148	tst_resm TINFO "'tpmtoken_init' skipped."
149	exit $TFAILCNT
150fi
151
152setup || exit $RC		# Exit if initializing testcases fails.
153
154test01 || TFAILCNT=$(($TFAILCNT+1))
155test02 || TFAILCNT=$(($TFAILCNT+1))
156test03 || TFAILCNT=$(($TFAILCNT+1))
157
158cleanup
159
160exit $TFAILCNT
161