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: add args_get and args_sizes_get #308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

matetokodi
Copy link
Contributor

@matetokodi matetokodi commented Nov 21, 2024

WASI: add args_get and args_sizes_get
Extend testing script for passing arguments and checking stdout.

Depends on #307 and #309

uvwasi_size_t bufSize;
uvwasi_args_sizes_get(WASI::g_uvwasi, &argc, &bufSize);

char** uvArgv = reinterpret_cast<char**>(get_memory_pointer(instance, argv[0], argc * sizeof(char*)));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this is correct. char* pointers can be 32 or 64 bit long depending on the cpu, while the output is 32 bit long offsets.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I have created a TemporaryData class in the #307 patch which should help.

@clover2123
Copy link
Collaborator

Please rebase this patch

@@ -1117,7 +1128,7 @@ static void parseArguments(int argc, char* argv[], ParseOptions& options)
}
}

int main(int argc, char* argv[])
int main(const int argc, const char* argv[])
Copy link
Collaborator

Choose a reason for hiding this comment

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

for an int const is pointless.

@@ -242,6 +242,42 @@ void WASI::random_get(ExecutionState& state, Value* argv, Value* result, Instanc
result[0] = Value(uvwasi_random_get(WASI::g_uvwasi, buf, length));
}

void WASI::args_get(ExecutionState& state, Value* argv, Value* result, Instance* instance)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer to follow the uvwasi order of API functions for these wasi functions, so put it above, not to the last place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell uvwasi sorts the functions alphabetically; But the order we have them in already is not alphabetical. Would you want me to sort the existing ones as well, or to just put the new args functions at the top?

src/wasi/WASI.h Outdated
@@ -47,7 +47,9 @@ class WASI {
F(fd_seek, I32I64I32I32_RI32) \
F(path_open, I32I32I32I32I32I64I64I32I32_RI32) \
F(environ_get, I32I32_RI32) \
F(environ_sizes_get, I32I32_RI32)
F(environ_sizes_get, I32I32_RI32) \
F(args_get, I32I32_RI32) \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Order here as well.

fails = 0
for file in files:
if jit:
filename = os.path.basename(file)
if filename in JIT_EXCLUDE_FILES:
continue

proc = Popen([engine, "--mapdirs", "./test/wasi", "/var", file], stdout=PIPE) if not jit else Popen([engine, "--mapdirs", "./test/wasi", "/var", "--jit", file], stdout=PIPE)
subprocess_args = [engine, "--mapdirs", "./test/wasi", "/var"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding expected output is a great thing, I like it very much! Most wasi test results are not really checked, and this would improve them a lot. However, I would do it in a wabt way:

https://github.com/WebAssembly/wabt/blob/main/test/interp/br.txt#L99

(;; STDOUT ;;;
;;; STDOUT ;;)

(; and ;) are WebAssembly comments, so these parts are ignored. However, it is easy to find them with a regex, and the output can be compared with it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I realized this is a bad idea because stdout is cluttered with debug output.

zherczeg and others added 2 commits December 2, 2024 12:51
Improve other WASI functions as well.

Signed-off-by: Zoltan Herczeg [email protected]
Update the test script to test passing the arguments as well

Signed-off-by: Máté Tokodi [email protected]
@@ -136,6 +145,24 @@ def run_wasi_tests(engine):
if fail_total > 0:
raise Exception("basic wasi tests failed")

@runner('wasi-args', default=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about merging this wasi-args runner into wasi test runner?

@zherczeg
Copy link
Collaborator

zherczeg commented Dec 3, 2024

#309 should land first.

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