1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2017 - 2018, Intel Corporation
4  * All rights reserved.
5  */
6 #include <glib.h>
7 #include <inttypes.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include <setjmp.h>
12 #include <cmocka.h>
13 
14 #include "tpm2-command.h"
15 #include "util.h"
16 
17 #define HANDLE_FIRST  0x80000000
18 #define HANDLE_SECOND 0x80000001
19 
20 uint8_t cmd_with_auths [] = {
21     0x80, 0x02, /* TPM2_ST_SESSIONS */
22     0x00, 0x00, 0x00, 0x73, /* command buffer size */
23     0x00, 0x00, 0x01, 0x37, /* command code: 0x137 / TPM2_CC_NV_Write */
24     0x01, 0x50, 0x00, 0x20, /* auth handle */
25     0x01, 0x50, 0x00, 0x20, /* nv index handle */
26     0x00, 0x00, 0x00, 0x92, /* size of auth area (2x73 byte auths) */
27     0x02, 0x00, 0x00, 0x00, /* auth session handle */
28     0x00, 0x20, /* sizeof caller nonce */
29     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
30     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
31     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
32     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
33     0x01, /* session attributes */
34     0x00, 0x20, /* sizeof  hmac */
35     0x4d, 0x91, 0x26, 0xa3, 0xd9, 0xf6, 0x74, 0xde,
36     0x98, 0x94, 0xb1, 0x0f, 0xe6, 0xb1, 0x5c, 0x72,
37     0x7d, 0x36, 0xeb, 0x39, 0x6b, 0xf2, 0x31, 0x72,
38     0x89, 0xb6, 0xc6, 0x8e, 0x54, 0xa9, 0x4c, 0x3e,
39     0x02, 0x00, 0x00, 0x01, /* auth session handle */
40     0x00, 0x20, /* sizeof caller nonce */
41     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
42     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
43     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
44     0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
45     0x01, /* session attributes */
46     0x00, 0x20, /* sizeof  hmac */
47     0x4d, 0x91, 0x26, 0xa3, 0xd9, 0xf6, 0x74, 0xde,
48     0x98, 0x94, 0xb1, 0x0f, 0xe6, 0xb1, 0x5c, 0x72,
49     0x7d, 0x36, 0xeb, 0x39, 0x6b, 0xf2, 0x31, 0x72,
50     0x89, 0xb6, 0xc6, 0x8e, 0x54, 0xa9, 0x4c, 0x3e,
51     0x00, 0x10, /* sizeof data */
52     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
53     0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
54     0x0f, 0x00, 0x00
55 };
56 /* command buffer for ContextFlush command with no handle */
57 uint8_t cmd_buf_context_flush_no_handle [] = {
58     0x80, 0x01, /* TPM2_ST_NO_SESSIONS */
59     0x00, 0x00, 0x00, 0x0a, /* size: 10 bytes */
60     0x00, 0x00, 0x01, 0x65, /* command code for ContextFlush */
61 };
62 
63 typedef struct {
64     Tpm2Command *command;
65     guint8      *buffer;
66     size_t       buffer_size;
67     Connection *connection;
68 } test_data_t;
69 /**
70  * This is the minimum work required to instantiate a Tpm2Command. It needs
71  * a data buffer to hold the command and a Connection object. We also
72  * allocate a structure to hold these things so that we can free them in
73  * the teardown.
74  */
75 static int
tpm2_command_setup_base(void ** state)76 tpm2_command_setup_base (void **state)
77 {
78     test_data_t *data   = NULL;
79     gint         client_fd;
80     GIOStream   *iostream;
81     HandleMap   *handle_map;
82 
83     data = calloc (1, sizeof (test_data_t));
84     /* allocate a buffer large enough to hold a TPM2 header and 3 handles */
85     data->buffer_size = TPM_RESPONSE_HEADER_SIZE + sizeof (TPM2_HANDLE) * 3;
86     data->buffer = calloc (1, data->buffer_size);
87     handle_map = handle_map_new (TPM2_HT_TRANSIENT, MAX_ENTRIES_DEFAULT);
88     iostream = create_connection_iostream (&client_fd);
89     data->connection = connection_new (iostream, 0, handle_map);
90     g_object_unref (handle_map);
91     g_object_unref (iostream);
92     *state = data;
93     return 0;
94 }
95 static int
tpm2_command_setup(void ** state)96 tpm2_command_setup (void **state)
97 {
98     test_data_t *data   = NULL;
99     TPMA_CC  attributes = 0x0;
100 
101     tpm2_command_setup_base (state);
102     data = (test_data_t*)*state;
103     data->command = tpm2_command_new (data->connection,
104                                       data->buffer,
105                                       data->buffer_size,
106                                       attributes);
107     *state = data;
108     return 0;
109 }
110 static int
tpm2_command_setup_two_handles(void ** state)111 tpm2_command_setup_two_handles (void **state)
112 {
113     test_data_t *data = NULL;
114     TPMA_CC  attributes = 2 << 25;
115 
116     tpm2_command_setup_base (state);
117     data = (test_data_t*)*state;
118     data->command = tpm2_command_new (data->connection,
119                                       data->buffer,
120                                       data->buffer_size,
121                                       attributes);
122     /*
123      * This sets the two handles to 0x80000000 and 0x80000001, assuming the
124      * buffer was initialized to all 0's
125      */
126     data->buffer [10] = 0x80;
127     data->buffer [14] = 0x80;
128     data->buffer [17] = 0x01;
129     return 0;
130 }
131 
132 uint8_t two_handles_not_three [] = {
133     0x80, 0x02, /* TPM2_ST_SESSIONS */
134     0x00, 0x00, 0x00, 0x12, /* command buffer size */
135     0x00, 0x00, 0x01, 0x49, /* command code: 0x149 / TPM2_CC_PolicyNV */
136     0x01, 0x02, 0x03, 0x04, /* first handle */
137     0xf0, 0xe0, 0xd0, 0xc0  /* second handle */
138 };
139 /*
140  * This setup function creates all of the components necessary to carry out
141  * a tpm2_command test. Additionally it creates a tpm2_command with a command
142  * buffer that should have 3 handles (per the TPMA_CC) but is only large
143  * enough to hold 2.
144  */
145 static int
tpm2_command_setup_two_handles_not_three(void ** state)146 tpm2_command_setup_two_handles_not_three (void **state)
147 {
148     test_data_t *data   = NULL;
149     gint         client_fd;
150     GIOStream   *iostream;
151     HandleMap   *handle_map;
152 
153     data = calloc (1, sizeof (test_data_t));
154     *state = data;
155     handle_map = handle_map_new (TPM2_HT_TRANSIENT, MAX_ENTRIES_DEFAULT);
156     iostream = create_connection_iostream (&client_fd);
157     data->connection = connection_new (iostream, 0, handle_map);
158     g_object_unref (handle_map);
159     g_object_unref (iostream);
160     /* */
161     data->buffer_size = sizeof (two_handles_not_three);
162     data->buffer = calloc (1, data->buffer_size);
163     memcpy (data->buffer,
164             two_handles_not_three,
165             data->buffer_size);
166     data->command = tpm2_command_new (data->connection,
167                                       data->buffer,
168                                       data->buffer_size,
169                                       (TPMA_CC)((UINT32)0x06000149));
170     return 0;
171 }
172 /*
173  * This test setup function is much like the others with the exception of the
174  * Tpm2Command buffer being set to the 'cmd_with_auths'. This allows testing
175  * of the functions that parse / process the auth are of the command.
176  */
177 static int
tpm2_command_setup_with_auths(void ** state)178 tpm2_command_setup_with_auths (void **state)
179 {
180     test_data_t *data   = NULL;
181     gint         client_fd;
182     GIOStream   *iostream;
183     HandleMap   *handle_map;
184     TPMA_CC attributes = 2 << 25;
185 
186     data = calloc (1, sizeof (test_data_t));
187     /* allocate a buffer large enough to hold the cmd_with_auths buffer */
188     data->buffer_size = sizeof (cmd_with_auths);
189     data->buffer = calloc (1, data->buffer_size);
190     memcpy (data->buffer, cmd_with_auths, sizeof (cmd_with_auths));
191     handle_map = handle_map_new (TPM2_HT_TRANSIENT, MAX_ENTRIES_DEFAULT);
192     iostream = create_connection_iostream (&client_fd);
193     data->connection = connection_new (iostream, 0, handle_map);
194     g_object_unref (handle_map);
195     g_object_unref (iostream);
196     data->command = tpm2_command_new (data->connection,
197                                       data->buffer,
198                                       data->buffer_size,
199                                       attributes);
200 
201     *state = data;
202     return 0;
203 }
204 static int
tpm2_command_setup_flush_context_no_handle(void ** state)205 tpm2_command_setup_flush_context_no_handle (void **state)
206 {
207     test_data_t *data   = NULL;
208     gint         client_fd;
209     GIOStream   *iostream;
210     HandleMap   *handle_map;
211     TPMA_CC attributes = 2 << 25;
212 
213     data = calloc (1, sizeof (test_data_t));
214     /* allocate a buffer large enough to hold the cmd_with_auths buffer */
215     data->buffer_size = sizeof (cmd_buf_context_flush_no_handle);
216     data->buffer = calloc (1, data->buffer_size);
217     memcpy (data->buffer,
218             cmd_buf_context_flush_no_handle,
219             data->buffer_size);
220     handle_map = handle_map_new (TPM2_HT_TRANSIENT, MAX_ENTRIES_DEFAULT);
221     iostream = create_connection_iostream (&client_fd);
222     data->connection = connection_new (iostream, 0, handle_map);
223     g_object_unref (handle_map);
224     g_object_unref (iostream);
225     data->command = tpm2_command_new (data->connection,
226                                       data->buffer,
227                                       data->buffer_size,
228                                       attributes);
229 
230     *state = data;
231     return 0;
232 }
233 /**
234  * Tear down all of the data from the setup function. We don't have to
235  * free the data buffer (data->buffer) since the Tpm2Command frees it as
236  * part of its finalize function.
237  */
238 static int
tpm2_command_teardown(void ** state)239 tpm2_command_teardown (void **state)
240 {
241     test_data_t *data = (test_data_t*)*state;
242 
243     g_object_unref (data->connection);
244     g_object_unref (data->command);
245     free (data);
246     return 0;
247 }
248 /**
249  * This is a test for memory management / reference counting. The setup
250  * function does exactly that so when we get the Tpm2Command object we just
251  * check to be sure it's a GObject and then we unref it. This test will
252  * probably only fail when run under ASAN if the reference counting is
253  * off.
254  */
255 static void
tpm2_command_type_test(void ** state)256 tpm2_command_type_test (void **state)
257 {
258     test_data_t *data = (test_data_t*)*state;
259 
260     assert_true (G_IS_OBJECT (data->command));
261     assert_true (IS_TPM2_COMMAND (data->command));
262 }
263 
264 static void
tpm2_command_get_connection_test(void ** state)265 tpm2_command_get_connection_test (void **state)
266 {
267     test_data_t *data = (test_data_t*)*state;
268 
269     assert_int_equal (data->connection, tpm2_command_get_connection (data->command));
270 }
271 
272 static void
tpm2_command_get_buffer_test(void ** state)273 tpm2_command_get_buffer_test (void **state)
274 {
275     test_data_t *data = (test_data_t*)*state;
276 
277     assert_int_equal (data->buffer, tpm2_command_get_buffer (data->command));
278 }
279 
280 static void
tpm2_command_get_tag_test(void ** state)281 tpm2_command_get_tag_test (void **state)
282 {
283     test_data_t         *data   = (test_data_t*)*state;
284     guint8              *buffer = tpm2_command_get_buffer (data->command);
285     TPMI_ST_COMMAND_TAG  tag_ret;
286 
287     /* this is TPM2_ST_SESSIONS in network byte order */
288     buffer[0] = 0x80;
289     buffer[1] = 0x02;
290 
291     tag_ret = tpm2_command_get_tag (data->command);
292     assert_int_equal (tag_ret, TPM2_ST_SESSIONS);
293 }
294 
295 static void
tpm2_command_get_size_test(void ** state)296 tpm2_command_get_size_test (void **state)
297 {
298     test_data_t *data     = (test_data_t*)*state;
299     guint8      *buffer   = tpm2_command_get_buffer (data->command);
300     guint32      size_ret = 0;
301 
302     /* this is tpm_st_connections in network byte order */
303     buffer[0] = 0x80;
304     buffer[1] = 0x02;
305     buffer[2] = 0x00;
306     buffer[3] = 0x00;
307     buffer[4] = 0x00;
308     buffer[5] = 0x06;
309 
310     size_ret = tpm2_command_get_size (data->command);
311     assert_int_equal (0x6, size_ret);
312 }
313 
314 static void
tpm2_command_get_code_test(void ** state)315 tpm2_command_get_code_test (void **state)
316 {
317     test_data_t *data     = (test_data_t*)*state;
318     guint8      *buffer   = tpm2_command_get_buffer (data->command);
319     TPM2_CC       command_code;
320 
321     /**
322      * This is TPM2_ST_SESSIONS + a size of 0x0a + the command code for
323      * GetCapability in network byte order
324      */
325     buffer[0] = 0x80;
326     buffer[1] = 0x02;
327     buffer[2] = 0x00;
328     buffer[3] = 0x00;
329     buffer[4] = 0x00;
330     buffer[5] = 0x0a;
331     buffer[6] = 0x00;
332     buffer[7] = 0x00;
333     buffer[8] = 0x01;
334     buffer[9] = 0x7a;
335 
336     command_code = tpm2_command_get_code (data->command);
337     assert_int_equal (command_code, TPM2_CC_GetCapability);
338 }
339 
340 static void
tpm2_command_get_two_handle_count_test(void ** state)341 tpm2_command_get_two_handle_count_test (void **state)
342 {
343     test_data_t *data = (test_data_t*)*state;
344     guint8 command_handles;
345 
346     command_handles = tpm2_command_get_handle_count (data->command);
347     assert_int_equal (command_handles, 2);
348 }
349 
350 static void
tpm2_command_get_handles_test(void ** state)351 tpm2_command_get_handles_test (void **state)
352 {
353     test_data_t *data = (test_data_t*)*state;
354     TPM2_HANDLE handles [3] = { 0, 0, 0 };
355     size_t count = 3;
356     gboolean ret;
357 
358     ret = tpm2_command_get_handles (data->command, handles, &count);
359     assert_true (ret == TRUE);
360     assert_int_equal (handles [0], HANDLE_FIRST);
361     assert_int_equal (handles [1], HANDLE_SECOND);
362 }
363 
364 /*
365  * Get the handle at the first position in the handle area of the command.
366  */
367 static void
tpm2_command_get_handle_first_test(void ** state)368 tpm2_command_get_handle_first_test (void **state)
369 {
370     test_data_t *data = (test_data_t*)*state;
371     TPM2_HANDLE   handle_out;
372 
373     handle_out = tpm2_command_get_handle (data->command, 0);
374     assert_int_equal (handle_out, HANDLE_FIRST);
375 }
376 /*
377  * Get the handle at the second position in the handle area of the command.
378  */
379 static void
tpm2_command_get_handle_second_test(void ** state)380 tpm2_command_get_handle_second_test (void **state)
381 {
382     test_data_t *data = (test_data_t*)*state;
383     TPM2_HANDLE   handle_out;
384 
385     handle_out = tpm2_command_get_handle (data->command, 1);
386     assert_int_equal (handle_out, HANDLE_SECOND);
387 }
388 /*
389  * Attempt to get the handle at the third position in the handle area of the
390  * command. This should fail since the command has only two handles.
391  */
392 static void
tpm2_command_get_handle_fail_test(void ** state)393 tpm2_command_get_handle_fail_test (void **state)
394 {
395     test_data_t *data = (test_data_t*)*state;
396     TPM2_HANDLE   handle_out;
397 
398     handle_out = tpm2_command_get_handle (data->command, 2);
399     assert_int_equal (handle_out, 0);
400 }
401 /*
402  */
403 static void
tpm2_command_set_handle_first_test(void ** state)404 tpm2_command_set_handle_first_test (void **state)
405 {
406     test_data_t *data = (test_data_t*)*state;
407     TPM2_HANDLE   handle_in = 0xdeadbeef, handle_out = 0;
408     gboolean     ret;
409 
410     ret = tpm2_command_set_handle (data->command, handle_in, 0);
411     assert_true (ret);
412     handle_out = tpm2_command_get_handle (data->command, 0);
413     assert_int_equal (handle_out, handle_in);
414 }
415 static void
tpm2_command_set_handle_second_test(void ** state)416 tpm2_command_set_handle_second_test (void **state)
417 {
418     test_data_t *data = (test_data_t*)*state;
419     TPM2_HANDLE   handle_in = 0xdeadbeef, handle_out = 0;
420     gboolean     ret;
421 
422     ret = tpm2_command_set_handle (data->command, handle_in, 1);
423     assert_true (ret);
424     handle_out = tpm2_command_get_handle (data->command, 1);
425     assert_int_equal (handle_out, handle_in);
426 }
427 static void
tpm2_command_set_handle_fail_test(void ** state)428 tpm2_command_set_handle_fail_test (void **state)
429 {
430     test_data_t *data = (test_data_t*)*state;
431     TPM2_HANDLE   handle_in = 0xdeadbeef;
432     gboolean     ret;
433 
434     ret = tpm2_command_set_handle (data->command, handle_in, 2);
435     assert_false (ret);
436 }
437 static void
tpm2_command_get_auth_size_test(void ** state)438 tpm2_command_get_auth_size_test (void **state)
439 {
440     test_data_t *data = (test_data_t*)*state;
441     UINT32 auths_area_size = 0;
442 
443     auths_area_size = tpm2_command_get_auths_size (data->command);
444     assert_int_equal (auths_area_size, 0x92);
445 }
446 /*
447  * This structure is used to track state while processing the authorizations
448  * from the command authorization area.
449  */
450 typedef struct {
451     Tpm2Command *command;
452     size_t counter;
453     size_t handles_count;
454     TPM2_HANDLE handles [3];
455 } callback_auth_state_t;
456 /*
457  * The tpm2_command_foreach_auth function invokes this function for each
458  * authorization in the command authorization area. The 'user_data' is an
459  * instance of the callback_auth_state_t structure that we use to track state.
460  * The expected handles from the auth area are in the handles array in the
461  * order that they should be received. We then use the 'counter' to identify
462  * which handle we should receive for each callback (assuming that the
463  * callback is invoked for each auth IN ORDER).
464  */
465 static void
tpm2_command_foreach_auth_callback(gpointer authorization,gpointer user_data)466 tpm2_command_foreach_auth_callback (gpointer authorization,
467                                     gpointer user_data)
468 {
469     size_t auth_offset = *(size_t*)authorization;
470     callback_auth_state_t *callback_state = (callback_auth_state_t*)user_data;
471     TPM2_HANDLE handle;
472 
473     handle = tpm2_command_get_auth_handle (callback_state->command,
474                                            auth_offset);
475     g_debug ("tpm2_command_foreach_auth_callback:\n  counter: %zd\n"
476             "  handles_count: %zd\n  handle: 0x%08" PRIx32,
477             callback_state->counter,
478             callback_state->handles_count,
479             callback_state->handles [callback_state->counter]);
480     g_debug ("  auth_offset: %zu", auth_offset);
481     g_debug ("  AUTH_HANDLE_GET: 0x%08" PRIx32, handle);
482 
483     assert_true (callback_state->counter < callback_state->handles_count);
484     assert_int_equal (handle,
485                       callback_state->handles [callback_state->counter]);
486     ++callback_state->counter;
487 }
488 /*
489  * This test exercises the tpm2_command_foreach_auth function. The state
490  * structure must be initialized with the handles that are expected from
491  * the command. Each time the callback is invoked we compare the authorization
492  * handle to the handles array.
493  */
494 static void
tpm2_command_foreach_auth_test(void ** state)495 tpm2_command_foreach_auth_test (void **state)
496 {
497     test_data_t *data = (test_data_t*)*state;
498     /* this data is highly dependent on the */
499     callback_auth_state_t callback_state = {
500         .command = data->command,
501         .counter = 0,
502         .handles_count = 2,
503         .handles = {
504             0x02000000,
505             0x02000001,
506         },
507     };
508 
509     tpm2_command_foreach_auth (data->command,
510                                tpm2_command_foreach_auth_callback,
511                                &callback_state);
512 }
513 static void
tpm2_command_flush_context_handle_test(void ** state)514 tpm2_command_flush_context_handle_test (void **state)
515 {
516     test_data_t *data = (test_data_t*)*state;
517     TSS2_RC rc;
518     TPM2_HANDLE handle;
519 
520     rc = tpm2_command_get_flush_handle (data->command,
521                                         &handle);
522     assert_int_equal (rc, RM_RC (TPM2_RC_INSUFFICIENT));
523 }
524 /*
525  * This test attempts to read 3 handles from a command. It's paired with
526  * the `tpm2_command_setup_two_handles_not_three` setup function which
527  * populates the command with data appropriate for this test. The command
528  * body is for a command with 3 handles but only enough room is provided
529  * for two handles. Attempts to read 3 should stop at the end of the buffer.
530  */
531 static void
tpm2_command_two_handles_not_three(void ** state)532 tpm2_command_two_handles_not_three (void **state)
533 {
534     test_data_t *data = (test_data_t*)*state;
535     TPM2_HANDLE   handles [3] = { 0 };
536     size_t       handle_count = 3;
537     gboolean     ret = TRUE;
538 
539     ret = tpm2_command_get_handles (data->command,
540                                     handles,
541                                     &handle_count);
542     assert_true (ret);
543 }
544 
545 uint8_t get_cap_no_cap [] = {
546     0x80, 0x02, /* TPM2_ST_SESSIONS */
547     0x00, 0x00, 0x00, 0x0a, /* command buffer size */
548     0x00, 0x00, 0x01, 0x7a, /* TPM2_CC_GetCapability */
549 };
550 /*
551  * This setup function creates all of the components necessary to carry out
552  * a tpm2_command test. Additionally it creates a tpm2_command with a command
553  * buffer that should have 3 handles (per the TPMA_CC) but is only large
554  * enough to hold 2.
555  */
556 static int
tpm2_command_setup_get_cap_no_cap(void ** state)557 tpm2_command_setup_get_cap_no_cap (void **state)
558 {
559     test_data_t *data   = NULL;
560     gint         client_fd;
561     GIOStream   *iostream;
562     HandleMap   *handle_map;
563 
564     data = calloc (1, sizeof (test_data_t));
565     *state = data;
566     handle_map = handle_map_new (TPM2_HT_TRANSIENT, MAX_ENTRIES_DEFAULT);
567     iostream = create_connection_iostream (&client_fd);
568     data->connection = connection_new (iostream, 0, handle_map);
569     g_object_unref (handle_map);
570     g_object_unref (iostream);
571 
572     data->buffer_size = sizeof (get_cap_no_cap);
573     data->buffer = calloc (1, data->buffer_size);
574     memcpy (data->buffer,
575             get_cap_no_cap,
576             data->buffer_size);
577     data->command = tpm2_command_new (data->connection,
578                                       data->buffer,
579                                       data->buffer_size,
580                                       (TPMA_CC)((UINT32)0x0600017a));
581     return 0;
582 }
583 static void
tpm2_command_get_cap_no_cap(void ** state)584 tpm2_command_get_cap_no_cap (void **state)
585 {
586     test_data_t *data = (test_data_t*)*state;
587     TPM2_CAP cap;
588 
589     cap = tpm2_command_get_cap (data->command);
590     assert_int_equal (cap, 0);
591 }
592 static void
tpm2_command_get_cap_no_prop(void ** state)593 tpm2_command_get_cap_no_prop (void **state)
594 {
595     test_data_t *data = (test_data_t*)*state;
596     UINT32 prop;
597 
598     prop = tpm2_command_get_prop (data->command);
599     assert_int_equal (prop, 0);
600 }
601 static void
tpm2_command_get_cap_no_count(void ** state)602 tpm2_command_get_cap_no_count (void **state)
603 {
604     test_data_t *data = (test_data_t*)*state;
605     UINT32 count;
606 
607     count = tpm2_command_get_prop_count (data->command);
608     assert_int_equal (count, 0);
609 }
610 
611 gint
main(void)612 main (void)
613 {
614     const struct CMUnitTest tests[] = {
615         cmocka_unit_test_setup_teardown (tpm2_command_type_test,
616                                          tpm2_command_setup,
617                                          tpm2_command_teardown),
618         cmocka_unit_test_setup_teardown (tpm2_command_get_connection_test,
619                                          tpm2_command_setup,
620                                          tpm2_command_teardown),
621         cmocka_unit_test_setup_teardown (tpm2_command_get_buffer_test,
622                                          tpm2_command_setup,
623                                          tpm2_command_teardown),
624         cmocka_unit_test_setup_teardown (tpm2_command_get_tag_test,
625                                          tpm2_command_setup,
626                                          tpm2_command_teardown),
627         cmocka_unit_test_setup_teardown (tpm2_command_get_size_test,
628                                          tpm2_command_setup,
629                                          tpm2_command_teardown),
630         cmocka_unit_test_setup_teardown (tpm2_command_get_code_test,
631                                          tpm2_command_setup,
632                                          tpm2_command_teardown),
633         cmocka_unit_test_setup_teardown (tpm2_command_get_two_handle_count_test,
634                                          tpm2_command_setup_two_handles,
635                                          tpm2_command_teardown),
636         cmocka_unit_test_setup_teardown (tpm2_command_get_handles_test,
637                                          tpm2_command_setup_two_handles,
638                                          tpm2_command_teardown),
639         cmocka_unit_test_setup_teardown (tpm2_command_get_handle_first_test,
640                                          tpm2_command_setup_two_handles,
641                                          tpm2_command_teardown),
642         cmocka_unit_test_setup_teardown (tpm2_command_get_handle_second_test,
643                                          tpm2_command_setup_two_handles,
644                                          tpm2_command_teardown),
645         cmocka_unit_test_setup_teardown (tpm2_command_get_handle_fail_test,
646                                          tpm2_command_setup_two_handles,
647                                          tpm2_command_teardown),
648         cmocka_unit_test_setup_teardown (tpm2_command_set_handle_first_test,
649                                          tpm2_command_setup_two_handles,
650                                          tpm2_command_teardown),
651         cmocka_unit_test_setup_teardown (tpm2_command_set_handle_second_test,
652                                          tpm2_command_setup_two_handles,
653                                          tpm2_command_teardown),
654         cmocka_unit_test_setup_teardown (tpm2_command_set_handle_fail_test,
655                                          tpm2_command_setup_two_handles,
656                                          tpm2_command_teardown),
657         cmocka_unit_test_setup_teardown (tpm2_command_get_auth_size_test,
658                                          tpm2_command_setup_with_auths,
659                                          tpm2_command_teardown),
660         cmocka_unit_test_setup_teardown (tpm2_command_foreach_auth_test,
661                                          tpm2_command_setup_with_auths,
662                                          tpm2_command_teardown),
663         cmocka_unit_test_setup_teardown (tpm2_command_flush_context_handle_test,
664                                          tpm2_command_setup_flush_context_no_handle,
665                                          tpm2_command_teardown),
666         cmocka_unit_test_setup_teardown (tpm2_command_two_handles_not_three,
667                                          tpm2_command_setup_two_handles_not_three,
668                                          tpm2_command_teardown),
669         cmocka_unit_test_setup_teardown (tpm2_command_get_cap_no_cap,
670                                          tpm2_command_setup_get_cap_no_cap,
671                                          tpm2_command_teardown),
672         cmocka_unit_test_setup_teardown (tpm2_command_get_cap_no_prop,
673                                          tpm2_command_setup_get_cap_no_cap,
674                                          tpm2_command_teardown),
675         cmocka_unit_test_setup_teardown (tpm2_command_get_cap_no_count,
676                                          tpm2_command_setup_get_cap_no_cap,
677                                          tpm2_command_teardown),
678     };
679     return cmocka_run_group_tests (tests, NULL, NULL);
680 }
681