From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 3797F5AB9 for ; Fri, 6 May 2016 15:59:20 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 06 May 2016 06:59:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,587,1455004800"; d="scan'208";a="98426491" Received: from sie-lab-212-116.ir.intel.com (HELO silpixa00378492.ir.intel.com) ([10.237.212.116]) by fmsmga004.fm.intel.com with ESMTP; 06 May 2016 06:59:19 -0700 From: Pablo de Lara To: dev@dpdk.org Cc: declan.doherty@intel.com, Pablo de Lara Date: Fri, 6 May 2016 15:03:45 +0100 Message-Id: <1462543429-26741-5-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462543429-26741-1-git-send-email-pablo.de.lara.guarch@intel.com> References: <1462543429-26741-1-git-send-email-pablo.de.lara.guarch@intel.com> Subject: [dpdk-dev] [PATCH 4/8] test: use new bit-level memcmp macro X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 13:59:20 -0000 Instead of modifying the content of the buffers, to compare them at bit-level, use the new macro TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT, which does not make any modifications in the buffers. Signed-off-by: Pablo de Lara --- app/test/test_cryptodev.c | 68 +++++++++-------------------------------------- 1 file changed, 12 insertions(+), 56 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 176de59..f56e622 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -3392,8 +3392,6 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata) int retval; uint8_t *plaintext, *ciphertext; uint8_t plaintext_pad_len; - uint8_t lastByteValidBits = 8; - uint8_t lastByteMask = 0xFF; /* Create SNOW3G session */ retval = create_snow3g_cipher_session(ts_params->valid_devs[0], @@ -3440,20 +3438,14 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata) else ciphertext = plaintext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); - if (lastByteValidBits == 0) - lastByteValidBits = 8; - lastByteMask = lastByteMask << (8 - lastByteValidBits); - (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; - #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); #endif /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL( + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len >> 3, + tdata->validDataLenInBits.len, "Snow3G Ciphertext data not as expected"); return 0; } @@ -3468,8 +3460,6 @@ test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) int retval; uint8_t plaintext_pad_len; - uint8_t lastByteValidBits = 8; - uint8_t lastByteMask = 0xFF; /* Create SNOW3G session */ retval = create_snow3g_cipher_session(ts_params->valid_devs[0], @@ -3527,20 +3517,14 @@ test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) else ciphertext = plaintext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); - if (lastByteValidBits == 0) - lastByteValidBits = 8; - lastByteMask = lastByteMask << (8 - lastByteValidBits); - (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; - #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); #endif /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL( + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len >> 3, + tdata->validDataLenInBits.len, "Snow3G Ciphertext data not as expected"); return 0; } @@ -3555,8 +3539,6 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata) uint8_t *plaintext, *ciphertext; uint8_t ciphertext_pad_len; - uint8_t lastByteValidBits = 8; - uint8_t lastByteMask = 0xFF; /* Create SNOW3G session */ retval = create_snow3g_cipher_session(ts_params->valid_devs[0], @@ -3600,19 +3582,14 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata) + tdata->iv.len; else plaintext = ciphertext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); - if (lastByteValidBits == 0) - lastByteValidBits = 8; - lastByteMask = lastByteMask << (8 - lastByteValidBits); - (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); #endif /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext, + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, tdata->plaintext.data, - tdata->plaintext.len >> 3, + tdata->validDataLenInBits.len, "Snow3G Plaintext data not as expected"); return 0; } @@ -3626,8 +3603,6 @@ static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) uint8_t *plaintext, *ciphertext; uint8_t ciphertext_pad_len; - uint8_t lastByteValidBits = 8; - uint8_t lastByteMask = 0xFF; /* Create SNOW3G session */ retval = create_snow3g_cipher_session(ts_params->valid_devs[0], @@ -3685,19 +3660,14 @@ static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata) + tdata->iv.len; else plaintext = ciphertext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); - if (lastByteValidBits == 0) - lastByteValidBits = 8; - lastByteMask = lastByteMask << (8 - lastByteValidBits); - (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); #endif /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext, + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext, tdata->plaintext.data, - tdata->plaintext.len >> 3, + tdata->validDataLenInBits.len, "Snow3G Plaintext data not as expected"); return 0; } @@ -3712,8 +3682,6 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata) uint8_t *plaintext, *ciphertext; uint8_t plaintext_pad_len; - uint8_t lastByteValidBits = 8; - uint8_t lastByteMask = 0xFF; /* Create SNOW3G session */ retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0], @@ -3763,20 +3731,15 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata) + tdata->iv.len; else ciphertext = plaintext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); - if (lastByteValidBits == 0) - lastByteValidBits = 8; - lastByteMask = lastByteMask << (8-lastByteValidBits); - (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); #endif /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL( + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len >> 3, + tdata->validDataLenInBits.len, "Snow3G Ciphertext data not as expected"); ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) @@ -3800,8 +3763,6 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata) uint8_t *plaintext, *ciphertext; uint8_t plaintext_pad_len; - uint8_t lastByteValidBits = 8; - uint8_t lastByteMask = 0xFF; /* Create SNOW3G session */ retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0], @@ -3855,21 +3816,16 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata) else ciphertext = plaintext; - lastByteValidBits = (tdata->validDataLenInBits.len % 8); - if (lastByteValidBits == 0) - lastByteValidBits = 8; - lastByteMask = lastByteMask << (8-lastByteValidBits); - (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask; ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + plaintext_pad_len + tdata->aad.len + tdata->iv.len; #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); #endif /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL( + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( ciphertext, tdata->ciphertext.data, - tdata->ciphertext.len >> 3, + tdata->validDataLenInBits.len, "Snow3G Ciphertext data not as expected"); /* Validate obuf */ -- 2.5.0