diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-09-10 11:30:15 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2019-09-10 11:30:15 +0100 |
commit | 05f7921b1d89aa8178d9d33e6ff8c7f592ebedc5 (patch) | |
tree | 79c8b2f6f1aa11cfe777a89262a3266c948b2c89 | |
parent | 22ba1a364d876f31c3db54e6a3dc8a97aa2652d9 (diff) |
semihosting tests: Add test for feature-detection
Add testing of the v2.0 feature-detection support.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r-- | semihosting.h | 6 | ||||
-rw-r--r-- | usertest.c | 94 |
2 files changed, 100 insertions, 0 deletions
diff --git a/semihosting.h b/semihosting.h index 8361ffd..f8c4e7b 100644 --- a/semihosting.h +++ b/semihosting.h @@ -38,6 +38,12 @@ #define REPORTEXC_REASON_APP_EXIT 0x20026 #define SEMIHOSTING_SVC 0x123456 /* SVC comment field for semihosting */ +#define FEATURE_DETECT_FILE ":semihosting-features" +#define SHFB_MAGIC_0 0x53 +#define SHFB_MAGIC_1 0x48 +#define SHFB_MAGIC_2 0x46 +#define SHFB_MAGIC_3 0x42 + #ifndef __ASSEMBLER__ int __semi_call(int id, ...); @@ -208,6 +208,96 @@ static int test_write(void) return 0; } +static int test_feature_detect(void) +{ + int fd, fd2, remaining, len; + + fd = semi_open(FEATURE_DETECT_FILE, OPEN_RDONLY); + if (fd == -1) { + semi_write0("SKIP implementation does not support feature-detection\n"); + return 0; + } + + /* + * Strictly as a semihosting client we should assume that if the + * magic file has less than 5 bytes or the wrong magic numbers then + * this indicates an implementation without feature-detection. + * However it's more useful for a test program to insist that they + * are correct. + */ + len = semi_flen(fd); + if (len < 5) { + semi_write0("FAIL semihosting features file too short\n"); + return 1; + } + + /* Try an overlong read and check we get back something sensible */ + remaining = semi_read(fd, filebuf, CHUNK_SZ); + if (remaining + len != CHUNK_SZ) { + semi_write0("FAIL read from semihosting features file wrong size\n"); + return 1; + } + if (filebuf[0] != SHFB_MAGIC_0 || filebuf[1] != SHFB_MAGIC_1 || + filebuf[2] != SHFB_MAGIC_2 || filebuf[3] != SHFB_MAGIC_3) { + semi_write0("FAIL semihosting features file has bad magic\n"); + return 1; + } + + semi_write0("PASS semihosting features file read successfully\n"); + + if (semi_istty(fd)) { + semi_write0("FAIL semihosting features file is a TTY?\n"); + } else { + semi_write0("PASS semihosting features file is not a TTY\n"); + } + + /* + * Check we can open multiple fds on the magic file and that + * they seek independently. + */ + fd2 = semi_open(FEATURE_DETECT_FILE, OPEN_RDONLY); + if (fd2 == -1) { + semi_write0("FAIL could not open feature-detection file twice\n"); + return 1; + } + + if (semi_seek(fd, 3) != 0) { + semi_write0("FAIL could not seek feature-detection file\n"); + return 1; + } + + if (semi_seek(fd2, 1) != 0) { + semi_write0("FAIL could not seek feature-detection file\n"); + return 1; + } + + if (semi_read(fd, filebuf, 1) != 0) { + semi_write0("FAIL could not read from feature-detection file\n"); + return 1; + } + + if (filebuf[0] != SHFB_MAGIC_3) { + semi_write0("FAIL feature-detection file had wrong data after seek\n"); + return 1; + } + + if (semi_read(fd2, filebuf, 1) != 0) { + semi_write0("FAIL could not read from feature-detection file\n"); + return 1; + } + + if (filebuf[0] != SHFB_MAGIC_1) { + semi_write0("FAIL feature-detection file had wrong data after seek\n"); + return 1; + } + + semi_write0("PASS feature-detect files seek independently\n"); + + semi_close(fd); + semi_close(fd2); + return 0; +} + int main(void) { void *bufp; @@ -255,6 +345,10 @@ int main(void) return 1; } + if (test_feature_detect()) { + return 1; + } + semi_write0("ALL TESTS PASSED\n"); semi_exit(0); /* not reached */ |