1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*
4 * Copyright (c) International Business Machines Corp., 2002
5 * 01/02/2003 Port to LTP avenkat@us.ibm.com
6 * 11/11/2002: Ported to LTP Suite by Ananda
7 * 06/30/2001 Port to Linux nsharoff@us.ibm.com
8 *
9 * ALGORITHM
10 * Fork child. Have child abort, check return status.
11 *
12 * RESTRICTIONS
13 * The ulimit for core file size must be greater than 0.
14 */
15
16 #include <sys/types.h>
17 #include <sys/wait.h>
18 #include <errno.h>
19 #include <signal.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <unistd.h>
23 #include <sys/resource.h>
24
25 #include "tst_test.h"
26
do_child(void)27 static void do_child(void)
28 {
29 abort();
30 tst_res(TFAIL, "Abort returned");
31 exit(0);
32 }
33
verify_abort(void)34 void verify_abort(void)
35 {
36 int status, kidpid;
37 int sig, core;
38
39 kidpid = SAFE_FORK();
40 if (kidpid == 0)
41 do_child();
42
43 SAFE_WAIT(&status);
44
45 if (!WIFSIGNALED(status)) {
46 tst_res(TFAIL, "Child %s, expected SIGIOT",
47 tst_strstatus(status));
48 return;
49 }
50
51 core = WCOREDUMP(status);
52 sig = WTERMSIG(status);
53
54 if (core == 0)
55 tst_res(TFAIL, "abort() failed to dump core");
56 else
57 tst_res(TPASS, "abort() dumped core");
58
59 if (sig == SIGIOT)
60 tst_res(TPASS, "abort() raised SIGIOT");
61 else
62 tst_res(TFAIL, "abort() raised %s", tst_strsig(sig));
63 }
64
65 #define MIN_RLIMIT_CORE (1024 * 1024)
66
setup(void)67 static void setup(void)
68 {
69 struct rlimit rlim;
70
71 /* make sure we get core dumps */
72 SAFE_GETRLIMIT(RLIMIT_CORE, &rlim);
73 if (rlim.rlim_cur < MIN_RLIMIT_CORE) {
74 rlim.rlim_cur = MIN_RLIMIT_CORE;
75 SAFE_SETRLIMIT(RLIMIT_CORE, &rlim);
76 }
77 }
78
79 static struct tst_test test = {
80 .needs_tmpdir = 1,
81 .forks_child = 1,
82 .setup = setup,
83 .test_all = verify_abort,
84 };
85