selftests/logger: check return values of open() and ioctl() 36/268736/3
authorŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 30 Dec 2021 17:04:56 +0000 (18:04 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 4 Jan 2022 02:04:05 +0000 (02:04 +0000)
Change-Id: I4948fa04096b15b390f2d3b5f8c701a461cfc899
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
tools/testing/selftests/logger/logger.c

index 35891a3..d6d4d77 100644 (file)
@@ -34,7 +34,7 @@ int main(int ac, char *av[]) {
                .len = 6,
                .ptr = (uintptr_t)tag,
        };
-       int c, fd, s;
+       int c, fd, s, ret;
        pid_t child;
        pthread_t tid;
        struct iovec vec[3];
@@ -74,6 +74,10 @@ int main(int ac, char *av[]) {
 
        setlinebuf(stdout);
        fd = open(device, O_WRONLY);
+       if (fd < 0) {
+               perror("open");
+               exit(EXIT_FAILURE);
+       }
 
        if (test_mask & BIT(0)) {
                vec[0].iov_base = &prio;
@@ -93,14 +97,22 @@ int main(int ac, char *av[]) {
                }
        }
 
-       ioctl(fd, LOGGER_SET_PRIO, prio);
-       ioctl(fd, LOGGER_SET_TAG, &struct_tag);
+       ret = ioctl(fd, LOGGER_SET_PRIO, prio);
+       if (ret < 0) {
+               perror("ioctl(SET_PRIO)");
+               exit(EXIT_FAILURE);
+       }
+       ret = ioctl(fd, LOGGER_SET_TAG, &struct_tag);
+       if (ret < 0) {
+               perror("ioctl(SET_TAG)");
+               exit(EXIT_FAILURE);
+       }
 
        if (test_mask & BIT(2)) {
                int count;
                count = write(fd, "The Foo From STDIO\n", 19);
                if (count != 19)
-                       printf("count != 19\n");
+                       fprintf(stderr, "%d != 19\n", count);
 
                write(fd, "LINE #1\nLINE #2", 15);
                write(fd, " CONTINUED\nONCE", 15);