MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / test

Function test

test/stat/test_stat.c:51–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49}
50
51void test() {
52 int err;
53 struct stat s;
54 struct utimbuf t = {TEST_TIME, TEST_TIME};
55
56 // non-existent
57 err = stat("does_not_exist", &s);
58 assert(err == -1);
59 assert(errno == ENOENT);
60
61 // test stat64 LFS functions
62 struct stat64 s64;
63 err = stat64("does_not_exist", &s64);
64 assert(err == -1);
65 assert(errno == ENOENT);
66
67 // stat a folder
68 memset(&s, 0, sizeof(s));
69 err = stat("folder", &s);
70 assert(!err);
71 assert(s.st_dev);
72 assert(s.st_ino);
73 assert(S_ISDIR(s.st_mode));
74 assert(s.st_nlink);
75#ifndef WASMFS
76 assert(s.st_rdev == 0);
77#endif
78 assert(s.st_size);
79 printf("TEST_TIME: %llx\n", TEST_TIME);
80 printf("s.st_atime: %llx\n", (long long)s.st_atime);
81 printf("s.st_mtime: %llx\n", (long long)s.st_mtime);
82 assert(s.st_atime == TEST_TIME);
83 assert(s.st_mtime == TEST_TIME);
84 assert(s.st_ctime);
85#ifdef __EMSCRIPTEN__
86 assert(s.st_blksize == 4096);
87#ifdef WASMFS
88 assert(s.st_blocks == 8);
89#else
90 assert(s.st_blocks == 1);
91#endif
92#endif
93 // stat a file
94 memset(&s, 0, sizeof(s));
95 err = stat("folder/file", &s);
96 assert(!err);
97 assert(s.st_dev);
98 assert(s.st_ino);
99 assert(S_ISREG(s.st_mode));
100 assert(s.st_nlink);
101 assert(s.st_rdev == 0);
102 assert(s.st_size == 6);
103 assert(s.st_atime == TEST_TIME);
104 assert(s.st_mtime == TEST_TIME);
105 assert(s.st_ctime);
106#ifdef __EMSCRIPTEN__
107 assert(s.st_blksize == 4096);
108 assert(s.st_blocks == 1);

Callers 1

mainFunction · 0.70

Calls 15

memsetFunction · 0.85
printfFunction · 0.85
putsFunction · 0.85
statClass · 0.70
stat64Class · 0.70
create_fileFunction · 0.70
assertFunction · 0.50
fstatFunction · 0.50
openFunction · 0.50
lstatFunction · 0.50
mkdirFunction · 0.50
utimeFunction · 0.50

Tested by

no test coverage detected