• 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	tst_resm TINFO "INIT: Inititalizing tests."
35
36	which tpm_selftest 1>$TPM_TMPFILE 2>&1 || RC=$?
37	if [ $RC -ne 0 ]
38	then
39		tst_brk TBROK $TPM_TMPFILE NULL \
40			"Setup: tpm_selftest command does not exist. Reason:"
41		return $RC
42	fi
43
44	return $RC
45}
46
47test01()
48{
49	RC=0				# Return value from commands
50	export TCID=tpm_selftest01	# Test ID
51	export TST_COUNT=1		# Test number
52
53	tpm_selftest 1>$TPM_TMPFILE 2>&1 || RC=$?
54	if [ $RC -eq 0 ]
55	then
56		tst_resm TPASS "'tpm_selftest' passed."
57		RC=0
58	else
59		tst_res TFAIL $TPM_TMPFILE "'tpm_selftest' failed."
60		RC=1
61	fi
62	return $RC
63}
64
65test02()
66{
67	RC=0				# Return value from commands
68	export TCID=tpm_selftest02	# Test ID
69	export TST_COUNT=2		# Test number
70
71	tpm_selftest -r 1>$TPM_TMPFILE 2>&1 || RC=$?
72	if [ $RC -eq 0 ]
73	then
74		tst_resm TPASS "'tpm_selftest -r' passed."
75		RC=0
76	else
77		tst_res TFAIL $TPM_TMPFILE "'tpm_selftest -r' failed."
78		RC=1
79	fi
80	return $RC
81}
82
83cleanup()
84{
85	rm -f $TPM_TMPFILE 2>&1
86}
87
88# Function:	main
89#
90# Description:	- Execute all tests, report results.
91#
92# Exit:		- zero on success
93# 		- non-zero on failure.
94
95TFAILCNT=0			# Set TFAILCNT to 0, increment on failure.
96RC=0				# Return code from tests.
97
98export TCID=tpm_selftest	# Test ID
99export TST_TOTAL=2		# Total numner of tests in this file.
100export TST_COUNT=0		# Initialize identifier
101
102setup || exit $RC		# Exit if initializing testcases fails.
103
104test01 || TFAILCNT=$(($TFAILCNT+1))
105test02 || TFAILCNT=$(($TFAILCNT+1))
106
107cleanup
108
109exit $TFAILCNT
110