| 1 |
package client |
| 2 |
|
| 3 |
import ( |
| 4 |
"io" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/google/go-tpm/legacy/tpm2" |
| 8 |
) |
| 9 |
|
| 10 |
// CheckedClose closes the simulator and asserts that there were no leaked handles. |
| 11 |
func CheckedClose(tb testing.TB, rwc io.ReadWriteCloser) { |
| 12 |
for _, t := range []tpm2.HandleType{ |
| 13 |
tpm2.HandleTypeLoadedSession, |
| 14 |
tpm2.HandleTypeSavedSession, |
| 15 |
tpm2.HandleTypeTransient, |
| 16 |
} { |
| 17 |
handles, err := Handles(rwc, t) |
| 18 |
if err != nil { |
| 19 |
tb.Errorf("failed to fetch handles of type %v: %v", t, err) |
| 20 |
} |
| 21 |
if len(handles) != 0 { |
| 22 |
tb.Errorf("tests leaked handles: %v", handles) |
| 23 |
} |
| 24 |
} |
| 25 |
|
| 26 |
if err := rwc.Close(); err != nil { |
| 27 |
tb.Errorf("when closing simulator: %v", err) |
| 28 |
} |
| 29 |
} |