Skip to content

Commit e82aeb7

Browse files
authored
Split test_proxyfs into external files. NFC (#25306)
This was the longest test in `test_other.py` weighing it at 302 lines.
1 parent ec6bc2b commit e82aeb7

File tree

3 files changed

+233
-242
lines changed

3 files changed

+233
-242
lines changed

test/other/test_proxyfs.c

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <fcntl.h>
4+
#include <emscripten/emscripten.h>
5+
6+
EMSCRIPTEN_KEEPALIVE int mywrite1() {
7+
FILE* out = fopen("/working/hoge.txt","w");
8+
fprintf(out,"test1\n");
9+
fclose(out);
10+
return 0;
11+
}
12+
13+
EMSCRIPTEN_KEEPALIVE int myread1() {
14+
FILE* in = fopen("/working/hoge.txt","r");
15+
char buf[1024];
16+
int len;
17+
if(in==NULL)
18+
printf("open failed\n");
19+
20+
while(! feof(in)){
21+
if(fgets(buf,sizeof(buf),in)==buf){
22+
printf("%s",buf);
23+
}
24+
}
25+
fclose(in);
26+
return 0;
27+
}
28+
29+
EMSCRIPTEN_KEEPALIVE int mywrite2() {
30+
FILE* out = fopen("/working2/hoge.txt","w");
31+
fprintf(out,"test2\n");
32+
fclose(out);
33+
return 0;
34+
}
35+
36+
EMSCRIPTEN_KEEPALIVE int myread2() {
37+
FILE* in = fopen("/working2/hoge.txt","r");
38+
char buf[1024];
39+
int len;
40+
if(in==NULL)
41+
printf("open failed\n");
42+
43+
while(! feof(in)){
44+
if(fgets(buf,sizeof(buf),in)==buf){
45+
printf("%s",buf);
46+
}
47+
}
48+
fclose(in);
49+
return 0;
50+
}
51+
52+
EMSCRIPTEN_KEEPALIVE int mywrite0(int i) {
53+
FILE* out = fopen("hoge.txt","w");
54+
fprintf(out,"test0_%d\n",i);
55+
fclose(out);
56+
return 0;
57+
}
58+
59+
EMSCRIPTEN_KEEPALIVE int myread0() {
60+
FILE* in = fopen("hoge.txt","r");
61+
char buf[1024];
62+
int len;
63+
if(in==NULL)
64+
printf("open failed\n");
65+
66+
while(! feof(in)){
67+
if(fgets(buf,sizeof(buf),in)==buf){
68+
printf("%s",buf);
69+
}
70+
}
71+
fclose(in);
72+
return 0;
73+
}
74+
75+
EMSCRIPTEN_KEEPALIVE int myaccess0existing() {
76+
int canAccess = access("/working/hoge.txt",O_RDONLY);
77+
printf("access=%d\n", canAccess);
78+
return 0;
79+
}
80+
81+
EMSCRIPTEN_KEEPALIVE int myaccess0absent() {
82+
int canAccess = access("/working/nosuchfile",O_RDONLY);
83+
printf("access=%d\n", canAccess);
84+
return 0;
85+
}
86+
87+
EMSCRIPTEN_KEEPALIVE int myaccess1existing() {
88+
int canAccess = access("/hoge.txt",O_RDONLY);
89+
printf("access=%d\n", canAccess);
90+
return 0;
91+
}
92+
93+
EMSCRIPTEN_KEEPALIVE int myaccess1absent() {
94+
int canAccess = access("/nosuchfile",O_RDONLY);
95+
printf("access=%d\n", canAccess);
96+
return 0;
97+
}
98+
99+
EMSCRIPTEN_KEEPALIVE int myreade() {
100+
FILE* in = fopen("proxyfs_embed.txt","r");
101+
char buf[1024];
102+
int len;
103+
if(in==NULL)
104+
printf("open failed\n");
105+
106+
while(! feof(in)){
107+
if(fgets(buf,sizeof(buf),in)==buf){
108+
printf("%s",buf);
109+
}
110+
}
111+
fclose(in);
112+
return 0;
113+
}
114+
115+
EMSCRIPTEN_KEEPALIVE int myreadSeekEnd() {
116+
FILE* in = fopen("/working2/hoge.txt","r");
117+
118+
fseek(in, 0L, SEEK_END);
119+
int fileSize = ftell(in);
120+
fseek(in, 0L, SEEK_SET);
121+
printf("%d\n", fileSize);
122+
123+
fclose(in);
124+
return 0;
125+
}

test/other/test_proxyfs_main.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
var m0 = require('./test_proxyfs.js');
2+
var m1 = require('./test_proxyfs1.js');
3+
var m2 = require('./test_proxyfs2.js');
4+
5+
var section;
6+
function print(str){
7+
process.stdout.write(section+":"+str+":");
8+
}
9+
10+
m0.FS.mkdir('/working');
11+
m0.FS.mount(m0.PROXYFS,{root:'/',fs:m1.FS},'/working');
12+
m0.FS.mkdir('/working2');
13+
m0.FS.mount(m0.PROXYFS,{root:'/',fs:m2.FS},'/working2');
14+
15+
section = "child m1 reads and writes local file.";
16+
print("m1 read embed");
17+
m1.ccall('myreade','number',[],[]);
18+
print("m1 write");console.log("");
19+
m1.ccall('mywrite0','number',['number'],[1]);
20+
print("m1 read");
21+
m1.ccall('myread0','number',[],[]);
22+
23+
section = "child m2 reads and writes local file.";
24+
print("m2 read embed");
25+
m2.ccall('myreade','number',[],[]);
26+
print("m2 write");console.log("");
27+
m2.ccall('mywrite0','number',['number'],[2]);
28+
print("m2 read");
29+
m2.ccall('myread0','number',[],[]);
30+
31+
section = "child m1 reads local file.";
32+
print("m1 read");
33+
m1.ccall('myread0','number',[],[]);
34+
35+
section = "parent m0 accesses children's file.";
36+
print("m0 access existing");
37+
m0.ccall('myaccess0existing','number',[],[]);
38+
print("m0 access absent");
39+
m0.ccall('myaccess0absent','number',[],[]);
40+
41+
section = "child m1 accesses local file.";
42+
print("m1 access existing");
43+
m1.ccall('myaccess1existing','number',[],[]);
44+
print("m1 access absent");
45+
m1.ccall('myaccess1absent','number',[],[]);
46+
47+
section = "parent m0 reads and writes local and children's file.";
48+
print("m0 read embed");
49+
m0.ccall('myreade','number',[],[]);
50+
print("m0 read m1");
51+
m0.ccall('myread1','number',[],[]);
52+
print("m0 read m2");
53+
m0.ccall('myread2','number',[],[]);
54+
55+
section = "m0,m1 and m2 verify local files.";
56+
print("m0 write");console.log("");
57+
m0.ccall('mywrite0','number',['number'],[0]);
58+
print("m0 read");
59+
m0.ccall('myread0','number',[],[]);
60+
print("m1 read");
61+
m1.ccall('myread0','number',[],[]);
62+
print("m2 read");
63+
m2.ccall('myread0','number',[],[]);
64+
65+
print("m0 read embed");
66+
m0.ccall('myreade','number',[],[]);
67+
print("m1 read embed");
68+
m1.ccall('myreade','number',[],[]);
69+
print("m2 read embed");
70+
m2.ccall('myreade','number',[],[]);
71+
72+
section = "parent m0 writes and reads children's files.";
73+
print("m0 write m1");console.log("");
74+
m0.ccall('mywrite1','number',[],[]);
75+
print("m0 read m1");
76+
m0.ccall('myread1','number',[],[]);
77+
print("m0 write m2");console.log("");
78+
m0.ccall('mywrite2','number',[],[]);
79+
print("m0 read m2");
80+
m0.ccall('myread2','number',[],[]);
81+
print("m1 read");
82+
m1.ccall('myread0','number',[],[]);
83+
print("m2 read");
84+
m2.ccall('myread0','number',[],[]);
85+
print("m0 read m0");
86+
m0.ccall('myread0','number',[],[]);
87+
88+
section = "parent m0 renames a file in child fs.";
89+
m0.FS.writeFile('/working/test', 'testme');
90+
m0.FS.rename('/working/test', '/working/test.bak');
91+
console.log(section + ":renamed file accessible by the new name:" + m0.FS.analyzePath('/working/test.bak').exists);
92+
console.log(section + ":renamed file accessible by the old name:" + m0.FS.analyzePath('/working/test').exists);
93+
94+
section = "test seek.";
95+
print("file size");
96+
m0.ccall('myreadSeekEnd', 'number', [], []);

0 commit comments

Comments
 (0)