hot fix: remove outdated objcpy
[lunaix-os.git] / lunaix-os / usr / testp.c
1 #include <errno.h>
2 #include <fcntl.h>
3 #include <lunaix/lunaix.h>
4 #include <stdio.h>
5 #include <string.h>
6 #include <unistd.h>
7
8 void
9 test_serial()
10 {
11     int fd = open("/dev/ttyS0", FO_WRONLY);
12     if (fd < 0) {
13         printf("ttyS0 not accessable (%d)\n", errno);
14         return;
15     }
16
17     char buf[32];
18     int sz = 0;
19
20     printf("ttyS0 input: ");
21
22     if ((sz = read(fd, buf, 31)) < 0) {
23         printf("write to ttyS0 failed (%d)\n", errno);
24     }
25
26     buf[sz] = 0;
27
28     printf("%s", buf);
29
30     close(fd);
31 }
32
33 int
34 main(int argc, char* argv[])
35 {
36     if (argc <= 1) {
37         return 1;
38     }
39
40     char* target = argv[1];
41
42     if (!strcmp(target, "serial")) {
43         test_serial();
44     } else {
45         printf("unknown test: %s\n", target);
46         return 1;
47     }
48
49     return 0;
50 }