mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
6a8aed12ee
Disabled test cases are tracked in: IDF-4465, IDF-5045, IDF-5057, IDF-5058, IDF-5059, IDF-5060, IDF-5061, IDF-5131 - test_fatfs: IDF-5136 - test_pm: IDF-5053 - test_cache_mmu: IDF-5138 - test_partitions: IDF-5137 - test_vfs: IDF-5139 - test_freertos: IDF-5140 - test_wpa_supplicant: IDF-5046 - test_mbedtls: IDF-5141 - test_pthread: IDF-5142 - test_protocomm: IDF-5143 - test_lightsleep: IDF-5053 - test_taskwdt: IDF-5055 - test_tcp_transport: IDF-5144 - test_app_update: IDF-5145 - test_timer: IDF-5052 - test_spi: IDF-5146 - test_rtc_clk: IDF-5060 - test_heap: IDF-5167 ci: fixed issues for tests of libgcc, ets_timer, newlib test_pm: support on C2
66 lines
2.0 KiB
C
66 lines
2.0 KiB
C
/*
|
|
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
/*
|
|
* mbedTLS SHA performance test
|
|
*/
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <string.h>
|
|
#include "mbedtls/sha256.h"
|
|
#include "unity.h"
|
|
#include "sdkconfig.h"
|
|
#include "esp_heap_caps.h"
|
|
#include "test_utils.h"
|
|
#include "ccomp_timer.h"
|
|
#include "test_mbedtls_utils.h"
|
|
|
|
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
|
//IDF-5141
|
|
TEST_CASE("mbedtls SHA performance", "[aes]")
|
|
{
|
|
const unsigned CALLS = 256;
|
|
const unsigned CALL_SZ = 16 * 1024;
|
|
mbedtls_sha256_context sha256_ctx;
|
|
float elapsed_usec;
|
|
unsigned char sha256[32];
|
|
|
|
// allocate internal memory
|
|
uint8_t *buf = heap_caps_malloc(CALL_SZ, MALLOC_CAP_DMA | MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL);
|
|
TEST_ASSERT_NOT_NULL(buf);
|
|
memset(buf, 0x55, CALL_SZ);
|
|
|
|
mbedtls_sha256_init(&sha256_ctx);
|
|
ccomp_timer_start();
|
|
TEST_ASSERT_EQUAL(0, mbedtls_sha256_starts(&sha256_ctx, false));
|
|
for (int c = 0; c < CALLS; c++) {
|
|
TEST_ASSERT_EQUAL(0, mbedtls_sha256_update(&sha256_ctx, buf, CALL_SZ));
|
|
}
|
|
TEST_ASSERT_EQUAL(0, mbedtls_sha256_finish(&sha256_ctx, sha256));
|
|
elapsed_usec = ccomp_timer_stop();
|
|
|
|
free(buf);
|
|
mbedtls_sha256_free(&sha256_ctx);
|
|
|
|
/* Check the result. Reference value can be calculated using:
|
|
* dd if=/dev/zero bs=$((16*1024)) count=256 | tr '\000' '\125' | sha256sum
|
|
*/
|
|
const char *expected_hash = "c88df2638fb9699abaad05780fa5e0fdb6058f477069040eac8bed3231286275";
|
|
char hash_str[sizeof(sha256) * 2 + 1];
|
|
utils_bin2hex(hash_str, sizeof(hash_str), sha256, sizeof(sha256));
|
|
|
|
TEST_ASSERT_EQUAL_STRING(expected_hash, hash_str);
|
|
|
|
// bytes/usec = MB/sec
|
|
float mb_sec = (CALL_SZ * CALLS) / elapsed_usec;
|
|
printf("SHA256 rate %.3fMB/sec\n", mb_sec);
|
|
#ifdef CONFIG_MBEDTLS_HARDWARE_SHA
|
|
// Don't put a hard limit on software SHA performance
|
|
TEST_PERFORMANCE_CCOMP_GREATER_THAN(SHA256_THROUGHPUT_MBSEC, "%.3fMB/sec", mb_sec);
|
|
#endif
|
|
}
|
|
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|