Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ def require_wasm2js(self):
if self.is_2gb() or self.is_4gb():
self.skipTest('wasm2js does not support over 2gb of memory')

def setup_nodefs_test(self):
self.require_node()
self.emcc_args += ['-lnodefs.js', '--pre-js', test_file('setup_nodefs.js')]

def setup_node_pthreads(self):
self.require_node()
self.emcc_args += ['-Wno-pthreads-mem-growth', '-pthread']
Expand Down
37 changes: 6 additions & 31 deletions test/fs/test_fs_rename_on_existing.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,6 @@
#include <errno.h>
#include <string.h>


#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
#endif

void makedir(const char *dir) {
int rtn = mkdir(dir, 0777);
assert(rtn == 0);
}

void changedir(const char *dir) {
int rtn = chdir(dir);
assert(rtn == 0);
}

static void create_file(const char *path, const char *buffer) {
printf("creating: %s\n", path);
int fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0666);
Expand All @@ -35,21 +20,11 @@ static void create_file(const char *path, const char *buffer) {
close(fd);
}


void setup() {
#if defined(__EMSCRIPTEN__) && defined(NODEFS)
makedir("working");
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
changedir("working");
#endif
}

int main() {
setup();
create_file("a", "abc");
create_file("b", "xyz");
assert(rename("a", "b") == 0);
assert(unlink("b") == 0);
create_file("b", "xyz");
printf("success\n");
create_file("a", "abc");
create_file("b", "xyz");
assert(rename("a", "b") == 0);
assert(unlink("b") == 0);
create_file("b", "xyz");
printf("success\n");
}
8 changes: 0 additions & 8 deletions test/fs/test_fs_symlink_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#if defined(__EMSCRIPTEN__)
#include "emscripten.h"
#endif

