Skip to content

Commit cf747df

Browse files
authored
Merge pull request #34 from hermit-os/fstat
feat: add test for fstat
2 parents c296803 + ea632c4 commit cf747df

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
tar -xvf opensbi-*-rv-bin.tar.xz opensbi-1.6-rv-bin/share/opensbi/lp64/generic/firmware/fw_jump.bin
8282
- run: cargo xtask ci c --arch ${{ matrix.arch }} --buildtype ${{ matrix.buildtype }} --target hello_world qemu ${{ matrix.flags }}
8383
- run: cargo xtask ci c --arch ${{ matrix.arch }} --buildtype ${{ matrix.buildtype }} --target fs qemu ${{ matrix.flags }}
84+
- run: cargo xtask ci c --arch ${{ matrix.arch }} --buildtype ${{ matrix.buildtype }} --target fstat qemu ${{ matrix.flags }}
8485
- run: cargo xtask ci c --arch ${{ matrix.arch }} --buildtype ${{ matrix.buildtype }} --target http_server qemu ${{ matrix.flags }} --netdev ${{ matrix.netdev }}
8586
- run: cargo xtask ci c --arch ${{ matrix.arch }} --buildtype ${{ matrix.buildtype }} --target http_server_poll qemu ${{ matrix.flags }} --netdev ${{ matrix.netdev }}
8687
- run: cargo xtask ci c --arch ${{ matrix.arch }} --buildtype ${{ matrix.buildtype }} --target limits qemu ${{ matrix.flags }}
@@ -105,6 +106,7 @@ jobs:
105106
- run: meson compile -C build
106107
- run: ./build/hello_world
107108
- run: ./build/fs
109+
- run: ./build/fstat
108110
- run: |
109111
./build/http_server &
110112
curl localhost:9975

kernel

Submodule kernel updated 95 files

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ else
4646
endif
4747

4848
executable('fs', 'src/fs.c', link_whole: hermit)
49+
executable('fstat', 'src/fstat.c', link_whole: hermit)
4950
executable('hello_world', 'src/hello_world.c', link_whole: hermit)
5051
executable('http_server', 'src/http_server.c', link_whole: hermit)
5152
executable('http_server_poll', 'src/http_server_poll.c', link_whole: hermit)

src/fstat.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "print_assert.h"
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <sys/stat.h>
6+
#include <unistd.h>
7+
8+
int test_stdio(int fildes) {
9+
struct stat buf;
10+
11+
int fstat_status = fstat(fildes, &buf);
12+
if (fstat_status == -1) {
13+
perror("fstat() failed");
14+
return -1;
15+
}
16+
17+
fprintf(stderr, "mode = %#o\n", buf.st_mode);
18+
#ifdef __hermit__
19+
print_assert((buf.st_mode & S_IFCHR) == S_IFCHR);
20+
#endif /* __hermit__ */
21+
22+
return 0;
23+
}
24+
25+
int main(void) {
26+
int stdin_status = test_stdio(STDIN_FILENO);
27+
if (stdin_status == -1) {
28+
return EXIT_FAILURE;
29+
}
30+
31+
int stdout_status = test_stdio(STDOUT_FILENO);
32+
if (stdout_status == -1) {
33+
return EXIT_FAILURE;
34+
}
35+
36+
int stderr_status = test_stdio(STDERR_FILENO);
37+
if (stderr_status == -1) {
38+
return EXIT_FAILURE;
39+
}
40+
}

0 commit comments

Comments
 (0)