Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: ipc: Replace fail print statements with ksft_test_result_fail

Use the standard kselftest failure report function to ensure consistent
test output formatting. This improves readability and integration with
automated test frameworks.

Link: https://lore.kernel.org/r/20250531070140.24287-1-sef1548@gmail.com
Signed-off-by: Nick Huang <sef1548@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Nick Huang and committed by
Shuah Khan
da9ba413 cd9f02ad

+23 -24
+23 -24
tools/testing/selftests/ipc/msgque.c
··· 39 39 40 40 fd = open("/proc/sys/kernel/msg_next_id", O_WRONLY); 41 41 if (fd == -1) { 42 - printf("Failed to open /proc/sys/kernel/msg_next_id\n"); 42 + ksft_test_result_fail("Failed to open /proc/sys/kernel/msg_next_id\n"); 43 43 return -errno; 44 44 } 45 45 sprintf(buf, "%d", msgque->msq_id); 46 46 47 47 ret = write(fd, buf, strlen(buf)); 48 48 if (ret != strlen(buf)) { 49 - printf("Failed to write to /proc/sys/kernel/msg_next_id\n"); 49 + ksft_test_result_fail("Failed to write to /proc/sys/kernel/msg_next_id\n"); 50 50 return -errno; 51 51 } 52 52 53 53 id = msgget(msgque->key, msgque->mode | IPC_CREAT | IPC_EXCL); 54 54 if (id == -1) { 55 - printf("Failed to create queue\n"); 55 + ksft_test_result_fail("Failed to create queue\n"); 56 56 return -errno; 57 57 } 58 58 59 59 if (id != msgque->msq_id) { 60 - printf("Restored queue has wrong id (%d instead of %d)\n", 61 - id, msgque->msq_id); 60 + ksft_test_result_fail("Restored queue has wrong id (%d instead of %d)\n" 61 + , id, msgque->msq_id); 62 62 ret = -EFAULT; 63 63 goto destroy; 64 64 } ··· 66 66 for (i = 0; i < msgque->qnum; i++) { 67 67 if (msgsnd(msgque->msq_id, &msgque->messages[i].mtype, 68 68 msgque->messages[i].msize, IPC_NOWAIT) != 0) { 69 - printf("msgsnd failed (%m)\n"); 69 + ksft_test_result_fail("msgsnd failed (%m)\n"); 70 70 ret = -errno; 71 71 goto destroy; 72 72 } ··· 90 90 if (ret < 0) { 91 91 if (errno == ENOMSG) 92 92 break; 93 - printf("Failed to read IPC message: %m\n"); 93 + ksft_test_result_fail("Failed to read IPC message: %m\n"); 94 94 ret = -errno; 95 95 goto err; 96 96 } 97 97 if (ret != msgque->messages[cnt].msize) { 98 - printf("Wrong message size: %d (expected %d)\n", ret, 99 - msgque->messages[cnt].msize); 98 + ksft_test_result_fail("Wrong message size: %d (expected %d)\n", ret, msgque->messages[cnt].msize); 100 99 ret = -EINVAL; 101 100 goto err; 102 101 } 103 102 if (message.mtype != msgque->messages[cnt].mtype) { 104 - printf("Wrong message type\n"); 103 + ksft_test_result_fail("Wrong message type\n"); 105 104 ret = -EINVAL; 106 105 goto err; 107 106 } 108 107 if (memcmp(message.mtext, msgque->messages[cnt].mtext, ret)) { 109 - printf("Wrong message content\n"); 108 + ksft_test_result_fail("Wrong message content\n"); 110 109 ret = -EINVAL; 111 110 goto err; 112 111 } ··· 113 114 } 114 115 115 116 if (cnt != msgque->qnum) { 116 - printf("Wrong message number\n"); 117 + ksft_test_result_fail("Wrong message number\n"); 117 118 ret = -EINVAL; 118 119 goto err; 119 120 } ··· 138 139 if (ret < 0) { 139 140 if (errno == EINVAL) 140 141 continue; 141 - printf("Failed to get stats for IPC queue with id %d\n", 142 + ksft_test_result_fail("Failed to get stats for IPC queue with id %d\n", 142 143 kern_id); 143 144 return -errno; 144 145 } ··· 149 150 150 151 msgque->messages = malloc(sizeof(struct msg1) * ds.msg_qnum); 151 152 if (msgque->messages == NULL) { 152 - printf("Failed to get stats for IPC queue\n"); 153 + ksft_test_result_fail("Failed to get stats for IPC queue\n"); 153 154 return -ENOMEM; 154 155 } 155 156 ··· 161 162 ret = msgrcv(msgque->msq_id, &msgque->messages[i].mtype, 162 163 MAX_MSG_SIZE, i, IPC_NOWAIT | MSG_COPY); 163 164 if (ret < 0) { 164 - printf("Failed to copy IPC message: %m (%d)\n", errno); 165 + ksft_test_result_fail("Failed to copy IPC message: %m (%d)\n", errno); 165 166 return -errno; 166 167 } 167 168 msgque->messages[i].msize = ret; ··· 177 178 memcpy(msgbuf.mtext, TEST_STRING, sizeof(TEST_STRING)); 178 179 if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(TEST_STRING), 179 180 IPC_NOWAIT) != 0) { 180 - printf("First message send failed (%m)\n"); 181 + ksft_test_result_fail("First message send failed (%m)\n"); 181 182 return -errno; 182 183 } 183 184 ··· 185 186 memcpy(msgbuf.mtext, ANOTHER_TEST_STRING, sizeof(ANOTHER_TEST_STRING)); 186 187 if (msgsnd(msgque->msq_id, &msgbuf.mtype, sizeof(ANOTHER_TEST_STRING), 187 188 IPC_NOWAIT) != 0) { 188 - printf("Second message send failed (%m)\n"); 189 + ksft_test_result_fail("Second message send failed (%m)\n"); 189 190 return -errno; 190 191 } 191 192 return 0; ··· 201 202 202 203 msgque.key = ftok(argv[0], 822155650); 203 204 if (msgque.key == -1) { 204 - printf("Can't make key: %d\n", -errno); 205 + ksft_test_result_fail("Can't make key: %d\n", -errno); 205 206 ksft_exit_fail(); 206 207 } 207 208 208 209 msgque.msq_id = msgget(msgque.key, IPC_CREAT | IPC_EXCL | 0666); 209 210 if (msgque.msq_id == -1) { 210 211 err = -errno; 211 - printf("Can't create queue: %d\n", err); 212 + ksft_test_result_fail("Can't create queue: %d\n", err); 212 213 goto err_out; 213 214 } 214 215 215 216 err = fill_msgque(&msgque); 216 217 if (err) { 217 - printf("Failed to fill queue: %d\n", err); 218 + ksft_test_result_fail("Failed to fill queue: %d\n", err); 218 219 goto err_destroy; 219 220 } 220 221 221 222 err = dump_queue(&msgque); 222 223 if (err) { 223 - printf("Failed to dump queue: %d\n", err); 224 + ksft_test_result_fail("Failed to dump queue: %d\n", err); 224 225 goto err_destroy; 225 226 } 226 227 227 228 err = check_and_destroy_queue(&msgque); 228 229 if (err) { 229 - printf("Failed to check and destroy queue: %d\n", err); 230 + ksft_test_result_fail("Failed to check and destroy queue: %d\n", err); 230 231 goto err_out; 231 232 } 232 233 233 234 err = restore_queue(&msgque); 234 235 if (err) { 235 - printf("Failed to restore queue: %d\n", err); 236 + ksft_test_result_fail("Failed to restore queue: %d\n", err); 236 237 goto err_destroy; 237 238 } 238 239 239 240 err = check_and_destroy_queue(&msgque); 240 241 if (err) { 241 - printf("Failed to test queue: %d\n", err); 242 + ksft_test_result_fail("Failed to test queue: %d\n", err); 242 243 goto err_out; 243 244 } 244 245 ksft_exit_pass();