From 2fcb056ea98c158e0bb2019531f4acb92b9aead3 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Wed, 27 Jul 2022 17:30:49 +0800 Subject: [PATCH] Add requires_{any,all}_configs_enabled functions - requires_any_configs_enabled - requires_all_configs_enabled - requires_any_configs_disabled - requires_all_configs_disabled Signed-off-by: Jerry Yu --- programs/test/query_compile_time_config.c | 53 ++++++++++++++++++----- tests/ssl-opt.sh | 28 ++++++++++++ 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/programs/test/query_compile_time_config.c b/programs/test/query_compile_time_config.c index 6d92de3100..473c9a656f 100644 --- a/programs/test/query_compile_time_config.c +++ b/programs/test/query_compile_time_config.c @@ -28,20 +28,27 @@ #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif -#define USAGE \ - "usage: %s [ | -l ]\n\n" \ - "This program takes one command line argument which corresponds to\n" \ - "the string representation of a Mbed TLS compile time configuration.\n" \ - "The value 0 will be returned if this configuration is defined in the\n" \ - "Mbed TLS build and the macro expansion of that configuration will be\n" \ - "printed (if any). Otherwise, 1 will be returned.\n" \ - "-l\tPrint all available configuration.\n" +#define USAGE \ + "usage: %s [ -all | -any | -l ] ...\n\n" \ + "This program takes command line arguments which correspond to\n" \ + "the string representation of Mbed TLS compile time configurations.\n\n" \ + "If only one argument is available, the value 0 will be returned if\n" \ + "this configuration is defined in the Mbed TLS build and the macro\n" \ + "expansion of that configuration will be printed (if any). Otherwise,\n" \ + " 1 will be returned.\n" \ + "-l\tPrint all available configuration.\n" \ + "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \ + "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \ + "-h\tPrint this usage\n" + #include #include "query_config.h" int main( int argc, char *argv[] ) { - if ( argc != 2 ) + int i; + + if ( argc == 1 || strcmp( argv[1], "-h" ) == 0 ) { mbedtls_printf( USAGE, argv[0] ); return( MBEDTLS_EXIT_FAILURE ); @@ -53,5 +60,31 @@ int main( int argc, char *argv[] ) return( 0 ); } - return( query_config( argv[1] ) ); + if( strcmp( argv[1], "-all" ) == 0 ) + { + for( i = 2; i < argc; i++ ) + { + if( query_config( argv[i] ) != 0 ) + return( 1 ); + } + return( 0 ); + } + + if( strcmp( argv[1], "-any" ) == 0 ) + { + for( i = 2; i < argc; i++ ) + { + if( query_config( argv[i] ) == 0 ) + return( 0 ); + } + return( 1 ); + } + + for( i = 1; i < argc; i++ ) + { + if( query_config( argv[i] ) != 0 ) + return( 1 ); + } + + return( 0 ); } diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 398ce57ce2..ec243adf74 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -223,6 +223,34 @@ requires_config_disabled() { esac } +requires_all_configs_enabled() { + if ! $P_QUERY -all $* + then + SKIP_NEXT="YES" + fi +} + +requires_all_configs_disabled() { + if $P_QUERY -any $* + then + SKIP_NEXT="YES" + fi +} + +requires_any_configs_enabled() { + if ! $P_QUERY -any $* + then + SKIP_NEXT="YES" + fi +} + +requires_any_configs_disabled() { + if $P_QUERY -all $* + then + SKIP_NEXT="YES" + fi +} + get_config_value_or_default() { # This function uses the query_config command line option to query the # required Mbed TLS compile time configuration from the ssl_server2