@@ -39,34 +39,34 @@ int restore_queue(struct msgque_data *msgque)
3939
4040 fd = open ("/proc/sys/kernel/msg_next_id" , O_WRONLY );
4141 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" );
4343 return - errno ;
4444 }
4545 sprintf (buf , "%d" , msgque -> msq_id );
4646
4747 ret = write (fd , buf , strlen (buf ));
4848 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" );
5050 return - errno ;
5151 }
5252
5353 id = msgget (msgque -> key , msgque -> mode | IPC_CREAT | IPC_EXCL );
5454 if (id == -1 ) {
55- printf ("Failed to create queue\n" );
55+ ksft_test_result_fail ("Failed to create queue\n" );
5656 return - errno ;
5757 }
5858
5959 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 );
6262 ret = - EFAULT ;
6363 goto destroy ;
6464 }
6565
6666 for (i = 0 ; i < msgque -> qnum ; i ++ ) {
6767 if (msgsnd (msgque -> msq_id , & msgque -> messages [i ].mtype ,
6868 msgque -> messages [i ].msize , IPC_NOWAIT ) != 0 ) {
69- printf ("msgsnd failed (%m)\n" );
69+ ksft_test_result_fail ("msgsnd failed (%m)\n" );
7070 ret = - errno ;
7171 goto destroy ;
7272 }
@@ -90,31 +90,30 @@ int check_and_destroy_queue(struct msgque_data *msgque)
9090 if (ret < 0 ) {
9191 if (errno == ENOMSG )
9292 break ;
93- printf ("Failed to read IPC message: %m\n" );
93+ ksft_test_result_fail ("Failed to read IPC message: %m\n" );
9494 ret = - errno ;
9595 goto err ;
9696 }
9797 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 );
10099 ret = - EINVAL ;
101100 goto err ;
102101 }
103102 if (message .mtype != msgque -> messages [cnt ].mtype ) {
104- printf ("Wrong message type\n" );
103+ ksft_test_result_fail ("Wrong message type\n" );
105104 ret = - EINVAL ;
106105 goto err ;
107106 }
108107 if (memcmp (message .mtext , msgque -> messages [cnt ].mtext , ret )) {
109- printf ("Wrong message content\n" );
108+ ksft_test_result_fail ("Wrong message content\n" );
110109 ret = - EINVAL ;
111110 goto err ;
112111 }
113112 cnt ++ ;
114113 }
115114
116115 if (cnt != msgque -> qnum ) {
117- printf ("Wrong message number\n" );
116+ ksft_test_result_fail ("Wrong message number\n" );
118117 ret = - EINVAL ;
119118 goto err ;
120119 }
@@ -139,7 +138,7 @@ int dump_queue(struct msgque_data *msgque)
139138 if (ret < 0 ) {
140139 if (errno == EINVAL )
141140 continue ;
142- printf ("Failed to get stats for IPC queue with id %d\n" ,
141+ ksft_test_result_fail ("Failed to get stats for IPC queue with id %d\n" ,
143142 kern_id );
144143 return - errno ;
145144 }
@@ -150,7 +149,7 @@ int dump_queue(struct msgque_data *msgque)
150149
151150 msgque -> messages = malloc (sizeof (struct msg1 ) * ds .msg_qnum );
152151 if (msgque -> messages == NULL ) {
153- printf ("Failed to get stats for IPC queue\n" );
152+ ksft_test_result_fail ("Failed to get stats for IPC queue\n" );
154153 return - ENOMEM ;
155154 }
156155
@@ -162,7 +161,7 @@ int dump_queue(struct msgque_data *msgque)
162161 ret = msgrcv (msgque -> msq_id , & msgque -> messages [i ].mtype ,
163162 MAX_MSG_SIZE , i , IPC_NOWAIT | MSG_COPY );
164163 if (ret < 0 ) {
165- printf ("Failed to copy IPC message: %m (%d)\n" , errno );
164+ ksft_test_result_fail ("Failed to copy IPC message: %m (%d)\n" , errno );
166165 return - errno ;
167166 }
168167 msgque -> messages [i ].msize = ret ;
@@ -178,15 +177,15 @@ int fill_msgque(struct msgque_data *msgque)
178177 memcpy (msgbuf .mtext , TEST_STRING , sizeof (TEST_STRING ));
179178 if (msgsnd (msgque -> msq_id , & msgbuf .mtype , sizeof (TEST_STRING ),
180179 IPC_NOWAIT ) != 0 ) {
181- printf ("First message send failed (%m)\n" );
180+ ksft_test_result_fail ("First message send failed (%m)\n" );
182181 return - errno ;
183182 }
184183
185184 msgbuf .mtype = ANOTHER_MSG_TYPE ;
186185 memcpy (msgbuf .mtext , ANOTHER_TEST_STRING , sizeof (ANOTHER_TEST_STRING ));
187186 if (msgsnd (msgque -> msq_id , & msgbuf .mtype , sizeof (ANOTHER_TEST_STRING ),
188187 IPC_NOWAIT ) != 0 ) {
189- printf ("Second message send failed (%m)\n" );
188+ ksft_test_result_fail ("Second message send failed (%m)\n" );
190189 return - errno ;
191190 }
192191 return 0 ;
@@ -202,44 +201,44 @@ int main(int argc, char **argv)
202201
203202 msgque .key = ftok (argv [0 ], 822155650 );
204203 if (msgque .key == -1 ) {
205- printf ("Can't make key: %d\n" , - errno );
204+ ksft_test_result_fail ("Can't make key: %d\n" , - errno );
206205 ksft_exit_fail ();
207206 }
208207
209208 msgque .msq_id = msgget (msgque .key , IPC_CREAT | IPC_EXCL | 0666 );
210209 if (msgque .msq_id == -1 ) {
211210 err = - errno ;
212- printf ("Can't create queue: %d\n" , err );
211+ ksft_test_result_fail ("Can't create queue: %d\n" , err );
213212 goto err_out ;
214213 }
215214
216215 err = fill_msgque (& msgque );
217216 if (err ) {
218- printf ("Failed to fill queue: %d\n" , err );
217+ ksft_test_result_fail ("Failed to fill queue: %d\n" , err );
219218 goto err_destroy ;
220219 }
221220
222221 err = dump_queue (& msgque );
223222 if (err ) {
224- printf ("Failed to dump queue: %d\n" , err );
223+ ksft_test_result_fail ("Failed to dump queue: %d\n" , err );
225224 goto err_destroy ;
226225 }
227226
228227 err = check_and_destroy_queue (& msgque );
229228 if (err ) {
230- printf ("Failed to check and destroy queue: %d\n" , err );
229+ ksft_test_result_fail ("Failed to check and destroy queue: %d\n" , err );
231230 goto err_out ;
232231 }
233232
234233 err = restore_queue (& msgque );
235234 if (err ) {
236- printf ("Failed to restore queue: %d\n" , err );
235+ ksft_test_result_fail ("Failed to restore queue: %d\n" , err );
237236 goto err_destroy ;
238237 }
239238
240239 err = check_and_destroy_queue (& msgque );
241240 if (err ) {
242- printf ("Failed to test queue: %d\n" , err );
241+ ksft_test_result_fail ("Failed to test queue: %d\n" , err );
243242 goto err_out ;
244243 }
245244 ksft_exit_pass ();
0 commit comments