Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls-eio: improve fuzz tests #463

Merged
merged 1 commit into from
Feb 4, 2023
Merged

Conversation

talex5
Copy link
Contributor

@talex5 talex5 commented Dec 21, 2022

These are the improvements to the fuzz tests that were part of #459. I think it's worth merging these on their own, since that PR isn't ready.

  • The mock_socket has changed slightly. Previously, it would request a size to read, do the read, and then wait for another size for the next read, which would typically just be the EOF for that request. This made it harder for the fuzzer to reach useful states. Now you can do a single transmit with a single test action.

  • Simplified the write in Tls_eio slightly by using the new Flow.write operation.

  • Only log a send when we actually send some data.

  • Allow the fuzzer to perform all the actions needed for the Tls handshake in one go instead of requiring it to find them by searching. This provides it a way to get to the interesting cases quickly.

Some (To_client, Send 5);
]
*)
if true then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I don't quite get this style of code? would you mind to explain the construct in more detail, and/or make it disappear. I've no clue in which cases the alternative should be executed (with manual code modification, likely).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you get a crash and you want to reproduce it manually for testing (e.g. to try variations) you can input it here directly. Keeping it in an if makes it easier to switch between the two modes, means it still gets type-checked when disabled, and you don't get bothered by unused variable errors from dune.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is possible to use "cmdliner" and have this "true" hidden behind a flag?

eio/tls_eio.ml Outdated
@@ -29,7 +29,7 @@ module Raw = struct
raise exn

let write_t t cs =
try Flow.copy (Flow.cstruct_source [cs]) t.flow
try Flow.write t.flow [cs]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this really part of improve fuzz test? or a performance improvement? or a semantic change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It at least deserves a separate commit with a slightly more descriptive commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly just a simplification. It could be an optimisation if the underlying flow implements write directly. Otherwise, write just falls back to doing a copy, as in the old code. I can remove it if you prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said, a separate commit with a commit message that includes your above description would be sufficient for me. I've disliked myself in the past to sneak any library changes in "update tests" commits, not being able to properly track years later why something changed in one way or another.

@bikallem
Copy link
Contributor

My comment here - #460 (comment) - is applicable to this PR I believe.

- The mock_socket has changed slightly. Previously, it would request a
  size to read, do the read, and then wait for another size for the next
  read, which would typically just be the EOF for that request. This
  made it harder for the fuzzer to reach useful states. Now you can do a
  single transmit with a single test action.

- Only log a send when we actually send some data.

- Allow the fuzzer to perform all the actions needed for the Tls
  handshake in one go instead of requiring it to find them by searching.
  This provides it a way to get to the interesting cases quickly.
@talex5
Copy link
Contributor Author

talex5 commented Jan 3, 2023

OK, I've now updated this PR to remove the change to tls_eio.ml so this PR only affects the fuzz tests (and I've updated the commit message to reflect that). We can make that change next time we're changing the code itself, to keep this PR clean.

Do you think it is possible to use "cmdliner" and have this "true" hidden behind a flag?

It's a bit tricky, as crowbar likes to parse the command-line options itself (in an at_exit handler!). I've now removed the code you objected to. It was just a convenience.

@bikallem wrote:

I believe we need to update the test to not generate send action after send_close action is generated

There is no "send_close". You mean Shutdown_send? That sends Exit to the sending fiber, which calls Eio.Flow.shutdown and then exits, so it already doesn't send anything after a shut down.

@hannesm
Copy link
Member

hannesm commented Feb 4, 2023

Thanks for your PR.

@hannesm hannesm merged commit 0c718bd into mirleft:main Feb 4, 2023
hannesm added a commit to hannesm/opam-repository that referenced this pull request Feb 14, 2023
CHANGES:

* BREAKING: new opam package tls-lwt (formerly tls.lwt), in dune:
  (libraries tls.lwt) should now be libraries (tls-lwt)
  (mirleft/ocaml-tls#468 @hannesm, reported mirleft/ocaml-tls#449 by @mbacarella)
* tls: update to mirage-crypto 0.11 API (mirleft/ocaml-tls#468 @hannesm)
* tls: relax SignatureAlgorithms extension handling to allow OpenSSL
  interoperability tests with TLS 1.0 and TLS 1.1 (mirleft/ocaml-tls#469 @hannesm)
* tls: remove Utils.filter_map and and Utils.option, use Stdlib instead (mirleft/ocaml-tls#455
  @hannesm)
* tls: do not globally open Utils (mirleft/ocaml-tls#455 @hannesm)
* tls: export log source of Tracing module (mirleft/ocaml-tls#461 @bikallem)
* tls: remove unused ciphersuites to reduce binary size (mirleft/ocaml-tls#467 @hannesm)
* tls-lwt: do not catch out of memory exception (mirleft/ocaml-tls#469 @hannesm)
* tls-eio: add fuzz testing using crowbar (mirleft/ocaml-tls#456 mirleft/ocaml-tls#463 @talex5)
* tls-eio: update to eio 0.7 (mirleft/ocaml-tls#456 @talex5)
* tls-eio: fix test for develop with vendoring (mirleft/ocaml-tls#462 @bikallem)