diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-04-19 12:34:48 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-04-19 12:34:48 +0200 |
commit | bacaaf0b7595730904613e86d40400f72682904d (patch) | |
tree | e0394a93cd8eeed53962fce04e03916ccdfda579 /1/test | |
parent | 4335a620a364b70f06421b1698706a9dc3324a46 (diff) |
finish tests
Diffstat (limited to '1/test')
-rw-r--r-- | 1/test/main.c | 38 | ||||
-rwxr-xr-x | 1/test/test.sh | 10 |
2 files changed, 48 insertions, 0 deletions
diff --git a/1/test/main.c b/1/test/main.c index 7329e16..b87e56c 100644 --- a/1/test/main.c +++ b/1/test/main.c @@ -1,5 +1,8 @@ #include <stdio.h> #include <unistd.h> +#include <fcntl.h> +#include <errno.h> +#include <string.h> int main(int argc, char** argv) { if (geteuid() != 0) { @@ -13,6 +16,41 @@ int main(int argc, char** argv) { return 1; } + char* dev = argv[1]; + const char* input = "test"; + int fd; + ssize_t bytes; + + fd = open(dev, O_RDWR); + if (-1 == fd) { + fprintf(stderr, "open() failed with code %d\n", errno); + return 1; + } + + bytes = write(fd, input, strlen(input)); + if (-1 == bytes) { + fprintf(stderr, "write() failed with code %d\n", errno); + return 1; + } + fprintf(stderr, "input \"%s\" to %s (%ld bytes succesful)\n", input, dev, bytes); + + char buf[80]; + bytes = read(fd, buf, 80); + if (-1 == bytes) { + fprintf(stderr, "read() failed with code %d\n", errno); + return 1; + } + fprintf(stderr, "output from %s: (%ld bytes)\n", dev, bytes); + if (bytes > 0) { + if (bytes < 80) buf[bytes] = '\0'; // null terminate string for printf + printf("%s\n", buf); + } + + if (-1 == close(fd)) { + fprintf(stderr, "close() failed with code %d\n", errno); + return 1; + } + return 0; } diff --git a/1/test/test.sh b/1/test/test.sh index 18263e6..7dba005 100755 --- a/1/test/test.sh +++ b/1/test/test.sh @@ -10,5 +10,15 @@ if [ $# -eq 0 ] ; then exit 1 fi +DEV="$1" +INPUT="test" + +echo "input \"$INPUT\" to $DEV" >&2 +echo "$INPUT" > "$DEV" +echo "(EC $?)" >&2 + +echo "output from $DEV:" >&2 +cat "$DEV" +echo "(EC $?)" >&2 exit 0 |