Skip to content

Commit 09a2698

Browse files
Remove a file test outside of the specs and improve CI reporting (#2057)
Remove the test in the sample of file interaction that tries to extend the file at the end, because this is not supported by the specifications of fseek. The WASI exit code is now propagated by the runtime, so the CI will indicate when a test is failing.
1 parent c7cdb78 commit 09a2698

2 files changed

Lines changed: 29 additions & 13 deletions

File tree

samples/file/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ main(int argc, char *argv_main[])
2020
static char global_heap_buf[512 * 1024];
2121
char *buffer, error_buf[128];
2222
const char *wasm_path = NULL, *wasi_dir = NULL;
23-
int opt;
23+
int opt, main_result = 1;
2424

2525
wasm_module_t module = NULL;
2626
wasm_module_inst_t module_inst = NULL;
@@ -91,7 +91,7 @@ main(int argc, char *argv_main[])
9191
}
9292

9393
if (wasm_application_execute_main(module_inst, 0, NULL)) {
94-
printf("Main wasm function successfully finished.\n");
94+
main_result = wasm_runtime_get_wasi_exit_code(module_inst);
9595
}
9696
else {
9797
printf("call wasm function main failed. error: %s\n",
@@ -109,5 +109,5 @@ main(int argc, char *argv_main[])
109109
if (buffer)
110110
BH_FREE(buffer);
111111
wasm_runtime_destroy();
112-
return 0;
112+
return main_result;
113113
}

samples/file/wasm-app/main.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,32 @@ main(int argc, char **argv)
9999
assert(ftell(file) == strlen(FILE_TEXT));
100100
printf("[Test] Reading at specified offset passed.\n");
101101

102+
// Test: moving at the start of the file (fseek)
103+
printf("Move at the start of the file (fseek)..\n");
104+
printf("File current offset: %ld\n", ftell(file));
105+
fseek(file, 0, SEEK_SET);
106+
printf("File current offset: %ld\n", ftell(file));
107+
assert(ftell(file) == 0);
108+
109+
// Test: moving at the end of the file (fseek)
110+
printf("Move at the end of the file (fseek)..\n");
111+
printf("File current offset: %ld\n", ftell(file));
112+
fseek(file, 0, SEEK_END);
113+
printf("File current offset: %ld\n", ftell(file));
114+
assert(ftell(file) == strlen(FILE_TEXT));
115+
int end_position = ftell(file) / 2;
116+
117+
// Test: moving at the middle of the file (fseek)
118+
printf("Move at the middle of the file (fseek)..\n");
119+
printf("File current offset: %ld\n", ftell(file));
120+
fseek(file, 0, SEEK_SET);
121+
fseek(file, end_position, SEEK_CUR);
122+
printf("File current offset: %ld\n", ftell(file));
123+
assert(ftell(file) == end_position);
124+
102125
// Test: allocate more space to the file (posix_fallocate)
103126
printf("Allocate more space to the file (posix_fallocate)..\n");
127+
fseek(file, 0, SEEK_END);
104128
posix_fallocate(fileno(file), ftell(file), ADDITIONAL_SPACE);
105129
printf("File current offset: %ld\n", ftell(file));
106130
printf("Moving to the end..\n");
@@ -120,23 +144,15 @@ main(int argc, char **argv)
120144
assert(ftell(file) == strlen(text) + 2 * ADDITIONAL_SPACE);
121145
printf("[Test] Extension of the file size passed.\n");
122146

123-
// Test: allocate more space to the file (fseek)
147+
// Test: allocate more space to the file (fseek, from the start)
124148
printf("Allocate more space to the file (fseek) from the start..\n");
125149
printf("File current offset: %ld\n", ftell(file));
126150
fseek(file, 3 * ADDITIONAL_SPACE, SEEK_SET);
127151
printf("File current offset: %ld\n", ftell(file));
128152
assert(ftell(file) == 3 * ADDITIONAL_SPACE);
129153
printf("[Test] Extension of the file size passed.\n");
130154

131-
// Test: allocate more space to the file (fseek)
132-
printf("Allocate more space to the file (fseek) from the end..\n");
133-
printf("File current offset: %ld\n", ftell(file));
134-
fseek(file, ADDITIONAL_SPACE, SEEK_END);
135-
printf("File current offset: %ld\n", ftell(file));
136-
assert(ftell(file) == 4 * ADDITIONAL_SPACE);
137-
printf("[Test] Extension of the file size passed.\n");
138-
139-
// Test: allocate more space to the file (fseek)
155+
// Test: allocate more space to the file (fseek, from the middle)
140156
printf("Allocate more space to the file (fseek) from the middle..\n");
141157
fseek(file, 3 * ADDITIONAL_SPACE, SEEK_SET);
142158
printf("File current offset: %ld\n", ftell(file));

0 commit comments

Comments
 (0)