Repository navigation
Implementation of cwd function done and tested - #18856
impact-maker wants to merge 0 commit into
Conversation
|
I would say the next step is to find or add a test for this, and then to see that it works. There is likely an existing test for the old FS, which we should get working in WasmFS. To find a test, you can search for There are more details that might help in the main issue for this. |
@kripken The mount function implementation might use cwd function as well. I have tried to implement the cwd() function. Currently it requires testing which I am working on. After testing cwd function, will give a try to implement and test the mount function. |
| int __syscall_mremap(intptr_t old_addr, size_t old_size, size_t new_size, int flags, intptr_t new_addr); | ||
| int __syscall_poll(intptr_t fds, int nfds, int timeout); | ||
| int __syscall_getcwd(intptr_t buf, size_t size); | ||
| const char* __syscall_getcwd_woutargs(); |
There was a problem hiding this comment.
If possible we should avoid adding a new syscall here.
There was a problem hiding this comment.
I was getting an unidentified declaration error without adding this function in this class. Any alternate suggestions from your end could help.
|
|
||
| auto res = result.c_str(); | ||
|
|
||
| return res; |
There was a problem hiding this comment.
Here you are returning a pointer into result which is a std::string on the stack.. so the pointer won't be valid once you return.
There was a problem hiding this comment.
Also, is there some reason to create a new function that seems to duplicate the existing __syscall_getcwd ?
There was a problem hiding this comment.
@sbc100 I refered the documention which states that the cwd() does not take any arguments so I had to make a new getcwd() function because the old one takes the path and size as the arguments. Do correct if I am thinking in the wrong direction or if the function can support arguments contrary to what the documentation states.
Kindly refer https://emscripten.org/docs/api_reference/Filesystem-API.html#new-file-system-wasmfs for the FS.cwd() function definition.
There was a problem hiding this comment.
The high level FS.cwd() doesn't take any args but it can call the lower level __syscall_getcwd that does take args.
IIUC it can/should then read the result from the output pointer and return a JS string based on those results.
| free(state); | ||
| } | ||
|
|
||
| const char* __wasmfs_getcwd(){ |
There was a problem hiding this comment.
The convention here seems to be a single underscore prefix.
There was a problem hiding this comment.
Will rectify this. Thank you
| // For file preloading, cwd should be '/' to begin with. | ||
| return '/'; | ||
| return withStackSave(() => { | ||
| return __wasmfs_getcwd(); |
There was a problem hiding this comment.
Since this function is JS function that returns a string I don't think you want to just return a "char *" here since that will result in Number (pointer) in JavaScript.
There was a problem hiding this comment.
@sbc100 I have declared the return type for __wasmfs_getcwd() as const char. Could you check the function singature and help me rectify it.
9c828ef to
ed11a06
Compare
|
Description Testing |
| // For file preloading, cwd should be '/' to begin with. | ||
| return '/'; | ||
| return withStackSave(() => { | ||
| var buffer = allocateUTF8OnStack(path); |
There was a problem hiding this comment.
Where is path being defined here?
The argument to allocateUTF8OnStack is a number of bytes so I would have expected something liuke {{{ PATH_MAX }}} here.
There was a problem hiding this comment.
@sbc100 Thank you for your feeback. I had some counter queries
Is it possible to pass path argument to cwd() like the below code snippet
cwd: (path) => {
return withStackSave(() => {
var buffer = allocateUTF8OnStack(path);
var result = _wasmfs_getcwd(buffer,buffer.length);
return UTF8ToString(buffer);
});
},
In case it is not allowed how are we expected to add the path to allocateUTF function.
Also wanted to clarify if the PATH_MAX you are refering to, is same as the path I would pass in the FS.cwd() argument.
There was a problem hiding this comment.
IIUC FS.cwd() doesn't take an argument ever, it just returns the current working directory as a JS string.
There was a problem hiding this comment.
In this case you would want to use stackAlloc rather than allocateUTF8OnStack because you do not already have a string. The argument to stackAlloc would be the {{{ PATH_MAX }}} @sbc100 mentioned, and is the number of bytes necessary for the largest allowable path string.
There was a problem hiding this comment.
@tlively @sbc100 Thanks for the clarification and being patient enough to answer my queries. I have made the changes in the latest commit. Kindly review the changes.
Meanwhile I had some few queries
- I was trying to understand different implementation of cwd() which made me come to an alternative to stackAlloc which is adding char buffer[PATH_MAX] in _wasmfs_getcwd() function and then passing it to the __syscall_getcwd call. Should I implement with that approach.
- To compile library_wasmfs.js I had to comment out FS__deps and set {{{ cDefine('S_IRUGO') }}} {{{ cDefine('S_IXUGO') }}} and {{{ cDefine('S_IWUGO') }}} to some dummy integer. Not sure if it the right approach but the build and testing seems to work after these changes. Can you some alternative to this error resolution.
There was a problem hiding this comment.
- Using stack space more sense to me in this case since it avoids permanntly allocating the space (you would need to write (since you would need to add static to
char buffer[PATH_MAX]I believe). {{{ cDefine('S_IRUGO') }}}should work. If they don't then something odd is going on with your checkout. What errors do you see?
There was a problem hiding this comment.
@sbc100 Understood and it seems like a better approach to allocate the space.
I was getting an 'S_IRUGO' not defined error earlier but now suddenly its not occuring. Trying to figure out the root cause for it for future development and testing purposes. I reckon I missed ./emcc --clear-cache command. Will try to raise an issue for the same.
@kripken @kripken @sbc100 Since I have made all the required changes and the build and testing is successful. Kindly suggest me if I need to make any other changes in the code or the testing.
Also I had a curious question on how to make this code merge ready as I can see some of the checks blocked. Is there any documentation to pass all the checks with proper coding standards.
There was a problem hiding this comment.
@impact-maker
I had a similar error with S_IRUGO and for me it was caused by settings WASMFS=TRUE in settings.js. Leaving WASMFS=FALSE and manually setting the flags in the test_core.py as shown below fixed the problem for me.
self.emcc_args += ['-sWASMFS']
self.emcc_args += ['-sFORCE_FILESYSTEM']
| } | ||
|
|
||
| int _wasmfs_getcwd(char* path, size_t size){ | ||
| return __syscall_getcwd((intptr_t)path,size); |
There was a problem hiding this comment.
Looking like this file uses 2 spaces for indentation.
Can you add a space after the comma in the argument list?
There was a problem hiding this comment.
@sbc100 Remove the single space from the return statement and added spaces in the argument after comma
| // For file preloading, cwd should be '/' to begin with. | ||
| return '/'; | ||
| return withStackSave(() => { | ||
| var buffer = stackAlloc({{{PATH_MAX}}}); |
There was a problem hiding this comment.
PATH_MAX is defined in C code, so this will not just work as it is. Instead, {{{ cDefine('PATH_MAX') }}} is what we want - that looks up a C define. Note that you must also add PATH_MAX to src/struct_info.json.
| "S_IRWXUGO", | ||
| "S_IXUGO" | ||
| "S_IXUGO", | ||
| "PATH_MAX" |
There was a problem hiding this comment.
Oh, I assumed we were already exporting this defined.
Can you make a new block for limits.h (where MAX_PATH is defined).
You will also need to run ./test/runner other.test_gen_struct_info --rebase to update the test expectation.
There was a problem hiding this comment.
@sbc100 Working on this. Since you mentioned one test here, I was curious enough to know what are the exact set of test commands one has to check locally before submitting the code patch and send the pull request here.
|
@sbc100 @kripken @tlively I have tried to give a fair amount of time to the cloud test cases. I have drawn the following inferences and would need your help to proceed further to resolve all the checks.
Also while testing locally what are mandatory tests one would recommend to use before pusing the code to github main repository. Do we need to use all the test cases mentioned in https://emscripten.org/docs/getting_started/test-suite.html documentation or just the subset of it . I hope these inputs will help me complete this pull request and guide me for the upcoming functions implementation contributions. |
|
its up to you what tests you run locally. The CI systems will run all them either way, once you upload. |
|
It's not immediately obvious to me why you are getting those errors on CI. @impact-maker, are you able to reproduce the errors when you test locally? Passing |
c14ca4a to
ce18bc5
Compare
|
@tlively @kripken @sbc100 I am consistently trying to run the test case but still encountering errors in three test cases
Kindly assist me to help complete this long due pull request or any workouts to resolve these specific function related errors. |
| self.emcc_args += ['-sWASMFS'] | ||
| self.emcc_args += ['-sFORCE_FILESYSTEM'] |
There was a problem hiding this comment.
Instead of forcing this test to use WasmFS, it would be better to use the @also_with_wasmfs_js decorator. But looking at the test file, it doesn't look like it even uses the getcwd JS API, so we probably don't want to modify this test at all.
Is there another test we can reuse that already uses the JS API? If not, we should add a new test.
There was a problem hiding this comment.
@tlively config.yml is calling wasmfs.test_getcwd_with_non_ascii_name so that the reason why I did not write a new test. Is there any other place where this test needs to be called or should I go ahead to write a new test for this.
| '$allocateUTF8OnStack', | ||
| '$withStackSave', | ||
| '$readI53FromI64', | ||
|
|
| # JS API directly. | ||
| settings.REQUIRED_EXPORTS += [ | ||
| '_wasmfs_write_file', | ||
| '_wasmfs_getcwd', |
There was a problem hiding this comment.
I took a look at the failing wasmfs.test_emscripten_get_now test locally, and the problem is that this line here adds _wasmfs_getcwd only if FORCE_FILESYSTEM is enabled, but in library_wasmfs.js, FS.getcwd is included even without that option. So we need to add _wasmfs_getcwd to REQUIRED_EXPORTS up where _wasmfs_read_file is added rather than here.
There was a problem hiding this comment.
@tlively Thank you for helping me out with the error, almost all the test cases error are resolved. One last error is the browser test case
Expected to find '/report_result?0
' in '[no http server activity]
', diff:
This is happening on my local too. I am not able to find any solution to this browser error, neither I am able to find any workaround this.
There was a problem hiding this comment.
Sometimes that error message is caused by flaky CI. If you modify the command the test executes (which you can find with runner --verbose) to build to .html instead of .js, you should be able to serve the test to yourself with emrun --no_browser <path to build directory>. If you do that, does the test behave as expected in the browser locally?
| //Implemented cwd | ||
| //test commit | ||
| // TODO: Remove dependency on FS.cwd(). | ||
| // User code should not be using FS.cwd(). | ||
| // For file preloading, cwd should be '/' to begin with. |
There was a problem hiding this comment.
It looks like all these comments should be removed.
Description
Currently the mount function is copied from library_fs.js and needs a cleanup and some code changes and testing to be successfully implemented.