From 84e63a73cd25e75289eb9c9f1067a14da27d57d4 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Mon, 6 Dec 2021 13:40:37 +0800 Subject: [PATCH 1/7] Add list_config generation Signed-off-by: Jerry Yu --- programs/test/query_config.h | 8 ++++++++ scripts/data_files/query_config.fmt | 8 ++++++++ scripts/generate_query_config.pl | 7 +++++++ 3 files changed, 23 insertions(+) diff --git a/programs/test/query_config.h b/programs/test/query_config.h index 0fad886d14..290100f36f 100644 --- a/programs/test/query_config.h +++ b/programs/test/query_config.h @@ -35,4 +35,12 @@ */ int query_config( const char *config ); +/** List all enabled configuration symbols + * + * \note This function is defined in `programs/test/query_config.c` + * which is automatically generated by + * `scripts/generate_query_config.pl`. + */ +void list_config( void ); + #endif /* MBEDTLS_PROGRAMS_TEST_QUERY_CONFIG_H */ diff --git a/scripts/data_files/query_config.fmt b/scripts/data_files/query_config.fmt index ffa816ecee..e0e14cbd8f 100644 --- a/scripts/data_files/query_config.fmt +++ b/scripts/data_files/query_config.fmt @@ -99,6 +99,10 @@ #define MACRO_NAME_TO_STR(macro) \ mbedtls_printf( "%s", strlen( #macro "" ) > 0 ? #macro "\n" : "" ) +#define NAME_TO_STR(macro) #macro +#define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \ + strlen( NAME_TO_STR(macro) "") > 0 ? "=" NAME_TO_STR(macro) : "" ) + #if defined(_MSC_VER) /* * Visual Studio throws the warning 4003 because many Mbed TLS feature macros @@ -118,6 +122,10 @@ CHECK_CONFIG /* If the symbol is not found, return an error */ return( 1 ); } +void list_config( void ) +{ + LIST_CONFIG +} #if defined(_MSC_VER) #pragma warning(pop) #endif /* _MSC_VER */ diff --git a/scripts/generate_query_config.pl b/scripts/generate_query_config.pl index 7855c7caa4..b2ce8fc4c6 100755 --- a/scripts/generate_query_config.pl +++ b/scripts/generate_query_config.pl @@ -68,6 +68,7 @@ open(CONFIG_FILE, "$config_file") or die "Opening config file '$config_file': $! # This variable will contain the string to replace in the CHECK_CONFIG of the # format file my $config_check = ""; +my $list_config = ""; while (my $line = ) { if ($line =~ /^(\/\/)?\s*#\s*define\s+(MBEDTLS_\w+).*/) { @@ -84,6 +85,11 @@ while (my $line = ) { $config_check .= " }\n"; $config_check .= "#endif /* $name */\n"; $config_check .= "\n"; + + $list_config .= "#if defined($name)\n"; + $list_config .= " OUTPUT_MACRO_NAME_VALUE($name);\n"; + $list_config .= "#endif /* $name */\n"; + $list_config .= "\n"; } } @@ -95,6 +101,7 @@ close(FORMAT_FILE); # Replace the body of the query_config() function with the code we just wrote $query_config_format =~ s/CHECK_CONFIG/$config_check/g; +$query_config_format =~ s/LIST_CONFIG/$list_config/g; # Rewrite the query_config.c file open(QUERY_CONFIG_FILE, ">$query_config_file") or die "Opening destination file '$query_config_file': $!"; From a15f3cc35085bd37c925b269e5dad5e03ddbbcb6 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Mon, 6 Dec 2021 13:44:39 +0800 Subject: [PATCH 2/7] Add list_config into query_comile_time_config Signed-off-by: Jerry Yu --- programs/test/query_compile_time_config.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/programs/test/query_compile_time_config.c b/programs/test/query_compile_time_config.c index a6eaf61590..0bc9dee930 100644 --- a/programs/test/query_compile_time_config.c +++ b/programs/test/query_compile_time_config.c @@ -29,13 +29,14 @@ #endif #define USAGE \ - "usage: %s \n\n" \ + "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" - + "printed (if any). Otherwise, 1 will be returned.\n" \ + "-l\tPrint all available configuration" +#include #include "query_config.h" int main( int argc, char *argv[] ) @@ -46,5 +47,11 @@ int main( int argc, char *argv[] ) return( MBEDTLS_EXIT_FAILURE ); } + if( strcmp( argv[1], "-l" ) == 0 ) + { + list_config(); + return( 0 ); + } + return( query_config( argv[1] ) ); } From d04fd35c063c89359e91e0004196a472f5dd8458 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Mon, 6 Dec 2021 16:52:57 +0800 Subject: [PATCH 3/7] Replace configs_enabled check with query_compile_time_config Signed-off-by: Jerry Yu --- tests/ssl-opt.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index d5e9e01999..0471d7a865 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -45,6 +45,7 @@ fi : ${P_SRV:=../programs/ssl/ssl_server2} : ${P_CLI:=../programs/ssl/ssl_client2} : ${P_PXY:=../programs/test/udp_proxy} +: ${P_QUERY:=../programs/test/query_compile_time_config} : ${OPENSSL_CMD:=openssl} # OPENSSL would conflict with the build system : ${GNUTLS_CLI:=gnutls-cli} : ${GNUTLS_SERV:=gnutls-serv} @@ -194,10 +195,7 @@ esac # testing. Skip non-boolean options (with something other than spaces # and a comment after "#define SYMBOL"). The variable contains a # space-separated list of symbols. -CONFIGS_ENABLED=" $(<"$CONFIG_H" \ - sed -n 's!^ *#define *\([A-Za-z][0-9A-Z_a-z]*\) *\(/*\)*!\1!p' | - tr '\n' ' ')" - +CONFIGS_ENABLED="$($P_QUERY -l)" # Skip next test; use this macro to skip tests which are legitimate # in theory and expected to be re-introduced at some point, but # aren't expected to succeed at the moment due to problems outside @@ -210,6 +208,7 @@ skip_next_test() { requires_config_enabled() { case $CONFIGS_ENABLED in *" $1 "*) :;; + *" $1="*) :;; *) SKIP_NEXT="YES";; esac } @@ -218,6 +217,7 @@ requires_config_enabled() { requires_config_disabled() { case $CONFIGS_ENABLED in *" $1 "*) SKIP_NEXT="YES";; + *" $1="*) SKIP_NEXT="YES";; esac } From d0fcf7f6a08072a7d61f702a2804c0dca9894171 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Fri, 10 Dec 2021 18:45:51 +0800 Subject: [PATCH 4/7] fix ci fail Signed-off-by: Jerry Yu --- tests/ssl-opt.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 0471d7a865..7b994cd9e2 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -195,7 +195,7 @@ esac # testing. Skip non-boolean options (with something other than spaces # and a comment after "#define SYMBOL"). The variable contains a # space-separated list of symbols. -CONFIGS_ENABLED="$($P_QUERY -l)" +CONFIGS_ENABLED=" $(echo `$P_QUERY -l` )" # Skip next test; use this macro to skip tests which are legitimate # in theory and expected to be re-introduced at some point, but # aren't expected to succeed at the moment due to problems outside From 2e8b00172bfc1d1df48baad86db57aa90a66a66a Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Fri, 10 Dec 2021 20:29:02 +0800 Subject: [PATCH 5/7] Beauty source code Signed-off-by: Jerry Yu --- scripts/data_files/query_config.fmt | 4 ++-- tests/ssl-opt.sh | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/data_files/query_config.fmt b/scripts/data_files/query_config.fmt index e0e14cbd8f..b22474ac24 100644 --- a/scripts/data_files/query_config.fmt +++ b/scripts/data_files/query_config.fmt @@ -99,9 +99,9 @@ #define MACRO_NAME_TO_STR(macro) \ mbedtls_printf( "%s", strlen( #macro "" ) > 0 ? #macro "\n" : "" ) -#define NAME_TO_STR(macro) #macro +#define STRINGIFY(macro) #macro #define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \ - strlen( NAME_TO_STR(macro) "") > 0 ? "=" NAME_TO_STR(macro) : "" ) + STRINGIFY(macro)[0] != 0 ? "=" STRINGIFY(macro) : "" ) #if defined(_MSC_VER) /* diff --git a/tests/ssl-opt.sh b/tests/ssl-opt.sh index 7b994cd9e2..0c6afae423 100755 --- a/tests/ssl-opt.sh +++ b/tests/ssl-opt.sh @@ -207,8 +207,7 @@ skip_next_test() { # skip next test if the flag is not enabled in mbedtls_config.h requires_config_enabled() { case $CONFIGS_ENABLED in - *" $1 "*) :;; - *" $1="*) :;; + *" $1"[\ =]*) :;; *) SKIP_NEXT="YES";; esac } @@ -216,8 +215,7 @@ requires_config_enabled() { # skip next test if the flag is enabled in mbedtls_config.h requires_config_disabled() { case $CONFIGS_ENABLED in - *" $1 "*) SKIP_NEXT="YES";; - *" $1="*) SKIP_NEXT="YES";; + *" $1"[\ =]*) SKIP_NEXT="YES";; esac } From b54b53142a0f05fa1697efd67e48a45c64bc5dd5 Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Fri, 10 Dec 2021 21:38:12 +0800 Subject: [PATCH 6/7] fix msvc build faile Signed-off-by: Jerry Yu --- scripts/data_files/query_config.fmt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/data_files/query_config.fmt b/scripts/data_files/query_config.fmt index b22474ac24..8b0057cb00 100644 --- a/scripts/data_files/query_config.fmt +++ b/scripts/data_files/query_config.fmt @@ -101,7 +101,7 @@ #define STRINGIFY(macro) #macro #define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n", \ - STRINGIFY(macro)[0] != 0 ? "=" STRINGIFY(macro) : "" ) + ( STRINGIFY(macro) "" )[0] != 0 ? "=" STRINGIFY(macro) : "" ) #if defined(_MSC_VER) /* From 29ceb564f859681e0ab95b27ea6bed00123d38ce Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Fri, 10 Dec 2021 23:38:57 +0800 Subject: [PATCH 7/7] fix help message issues Signed-off-by: Jerry Yu --- programs/test/query_compile_time_config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/programs/test/query_compile_time_config.c b/programs/test/query_compile_time_config.c index 0bc9dee930..6d92de3100 100644 --- a/programs/test/query_compile_time_config.c +++ b/programs/test/query_compile_time_config.c @@ -29,13 +29,13 @@ #endif #define USAGE \ - "usage: %s | -l\n\n" \ + "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" + "-l\tPrint all available configuration.\n" #include #include "query_config.h"