1 /* Test the sig2str and str2sig functions.
2 Copyright (C) 2024 Free Software Foundation, Inc.
4 This file is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published
6 by the Free Software Foundation, either version 3 of the License,
7 or (at your option) any later version.
9 This file is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Collin Funk <collin.funk1@gmail.com>, 2024. */
31 char buffer
[SIG2STR_MAX
];
33 /* Test sig2str on signals specified by ISO C. */
35 ASSERT (sig2str (SIGABRT
, buffer
) == 0);
36 ASSERT (STREQ (buffer
, "ABRT"));
38 ASSERT (sig2str (SIGFPE
, buffer
) == 0);
39 ASSERT (STREQ (buffer
, "FPE"));
41 ASSERT (sig2str (SIGILL
, buffer
) == 0);
42 ASSERT (STREQ (buffer
, "ILL"));
44 ASSERT (sig2str (SIGINT
, buffer
) == 0);
45 ASSERT (STREQ (buffer
, "INT"));
47 ASSERT (sig2str (SIGSEGV
, buffer
) == 0);
48 ASSERT (STREQ (buffer
, "SEGV"));
50 ASSERT (sig2str (SIGTERM
, buffer
) == 0);
51 ASSERT (STREQ (buffer
, "TERM"));
53 /* Check behavior of sig2str on invalid signals. */
55 ASSERT (sig2str (-714, buffer
) == -1);
63 /* Test str2sig on signals specified by ISO C. */
65 ASSERT (str2sig ("ABRT", &signo
) == 0);
66 ASSERT (signo
== SIGABRT
);
68 ASSERT (str2sig ("FPE", &signo
) == 0);
69 ASSERT (signo
== SIGFPE
);
71 ASSERT (str2sig ("ILL", &signo
) == 0);
72 ASSERT (signo
== SIGILL
);
74 ASSERT (str2sig ("INT", &signo
) == 0);
75 ASSERT (signo
== SIGINT
);
77 ASSERT (str2sig ("SEGV", &signo
) == 0);
78 ASSERT (signo
== SIGSEGV
);
80 ASSERT (str2sig ("TERM", &signo
) == 0);
81 ASSERT (signo
== SIGTERM
);
83 /* Check behavior of str2sig on invalid signals. */
85 ASSERT (str2sig ("Not a signal", &signo
) == -1);
94 return test_exit_status
;