Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

gilles-peskine-arm
Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm commented Jul 3, 2025

Simplify the use of SSL debug logs (provided by debug.c) in unit tests.

  1. Streamline log pattern searches in unit tests: now you just need to declare the pattern to search, and the test helpers will set things up.
  2. Make it easier to get debug logs on stdout while debugging: set mbedtls_test_ssl_debug_stdout_threshold = 4; in the C code and run tests/test_suite_ssl -v.

Status: works in the default config. Probably needs work for weird configs.

Follow-up: I'd prefer to write debug logs to a file if MBEDTLS_SSL_DEBUG=filename.log is set in the environment. But I haven't coded this yet.

Code extracted from #10217.

Builds on #10197. The same remarks apply regarding a 3.6 backport.

PR checklist

  • changelog not required because: test only
  • development PR here
  • TF-PSA-Crypto PR not required because: SSL only
  • framework PR provided Mbed-TLS/mbedtls-framework# | not required
  • 3.6 PR not required because: depends on Break down mbedtls_test_ssl_perform_handshake #10197
  • tests provided

Rework how debug logs are handled in SSL unit tests. The big change is that
test endpoints now automatically set up the new function
`mbedtls_test_ssl_debug_handler()` a debug callback, and they set the debug
level to high so that the handler is always called. Test functions no longer
call `mbedtls_ssl_conf_dbg()` or `mbedtls_debug_set_threshold()`.

As part of this change, the interface for setting a pattern that must be
present in the logs has changed, and is now a bit simpler: just set
`options.debug_threshold`, `options.cli_log_pattern` and
`options.srv_log_pattern`. The endpoint structure now owns its own counter.

This refactoring will make it a lot easier to enable debug logs temporarily
when debugging tests.

This commit changes how the test helpers work, but there is no intended
change to what the test functions actually test for.

Signed-off-by: Gilles Peskine <[email protected]>
Use a runtime variable rather than a compile-time edit to determine whether
to print SSL debug logs to stdout. This makes it easier to selectively
enable it, and allows controlling the level.

Also fix bitrot in the code that was guarded by `#if 0`.

Signed-off-by: Gilles Peskine <[email protected]>
@gilles-peskine-arm gilles-peskine-arm added size-s Estimated task size: small (~2d) priority-medium Medium priority - this can be reviewed as time permits labels Jul 3, 2025
@gilles-peskine-arm gilles-peskine-arm added the needs-ci Needs to pass CI tests label Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-tls enhancement needs-ci Needs to pass CI tests priority-medium Medium priority - this can be reviewed as time permits size-s Estimated task size: small (~2d)
Projects
Status: In Development
Development

Successfully merging this pull request may close these issues.

1 participant