mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-10-22 16:37:56 +00:00
New test helper mbedtls_test_fork_run_child()
Run some code in a child process. Propagate output from the child if the test succeeds, and propagate the test result information otherwise. Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/** Helper functions for testing with subprocesses.
|
||||
*/
|
||||
/*
|
||||
* Copyright The Mbed TLS Contributors
|
||||
* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#ifndef TEST_FORK_HELPERS_H
|
||||
#define TEST_FORK_HELPERS_H
|
||||
|
||||
#include "test/helpers.h"
|
||||
|
||||
/** Type of a function to run in a child process.
|
||||
*
|
||||
* The function can mark the test case as failed by calling
|
||||
* mbedtls_test_fail(). This information will be reported to the parent.
|
||||
*
|
||||
* \param param Parameter passed to the callback.
|
||||
* \param[out] output Buffer for data to pass to the parent.
|
||||
* This data is ignored if the test case is marked
|
||||
* as failed.
|
||||
* \param output_size Size of \p output in bytes.
|
||||
* \param[out] output_length Number of bytes written to \p output, to be
|
||||
* passed to the parent. The default is \c 0.
|
||||
*/
|
||||
typedef void mbedtls_test_fork_child_callback_t(
|
||||
void *param,
|
||||
unsigned char *output, size_t output_size, size_t *output_length);
|
||||
|
||||
/* Fork a child process and wait for it to collect some data.
|
||||
*
|
||||
* This is similar to backquotes or `$(...)` in a shell.
|
||||
*
|
||||
* This function blocks until the child exits.
|
||||
*
|
||||
* If the child marks the test as failed or skipped, the child's test
|
||||
* information (test result and failure location) is propagated to the
|
||||
* parent.
|
||||
*
|
||||
* \param child_callback Callback function to run in the child.
|
||||
* \param param Parameter to pass to the callback function.
|
||||
* \param[out] child_output On success, data retrieved from the child.
|
||||
* Note that the data is only available if the
|
||||
* child did not mark the test case as failed
|
||||
* or skipped.
|
||||
* \param child_output_size Size of \p child_output in bytes.
|
||||
* \param[out] child_output_length On success, the number of bytes collected
|
||||
* from the child in \c child_output.
|
||||
*
|
||||
* \return \c 0 on success.
|
||||
* A nonzero value if the test case is marked as failed or skipped.
|
||||
*/
|
||||
int mbedtls_test_fork_run_child(
|
||||
mbedtls_test_fork_child_callback_t *child_callback,
|
||||
void *param,
|
||||
unsigned char *child_output, size_t child_output_size,
|
||||
size_t *child_output_length);
|
||||
|
||||
#endif /* TEST_FORK_HELPERS_H */
|
||||
@@ -147,6 +147,25 @@ void mbedtls_test_get_line1(char *line);
|
||||
*/
|
||||
void mbedtls_test_get_line2(char *line);
|
||||
|
||||
/**
|
||||
* \brief Get a copy of the test result information.
|
||||
*
|
||||
* \param[out] out On output, contains a copy of the current test info.
|
||||
*/
|
||||
void mbedtls_test_info_save(mbedtls_test_info_t *out);
|
||||
|
||||
/**
|
||||
* \brief Overwrite the test result information.
|
||||
* This is intended for some unusual scenarios.
|
||||
* You probably shouldn't use this in a test function.
|
||||
*
|
||||
* \param[in] replacement
|
||||
* The test info to use instead of the current one.
|
||||
* The function copies the data, so the pointer does
|
||||
* not need to be valid after this function returns.
|
||||
*/
|
||||
void mbedtls_test_info_overwrite(const mbedtls_test_info_t *replacement);
|
||||
|
||||
#if defined(MBEDTLS_TEST_MUTEX_USAGE)
|
||||
/**
|
||||
* \brief Get the current mutex usage error message
|
||||
|
||||
Reference in New Issue
Block a user