Mercurial > pub > dyncall > dyncall
comparison test/syscall/syscall.c @ 410:7608e34098b0
- cleanups, simplifications, some api clarification, ...
- test cases consistency:
* return status code depending on test results (for actual conformance tests, not stuff that is not an example or hack to check something, ..)
* platform init helper added for some
author | Tassilo Philipp |
---|---|
date | Tue, 05 Oct 2021 21:53:04 +0200 |
parents | f5577f6bf97a |
children | dfc2e6ee8782 |
comparison
equal
deleted
inserted
replaced
409:15698dc0cba3 | 410:7608e34098b0 |
---|---|
4 Library: test | 4 Library: test |
5 File: test/syscall/syscall.c | 5 File: test/syscall/syscall.c |
6 Description: | 6 Description: |
7 License: | 7 License: |
8 | 8 |
9 Copyright (c) 2011-2018 Daniel Adler <dadler@uni-goettingen.de>, | 9 Copyright (c) 2011-2021 Daniel Adler <dadler@uni-goettingen.de>, |
10 Tassilo Philipp <tphilipp@potion-studios.com> | 10 Tassilo Philipp <tphilipp@potion-studios.com> |
11 | 11 |
12 Permission to use, copy, modify, and distribute this software for any | 12 Permission to use, copy, modify, and distribute this software for any |
13 purpose with or without fee is hereby granted, provided that the above | 13 purpose with or without fee is hereby granted, provided that the above |
14 copyright notice and this permission notice appear in all copies. | 14 copyright notice and this permission notice appear in all copies. |
23 | 23 |
24 */ | 24 */ |
25 | 25 |
26 #include "dyncall.h" | 26 #include "dyncall.h" |
27 #include <sys/syscall.h> | 27 #include <sys/syscall.h> |
28 #include <assert.h> | |
29 DCCallVM* callvm; | 28 DCCallVM* callvm; |
30 | 29 |
31 void syscallvm_init() | |
32 { | |
33 callvm = dcNewCallVM(4096); | |
34 dcMode(callvm, DC_CALL_SYS_DEFAULT); | |
35 assert( dcGetError(callvm) == DC_ERROR_NONE ); | |
36 } | |
37 | 30 |
38 int syscall_write(int fd, char* buf, size_t len) | 31 int syscall_write(int fd, char* buf, size_t len) |
39 { | 32 { |
40 dcReset(callvm); | 33 dcReset(callvm); |
41 dcArgInt(callvm, fd); | 34 dcArgInt(callvm, fd); |
44 return dcCallInt(callvm, (DCpointer)(ptrdiff_t)SYS_write); | 37 return dcCallInt(callvm, (DCpointer)(ptrdiff_t)SYS_write); |
45 } | 38 } |
46 | 39 |
47 int main(int argc, char* argv[]) | 40 int main(int argc, char* argv[]) |
48 { | 41 { |
49 syscallvm_init(); | 42 int r = -1; |
50 syscall_write(1/*stdout*/, "result: syscall: 1\n", 19); | 43 callvm = dcNewCallVM(4096); |
51 return 0; | 44 dcMode(callvm, DC_CALL_SYS_DEFAULT); |
45 | |
46 if(dcGetError(callvm) == DC_ERROR_NONE) | |
47 { | |
48 r = syscall_write(1/*stdout*/, "result: syscall: ", 17); | |
49 r += syscall_write(1/*stdout*/, r==17?"1":"0", 2); | |
50 } | |
51 return !(r == 19); | |
52 } | 52 } |
53 | 53 |