diff -r 950fec11ef90 tboot/common/tboot.c
--- a/tboot/common/tboot.c	Sun Jan 15 23:21:20 2012 +0800
+++ b/tboot/common/tboot.c	Tue Apr 17 10:15:33 2012 +0800
@@ -313,6 +313,7 @@ void begin_launch(multiboot_info_t *mbi)
     /* has already been launched */
 
     /* make TPM ready for measured launch */
+    tpm_unit_test_before_senter();
     if ( !is_tpm_ready(0) )
         apply_policy(TB_ERR_TPM_NOT_READY);
 
diff -r 950fec11ef90 tboot/common/tpm.c
--- a/tboot/common/tpm.c	Sun Jan 15 23:21:20 2012 +0800
+++ b/tboot/common/tpm.c	Tue Apr 17 10:13:40 2012 +0800
@@ -2121,6 +2121,2815 @@ uint32_t tpm_get_random(uint32_t localit
     return ret;
 }
 
+#ifdef TPM_UNIT_TEST
+
+static void clean_buf(void)
+{
+    memset(cmd_buf, 0, TPM_CMD_SIZE_MAX); 
+    memset(rsp_buf, 0, TPM_RSP_SIZE_MAX); 
+}
+
+static bool check_buf(uint8_t *exp_cmd, uint32_t cmd_size,
+                      uint8_t *exp_rsp, uint32_t rsp_size)
+{
+    if ( memcmp(exp_cmd, cmd_buf, cmd_size) != 0 )
+        return false;
+    if ( memcmp(exp_rsp, rsp_buf, rsp_size) != 0 )
+        return false;
+    return true;
+}
+
+static bool UNIT_PE_V_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 16;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 0x04, 0x0a, 
+        0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 0x8f, 0x1d, 
+        0x68, 0xd1, 0x39, 0x61}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 
+        0x04, 0x0a, 0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 
+        0x8f, 0x1d, 0x68, 0xd1, 0x39, 0x61};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_V_02(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 16;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t *out = NULL;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, out);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_V_03(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 16;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 0x04, 0x0a, 
+        0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 0x8f, 0x1d, 
+        0x68, 0xd1, 0x39, 0x61}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x10, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 
+        0x04, 0x0a, 0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 
+        0x8f, 0x1d, 0x68, 0xd1, 0x39, 0x61};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_V_04(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 17;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        /* for SDP3 */
+        /*
+        0xe2, 0x76, 0x21, 0x70, 0x8d, 0x8b, 0x74, 0x20, 
+        0x5e, 0x61, 0x3c, 0xe6, 0xd3, 0x39, 0xf8, 0x0b, 
+        0x3d, 0x83, 0x18, 0x42}};*/
+        /* for WB */
+        0x46, 0xF5, 0xBE, 0x07, 0x41, 0xA0, 0xCC, 0x80,
+        0x0C, 0x9D, 0x14, 0x68, 0x25, 0x75, 0x48, 0x7B,
+        0x78, 0xB6, 0xD2, 0xA1}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x11, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        /* for SDP3 */
+        /* 0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xe2, 0x76, 0x21, 0x70, 0x8d, 0x8b, 
+        0x74, 0x20, 0x5e, 0x61, 0x3c, 0xe6, 0xd3, 0x39, 
+        0xf8, 0x0b, 0x3d, 0x83, 0x18, 0x42}; */
+        /* for WB */
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0x46, 0xF5, 0xBE, 0x07, 0x41, 0xA0,
+        0xCC, 0x80, 0x0C, 0x9D, 0x14, 0x68, 0x25, 0x75,
+        0x48, 0x7B, 0x78, 0xB6, 0xD2, 0xA1};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_V_05(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 18;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    /*
+    tpm_pcr_value_t exp_out = {{
+        0xe5, 0x9b, 0x4b, 0xf8, 0xd3, 0x42, 0x3f, 0xe7, 
+        0xeb, 0xc4, 0x2c, 0xe3, 0xb0, 0xf8, 0x98, 0x35, 
+        0x09, 0x9e, 0x2b, 0x96}};
+    */
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x12, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00/*, 0xe5, 0x9b, 0x4b, 0xf8, 0xd3, 0x42, 
+        0x3f, 0xe7, 0xeb, 0xc4, 0x2c, 0xe3, 0xb0, 0xf8, 
+        0x98, 0x35, 0x09, 0x9e, 0x2b, 0x96*/};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    /*
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    */
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_V_06(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 19;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 0x04, 0x0a, 
+        0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 0x8f, 0x1d, 
+        0x68, 0xd1, 0x39, 0x61}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x13, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 
+        0x04, 0x0a, 0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 
+        0x8f, 0x1d, 0x68, 0xd1, 0x39, 0x61};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_V_07(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 20;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 0x04, 0x0a, 
+        0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 0x8f, 0x1d, 
+        0x68, 0xd1, 0x39, 0x61}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 
+        0x04, 0x0a, 0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 
+        0x8f, 0x1d, 0x68, 0xd1, 0x39, 0x61};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_IV_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 16;
+    tpm_digest_t *in = NULL;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, in, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_IV_02(void)
+{
+    uint32_t locality = 5;
+    uint32_t pcr = 16;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_IV_03(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 24;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_IV_04(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 16;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_FAIL;
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_IV_05(void)
+{
+    uint32_t locality = 1;
+    uint32_t pcr = 16;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_FAIL;
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PE_IV_06(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 17;
+    tpm_digest_t in = {{
+        1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4}};
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_LOCALITY;/* in SPD 3 whould be TPM_NOTLOCAL */
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x11, 0x01, 0x01, 
+        0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 
+        0x03, 0x03, 0x03, 0x03, 0x03, 0x04, 0x04, 0x04, 
+        0x04, 0x04};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x3d};
+
+    clean_buf();
+    ret = tpm_pcr_extend(locality, pcr, &in, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x10};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_02(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 0x04, 0x0a, 
+        0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 0x8f, 0x1d, 
+        0x68, 0xd1, 0x39, 0x61}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x10};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 
+        0x04, 0x0a, 0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 
+        0x8f, 0x1d, 0x68, 0xd1, 0x39, 0x61};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_03(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x10};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_04(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 0x04, 0x0a, 
+        0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 0x8f, 0x1d, 
+        0x68, 0xd1, 0x39, 0x61}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x10};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xfd, 0x60, 0xed, 0x16, 0xe5, 0x04, 
+        0x04, 0x0a, 0xaf, 0xa1, 0xc1, 0xcc, 0xed, 0x33, 
+        0x8f, 0x1d, 0x68, 0xd1, 0x39, 0x61};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_05(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 17;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        /* for SDP3 */ 
+        /* 0xf8, 0xf2, 0xfb, 0x54, 0xdb, 0x1b, 0xcb, 0xdf, 
+        0xcf, 0x48, 0xbe, 0xde, 0xb4, 0xf6, 0x94, 0x97, 
+        0x19, 0x25, 0xbd, 0x9b}}; */
+        /* for WB */
+        0x68, 0x2C, 0xC6, 0x4B, 0x89, 0x60, 0x4A, 0xF6,
+        0x53, 0x0B, 0x80, 0xC2, 0xD7, 0x35, 0x00, 0x4F,
+        0xC8, 0x95, 0x74, 0xE0}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x11};
+    uint8_t exp_rsp[] = {
+        /* for SDP3 */
+        /* 0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xf8, 0xf2, 0xfb, 0x54, 0xdb, 0x1b, 
+        0xcb, 0xdf, 0xcf, 0x48, 0xbe, 0xde, 0xb4, 0xf6, 
+        0x94, 0x97, 0x19, 0x25, 0xbd, 0x9b}; */
+        /* for WB */
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0x68, 0x2C, 0xC6, 0x4B, 0x89, 0x60,
+        0x4A, 0xF6, 0x53, 0x0B, 0x80, 0xC2, 0xD7, 0x35,
+        0x00, 0x4F, 0xC8, 0x95, 0x74, 0xE0};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_06(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 18;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    /*
+    tpm_pcr_value_t exp_out = {{
+        0x8d, 0x84, 0xdb, 0x02, 0xc0, 0x13, 0x9d, 0x2c, 
+        0x51, 0xdb, 0x15, 0xd8, 0xc6, 0xc4, 0x1b, 0xc0, 
+        0x6b, 0x34, 0xbe, 0xeb}};
+    */
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x12};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00/*, 0x8d, 0x84, 0xdb, 0x02, 0xc0, 0x13, 
+        0x9d, 0x2c, 0x51, 0xdb, 0x15, 0xd8, 0xc6, 0xc4, 
+        0x1b, 0xc0, 0x6b, 0x34, 0xbe, 0xeb*/};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    /*
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    */
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_07(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 19;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x13};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_08(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 20;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x14};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_V_09(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 17;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    tpm_pcr_value_t exp_out = {{
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
+        0xff, 0xff, 0xff, 0xff}};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 
+        0x00, 0x15, 0x00, 0x00, 0x00, 0x11};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 
+        0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
+        0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+    if ( memcmp(&out, &exp_out, sizeof(out)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_IV_01(void)
+{
+    uint32_t locality = 5;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_IV_02(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 24;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_IV_03(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_FAIL;
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PR_IV_04(void)
+{
+    uint32_t locality = 1;
+    uint32_t pcr = 16;
+    tpm_pcr_value_t out = {{0,}};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_FAIL;
+
+    clean_buf();
+    ret = tpm_pcr_read(locality, pcr, &out);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_V_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 16;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 
+        0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x01};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_V_02(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 16;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 
+        0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x01};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_V_03(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 20;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 
+        0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x10};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_IV_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 15;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_IV_02(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 24;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_IV_03(void)
+{
+    uint32_t locality = 5;
+    uint32_t pcr = 16;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_IV_04(void)
+{
+    uint32_t locality = 0;
+    uint32_t pcr = 20;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_NOTLOCAL;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 
+        0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x10};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x33};
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_PS_IV_05(void)
+{
+    uint32_t locality = 2;
+    uint32_t pcr = 17;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_NOTLOCAL;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 
+        0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x02};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x33};
+
+    clean_buf();
+    ret = tpm_pcr_reset(locality, pcr);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+#define TPM_NV_INDEX_LCP_OWN    0x40000002
+#define TPM_NV_INDEX_SELFDEF    0x400000ff
+#define TPM_NV_INDEX_UNDEF      0x400000ee
+
+static bool UNIT_NW_V_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
+        0x18, 0x19, 0x1a, 0x1b, 0x1c};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 
+        0x1a, 0x1b, 0x1c};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_V_02(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_SELFDEF;
+    uint32_t offset = 0;
+    static uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 256 */ 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 512 */
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09}; /* 746 */
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    static uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0xff, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x02, 0xea, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09}; /* 768 */
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset,
+                             (uint8_t *)data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf((uint8_t *)exp_cmd, sizeof(exp_cmd), 
+                    exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_V_03(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_SELFDEF;
+    uint32_t offset = 746;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13, 0x14, 0x15};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0xff, 0x00, 0x00, 
+        0x02, 0xea, 0x00, 0x00, 0x00, 0x16, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13, 0x14, 0x15};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_V_04(void)
+{
+    uint32_t locality = 2;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x00};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_IV_01(void)
+{
+    uint32_t locality = 5;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_IV_02(void)
+{
+    uint32_t locality = 2;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_FAIL;
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_IV_03(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_UNDEF;
+    uint32_t offset = 0;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BADINDEX;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0xee, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x02};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_IV_04(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 29;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_NOSPACE;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x1d, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x11};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_IV_05(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 20;
+    uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_NOSPACE;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 
+        0x00, 0xcd, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x11};
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset, data, data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NW_IV_06(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_SELFDEF;
+    uint32_t offset = 0;
+    static uint8_t  data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 256 */ 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 512 */
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a}; /* 747 */
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_nv_write_value(locality, index, offset,
+                             (uint8_t *)data, data_size);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_V_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[29] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_size = sizeof(data);
+    uint8_t  exp_data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 
+        0x18, 0x19, 0x1a, 0x1b, 0x1c};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x1d};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 
+        0x1a, 0x1b, 0x1c};
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_size )
+        return false;
+    if ( memcmp(data, &exp_data, sizeof(data)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_V_02(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_SELFDEF;
+    uint32_t offset = 0;
+    static uint8_t  data[TPM_NV_READ_VALUE_DATA_SIZE_MAX] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_size = sizeof(data);
+    static uint8_t  exp_data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 256 */ 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 512 */
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 
+        0x06, 0x07, }; /* 754 */
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0xff, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x02, 0xf2};
+    static uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x02, 0xf2, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; /* 768 */
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, 
+                            (uint8_t *)data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_size )
+        return false;
+    if ( memcmp((uint8_t *)data, (uint8_t *)exp_data, sizeof(data)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd),
+                    (uint8_t *)exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_V_03(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_SELFDEF;
+    uint32_t offset = 754;
+    uint8_t  data[14] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_size = sizeof(data);
+    uint8_t  exp_data[] = {
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13, 0x14, 0x15};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0xff, 0x00, 0x00, 
+        0x02, 0xf2, 0x00, 0x00, 0x00, 0x0e};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13, 0x14, 0x15};
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_size )
+        return false;
+    if ( memcmp(data, &exp_data, sizeof(data)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_V_04(void)
+{
+    uint32_t locality = 2;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[20] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_size = sizeof(data);
+    uint8_t  exp_data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x10, 0x11, 0x12, 0x13};
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 
+        0x12, 0x13};
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_size )
+        return false;
+    if ( memcmp(data, &exp_data, sizeof(data)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_IV_01(void)
+{
+    uint32_t locality = 5;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[20] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BAD_PARAMETER;
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_IV_02(void)
+{
+    uint32_t locality = 2;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 0;
+    uint8_t  data[20] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_FAIL;
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_IV_03(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_UNDEF;
+    uint32_t offset = 0;
+    uint8_t  data[20] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_BADINDEX;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0xee, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x14};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x02};
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_IV_04(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 29;
+    uint8_t  data[20] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_NOSPACE;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x1d, 0x00, 0x00, 0x00, 0x14};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x11};
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_IV_05(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_LCP_OWN;
+    uint32_t offset = 20;
+    uint8_t  data[20] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_NOSPACE;
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0x02, 0x00, 0x00, 
+        0x00, 0x14, 0x00, 0x00, 0x00, 0x14};
+    uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 
+        0x00, 0x11};
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_NR_IV_06(void)
+{
+    uint32_t locality = 0;
+    uint32_t index = TPM_NV_INDEX_SELFDEF;
+    uint32_t offset = 0;
+    static uint8_t  data[TPM_NV_READ_VALUE_DATA_SIZE_MAX + 1] = {0,};
+    uint32_t data_size = sizeof(data);
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_size = TPM_NV_READ_VALUE_DATA_SIZE_MAX;
+    static uint8_t  exp_data[] = {
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 256 */ 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* 512 */
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
+        0x08, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 
+        0x06, 0x07, }; /* 754 */
+    uint8_t exp_cmd[] = {
+        0x00, 0xc1, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 
+        0x00, 0xcf, 0x40, 0x00, 0x00, 0xff, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x02, 0xf2};
+    static uint8_t exp_rsp[] = {
+        0x00, 0xc4, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 
+        0x00, 0x00, 0x00, 0x00, 0x02, 0xf2, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x01, 
+        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 
+        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; /* 768 */
+
+    clean_buf();
+    ret = tpm_nv_read_value(locality, index, offset, 
+                            (uint8_t *)data, &data_size);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_size )
+        return false;
+    if ( memcmp((uint8_t *)data, (uint8_t *)exp_data, sizeof(data)) != 0 )
+        return false;
+    if ( !check_buf(exp_cmd, sizeof(exp_cmd), 
+                    (uint8_t *)exp_rsp, sizeof(exp_rsp)) )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_HMAC_V_01(void)
+{
+    uint8_t key[20] = {
+        0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
+        0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x00, 0x00, 0x00};
+    uint32_t in_data_size = 8;
+    uint8_t in_data[9] = "Hi There";
+    uint8_t digest[20];
+    bool ret;
+
+    bool exp_ret = true;
+    uint8_t exp_md[20] = {
+        0x67, 0x5b, 0x0b, 0x3a, 0x1b, 0x4d, 0xdf, 0x4e, 0x12, 0x48,
+        0x72, 0xda, 0x6c, 0x2f, 0x63, 0x2b, 0xfe, 0xd9, 0x57, 0xe9};
+
+    clean_buf();
+    ret = hmac(key, in_data, in_data_size, digest);
+
+    if ( ret != exp_ret )
+        return false;
+    {
+        printk("hmac result:\n");
+        for ( int i = 0; i < 20; i++ )
+            printk("%02x ", digest[i]);
+        printk("\n");
+    }
+
+    if ( memcmp( digest, exp_md, sizeof(digest)) != 0 )
+        return false;
+
+    return true;
+}
+
+/*
+static bool UNIT_OS_V_01(void)
+{
+    uint32_t locality = 0;
+    tpm_entity_type_t ent_type = TPM_ET_SRK;
+    uint32_t ent_value = TPM_KH_SRK;
+    tpm_nonce_t odd_osap, even_osap, nonce_even;
+    tpm_authhandle_t hauth;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+    clean_buf();
+    ret = tpm_osap(locality, ent_type, ent_value, &odd_osap, &hauth,
+                   &nonce_even, &even_osap);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_OI_V_01(void)
+{
+    uint32_t locality = 0;
+    tpm_nonce_t nonce_even;
+    tpm_authhandle_t hauth;
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+    clean_buf();
+    ret = tpm_oiap(locality, &hauth, &nonce_even);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+*/
+
+static bool test_tpm_wrap_seal(void)
+{
+    //uint32_t locality = 0;
+    //tpm_pcr_info_long_t pcr_info = 
+    //    {0x16, 0x01, 0x01, {3, {0, 0, 0}}, {3, {0, 0, 0}}, {{0,}}, {{0,}}};
+    uint32_t in_data_size = 0x20;
+    uint8_t in_data[] = {
+        0xaa,0xbd,0x5e,0x82,0xee,0x67,0x78,0x5e,0x43,0xbc,0x5e,0x26,
+        0x64,0x5e,0x12,0x12,0x5b,0x90,0xdf,0x0a,0x53,0x61,0x96,0x4b,
+        0xb9,0x4e,0x1d,0x2e,0x3c,0xb5,0xe6,0x1d};
+    //tpm_stored_data12_t *sealed_data = (tpm_stored_data12_t *)&blob;
+    uint32_t ret = true;
+    uint8_t key_authdata[20] = {
+        0x5b, 0xaa, 0x61, 0xe4, 0xc9, 0xb9, 0x3f, 0x3f, 0x06, 0x82,
+        0x25, 0x0b, 0x6c, 0xf8, 0x33, 0x1b, 0x7e, 0xe6, 0x8f, 0xd8};
+    uint8_t bb_authdata[20] = {
+        0x5b, 0xaa, 0x61, 0xe4, 0xc9, 0xb9, 0x3f, 0x3f, 0x06, 0x82,
+        0x25, 0x0b, 0x6c, 0xf8, 0x33, 0x1b, 0x7e, 0xe6, 0x8f, 0xd8};
+    tpm_nonce_t odd_osap = {{
+        0x1f, 0xd5, 0xc9, 0xa9, 0x4c, 0x67, 0xed, 0xe2, 0x66, 0x8d,
+        0x7f, 0xde, 0x7e, 0x81, 0xd4, 0x29, 0xc3, 0xbe, 0xbb, 0xb3}};
+    tpm_nonce_t even_osap = {{
+        0x4f, 0xe5, 0xf4, 0xe3, 0x92, 0x35, 0x2e, 0x22, 0x9b, 0xe7,
+        0xdd, 0x1b, 0xe0, 0xb7, 0x70, 0xf9, 0xd1, 0xf5, 0x6f, 0x74}};
+    tpm_nonce_t nonce_even = {{
+        0xff, 0xbe, 0x07, 0x7c, 0x87, 0x07, 0x98, 0x0c, 0x00, 0xbc,
+        0xbb, 0x96, 0x01, 0x88, 0xda, 0xc3, 0x0d, 0x02, 0xc0, 0x2e}};
+    tpm_nonce_t nonce_odd = {{
+        0x1f, 0xd5, 0xc9, 0xa9, 0x4c, 0x67, 0xed, 0xe2, 0x66, 0x8d,
+        0x7f, 0xde, 0x7e, 0x81, 0xd4, 0x29, 0xc3, 0xbe, 0xbb, 0xb3}};
+    //tpm_authhandle_t hauth = 0;
+    tpm_authdata_t shared_secret, pub_auth;//, res_auth;
+    tpm_encauth_t enc_auth;
+    uint8_t cont_session = false;
+    //tpm_key_handle_t hkey = TPM_KH_SRK;
+    uint32_t pcr_info_size = 0;//sizeof(pcr_info);
+    uint32_t offset;
+    uint32_t ordinal = TPM_ORD_SEAL;
+    tpm_digest_t digest;
+
+    /* generate nonce */
+    //odd_osap = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
+
+    /* establish a osap session */
+    //ret = tpm_osap(locality, TPM_ET_SRK, TPM_KH_SRK, &odd_osap, &hauth, 
+    //               &nonce_even, &even_osap);
+    //if ( ret != TPM_SUCCESS )
+    //        return ret;
+
+    /* calculate the shared secret 
+       shared-secret = HMAC(srk_auth, even_osap || odd_osap) */
+    offset = 0;
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &even_osap);
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &odd_osap);
+    hmac((uint8_t *)&key_authdata, WRAPPER_IN_BUF, offset,
+         (uint8_t *)&shared_secret);
+    {
+        printk("shared_secret:\n");
+        for ( int i = 0; i < 20; i++ )
+            printk("%02x ", shared_secret[i]);
+        printk("\n");
+    }
+
+    /* generate ecrypted authdata for data
+       enc_auth = XOR(authdata, sha1(shared_secret || last_even_nonce)) */
+    offset = 0;
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &shared_secret);
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &nonce_even);
+    sha1_buffer(WRAPPER_IN_BUF, offset, (uint8_t *)&digest);
+    memcpy(&enc_auth, &bb_authdata, sizeof(blob_authdata));
+    XOR_BLOB_TYPE(&enc_auth, &digest);
+    {
+        printk("enc_auth:\n");
+        for ( int i = 0; i < 20; i++ )
+            printk("%02x ", enc_auth[i]);
+        printk("\n");
+    }
+
+    /* generate nonce */
+    //nonce_odd = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
+
+    /* calculate authdata */
+    /* in_param_digest = sha1(1S ~ 6S) */
+    offset = 0;
+    UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, ordinal);
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &enc_auth);
+    UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, pcr_info_size);
+    //UNLOAD_PCR_INFO_LONG(WRAPPER_IN_BUF, offset, &pcr_info);
+    UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, in_data_size);
+    UNLOAD_BLOB(WRAPPER_IN_BUF, offset, in_data, in_data_size);
+    sha1_buffer(WRAPPER_IN_BUF, offset, (uint8_t *)&digest);
+    {
+        printk("in param digest:\n");
+        for ( int i = 0; i < 20; i++ )
+            printk("%02x ", digest.digest[i]);
+        printk("\n");
+    }
+
+
+    /* authdata = hmac(key, in_param_digest || auth_params) */
+    offset = 0;
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &digest);
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &nonce_even);
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &nonce_odd);
+    UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, cont_session);
+    hmac((uint8_t *)&shared_secret, WRAPPER_IN_BUF, offset,
+         (uint8_t *)&pub_auth);
+    {
+        printk("pub auth data:\n");
+        for ( int i = 0; i < 20; i++ )
+            printk("%02x ", pub_auth[i]);
+        printk("\n");
+    }
+
+
+    /* call the simple seal function */
+    /*ret = tpm_seal(locality, hkey, (const tpm_encauth_t *)&enc_auth,
+                   pcr_info_size, &pcr_info, in_data_size, in_data, 
+                   hauth, &nonce_odd, &cont_session, 
+                   (const tpm_authdata_t *)&pub_auth,
+                   (tpm_stored_data12_header_t *)sealed_data,
+                   &nonce_even, &res_auth);
+    */
+
+    return ret;
+}
+
+static uint8_t blob[512];
+static uint32_t sealed_data_size;
+
+static bool UNIT_SL_V_01(void)
+{
+    uint32_t locality = 0;
+    tpm_pcr_info_long_t pcr_info = 
+        {0x6, 0x01, 0x01, {3, {0, 0, 0}}, {3, {0, 0, 0}}, {{0,}}, {{0,}}};
+    uint32_t in_data_size = 20;
+    uint8_t in_data[20] = 
+        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+    sealed_data_size = 512;
+    clean_buf();
+    ret = _tpm_wrap_seal(locality, &pcr_info, in_data_size, in_data,
+                         &sealed_data_size, blob);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_SL_V_02(void)
+{
+    uint32_t locality = 2;
+    tpm_pcr_info_long_t pcr_info = 
+        {0x6, 0x04, 0x04, {3, {0, 0, 2}}, {3, {0, 0, 2}}, {{0,}}, {{0,}}};
+    uint32_t in_data_size = 20;
+    uint8_t in_data[20] = 
+        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+    uint32_t ret;
+    uint32_t offset = 0;
+    uint32_t blob_size = 20;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+
+    tpm_pcr_value_t pcr_value;
+    ret = tpm_pcr_read(locality, 17, &pcr_value);
+    if ( ret != TPM_SUCCESS )
+        return false;
+    offset = 0;
+    UNLOAD_PCR_SELECTION(WRAPPER_IN_BUF, offset, &pcr_info.creation_pcr_selection);
+    UNLOAD_INTEGER(WRAPPER_IN_BUF, offset, blob_size);
+    UNLOAD_BLOB_TYPE(WRAPPER_IN_BUF, offset, &pcr_value);
+    sha1_buffer(WRAPPER_IN_BUF, offset,
+                (uint8_t *)&pcr_info.digest_at_creation);
+    memcpy((uint8_t *)&pcr_info.digest_at_release,
+           (uint8_t *)&pcr_info.digest_at_creation,
+            sizeof(pcr_info.digest_at_release));
+
+    sealed_data_size = 512;
+    clean_buf();
+    ret = _tpm_wrap_seal(locality, &pcr_info, in_data_size, in_data,
+                         &sealed_data_size, blob);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_SL_V_03(void)
+{
+    uint32_t locality = 0;
+    tpm_locality_selection_t release_locs = TPM_LOC_ZERO;
+    uint32_t pcr_nr_create = 0, pcr_nr_release = 0;
+    uint8_t *pcr_indcs_create = NULL, *pcr_indcs_release = NULL;
+    const tpm_pcr_value_t ** pcr_values_release = NULL;
+    uint32_t in_data_size = 20;
+    uint8_t in_data[20] = 
+        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+    sealed_data_size = 512;
+    clean_buf();
+    ret = tpm_seal(locality, release_locs, pcr_nr_create, pcr_indcs_create,
+                   pcr_nr_release, pcr_indcs_release, pcr_values_release,
+                   in_data_size, in_data, &sealed_data_size, blob);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_SL_V_04(void)
+{
+    uint32_t locality = 2;
+    tpm_locality_selection_t release_locs = TPM_LOC_TWO;
+    uint32_t pcr_nr_create = 1, pcr_nr_release = 1;
+    uint8_t pcr_indcs_create[1] = {17}, pcr_indcs_release[1] = {17};
+    const tpm_pcr_value_t *pcr_values_release[1];
+    uint32_t in_data_size = 20;
+    uint8_t in_data[20] = 
+        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+
+    tpm_pcr_value_t pcr_value;
+    ret = tpm_pcr_read(locality, 17, &pcr_value);
+    if ( ret != TPM_SUCCESS )
+        return false;
+    pcr_values_release[0] = &pcr_value;
+
+    sealed_data_size = 512;
+    clean_buf();
+    ret = tpm_seal(locality, release_locs, pcr_nr_create, pcr_indcs_create,
+                   pcr_nr_release, pcr_indcs_release, pcr_values_release,
+                   in_data_size, in_data, &sealed_data_size, blob);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_SL_V_05(void)
+{
+    uint32_t locality = 2;
+    tpm_locality_selection_t release_locs = TPM_LOC_TWO;
+    uint32_t pcr_nr_create = 4, pcr_nr_release = 4;
+    uint8_t pcr_indcs_create[4]  = {17,18,19,20},
+            pcr_indcs_release[4] = {17,18,19,20};
+    const tpm_pcr_value_t *pcr_values_release[4];
+    uint32_t in_data_size = 20;
+    uint8_t in_data[20] = 
+        {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+
+
+    tpm_pcr_value_t pcr_value[4];
+
+    for ( uint32_t i = 0; i < 4; i++ ) {
+        ret = tpm_pcr_read(locality, 17 + i, &pcr_value[i]);
+        if ( ret != TPM_SUCCESS )
+            return false;
+        pcr_values_release[i] = &pcr_value[i];
+    }
+
+    sealed_data_size = 512;
+    clean_buf();
+    ret = tpm_seal(locality, release_locs, pcr_nr_create, pcr_indcs_create,
+                   pcr_nr_release, pcr_indcs_release, pcr_values_release,
+                   in_data_size, in_data, &sealed_data_size, blob);
+    if ( ret != exp_ret )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_USL_V_01(void)
+{
+    uint32_t locality = 0;
+    uint32_t data_size = 20;
+    uint8_t data[20] = 
+        {0, };
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_data_size = 20;
+    uint8_t exp_data[20] = 
+         {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+
+    clean_buf();
+    ret = _tpm_wrap_unseal(locality, blob, &data_size, data);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_data_size )
+        return false;
+    if ( memcmp(data, exp_data, data_size) != 0 )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_USL_V_02(void)
+{
+    uint32_t locality = 2;
+    uint32_t data_size = 20;
+    uint8_t data[20] = 
+        {0, };
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_data_size = 20;
+    uint8_t exp_data[20] = 
+         {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+
+    clean_buf();
+    ret = _tpm_wrap_unseal(locality, blob, &data_size, data);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_data_size )
+        return false;
+    if ( memcmp(data, exp_data, data_size) != 0 )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_USL_V_03(void)
+{
+    uint32_t locality = 0;
+    uint32_t data_size = 20;
+    uint8_t data[20] = 
+        {0, };
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_data_size = 20;
+    uint8_t exp_data[20] = 
+         {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+
+    clean_buf();
+    ret = tpm_unseal(locality, sealed_data_size, blob, &data_size, data);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_data_size )
+        return false;
+    if ( memcmp(data, exp_data, data_size) != 0 )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_USL_V_04(void)
+{
+    uint32_t locality = 2;
+    uint32_t data_size = 20;
+    uint8_t data[20] = 
+        {0, };
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_data_size = 20;
+    uint8_t exp_data[20] = 
+         {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+
+    clean_buf();
+    ret = tpm_unseal(locality, sealed_data_size, blob, &data_size, data);
+    if ( ret != exp_ret )
+        return false;
+    if ( data_size != exp_data_size )
+        return false;
+    if ( memcmp(data, exp_data, data_size) != 0 )
+        return false;
+
+    return true;
+}
+
+static bool UNIT_USL_IV_01(void)
+{
+    uint32_t locality = 2;
+    uint32_t data_size = 20;
+    uint8_t data[20] = 
+        {0, };
+    uint32_t ret;
+
+    uint32_t exp_ret = TPM_SUCCESS;
+    uint32_t exp_data_size = 20;
+    uint8_t exp_data[20] = 
+         {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
+
+    blob[sealed_data_size/2] ^= 0x10;
+    clean_buf();
+    ret = tpm_unseal(locality, sealed_data_size, blob, &data_size, data);
+    if ( ret != exp_ret )
+        return true;
+    if ( data_size != exp_data_size )
+        return true;
+    if ( memcmp(data, exp_data, data_size) != 0 )
+        return true;
+
+    return false;
+}
+
+#define RUN_CASE(caseid) {\
+    if ( caseid() )\
+        printk("TPM_UNIT_TEST: " #caseid " passed\n");\
+    else\
+        printk("TPM_UNIT_TEST: " #caseid " failed\n");\
+}
+
+void tpm_unit_test_before_senter(void)
+{
+    RUN_CASE(UNIT_PR_V_01 ); /*   Pcr16                     */
+    RUN_CASE(UNIT_PE_V_01 ); /*   Pcr16, out != NULL        */
+    RUN_CASE(UNIT_PR_V_02 ); /*   Pcr16                     */
+    RUN_CASE(UNIT_PS_V_01 ); /*   Pcr16                     */
+    RUN_CASE(UNIT_PE_V_02 ); /*   Pcr16, out = NULL         */
+    RUN_CASE(UNIT_PR_V_09 ); /*  Pcr17                      */
+    RUN_CASE(UNIT_PE_IV_01); /*  in = NULL                  */
+    RUN_CASE(UNIT_PE_IV_02); /*  locality = 5               */
+    RUN_CASE(UNIT_PE_IV_03); /*  pcr24                      */
+    RUN_CASE(UNIT_PE_IV_04); /*  locality = 2               */
+    RUN_CASE(UNIT_PE_IV_06); /*  pcr17                      */
+    RUN_CASE(UNIT_PR_IV_01); /*  locality = 5               */
+    RUN_CASE(UNIT_PR_IV_02); /*  Pcr24                      */
+    RUN_CASE(UNIT_PR_IV_03); /*  Locality = 2               */
+    RUN_CASE(UNIT_PS_IV_01); /*  Pcr15                      */
+    RUN_CASE(UNIT_PS_IV_02); /*  Pcr24                      */
+    RUN_CASE(UNIT_PS_IV_03); /*  Locality = 5               */
+    RUN_CASE(UNIT_PS_IV_04); /*  Pcr20, locality = 0        */
+    RUN_CASE(UNIT_NW_V_01 ); /*   LCP_OWN, off 0, 29 bytes  */
+    RUN_CASE(UNIT_NR_V_01 ); /*   LCP_OWN, off 0, 29 bytes  */
+    RUN_CASE(UNIT_NW_V_02 ); /*   SELFDEF, off 0, 746 bytes */
+    RUN_CASE(UNIT_NW_V_03 ); /*   SELFDEF, off 746, 22bytes */
+    RUN_CASE(UNIT_NR_V_02 ); /*   SELFDEF, off 0, 754 bytes */
+    RUN_CASE(UNIT_NR_V_03 ); /*   SELFDEF, off 754, 14bytes */
+    RUN_CASE(UNIT_NW_IV_01); /*   Locality = 5              */
+    RUN_CASE(UNIT_NW_IV_02); /*   Locality = 2              */
+    RUN_CASE(UNIT_NW_IV_03); /*   UNDEF                     */
+    RUN_CASE(UNIT_NW_IV_04); /*   LCP_OWN, off 29           */
+    RUN_CASE(UNIT_NW_IV_05); /*   LCP_OWN, off 20, 20bytes  */
+    RUN_CASE(UNIT_NW_IV_06); /*   SELFDEF, off 0, 747bytes  */
+    RUN_CASE(UNIT_NR_IV_01); /*   Locality = 5              */
+    RUN_CASE(UNIT_NR_IV_02); /*   Locality = 2              */
+    RUN_CASE(UNIT_NR_IV_03); /*   UNDEF                     */
+    RUN_CASE(UNIT_NR_IV_04); /*   LCP_OWN, off 29           */
+    RUN_CASE(UNIT_NR_IV_05); /*   LCP_OWN, off 20, 20bytes  */
+    RUN_CASE(UNIT_NR_IV_06); /*   SELFDEF, off 0, 755bytes  */
+}
+
+void tpm_unit_test_after_senter(void)
+{
+    RUN_CASE(UNIT_PS_V_02 ); /*    Pcr16                    */
+    RUN_CASE(UNIT_PR_V_03 ); /*    Pcr16                    */
+    RUN_CASE(UNIT_PE_V_03 ); /*   pcr16, out != NULL        */
+    RUN_CASE(UNIT_PR_V_04 ); /*    Pcr16                    */
+    RUN_CASE(UNIT_PR_V_05 ); /*   Pcr17                     */
+    RUN_CASE(UNIT_PE_V_04 ); /*   Pcr17, out != NULL        */
+    RUN_CASE(UNIT_PR_V_06 ); /*   Pcr18                     */
+    RUN_CASE(UNIT_PE_V_05 ); /*   Pcr18, out != NULL        */
+    RUN_CASE(UNIT_PR_V_07 ); /*   Pcr19                     */
+    RUN_CASE(UNIT_PE_V_06 ); /*   Pcr19, out != NULL        */
+    RUN_CASE(UNIT_PR_V_08 ); /*   Pcr20                     */
+    RUN_CASE(UNIT_PE_V_07 ); /*   Pcr20, out != NULL        */
+    RUN_CASE(UNIT_PS_V_03 ); /*    Pcr20                    */
+    RUN_CASE(UNIT_PE_IV_05); /*   locality = 1              */
+    RUN_CASE(UNIT_PR_IV_04); /*   locality = 1              */
+    RUN_CASE(UNIT_PS_IV_05); /*   Pcr17, Locality = 2       */
+    RUN_CASE(UNIT_NW_V_04); /*    LCP_OWN, off 0, 20 bytes */
+    RUN_CASE(UNIT_NR_V_04); /*    LCP_OWN, off 0, 20 bytes */
+    //RUN_CASE(UNIT_OS_V_01 ); /*   TPM_ET_SRK                */
+    //RUN_CASE(UNIT_OI_V_01 ); /*   loc = 0                   */
+    RUN_CASE(UNIT_HMAC_V_01);/*                             */
+    RUN_CASE(test_tpm_wrap_seal);/*                             */
+    RUN_CASE(UNIT_SL_V_05 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_USL_V_04 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_USL_IV_01); /*   loc = 2                   */
+    RUN_CASE(UNIT_SL_V_04 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_USL_V_04 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_SL_V_03 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_USL_V_03 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_SL_V_02 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_USL_V_02 ); /*   loc = 2                   */
+    RUN_CASE(UNIT_SL_V_01 ); /*   loc = 0                   */
+    RUN_CASE(UNIT_USL_V_01 ); /*   loc = 0                   */
+}
+
+#endif /* TPM_UNIT_TEST */
+
 /*
  * Local variables:
  * mode: C
diff -r 950fec11ef90 tboot/include/tpm.h
--- a/tboot/include/tpm.h	Sun Jan 15 23:21:20 2012 +0800
+++ b/tboot/include/tpm.h	Tue Apr 17 10:13:40 2012 +0800
@@ -272,7 +272,18 @@ extern uint32_t tpm_get_random(uint32_t 
 extern uint32_t tpm_get_random(uint32_t locality, uint8_t *random_data,
                                uint32_t *data_size);
 
+#define TPM_UNIT_TEST 1
+
+#ifdef TPM_UNIT_TEST
+void tpm_unit_test_before_senter(void);
+void tpm_unit_test_after_senter(void);
+#else
+#define tpm_unit_test_before_senter()
+#define tpm_unit_test_after_senter()
+#endif   /* TPM_UNIT_TEST */
+
 #endif   /* __TPM_H__ */
+
 
 /*
  * Local variables:
diff -r 950fec11ef90 tboot/txt/txt.c
--- a/tboot/txt/txt.c	Sun Jan 15 23:21:20 2012 +0800
+++ b/tboot/txt/txt.c	Tue Apr 17 10:13:40 2012 +0800
@@ -741,6 +741,8 @@ void txt_post_launch(void)
     write_priv_config_reg(TXTCR_ERRORCODE, 0x00000000);
     write_priv_config_reg(TXTCR_ESTS, 0xffffffff);  /* write 1's to clear */
 
+    tpm_unit_test_after_senter();
+
     /* bring RLPs into environment (do this before restoring MTRRs to ensure */
     /* SINIT area is mapped WB for MONITOR-based RLP wakeup) */
     txt_wakeup_cpus();
