diff options
| author | Tom Rini <[email protected]> | 2024-10-08 13:56:50 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2024-10-08 13:56:50 -0600 |
| commit | 0344c602eadc0802776b65ff90f0a02c856cf53c (patch) | |
| tree | 236a705740939b84ff37d68ae650061dd14c3449 /tests/suites/helpers.function | |
Squashed 'lib/mbedtls/external/mbedtls/' content from commit 2ca6c285a0dd
git-subtree-dir: lib/mbedtls/external/mbedtls
git-subtree-split: 2ca6c285a0dd3f33982dd57299012dacab1ff206
Diffstat (limited to 'tests/suites/helpers.function')
| -rw-r--r-- | tests/suites/helpers.function | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/suites/helpers.function b/tests/suites/helpers.function new file mode 100644 index 00000000000..b5f5796e423 --- /dev/null +++ b/tests/suites/helpers.function @@ -0,0 +1,112 @@ +#line 2 "suites/helpers.function" +/*----------------------------------------------------------------------------*/ +/* Headers */ + +#include <test/arguments.h> +#include <test/helpers.h> +#include <test/macros.h> +#include <test/random.h> +#include <test/bignum_helpers.h> +#include <test/psa_crypto_helpers.h> +#include <test/threading_helpers.h> + +#include <errno.h> +#include <limits.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> + +#if defined(MBEDTLS_ERROR_C) +#include "mbedtls/error.h" +#endif +#include "mbedtls/platform.h" + +#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) +#include "mbedtls/memory_buffer_alloc.h" +#endif + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +#include <unistd.h> +#endif + +/*----------------------------------------------------------------------------*/ +/* Status and error constants */ + +#define DEPENDENCY_SUPPORTED 0 /* Dependency supported by build */ +#define KEY_VALUE_MAPPING_FOUND 0 /* Integer expression found */ +#define DISPATCH_TEST_SUCCESS 0 /* Test dispatch successful */ + +#define KEY_VALUE_MAPPING_NOT_FOUND -1 /* Integer expression not found */ +#define DEPENDENCY_NOT_SUPPORTED -2 /* Dependency not supported */ +#define DISPATCH_TEST_FN_NOT_FOUND -3 /* Test function not found */ +#define DISPATCH_INVALID_TEST_DATA -4 /* Invalid test parameter type. + Only int, string, binary data + and integer expressions are + allowed */ +#define DISPATCH_UNSUPPORTED_SUITE -5 /* Test suite not supported by the + build */ + +/*----------------------------------------------------------------------------*/ +/* Global variables */ + +/*----------------------------------------------------------------------------*/ +/* Helper flags for complex dependencies */ + +/* Indicates whether we expect mbedtls_entropy_init + * to initialize some strong entropy source. */ +#if !defined(MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES) && \ + (!defined(MBEDTLS_NO_PLATFORM_ENTROPY) || \ + defined(MBEDTLS_ENTROPY_HARDWARE_ALT) || \ + defined(ENTROPY_NV_SEED)) +#define ENTROPY_HAVE_STRONG +#endif + + +/*----------------------------------------------------------------------------*/ +/* Helper Functions */ + +#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) +static int redirect_output(FILE *out_stream, const char *path) +{ + int out_fd, dup_fd; + FILE *path_stream; + + out_fd = fileno(out_stream); + dup_fd = dup(out_fd); + + if (dup_fd == -1) { + return -1; + } + + path_stream = fopen(path, "w"); + if (path_stream == NULL) { + close(dup_fd); + return -1; + } + + fflush(out_stream); + if (dup2(fileno(path_stream), out_fd) == -1) { + close(dup_fd); + fclose(path_stream); + return -1; + } + + fclose(path_stream); + return dup_fd; +} + +static int restore_output(FILE *out_stream, int dup_fd) +{ + int out_fd = fileno(out_stream); + + fflush(out_stream); + if (dup2(dup_fd, out_fd) == -1) { + close(out_fd); + close(dup_fd); + return -1; + } + + close(dup_fd); + return 0; +} +#endif /* __unix__ || __APPLE__ __MACH__ */ |
