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

WASI tests #790

Merged
merged 8 commits into from
May 23, 2022
Merged

WASI tests #790

merged 8 commits into from
May 23, 2022

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented Apr 21, 2021

No description provided.

@gumb0 gumb0 force-pushed the uvwasi_interface branch 2 times, most recently from cbf1c6a to b6b0fa5 Compare April 22, 2021 10:24
@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #790 (7b700be) into master (c341e3a) will increase coverage by 0.02%.
The diff coverage is n/a.

❗ Current head 7b700be differs from pull request most recent head 145f2d2. Consider uploading reports for the commit 145f2d2 to get more accurate results

@@            Coverage Diff             @@
##           master     #790      +/-   ##
==========================================
+ Coverage   99.10%   99.12%   +0.02%     
==========================================
  Files          86       85       -1     
  Lines       13017    13010       -7     
==========================================
- Hits        12900    12896       -4     
+ Misses        117      114       -3     
Flag Coverage Δ
rust 99.90% <0.00%> (+0.29%) ⬆️
spectests 89.98% <0.00%> (ø)
unittests 98.94% <0.00%> (ø)
unittests-32 99.03% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
bindings/rust/src/constnonnull.rs
bindings/rust/src/lib.rs 99.90% <0.00%> (+<0.01%) ⬆️

@chfast
Copy link
Collaborator

chfast commented Apr 22, 2021

If this way is easier, I'm fine with this. Do you have estimate how much uvwasi methods are we are going to need?

@gumb0
Copy link
Collaborator Author

gumb0 commented Apr 23, 2021

If this way is easier, I'm fine with this. Do you have estimate how much uvwasi methods are we are going to need?

It seems it's about one uvwasi funciton per one WASI function + some serialization functions that we may or may not want to mock.

@gumb0 gumb0 force-pushed the uvwasi_interface branch 19 times, most recently from fff0787 to 8c58abc Compare April 28, 2021 17:38
tools/wasi/CMakeLists.txt Outdated Show resolved Hide resolved
@gumb0 gumb0 force-pushed the uvwasi_interface branch 2 times, most recently from 21dd342 to 3d9fa22 Compare May 4, 2021 10:51
@gumb0
Copy link
Collaborator Author

gumb0 commented May 4, 2021

Obeservations about serizaliation part of uvwasi:

  1. Deserialization functions for fd_write / fd_read check passed pointers against the bounds passed in end parameter:
    https://github.com/nodejs/uvwasi/blob/adda15515cbb5a478d0ddb85602d987278a43384/src/wasi_serdes.c#L191-L192

So I think passing the memory size here is correct:

// TODO: not sure what to pass as end, passing memory size...

  1. It doesn't check bounds when deserializing "buffer pointer" and "buffer size" values themselves:
    https://github.com/nodejs/uvwasi/blob/adda15515cbb5a478d0ddb85602d987278a43384/src/wasi_serdes.c#L188-L189
    We could check these pointers ourselves at our side of fd_write / fd_read.
    On our side of fd_write / fd_read we could check at least that pointers we pass to uvwasi (iov_ptr, nread_ptr, nwritten_ptr) are inside memory bounds.

Copy link
Collaborator

@chfast chfast left a comment

Choose a reason for hiding this comment

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

This looks good.

Some additional questions:

  1. This seems not using GMock. Is the include even needed?
  2. We considered before to create separate unit tests executable for wasi, e.g. fizzy-unittests-wasi to decouple this subproject and its dependencies. This would also allow us to create separate directory for wasi unit tests and split these into more files.

class UVWASI
{
public:
virtual ~UVWASI();
Copy link
Collaborator

Choose a reason for hiding this comment

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

= default.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This produces error: 'UVWASI' has no out-of-line virtual method definitions; its vtable will be emitted in every translation unit [clang-diagnostic-weak-vtables,-warnings-as-errors]

https://app.circleci.com/pipelines/github/wasmx/fizzy/6667/workflows/39a77e98-002f-42e8-a916-19acec64fcbc/jobs/58758/parallel-runs/0/steps/0-111

@@ -13,6 +13,9 @@ struct Instance;

namespace wasi
{
class UVWASI;
extern UVWASI* uvwasi;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this needed for mocking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

Alternatively maybe It could be declared in wasi_test.cpp and another time in wasi.cpp

@gumb0 gumb0 force-pushed the uvwasi_interface branch 2 times, most recently from 13995b6 to 72e7826 Compare May 19, 2021 13:54
@gumb0
Copy link
Collaborator Author

gumb0 commented May 19, 2021

@axic You've merged #796 here, I have removed the merge commit, the last commit is now a single commit from #796.

@axic
Copy link
Member

axic commented May 20, 2022

@gumb0 can you rebase this?

@axic axic requested a review from chfast May 20, 2022 10:41
@gumb0 gumb0 force-pushed the uvwasi_interface branch 2 times, most recently from 767a55e to 39f0c06 Compare May 20, 2022 13:37
@gumb0
Copy link
Collaborator Author

gumb0 commented May 20, 2022

Rebased.


EXPECT_TRUE(mock_uvwasi->init_called);
ASSERT_TRUE(mock_uvwasi->write_fd.has_value());
EXPECT_EQ(*mock_uvwasi->write_fd, 1);
Copy link
Member

Choose a reason for hiding this comment

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

Based on the tests, write_fd should be a vector too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure what you mean, WASI fd_write calls uvwasi_fd_write only once, with one fd argument, and this is what the mock saves in write_fd and the test checks.

Copy link
Member

Choose a reason for hiding this comment

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

In the current tests, but eventually can imagine multiple calls.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then it would rather be vector like vector<pair<fd, write_data>> to record all calls... not sure it's worth to complicate it now.

test/unittests/wasi_test.cpp Outdated Show resolved Hide resolved
/* wat2wasm
(func (import "wasi_snapshot_preview1" "fd_write") (param i32 i32 i32 i32) (result i32))
(memory (export "memory") 1)
(data (i32.const 0) "\00\00\01\00") ;; buf ptr - out of memory bounds
Copy link
Member

Choose a reason for hiding this comment

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

So this only checks the offset against pages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the test tries to check that error value returned from uvwasi is correctly propagated. I don't think we should test all possible errors that uvwasi returns.

Copy link
Member

Choose a reason for hiding this comment

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

I meant this only checks against exceeding memory pages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The test tries to get the data to write from the address out of memory bounds (0x10000 = 65536), so this is just one possible way to make fd_write fail.

test/unittests/wasi_test.cpp Outdated Show resolved Hide resolved
Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

Okay for now I think.

@axic axic merged commit ee99be7 into master May 23, 2022
@axic axic deleted the uvwasi_interface branch May 23, 2022 13:36
@axic axic mentioned this pull request May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants