X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/bef1210245bb3180a57f26405369654eaa477f63..1eeed1150149b63d6e49e033697454bc12b533b9:/lunaix-os/usr/testp.c?ds=inline diff --git a/lunaix-os/usr/testp.c b/lunaix-os/usr/testp.c new file mode 100644 index 0000000..8011c30 --- /dev/null +++ b/lunaix-os/usr/testp.c @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include +#include + +void +test_serial() +{ + int fd = open("/dev/ttyS0", FO_WRONLY); + if (fd < 0) { + printf("ttyS0 not accessable (%d)\n", errno); + return; + } + + char buf[32]; + int sz = 0; + + printf("ttyS0 input: "); + + if ((sz = read(fd, buf, 31)) < 0) { + printf("write to ttyS0 failed (%d)\n", errno); + } + + buf[sz] = 0; + + printf("%s", buf); + + close(fd); +} + +int +main(int argc, char* argv[]) +{ + if (argc <= 1) { + return 1; + } + + char* target = argv[1]; + + if (!strcmp(target, "serial")) { + test_serial(); + } else { + printf("unknown test: %s\n", target); + return 1; + } + + return 0; +} \ No newline at end of file