Add testcases for psa_crypto_alloc_and_copy()
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/tests/suites/test_suite_psa_crypto.data b/tests/suites/test_suite_psa_crypto.data
index ced02af..ca13b51 100644
--- a/tests/suites/test_suite_psa_crypto.data
+++ b/tests/suites/test_suite_psa_crypto.data
@@ -7424,3 +7424,15 @@
PSA output buffer copy: output buffer too small
psa_crypto_copy_output:20:10:PSA_ERROR_BUFFER_TOO_SMALL
+
+PSA buffers alloc and copy
+psa_crypto_alloc_and_copy:0:20:0:20:PSA_SUCCESS
+
+PSA buffers alloc and copy: null input
+psa_crypto_alloc_and_copy:1:0:0:20:PSA_SUCCESS
+
+PSA buffers alloc and copy: null output
+psa_crypto_alloc_and_copy:0:20:1:0:PSA_SUCCESS
+
+PSA buffers alloc and copy: null input and output
+psa_crypto_alloc_and_copy:1:0:1:0:PSA_SUCCESS
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index c8bbcdb..cd46fef 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -10363,3 +10363,44 @@
mbedtls_free(dst_buffer);
}
/* END_CASE */
+
+/* BEGIN_CASE */
+void psa_crypto_alloc_and_copy(int input_null, int input_len,
+ int output_null, int output_len,
+ int exp_ret)
+{
+ uint8_t data[] = {0x12, 0x34, 0x56, 0x78};
+ uint8_t *input_buffer = NULL;
+ uint8_t *output_buffer = NULL;
+ psa_crypto_buffer_copy_t buffer_copies = { 0 };
+ psa_status_t ret;
+
+ if (!input_null) {
+ TEST_CALLOC(input_buffer, input_len);
+ for (int i = 0; i < input_len; i++) {
+ input_buffer[i] = data[i % sizeof(data)];
+ }
+ }
+ if (!output_null) {
+ TEST_CALLOC(output_buffer, output_len);
+ for (int i = 0; i < output_len; i++) {
+ output_buffer[i] = data[i % sizeof(data)];
+ }
+ }
+ ret = psa_crypto_alloc_and_copy(input_buffer, input_len,
+ output_buffer, output_len,
+ &buffer_copies);
+ TEST_EQUAL(exp_ret, (int) ret);
+
+ if (exp_ret == PSA_SUCCESS) {
+ TEST_MEMORY_COMPARE(input_buffer, input_len, buffer_copies.input, buffer_copies.input_len);
+ TEST_EQUAL(output_len, buffer_copies.output_len);
+ }
+
+exit:
+ mbedtls_free(input_buffer);
+ mbedtls_free(output_buffer);
+ mbedtls_free(buffer_copies.input);
+ mbedtls_free(buffer_copies.output);
+}
+/* END_CASE */