Debian Codegraph @

crt/s2n/tests/unit/s2n_stacktrace_test.c

raw symbols SCIP
1 /*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16 #include "api/s2n.h"
17 #include "s2n_test.h"
18 #include "utils/s2n_blob.h"
19
20 int raises_error()
21 {
22 POSIX_BAIL(S2N_ERR_INVALID_ARGUMENT);
23 }
24
25 int main(int argc, char **argv)
26 {
27 BEGIN_TEST();
28 EXPECT_SUCCESS(s2n_disable_tls13_in_test());
29 #ifdef S2N_STACKTRACE
30 EXPECT_SUCCESS(s2n_stack_traces_enabled_set(true));
31 struct s2n_stacktrace trace;
32 /* If nothing has errored yet, we have no stacktrace */
33 EXPECT_SUCCESS(s2n_get_stacktrace(&trace));
34 EXPECT_NULL(trace.trace);
35 EXPECT_EQUAL(trace.trace_size, 0);
36
37 /* Raise an error, and see that it generates a stacktrace */
38 EXPECT_FAILURE(raises_error());
39 EXPECT_SUCCESS(s2n_get_stacktrace(&trace));
40 EXPECT_NOT_NULL(trace.trace);
41 EXPECT_NOT_EQUAL(trace.trace_size, 0);
42
43 /* Test printing the stacktrace. */
44 FILE *stream = fopen("/dev/null", "w");
45 EXPECT_SUCCESS(s2n_print_stacktrace(stream));
46 fclose(stream);
47
48 /* Free the stacktrace to avoid memory leaks */
49 EXPECT_SUCCESS(s2n_free_stacktrace());
50 END_TEST();
51 #else
52 END_TEST();
53 #endif
54 }