-
Notifications
You must be signed in to change notification settings - Fork 34
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 testing #713
WASI testing #713
Conversation
Codecov Report
@@ Coverage Diff @@
## master #713 +/- ##
==========================================
- Coverage 99.26% 99.24% -0.03%
==========================================
Files 74 76 +2
Lines 11462 11482 +20
==========================================
+ Hits 11378 11395 +17
- Misses 84 87 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
tools/wasi/CMakeLists.txt
Outdated
set(fizzy_include_dir ${PROJECT_SOURCE_DIR}/lib/fizzy) | ||
add_library(wasi) | ||
add_library(fizzy::wasi ALIAS wasi) | ||
target_compile_features(wasi PUBLIC cxx_std_17) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed, fizzy:fizzy
has it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fizzy::fizzy-internal
is private dependency: the fizzy::wasi
will be built with -std=c++17
, but users of fizzy::wasi
(e.g. fizzy-wasi
tool) will not have this requirement.
Here it make sense to declare fizzy::wasi
with C++17 because it uses a C++17 feature in the main header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not relevant any more because fizzy::wasi
now links fizzy::fizzy-internal
publicly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not relevant any more because
fizzy::wasi
now linksfizzy::fizzy-internal
publicly.
Why does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because now Fizzy is included in the wasi.hpp
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: all necessary changes are done to allow writing "top-down" unit tests - you can provide input as wat2wasm comment and check result and error string. For full testability we need WASI interface abstraction, but this should be done in a separate PR.
Without WASI abstraction we still have some integration tests in CTest. These are also nice so we know that the basic features of libuvwasi are working fine.
Finally, some unit tests truly accessing filesystem can be done in GTest provided it has some helpers creating/deleting temporary files.
Also see updated description.
tools/wasi/wasi.cpp
Outdated
|
||
bool run(int argc, const char** argv) | ||
std::optional<bytes> load_wasm_binary(const std::filesystem::path& path, std::ostream& err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has pretty bad API, but I'm not sure how exactly improve it right now.
Also current error reporting is in some middle ground: it provides some additional but not complete set of diagnostics. And finally, the std::ifstream
can sometimes be in "fail" state but it can also throw an exception in other cases...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how filesystem::path
works but maybe this function should take a string (provided by user) and create filesytem::path
inside, handling the errors like invalid symbols in path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered the following options and used the one which is the easiest to use at the moment.
const char*
- only literals andargv[]
work really,const std::string&
- specific string type used, conversion fromconst char*
is needed.std::string_view
- does not work withstd::ifstream
- conversion tostd::string
is needed.std::filesystem::path
- works with everything, emphasize that this is path.
I agree that invalid path format should be also handled inside. In the some time, there are other error cases that are not handled explicitly.
So switch to some other type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I imagined it like taking string_view
then constucting path
out of it, and then ifstream
out of this path
)
I'm fine to leave it like this for now. At some point exceptions thrown by path
constructor will need to be handled (when we address @todo Make noexcept.
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Lastly, this has triggered a know bug in stdlibc++'s I think we should disable GCC sanitizer for GCC 10 and wait for GCC 11 release (or use experimental Debian package). |
One ASan runtime option is disabled for current GCC runs. |
tools/wasi/wasi.cpp
Outdated
|
||
bool run(int argc, const char** argv) | ||
std::optional<bytes> load_wasm_binary(const std::filesystem::path& path, std::ostream& err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how filesystem::path
works but maybe this function should take a string (provided by user) and create filesytem::path
inside, handling the errors like invalid symbols in path.
9d76188
to
64f408d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
auto imports = fizzy::resolve_imported_functions(*module, wasi_functions); | ||
auto instance = fizzy::instantiate( | ||
std::move(module), std::move(imports), {}, {}, {}, fizzy::MemoryPagesValidationLimit); | ||
auto module = parse(wasm_binary); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually liked having the explicit fizzy prefix on things here, but I'm fine either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not make sense when we are in fizzy::wasi
.
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include "wasi.hpp" | ||
#include "execute.hpp" | ||
#include "limits.hpp" | ||
#include "parser.hpp" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the <iostream>
header still needed here (since std::cerr
is moved to main.cpp
)?
tools/wasi/wasi.cpp
Outdated
@@ -99,7 +99,7 @@ ExecutionResult environ_sizes_get(Instance& instance, const Value* args, int) | |||
} | |||
} // namespace | |||
|
|||
bool run(int argc, const char** argv) | |||
bool run(int argc, const char** argv, std::ostream& err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you say to make this noexcept, but if not noexcept we could consider just outputting error text as part of an exception? Or we want to pass stdout/stdin here too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to be able to inspect the error messages, one step from using std::cerr
implicitly inside. Further modifications are possible, but I'm not sure what's best.
target_include_directories(wasi PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
target_link_libraries(wasi PRIVATE fizzy::fizzy-internal uvwasi::uvwasi) | ||
target_link_libraries(wasi PUBLIC fizzy::fizzy-internal PRIVATE uvwasi::uvwasi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change below to the load_file commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because with this commit wasi.hpp
started including fizzy
headers.
/// @param err Error output stream. | ||
/// @return False in case of error. | ||
/// | ||
/// @todo Make noexcept. | ||
bool run(int argc, const char** argv, std::ostream& err); | ||
bool load_and_run(int argc, const char** argv, std::ostream& err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to do this separation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have load_and_run()
combo? There are some uses of it, previously run()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to address some of these comments, but I am also okay if not.
Downgrade GCC ASan detect_invalid_pointer_pairs check from 2 (comparisons/subtractions against null pointers are also invalid) to 1.
We forgot one thing: the |
This will be done with mocking. |
Closes #708
TODO
fizzy-wasi-unittests
. This relaxesWASI
andTESTING
CMake options dependencies. (resolution: It is fine for now; less CMake option combinations is good for development and nobody reported issues with compiling libuvwasi so far; the CMake option can always be added later).fizzy::wasi
library (resolution: it is fine where it is).Create interface for WASI implementation / uvwasi. This allows mocking the implementation.(To be done in a separate PR later)