mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 00:04:14 +01:00
Fix minor style issues in test framework
This commit is contained in:
parent
33388669ec
commit
2d9c46767a
@ -34,6 +34,9 @@ typedef UINT32 uint32_t;
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Constants */
|
||||
@ -102,6 +105,43 @@ static int test_errors = 0;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
static int redirect_output( FILE** out_stream, const char* path )
|
||||
{
|
||||
int stdout_fd = dup( fileno( *out_stream ) );
|
||||
|
||||
if( stdout_fd == -1 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
fflush( *out_stream );
|
||||
fclose( *out_stream );
|
||||
*out_stream = fopen( path, "w" );
|
||||
|
||||
if( *out_stream == NULL )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return stdout_fd;
|
||||
}
|
||||
|
||||
static int restore_output( FILE** out_stream, int old_fd )
|
||||
{
|
||||
fflush( *out_stream );
|
||||
fclose( *out_stream );
|
||||
|
||||
*out_stream = fdopen( old_fd, "w" );
|
||||
if( *out_stream == NULL )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
static int unhexify( unsigned char *obuf, const char *ibuf )
|
||||
{
|
||||
unsigned char c, c2;
|
||||
|
@ -79,12 +79,6 @@ SUITE_POST_DEP
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Test dispatch code */
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
int dep_check( char *str )
|
||||
{
|
||||
if( str == NULL )
|
||||
@ -257,7 +251,6 @@ int main(int argc, const char *argv[])
|
||||
const char **test_files = NULL;
|
||||
int testfile_count = 0;
|
||||
int option_verbose = 0;
|
||||
int tests_stdout;
|
||||
|
||||
/* Other Local variables */
|
||||
int arg_index = 1;
|
||||
@ -268,6 +261,7 @@ int main(int argc, const char *argv[])
|
||||
char buf[5000];
|
||||
char *params[50];
|
||||
void *pointer;
|
||||
int stdout_fd = 0;
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
!defined(TEST_SUITE_MEMORY_BUFFER_ALLOC)
|
||||
@ -412,18 +406,8 @@ int main(int argc, const char *argv[])
|
||||
*/
|
||||
if( !option_verbose )
|
||||
{
|
||||
/* Redirect all stdout output to /dev/null */
|
||||
tests_stdout = dup( fileno(stdout) );
|
||||
if( tests_stdout == -1 )
|
||||
{
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fflush( stdout );
|
||||
fclose( stdout );
|
||||
stdout = fopen("/dev/null", "w" );
|
||||
if( stdout == NULL )
|
||||
stdout_fd = redirect_output( &stdout, "/dev/null" );
|
||||
if( stdout_fd == -1 )
|
||||
{
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
exit( 1 );
|
||||
@ -434,19 +418,11 @@ int main(int argc, const char *argv[])
|
||||
ret = dispatch_test( cnt, params );
|
||||
|
||||
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
|
||||
if( !option_verbose )
|
||||
{
|
||||
/* Restore stdout */
|
||||
fflush( stdout );
|
||||
fclose( stdout );
|
||||
|
||||
stdout = fdopen ( tests_stdout, "w");
|
||||
if( stdout == NULL )
|
||||
if( !option_verbose && restore_output( &stdout, stdout_fd ) )
|
||||
{
|
||||
/* Redirection has failed with no stdout so exit */
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
#endif /* __unix__ || __APPLE__ __MACH__ */
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user