-
Notifications
You must be signed in to change notification settings - Fork 3.4k
WasmFS JS API: Implement allocate #19602
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
Changes from all commits
fb482de
1a4a7c1
69c0806
b42f61b
2a9a5fc
f791c4f
8747bd6
2d9b1e1
693273f
1f74313
91339bc
07e3bbb
0d15114
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,46 @@ | |
#include <assert.h> | ||
#include <fcntl.h> | ||
|
||
void test_fs_allocate() { | ||
EM_ASM( | ||
FS.writeFile("allocatetestfile", 'a=1\nb=2\n'); | ||
); | ||
struct stat allocateStat; | ||
stat("allocatetestfile", &allocateStat); | ||
assert(allocateStat.st_size == 8); | ||
|
||
EM_ASM( | ||
// Allocate more space at the very end. | ||
var stream = FS.open("allocatetestfile", "w"); | ||
FS.allocate(stream, 8, 10); | ||
); | ||
stat("allocatetestfile", &allocateStat); | ||
assert(allocateStat.st_size == 18); | ||
|
||
EM_ASM( | ||
// Reduce allocated space at the very start. | ||
var stream = FS.open("allocatetestfile", "w"); | ||
FS.allocate(stream, 0, 4); | ||
); | ||
stat("allocatetestfile", &allocateStat); | ||
assert(allocateStat.st_size == 4); | ||
|
||
EM_ASM( | ||
var stream = FS.open("allocatetestfile", "w"); | ||
|
||
var ex; | ||
try { | ||
// Attempt to allocate negative length. | ||
FS.allocate(stream, 0, -1); | ||
} catch (err) { | ||
ex = err; | ||
} | ||
assert(ex.name === "ErrnoError" && ex.errno === 28 /* EINVAL */); | ||
); | ||
|
||
remove("allocatetestfile"); | ||
} | ||
|
||
void test_fs_truncate() { | ||
EM_ASM( | ||
FS.writeFile('truncatetest', 'a=1\nb=2\n'); | ||
|
@@ -182,12 +222,11 @@ int main() { | |
FS.mkdir('/dir2'); | ||
); | ||
|
||
struct stat s; | ||
stat("/dir1", &s); | ||
assert(S_ISDIR(s.st_mode)); | ||
stat("/dir2", &s); | ||
assert(S_ISDIR(s.st_mode)); | ||
|
||
struct stat rmdirStat; | ||
stat("/dir1", &rmdirStat); | ||
assert(S_ISDIR(rmdirStat.st_mode)); | ||
stat("/dir2", &rmdirStat); | ||
assert(S_ISDIR(rmdirStat.st_mode)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the reason for the name change is to avoid a collision, another option is to add a scope, {
struct stat s;
..
} But the more explicit name also seems good by itself, either sgtm. Or, it might be nice to split up the tests into their own functions, as the new test here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was some collision after merging in the other tests, but I did move each test to its own function in the |
||
|
||
EM_ASM( | ||
// Remove the multiple directories | ||
|
@@ -255,15 +294,17 @@ int main() { | |
|
||
FS.create("createtest", 0400); /* S_IRUSR */ | ||
); | ||
struct stat stats; | ||
stat("mknodtest", &stats); | ||
struct stat mknodStats; | ||
stat("mknodtest", &mknodStats); | ||
|
||
assert(S_ISREG(mknodStats.st_mode)); | ||
assert(mknodStats.st_mode & 0777); | ||
|
||
assert(S_ISREG(stats.st_mode)); | ||
assert(stats.st_mode & 0777); | ||
stat("createtest", &mknodStats); | ||
assert(S_ISREG(mknodStats.st_mode)); | ||
assert(mknodStats.st_mode & 0400); | ||
|
||
stat("createtest", &stats); | ||
assert(S_ISREG(stats.st_mode)); | ||
assert(stats.st_mode & 0400); | ||
test_fs_allocate(); | ||
|
||
test_fs_truncate(); | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.