void makedir(const char *dir) {
int rtn = mkdir(dir, 0777);
Expand All @@ -29,11 +26,6 @@ static void create_file(const char *path) {
}

void setup() {
#if defined(__EMSCRIPTEN__) && defined(NODEFS)
makedir("working");
EM_ASM(FS.mount(NODEFS, { root: '.' }, 'working'));
changedir("working");
#endif
makedir("a");
makedir("b");
makedir("b/c");
Expand Down
42 changes: 18 additions & 24 deletions test/fs/test_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

void test_mmap_read() {
// Use mmap to read in.txt
EM_ASM(FS.writeFile('yolo/in.txt', 'mmap ftw!'));
EM_ASM(FS.writeFile('in.txt', 'mmap ftw!'));

int fd = open("yolo/in.txt", O_RDONLY);
int fd = open("in.txt", O_RDONLY);
assert(fd >= 0);

int filesize = 9;
char* map = (char*)mmap(NULL, filesize, PROT_READ, MAP_PRIVATE, fd, 0);
assert(map != MAP_FAILED);

printf("yolo/in.txt content=");
printf("in.txt content=");
for (int i = 0; i < filesize; i++) {
printf("%c", map[i]);
}
Expand All @@ -42,7 +42,7 @@ void test_mmap_read() {

void test_mmap_write() {
// Use mmap to write out.txt
int fd = open("yolo/out.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
int fd = open("out.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
assert(fd >= 0);

const char* text = "written mmap";
Expand All @@ -64,12 +64,12 @@ void test_mmap_write() {
close(fd);

{
FILE* fd = fopen("yolo/out.txt", "r");
FILE* fd = fopen("out.txt", "r");
assert(fd >= 0);
char buffer[15];
memset(buffer, 0, 15);
fread(buffer, 1, 14, fd);
printf("yolo/out.txt content=%s\n", buffer);
printf("out.txt content=%s\n", buffer);
fclose(fd);
}
}
Expand All @@ -79,7 +79,7 @@ void test_mmap_readonly() {
// but make sure it's not overwritten on munmap
const char* readonlytext = "readonly mmap\0";
const char* text = "write mmap\0";
const char* path = "yolo/outreadonly.txt";
const char* path = "outreadonly.txt";
size_t readonlytextsize = strlen(readonlytext);
size_t textsize = strlen(text);

Expand All @@ -102,18 +102,18 @@ void test_mmap_readonly() {
close(fd);

{
FILE* fd = fopen("yolo/outreadonly.txt", "r");
FILE* fd = fopen("outreadonly.txt", "r");
assert(fd >= 0);
char buffer[16];
memset(buffer, 0, 16);
fread(buffer, 1, 15, fd);
printf("yolo/outreadonly.txt content=%s\n", buffer);
printf("outreadonly.txt content=%s\n", buffer);
fclose(fd);
}
}

void test_mmap_private() {
int fd = open("yolo/private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
int fd = open("private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
assert(fd >= 0);

const char* text = "written mmap";
Expand All @@ -135,18 +135,18 @@ void test_mmap_private() {
close(fd);

{
FILE* fd = fopen("yolo/private.txt", "r");
FILE* fd = fopen("private.txt", "r");
assert(fd >= 0);
char buffer[15];
memset(buffer, 0, 15);
fread(buffer, 1, 14, fd);
printf("yolo/private.txt content=%s\n", buffer);
printf("private.txt content=%s\n", buffer);
fclose(fd);
}
}

void test_mmap_shared_with_offset() {
int fd = open("yolo/sharedoffset.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
int fd = open("sharedoffset.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
assert(fd > 0);

const char* text = "written shared mmap with offset";
Expand Down Expand Up @@ -176,7 +176,7 @@ void test_mmap_shared_with_offset() {
close(fd);

{
FILE* fd = fopen("yolo/sharedoffset.txt", "r");
FILE* fd = fopen("sharedoffset.txt", "r");
assert(fd >= 0);
size_t offset = sysconf(_SC_PAGE_SIZE) * 2;

Expand All @@ -185,14 +185,14 @@ void test_mmap_shared_with_offset() {
fseek(fd, offset, SEEK_SET);
fread(buffer, 1, 32, fd);
// expect text written from mmap operation to appear at offset in the file
printf("yolo/sharedoffset.txt content=%s %zu\n", buffer, offset);
printf("sharedoffset.txt content=%s %zu\n", buffer, offset);
fclose(fd);
}
}

void test_mmap_hint() {
// mmap with a address is expected to fail
int fd = open("yolo/private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
int fd = open("private.txt", O_RDWR | O_CREAT | O_TRUNC, (mode_t)0600);
assert(fd != -1);

size_t map_size = 1 << 16;
Expand Down Expand Up @@ -225,7 +225,7 @@ void test_mmap_hint() {
*/
void test_mmap_overallocate() {
#if !defined(NODEFS) && !defined(NODERAWFS) && !defined(WASMFS)
int fd = open("yolo/overallocatedfile.txt", O_RDWR | O_CREAT, (mode_t)0600);
int fd = open("overallocatedfile.txt", O_RDWR | O_CREAT, (mode_t)0600);
assert(fd != -1);

const size_t textsize = 33;
Expand All @@ -236,7 +236,7 @@ void test_mmap_overallocate() {
}

EM_ASM({
const stream = FS.streams.find(stream => stream.path.indexOf('yolo/overallocatedfile.txt') >= 0);
const stream = FS.streams.find(stream => stream.path.indexOf('overallocatedfile.txt') >= 0);
assert(stream.node.usedBytes === Number($0),
'Used bytes on the over-allocated file (' + stream.node.usedBytes + ') ' +
'should be ' + $0
Expand Down Expand Up @@ -264,12 +264,6 @@ void test_mmap_overallocate() {
}

int main() {
EM_ASM(
FS.mkdir('yolo');
#if NODEFS
FS.mount(NODEFS, { root: '.' }, 'yolo');
#endif
);
test_mmap_read();
test_mmap_write();
test_mmap_readonly();
Expand Down
10 changes: 5 additions & 5 deletions test/fs/test_mmap.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
yolo/in.txt content=mmap ftw!
yolo/out.txt content=written mmap
yolo/outreadonly.txt content=readonly mmap
yolo/private.txt content=
yolo/sharedoffset.txt content=written shared mmap with offset 131072
in.txt content=mmap ftw!
out.txt content=written mmap
outreadonly.txt content=readonly mmap
private.txt content=
sharedoffset.txt content=written shared mmap with offset 131072
27 changes: 7 additions & 20 deletions test/fs/test_nodefs_cloexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,11 @@
#include <fcntl.h>
#include <emscripten.h>

#ifdef NODERAWFS
#define CWD ""
#else
#define CWD "/working/"
#endif

int main(void)
{
EM_ASM(
#ifdef NODERAWFS
FS.close(FS.open('test.txt', 'w'));
#else
FS.mkdir('/working');
FS.mount(NODEFS, {root: '.'}, '/working');
FS.close(FS.open('/working/test.txt', 'w'));
#endif
);
assert(open(CWD "test.txt", O_RDONLY | O_CLOEXEC) != -1);
printf("success\n");
return 0;
int main(void) {
EM_ASM(
FS.close(FS.open('test.txt', 'w'));
);
assert(open("test.txt", O_RDONLY | O_CLOEXEC) != -1);
printf("success\n");
return 0;
}
50 changes: 21 additions & 29 deletions test/fs/test_nodefs_dup.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,27 @@
#include <stdio.h>
#include <unistd.h>

#ifdef NODERAWFS
#define CWD ""
#else
#define CWD "/working/"
#endif
int main(void) {
EM_ASM(
FS.close(FS.open('test.txt', 'w'));
);

int main(void)
{
EM_ASM(
#ifdef NODERAWFS
FS.close(FS.open('test.txt', 'w'));
#else
FS.mkdir('/working');
FS.mount(NODEFS, {root: '.'}, '/working');
FS.close(FS.open('/working/test.txt', 'w'));
#endif
);
int fd1 = open(CWD "test.txt", O_WRONLY);
int fd2 = dup(fd1);
int fd3 = fcntl(fd1, F_DUPFD_CLOEXEC, 0);
int fd = open("test.txt", O_CREAT, 0444);
assert(fd > 0);
close(fd);

assert(fd1 == 3);
assert(fd2 == 4);
assert(fd3 == 5);
assert(close(fd1) == 0);
assert(write(fd2, "abcdef", 6) == 6);
assert(close(fd2) == 0);
assert(write(fd3, "ghijkl", 6) == 6);
assert(close(fd3) == 0);
printf("success\n");
return 0;
int fd1 = open("test.txt", O_WRONLY);
int fd2 = dup(fd1);
int fd3 = fcntl(fd1, F_DUPFD_CLOEXEC, 0);

assert(fd1 == 3);
assert(fd2 == 4);
assert(fd3 == 5);
assert(close(fd1) == 0);
assert(write(fd2, "abcdef", 6) == 6);
assert(close(fd2) == 0);
assert(write(fd3, "ghijkl", 6) == 6);
assert(close(fd3) == 0);
printf("success\n");
return 0;
}
21 changes: 3 additions & 18 deletions test/fs/test_nodefs_rw.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@
#include <errno.h>
#include <emscripten.h>

#ifdef NODERAWFS
#define CWD ""
#else
#define CWD "/working/"
#endif

int main() {
FILE *file;
int res;
Expand All @@ -28,17 +22,8 @@ int main() {
fs.writeFileSync('foobar.txt', 'yeehaw');
);

#ifndef NODERAWFS
// mount the current folder as a NODEFS instance
// inside of emscripten
EM_ASM(
FS.mkdir('/working');
FS.mount(NODEFS, { root: '.' }, '/working');
);
#endif

// read and validate the contents of the file
file = fopen(CWD "foobar.txt", "r");
file = fopen("foobar.txt", "r");
assert(file);
res = fread(buffer, sizeof(char), 6, file);
assert(res == 6);
Expand All @@ -49,7 +34,7 @@ int main() {
assert(!strcmp(buffer, "yeehaw"));

// write out something new
file = fopen(CWD "foobar.txt", "w");
file = fopen("foobar.txt", "w");
assert(file);
res = fwrite("cheez", sizeof(char), 5, file);
assert(res == 5);
Expand All @@ -62,7 +47,7 @@ int main() {
assert(contents === 'cheez');
);

file = fopen(CWD "csfsq", "r");
file = fopen("csfsq", "r");
assert(file == NULL);
assert(errno == ENOENT);

Expand Down
Loading
Loading