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
106 changes: 0 additions & 106 deletions test/filesystem/bad_lookup.cpp

This file was deleted.

81 changes: 81 additions & 0 deletions test/fs/test_fs_bad_lookup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2014 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

//--------------------------------------------------------------------------
// Helper to create an empty file with the given path.
void touch(const char* path, const mode_t mode) {
printf("Touching file: %s with mode=%o\n", path, mode);

int fd = open(path, O_CREAT | O_WRONLY, mode);
if (fd == -1) {
int error = errno;
printf("Failed to touch file using open: %s; %s\n", path, strerror(errno));
} else {
close(fd);
}
}

//--------------------------------------------------------------------------
// Stats the given path and prints the mode. Returns true if the path
// exists; false otherwise.
bool exists(const char* path) {
struct stat path_stat;
if (lstat(path, &path_stat) != 0) {
int error = errno;
if (error == ENOENT) {
// Only bother logging if something other than the path not existing
// went wrong.
printf("Failed to lstat path: %s; %s", path, strerror(error));
}
return false;
}

printf("Mode for path=%s: %o\n", path, path_stat.st_mode);
return true;
}

int main() {
touch("file1", 0667);
if (!exists("file1")) {
printf("Failed to create path: file1\n");
return 1;
}
if (exists("file1/dir")) {
printf("Path should not exists: file1/dir\n");
return 1;
}

touch("file2", 0676);
if (!exists("file2")) {
printf("Failed to create path: file2\n");
return 1;
}
if (exists("file2/dir")) {
printf("Path should not exists: file2/dir\n");
return 1;
}

touch("file3", 0766);
if (!exists("file3")) {
printf("Failed to create path: file3\n");
return 1;
}
if (exists("file3/dir")) {
printf("Path should not exists: file3/dir\n");
return 1;
}

printf("ok.\n");
return 0;
}

4 changes: 4 additions & 0 deletions test/fs/test_fs_base.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
int main() {
// Nothing to do here. Test is written in JS. See test/fs/test_fs_base.js.
return 0;
}
File renamed without changes.
1 change: 1 addition & 0 deletions test/filesystem/output.txt → test/fs/test_fs_base.out
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,4 @@
parentExists: false
parentPath: null
parentObject.contents: null

Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ int main() {
assert(nread == byte_count);
fclose(fp);

printf("success\n");
return 0;
}
4 changes: 2 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@ def test():
# test()

@also_with_wasmfs
def test_dev_random(self):
self.btest_exit('filesystem/test_dev_random.c')
def test_fs_dev_random(self):
self.btest_exit('fs/test_fs_dev_random.c')

def test_sdl_swsurface(self):
self.btest_exit('test_sdl_swsurface.c', args=['-lSDL', '-lGL'])
Expand Down
6 changes: 2 additions & 4 deletions test/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5735,10 +5735,8 @@ def test_istream(self):

def test_fs_base(self):
self.set_setting('DEFAULT_LIBRARY_FUNCS_TO_INCLUDE', ['$FS'])
self.add_pre_run(read_file(test_file('filesystem/src.js')))
src = 'int main() {return 0;}\n'
expected = read_file(test_file('filesystem/output.txt'))
self.do_run(src, expected)
self.add_pre_run(read_file(test_file('fs/test_fs_base.js')))
self.do_run_in_out_file_test('fs/test_fs_base.c')

@also_with_noderawfs
@is_slow_test
Expand Down
12 changes: 10 additions & 2 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -6097,8 +6097,16 @@ class time_iterator {
''')
self.run_process([EMXX, 'src.cpp', '-O2', '-sSAFE_HEAP'])

def test_bad_lookup(self):
self.do_runf(path_from_root('test/filesystem/bad_lookup.cpp'), expected_output='ok')
@also_with_wasmfs
@also_with_noderawfs
@crossplatform
def test_fs_bad_lookup(self):
self.do_runf(path_from_root('test/fs/test_fs_bad_lookup.c'), expected_output='ok')

@also_with_wasmfs
@also_with_noderawfs
def test_fs_dev_random(self):
self.do_runf('fs/test_fs_dev_random.c', 'success')

@parameterized({
'none': [{'EMCC_FORCE_STDLIBS': None}, False],
Expand Down
Loading