| 1 |
package tpm2 |
| 2 |
|
| 3 |
import ( |
| 4 |
"reflect" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/google/go-tpm/tpmutil" |
| 8 |
) |
| 9 |
|
| 10 |
func TestError(t *testing.T) { |
| 11 |
tests := []struct { |
| 12 |
response tpmutil.ResponseCode |
| 13 |
expected error |
| 14 |
}{ |
| 15 |
{0x501, VendorError{Code: 0x501}}, |
| 16 |
{0x922, Warning{Code: RCRetry}}, |
| 17 |
{0x100, Error{Code: RCInitialize}}, |
| 18 |
{0xfc1, ParameterError{Code: RCAsymmetric, Parameter: RCF}}, |
| 19 |
{0x7a3, HandleError{Code: RCExpired, Handle: RC7}}, |
| 20 |
{0xfa2, SessionError{Code: RCBadAuth, Session: RC7}}, |
| 21 |
} |
| 22 |
|
| 23 |
for _, test := range tests { |
| 24 |
err := decodeResponse(test.response) |
| 25 |
if !reflect.DeepEqual(err, test.expected) { |
| 26 |
t.Fatalf("decodeResponse(0x%x) = %#v, want %#v", test.response, err, test.expected) |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
// nil ReadWriter handle causes tpmutil.RunCommand to return an error. |
| 32 |
func TestRunCommandErr(t *testing.T) { |
| 33 |
if _, err := runCommand(nil, TagSessions, CmdSign); err == nil { |
| 34 |
t.Error("runCommand returned nil error on error from tpmutil.RunCommand") |
| 35 |
} |
| 36 |
} |