Improve fork helper robustness #297
Open
gilles-peskine-arm wants to merge 13 commits from
gilles-peskine-arm/fork-helper-unit-tests-create-framework into main
pull from: gilles-peskine-arm/fork-helper-unit-tests-create-framework
merge into: gh-Mbed-TLS:main
gh-Mbed-TLS:main
gh-Mbed-TLS:archive/20261015T005621Z-force/pull/322
gh-Mbed-TLS:archive/20260929T231924Z-rescue/rohankl-arm/mldsa-899-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/Thomasdjb/pr/spake2p-9342-public-key-import-export
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/fork-helper-unit-tests-create-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/iar-1.1.0-check-names
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/mbedtls_test_stack_usage-create
gh-Mbed-TLS:archive/20260929T231924Z-rescue/sridhar-design/cert_chain
gh-Mbed-TLS:archive/20260929T231924Z-rescue/JulioLoayzaM/add-fuzzing-seeds
gh-Mbed-TLS:dev/gilles-peskine-arm/generate_test_code-unicode-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/tpambor/key-wrap
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/not-not-grep-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/davidhorstmann-arm/add-python-package-update-script
gh-Mbed-TLS:archive/20260929T231924Z-rescue/minosgalanakis/tools/fix-auto-generated-files
gh-Mbed-TLS:framework_mergeback
gh-Mbed-TLS:archive/20260929T231924Z-rescue/bjwtaylor/empty-digest-failure
gh-Mbed-TLS:archive/20260929T231924Z-rescue/asmellby/feature/dispatch-library
gh-Mbed-TLS:archive/20260929T231924Z-rescue/sigvartmh/spake2p-test-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/bensze01/component-groups
gh-Mbed-TLS:archive/20260929T231924Z-rescue/bensze01/undef
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/server9-2048
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/all.sh-call_stack_trace
gh-Mbed-TLS:archive/20260929T231924Z-rescue/Marandil/fix/mbedtls-4314-test-data
gh-Mbed-TLS:archive/20260929T231924Z-rescue/bensze01/ci-testing-development
gh-Mbed-TLS:archive/20260929T231924Z-rescue/schneider-electric/dev/plaj-se/parse-rsassa-pss
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/pk_helpers-coverity-20260224
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/python-scripts-vintage-split-proposal
gh-Mbed-TLS:archive/20260929T231924Z-rescue/davidhorstmann-arm/code-size-measurement-script
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/sha3-shake-builtin-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/mpg/fix-quiet
gh-Mbed-TLS:archive/20260929T231924Z-rescue/TakutoYamane/fix-typo
gh-Mbed-TLS:archive/20260929T231924Z-rescue/rgqsch/feature/csr_challenge_password
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/make_generated_files-improve-for-3.6
gh-Mbed-TLS:archive/20260929T231924Z-rescue/irwir/lean_and_mean
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/all.sh-generate-only-before-checks-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/test-data_t-empty_is_empty-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/jean-baptisteboric-eaton/pkcs7_test_artifacts
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/assemble_changelog-utffromtimestamp
gh-Mbed-TLS:dev/bensze01/public-only-commit
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/config-py-help-directory-percent-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/valeriosetti/issue9255-framework
gh-Mbed-TLS:features/tls-defragmentation
gh-Mbed-TLS:archive/20260929T231924Z-rescue/gilles-peskine-arm/outcome-log-make-3.6-framework
gh-Mbed-TLS:md-psa-dispatch-3.6-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/benmcollins/add-rsassa-pss-keys
gh-Mbed-TLS:archive/20260929T231924Z-rescue/BrianSipos/119-add-name-constraints
gh-Mbed-TLS:issue-39-follow-up
gh-Mbed-TLS:revert-84-issue-72
gh-Mbed-TLS:dev/paul-elliott-arm/add_iop_key_agreement_exercise_key
gh-Mbed-TLS:dev/gilles-peskine-arm/psa-storage-test-cases-never-supported-positive-framework
gh-Mbed-TLS:issue-72
gh-Mbed-TLS:issue-39
gh-Mbed-TLS:dev/davidhorstmann-arm/port-psa-exercise-key-changes
gh-Mbed-TLS:dev/davidhorstmann-arm/add-some-test-helpers
gh-Mbed-TLS:archive/20260929T231924Z-rescue/paul-elliott-arm/remove_re_sub_count_positional_arg
gh-Mbed-TLS:dev/mpg/move-all-core-dev
gh-Mbed-TLS:issue-51
gh-Mbed-TLS:dev/gilles-peskine-arm/outcome-check-repeated-configurations-framework
gh-Mbed-TLS:dev/gilles-peskine-arm/generate_config_tests-require_psa
gh-Mbed-TLS:dev/gilles-peskine-arm/analyze_outcome-split-framework
gh-Mbed-TLS:dev/gilles-peskine-arm/config-full-booleans-only-framework
gh-Mbed-TLS:archive/20260929T231924Z-rescue/juhaylinen/disable_allow_abbrev
gh-Mbed-TLS:dev/gilles-peskine-arm/ssl-opt-psk-detection-framework
gh-Mbed-TLS:fix-everst-build
gh-Mbed-TLS:dev/minos/minor/code_wrappers_fix_identation
gh-Mbed-TLS:dev/minos/feature/code_wrappers
gh-Mbed-TLS:dev/davidhorstmann-arm/add-test-helpers
gh-Mbed-TLS:dev/davidhorstmann-arm/add-test-data-files
gh-Mbed-TLS:dev/gilles-peskine-arm/test_suite_config-booleans-framework
gh-Mbed-TLS:dev/ronald-cron-arm/fix-generation-of-psa-test-wrappers
gh-Mbed-TLS:dev/ronald-cron-arm/move-psa-headers
gh-Mbed-TLS:dev/external-contrib-copy/mbedtls-pr-9189
gh-Mbed-TLS:dev/davidhorstmann-arm/add-test-generation-files
gh-Mbed-TLS:dev/davidhorstmann-arm/add-mbedtls-framework-module
gh-Mbed-TLS:dev/davidhorstmann-arm/move-test-code
gh-Mbed-TLS:dev/davidhorstmann-arm/move-scripts
gh-Mbed-TLS:dev/gilles-peskine-arm/create-makefiles
Labels
Clear labels
approved
Design and code approved - may be waiting for CI or backports
bug
Something isn't working
dependencies
Pull requests that update a dependency file
DO-NOT-MERGE
enhancement
New feature or request
good-first-issue
Good for newcomers
help-wanted
This issue is not being actively worked on, but PRs welcome.
historical-reviewed
Reviewed & agreed to keep legacy PR/issue
historical-reviewing
Currently reviewing (for legacy PR/issues)
needs-adoption
stalled PR that someone should pick up and complete
needs-ci
Needs to pass CI tests
needs-design-approval
needs-info
An issue or PR which needs further info from the reporter / author
needs-preceding-pr
Requires another PR to be merged first
needs-review
Every commit must be reviewed by at least two team members.
needs-reviewer
This PR needs someone to pick it up for review
needs-work
priority-high
High priority - will be reviewed soon
priority-low
Low priority - this may not receive review soon
priority-medium
Medium priority - this can be reviewed as time permits
priority-scheduled
This PR is big - it will require time to be scheduled for review
priority-very-high
Highest priority - prioritise this over other review work
single-reviewer
This PR qualifies for having only one reviewer
size-l
Estimated task size: large (2w+)
size-m
Estimated task size: medium (~1w)
size-s
Estimated task size: small (~2d)
size-xs
Estimated task size: extra small (a few hours at most)
No labels
approved
bug
dependencies
DO-NOT-MERGE
enhancement
good-first-issue
help-wanted
historical-reviewed
historical-reviewing
needs-adoption
needs-ci
needs-design-approval
needs-info
needs-preceding-pr
needs-review
needs-reviewer
needs-work
priority-high
priority-low
priority-medium
priority-scheduled
priority-very-high
single-reviewer
size-l
size-m
size-s
size-xs
Milestone
Clear milestone
No items
No milestone
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set
Reference
gh-Mbed-TLS/mbedtls-framework!297
Loading…
Reference in a new issue
No description provided.
Delete branch "gilles-peskine-arm/fork-helper-unit-tests-create-framework"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Resolves most of https://github.com/Mbed-TLS/mbedtls-framework/issues/295, except for the metatests which are added in a consuming branch instead: https://github.com/Mbed-TLS/TF-PSA-Crypto/pull/737.
PR checklist
@ -155,90 +156,93 @@ int mbedtls_test_fork_run_child({*child_output_length = 0;Would any scenario where less than child_test_info not be a failure here? I think it's minor, however presumably if the file was corrupted or truncated we would want it to fail here?
I suspect this has probably been consider, but just in case. This is a bit of a regression on the previous implementation as it now requires create/unlink permission, whereas before it could run in read only. Not sure it this will effect anyone though? Maybe if not already considered it might be worth using mkstemp()/tmpfile() as it creates a less predictable filename?
We already use files in the current directory for tests that use persistent keys. So yes, it's an additional requirement on the runtime environment compared with the previous fork helper code, but it isn't an additional requirement compared for our crypto testing as a whole.
I deliberately don't use
tmpfile()or similar to avoid concerns about choosing the right temporary directory, having to worry that it might require unpredictable file names, etc.@ -155,90 +156,93 @@ int mbedtls_test_fork_run_child({*child_output_length = 0;Good point, I meant to read one record of the intended size, but I wrote it the other way round out of habit. I'll fix that.
I didn't bother writing a metatest for a truncated file because it's an unlikely failure that would require us to go out of our way. We don't normally test test code to that extent.
Ok, sounds reasonable.
A few suggestions and typos
Improve wording
Clarify the behaviour of the function
@ -121,6 +121,25 @@goto exit; \I think this is easier to understand with the parameter names from
mbedtls_test_strstr().@ -25,20 +26,20 @@/** Child exit code for mbedtls_test_fork_run_child().Typo
@ -67,7 +68,7 @@ static int probably_running_under_valgrind(void)__attribute__((__noreturn__))Nit: I don't think this is necessary if the implementation of
fwritecomplies with POSIX.TEST_ASSERT_ERRNOwon't read the (stale) value oferrnoifn == lengthsince you've switched the order of1andlengthNit:
&& length != 0is unnecessary, since you've switched the positions of the arguments1andlength.The output produced by
%pis implementation defined, so I'm unsure if the size calculation for it is always correct.How about using
mkstemp()with the template "mbedtls_test_fork_run_child.tmp-XXXXXX"? We can also add the pid to the template if you'd like - but I'm not sure it's necessary.@ -67,7 +68,7 @@ static int probably_running_under_valgrind(void)__attribute__((__noreturn__))POSIX only states that “if a write error occurs, (…) errno shall be set to indicate the error.” It's a classic gotcha that historical implementations don't always set
errno = 0on success: they may leave it unchanged, or even leave a nonzero result from an internal call that failed in a non-fatal way. Modern implementations usually do seterrno = 0on success, but I'm old enough to be in the habit of setting it if I care.I'd rather not depend on
mkstemp, which might not exist on embedded platforms where we might want to testfork().The output of
%pis unspecified, but I think hex for non-null pointers is really common. But I should check the return value ofsnprintf.@ -67,7 +68,7 @@ static int probably_running_under_valgrind(void)__attribute__((__noreturn__))Sure, I was just pointing out that we don't read the undefined value of
errnoin the success case anyways.I got the impression that you fixed the issue of
fwrite()returning0ifsize == 0one way (requiring that you overwriteerrno), then switched thesizeandcountparameters around so nown == lengthis always true and we no longer need to reseterrno(like we don't anywhere else in this file).I don't see how this is more informative, since the readers doesn't know the parameters yet when they read the brief description.
There are a lot of CI failures, probably because this branch is too old. I'm going to rebase on top of the head of
main. The last reviewed commit isf61edfd639→dcf3f2b248@ -155,90 +156,93 @@ int mbedtls_test_fork_run_child({Does this account for truncation similar to this https://github.com/Mbed-TLS/mbedtls-framework/pull/297#discussion_r3766902665
Should the return be checked?
Does this also need to check the ferror?
The CI is failing on TF-PSA-Crypto development. I need to rebase this branch again to get a meaningful CI run. The last commit that Ben reviewed is
fd4cef7ad2→49e3acd53bView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.