diff --git a/test/filesystem/bad_lookup.cpp b/test/filesystem/bad_lookup.cpp deleted file mode 100644 index ebe55de3b1648..0000000000000 --- a/test/filesystem/bad_lookup.cpp +++ /dev/null @@ -1,106 +0,0 @@ -// 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 -#include -#include -#include -#include - -#include -#include -#include - -using std::endl; - -//============================================================================ -// :: Helpers - -namespace -{ - //-------------------------------------------------------------------------- - // Helper to create an empty file with the given path. - void touch(const std::string& path, const mode_t mode) - { - std::cout - << "Touching file: " << path << " with mode=" << std::oct << mode - << std::dec << endl; - - const int fd = ::open(path.c_str(), O_CREAT | O_WRONLY, mode); - if (fd == -1) { - const int error = errno; - std::cout - << "Failed to touch file using open: " << path << "; errno=" << error - << ";" << std::strerror(error) << endl; - } - else { - ::close(fd); - } - } - - //-------------------------------------------------------------------------- - // Stats the given path and prints the mode. Returns true if the path - // exists; false otherwise. - bool exists(const std::string& path) - { - struct ::stat path_stat; - if (::lstat(path.c_str(), &path_stat) != 0) { - const int error = errno; - if (error == ENOENT) { - // Only bother logging if something other than the path not existing - // went wrong. - std::cout - << "Failed to lstat path: " << path << "; errno=" << error << "; " - << std::strerror(error) << endl; - } - return false; - } - - std::cout - << std::oct << "Mode for path=" << path << ": " << path_stat.st_mode - << std::dec << endl; - return true; - } -} - -//============================================================================ -// :: Entry Point - -int main() -{ - touch("file1", 0667); - if (not exists("file1")) { - std::cout << "Failed to create path: file1" << endl; - return 1; - } - if (exists("file1/dir")) { - std::cout << "Path should not exists: file1/dir" << endl; - return 1; - } - - touch("file2", 0676); - if (not exists("file2")) { - std::cout << "Failed to create path: file2" << endl; - return 1; - } - if (exists("file2/dir")) { - std::cout << "Path should not exists: file2/dir" << endl; - return 1; - } - - touch("file3", 0766); - if (not exists("file3")) { - std::cout << "Failed to create path: file3" << endl; - return 1; - } - if (exists("file3/dir")) { - std::cout << "Path should not exists: file3/dir" << endl; - return 1; - } - - std::cout << "ok." << endl; - return 0; -} - diff --git a/test/fs/test_fs_bad_lookup.c b/test/fs/test_fs_bad_lookup.c new file mode 100644 index 0000000000000..690798bfc138a --- /dev/null +++ b/test/fs/test_fs_bad_lookup.c @@ -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 +#include +#include +#include +#include +#include +#include + +//-------------------------------------------------------------------------- +// 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; +} + diff --git a/test/fs/test_fs_base.c b/test/fs/test_fs_base.c new file mode 100644 index 0000000000000..da1f7462626f6 --- /dev/null +++ b/test/fs/test_fs_base.c @@ -0,0 +1,4 @@ +int main() { + // Nothing to do here. Test is written in JS. See test/fs/test_fs_base.js. + return 0; +} diff --git a/test/filesystem/src.js b/test/fs/test_fs_base.js similarity index 100% rename from test/filesystem/src.js rename to test/fs/test_fs_base.js diff --git a/test/filesystem/output.txt b/test/fs/test_fs_base.out similarity index 99% rename from test/filesystem/output.txt rename to test/fs/test_fs_base.out index c0ec00cf1059f..ac6b96ee0c110 100644 --- a/test/filesystem/output.txt +++ b/test/fs/test_fs_base.out @@ -195,3 +195,4 @@ parentExists: false parentPath: null parentObject.contents: null + diff --git a/test/filesystem/test_dev_random.c b/test/fs/test_fs_dev_random.c similarity index 96% rename from test/filesystem/test_dev_random.c rename to test/fs/test_fs_dev_random.c index e8b1d98497dd7..4200f0bdc8139 100644 --- a/test/filesystem/test_dev_random.c +++ b/test/fs/test_fs_dev_random.c @@ -22,5 +22,6 @@ int main() { assert(nread == byte_count); fclose(fp); + printf("success\n"); return 0; } diff --git a/test/test_browser.py b/test/test_browser.py index 89b7edbaa6740..b044613ef296e 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -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']) diff --git a/test/test_core.py b/test/test_core.py index 551d3d41e0e4d..09aaa129b6ffd 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -5674,10 +5674,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 diff --git a/test/test_other.py b/test/test_other.py index dfdff53977072..7e0e11ffb7a17 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -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],