diff --git a/test/setup_nodefs.js b/test/setup_nodefs.js index 5d1c38dd7898c..03feef8cdd345 100644 --- a/test/setup_nodefs.js +++ b/test/setup_nodefs.js @@ -1,3 +1,16 @@ +const statfsSync = require('fs').statfsSync; + +const DEFAULT_BLOCKS = 1e6; + +Module['preRun'] = () => { + try { + const statfs = statfsSync('/'); + ENV.EXPECTED_BLOCKS = statfs.blocks.toString(); + } catch (e) { + // Older versions of Node don't support statfsSync + } +}; + Module['onRuntimeInitialized'] = () => { out('mounting node filesystem under /nodefs'); FS.mkdir('/nodefs'); diff --git a/test/unistd/fstatfs.c b/test/unistd/fstatfs.c index be6c602d3e692..e19b9e9b0a371 100644 --- a/test/unistd/fstatfs.c +++ b/test/unistd/fstatfs.c @@ -3,19 +3,53 @@ #include #include #include +#include +#include // for strerror +#include // for errno#include + +#define DEFAULT_BLOCKS 1000000 int main() { struct statfs buf; + const char *expected_blocks_str = getenv("EXPECTED_BLOCKS"); + long expected_blocks = expected_blocks_str ? atol(expected_blocks_str) : DEFAULT_BLOCKS; + int fstatfs_rtn; + +#if NODEF || NODERAWFSS + fstatfs_rtn = statfs("/nodefs", &buf); + printf("f_type: %ld\n", buf.f_type); + assert(fstatfs_rtn == 0); + printf("f_blocks: %d\n", buf.f_blocks); + printf("expected_blocks: %ld\n", expected_blocks); + assert(buf.f_blocks == expected_blocks); +#endif - int rtn; - assert(fstatfs(STDOUT_FILENO, &buf) == 0); + fstatfs_rtn = fstatfs(STDOUT_FILENO, &buf); printf("f_type: %ld\n", buf.f_type); + assert(fstatfs_rtn == 0); + printf("f_blocks: %d\n", buf.f_blocks); + assert(buf.f_blocks == DEFAULT_BLOCKS); int f = open("file", O_RDWR | O_CREAT); - assert(fstatfs(f, &buf) == 0); + fstatfs_rtn = fstatfs(f, &buf); printf("f_type: %ld\n", buf.f_type); + printf("f_blocks: %d\n", buf.f_blocks); +#if NODEFS || NODERAWFS + assert(fstatfs_rtn == 0); + assert(buf.f_blocks != 0); +#else + assert(fstatfs_rtn == 0); + assert(buf.f_blocks == DEFAULT_BLOCKS); +#endif assert(statfs("file", &buf) == 0); printf("f_type: %ld\n", buf.f_type); + printf("f_blocks: %d\n", buf.f_blocks); +#if NODEFS || NODERAWFS + assert(buf.f_blocks != 0); +#else + assert(buf.f_blocks == DEFAULT_BLOCKS); +#endif + return 0; }