diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-09-09 17:28:40 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2019-09-10 11:08:44 +0100 |
commit | a47f15b2cd67f00f6352825f52997f7d590e5a6e (patch) | |
tree | d3d5a6458d1329c5bbeff125340d74ab1a2620bf | |
parent | 09e27a18d046e13f5b508cb004f7a7e81436eadb (diff) |
semihosting tests: Add tests for SYS_ISTTY
Add basic tests of SYS_ISTTY.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | semihosting.c | 10 | ||||
-rw-r--r-- | semihosting.h | 2 | ||||
-rw-r--r-- | usertest.c | 59 |
3 files changed, 71 insertions, 0 deletions
diff --git a/semihosting.c b/semihosting.c index 28e0aa7..6211b59 100644 --- a/semihosting.c +++ b/semihosting.c @@ -80,6 +80,16 @@ int semi_flen(int fd) return __semi_call(SYS_FLEN, &args); } +int semi_istty(int fd) +{ + struct { + intptr_t fd; + } args; + + args.fd = fd; + return __semi_call(SYS_ISTTY, &args); +} + int semi_get_cmdline(char *buffer, int size, int *length) { int result; diff --git a/semihosting.h b/semihosting.h index 405e355..dc097af 100644 --- a/semihosting.h +++ b/semihosting.h @@ -25,6 +25,7 @@ #define SYS_WRITEC 3 #define SYS_WRITE0 4 #define SYS_READ 6 +#define SYS_ISTTY 9 #define SYS_FLEN 0x0C #define SYS_GET_CMDLINE 0x15 #define SYS_REPORTEXC 0x18 @@ -40,6 +41,7 @@ int semi_write0(char const *string); void semi_writec(char c); int semi_read(int fd, char *buffer, int length); int semi_flen(int fd); +int semi_istty(int fd); int semi_get_cmdline(char *buffer, int size, int *length); int semi_reportexc(int reason, int subcode); void semi_fatal(char const *message); @@ -40,6 +40,61 @@ void semi_putc(void *p, char c) #define TESTDATA_FILE "testdata.txt" const char file[] = "Small file of text data for test.\n"; +static int test_istty(void) +{ + int fd; + int fail = 0; + + fd = semi_open(TESTDATA_FILE, OPEN_RDONLY); + if (fd == -1) { + semi_write0("FAIL could not open test data file\n"); + return 1; + } + + switch (semi_istty(fd)) { + case 0: + semi_write0("PASS istty(file) returned 0\n"); + break; + case 1: + semi_write0("FAIL istty(file) returned 1\n"); + fail++; + break; + default: + semi_write0("FAIL istty(file) failed\n"); + fail++; + break; + } + semi_close(fd); + if (fail) { + return 1; + } + + fd = semi_open(":tt", OPEN_RDONLY); + if (fd == -1) { + semi_write0("FAIL could not open stdin\n"); + return 1; + } + + switch (semi_istty(fd)) { + case 0: + semi_write0("FAIL istty(stdin) returned 0\n"); + fail++; + break; + case 1: + semi_write0("PASS istty(stdin) returned 1\n"); + break; + default: + semi_write0("FAIL istty(stdin) failed\n"); + fail++; + break; + } + semi_close(fd); + if (fail) { + return 1; + } + return 0; +} + int main(void) { void *bufp; @@ -75,6 +130,10 @@ int main(void) } semi_write0("PASS test file contents match\n"); + if (test_istty()) { + return 1; + } + semi_write0("ALL TESTS PASSED\n"); semi_exit(0); /* not reached */ |