Skip to content

Turn tests/c-api/alloc_async.ml back on#11596

Closed
dra27 wants to merge 2 commits intoocaml:trunkfrom
dra27:alloc_async-test
Closed

Turn tests/c-api/alloc_async.ml back on#11596
dra27 wants to merge 2 commits intoocaml:trunkfrom
dra27:alloc_async-test

Conversation

@dra27
Copy link
Copy Markdown
Member

@dra27 dra27 commented Oct 3, 2022

Follow-up from #10861, this test appears to be working (famous last words...)

@xavierleroy
Copy link
Copy Markdown
Contributor

What is the benefit? That is, what is this PR testing, and why does it matter?

What is the risk? That is, are we 100% sure this PR will never fail randomly because of scheduling oddities, legitimate differences between operating systems, etc ?

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Oct 4, 2022

I don't follow - this test is present in 4.14 (from #8897), was turned off with a TODO item in ocaml-multicore which was brought up in #10831 as being unnecessary?

@xavierleroy
Copy link
Copy Markdown
Contributor

I don't follow either, but I'd still like answers to my two questions: what is being tested? is the test reliable?

@kayceesrk
Copy link
Copy Markdown
Contributor

kayceesrk commented Oct 5, 2022

what is being tested? is the test reliable?

Paging @stedolan, who wrote the original test. Would you be able to tell us what's going on here?

@gadmm most recently worked on improving when and where asynchronous callbacks may be triggered in OCaml 5, who may also be able to tell us whether this test is expected to be reliable in OCaml 5.

(* TEST
modules = "alloc_async_stubs.c"
* skip
reason = "alloc async changes: https://github.com/ocaml/ocaml/pull/8897"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The reason line seems to explain why the test is there, rather than why it had been disabled. Let's keep it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

reason sets the message for the outcome of the test:

let reason = Variables.make ("reason",
"Let a test report why it passed/skipped/failed.")

It could be moved to a comment?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I imagine this was added as a reference while rebasing multicore (meaning "we must reimplement 8897 at some point"). This is now done, so it is a reason to put it back in. Instead, a comment would be welcome to explain that this is a test that allocations from C code do not run finalisers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Description added (see below)

@gadmm
Copy link
Copy Markdown
Contributor

gadmm commented Oct 5, 2022

This appears to test that the asynchronous callbacks do not run inside C code even when doing all sorts of allocations from C code. I think this is a nice test to have even though it relies on some implementation-dependent details, because if the behaviour changes at all it better be intentional.

The C stub tries to complete a major collection to make sure the finaliser enters the queue. I do not know if its logic is still valid (I have in mind full_major which now requires 3 cycles instead of 2, and I am not familiar with these sorts of changes to the GC behaviour). Note that you cannot call full_major because it would call finalisers immediately.

will never fail randomly because of scheduling oddities

This test should not depend on scheduling oddities (given that it is single-domain).

legitimate differences between operating systems

Only the legitimate differences between native and bytecode come to mind, but the test should work for both.

Copy link
Copy Markdown
Contributor

@gadmm gadmm left a comment

Choose a reason for hiding this comment

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

Assuming the trick to complete a full major collection still works, this looks good to me.

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Oct 14, 2022

From (hopefully correct) poking, the allocation loop does indeed cause finalisers to be enqueued and running the test with v=0x80 shows that those finalisers do not run until the C code has returned (as required).

@dra27
Copy link
Copy Markdown
Member Author

dra27 commented Dec 14, 2022

Am I OK to merge this?

@dra27 dra27 force-pushed the alloc_async-test branch from bede269 to 3686ced Compare June 8, 2023 07:46
@gadmm
Copy link
Copy Markdown
Contributor

gadmm commented Jun 8, 2023

ping @gasche or @kayceesrk

@gadmm
Copy link
Copy Markdown
Contributor

gadmm commented Aug 25, 2023

I need this test, and found that it could be made more robust (without changing the fact that it currently passes). Essentially, the allocation at the end is meant to trigger async callbacks, but instead, the polling is already done via caml_process_pending_actions called from the runtime/io.c functions called by Printf.printf. This is in effect testing caml_process_pending_actions instead of regular polling, and at a different location than intended. So this is not what is intended for the test.

To fix this, I propose to replace Printf.printf by a call to C printf that does not interfere with polling. If you like, could you please integrate the following commit inside this PR? 412db98

Regardless of this improvement, I'd like to see this PR merged as it is useful for the async callback mechanism.

@gasche
Copy link
Copy Markdown
Member

gasche commented Aug 25, 2023

I haven't looked at this, but I am happy to approve on @gadmm's behalf if his last proposal is addressed.

@gadmm
Copy link
Copy Markdown
Contributor

gadmm commented Sep 14, 2023

The testcase has finally been restored with the improvements I proposed as part of #11307. This PR can therefore be closed.

@gasche gasche closed this Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants