annotate libbacktrace/edtest.c @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* edtest.c -- Test for libbacktrace storage allocation stress handling
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 Redistribution and use in source and binary forms, with or without
kono
parents:
diff changeset
5 modification, are permitted provided that the following conditions are
kono
parents:
diff changeset
6 met:
kono
parents:
diff changeset
7
kono
parents:
diff changeset
8 (1) Redistributions of source code must retain the above copyright
kono
parents:
diff changeset
9 notice, this list of conditions and the following disclaimer.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 (2) Redistributions in binary form must reproduce the above copyright
kono
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in
kono
parents:
diff changeset
13 the documentation and/or other materials provided with the
kono
parents:
diff changeset
14 distribution.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 (3) The name of the author may not be used to
kono
parents:
diff changeset
17 endorse or promote products derived from this software without
kono
parents:
diff changeset
18 specific prior written permission.
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
kono
parents:
diff changeset
21 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
kono
parents:
diff changeset
22 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
kono
parents:
diff changeset
23 DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
kono
parents:
diff changeset
24 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
kono
parents:
diff changeset
25 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
kono
parents:
diff changeset
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
kono
parents:
diff changeset
27 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
kono
parents:
diff changeset
28 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
kono
parents:
diff changeset
29 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
kono
parents:
diff changeset
30 POSSIBILITY OF SUCH DAMAGE. */
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #include "config.h"
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 #include <assert.h>
kono
parents:
diff changeset
35 #include <stdio.h>
kono
parents:
diff changeset
36 #include <stdlib.h>
kono
parents:
diff changeset
37 #include <string.h>
kono
parents:
diff changeset
38 #include <sys/types.h>
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 #include "backtrace.h"
kono
parents:
diff changeset
41 #include "backtrace-supported.h"
kono
parents:
diff changeset
42 #include "internal.h"
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 #include "testlib.h"
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 static int test1 (void) __attribute__ ((noinline, unused));
kono
parents:
diff changeset
47 static int test1 (void) __attribute__ ((noinline, unused));
kono
parents:
diff changeset
48 extern int f2 (int);
kono
parents:
diff changeset
49 extern int f3 (int, int);
kono
parents:
diff changeset
50
kono
parents:
diff changeset
51 static int
kono
parents:
diff changeset
52 test1 (void)
kono
parents:
diff changeset
53 {
kono
parents:
diff changeset
54 /* Returning a value here and elsewhere avoids a tailcall which
kono
parents:
diff changeset
55 would mess up the backtrace. */
kono
parents:
diff changeset
56 return f2 (__LINE__) + 1;
kono
parents:
diff changeset
57 }
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 int
kono
parents:
diff changeset
60 f3 (int f1line, int f2line)
kono
parents:
diff changeset
61 {
kono
parents:
diff changeset
62 struct info all[20];
kono
parents:
diff changeset
63 struct bdata data;
kono
parents:
diff changeset
64 int f3line;
kono
parents:
diff changeset
65 int i;
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 data.all = &all[0];
kono
parents:
diff changeset
68 data.index = 0;
kono
parents:
diff changeset
69 data.max = 20;
kono
parents:
diff changeset
70 data.failed = 0;
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 f3line = __LINE__ + 1;
kono
parents:
diff changeset
73 i = backtrace_full (state, 0, callback_one, error_callback_one, &data);
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 if (i != 0)
kono
parents:
diff changeset
76 {
kono
parents:
diff changeset
77 fprintf (stderr, "test1: unexpected return value %d\n", i);
kono
parents:
diff changeset
78 data.failed = 1;
kono
parents:
diff changeset
79 }
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 if (data.index < 3)
kono
parents:
diff changeset
82 {
kono
parents:
diff changeset
83 fprintf (stderr,
kono
parents:
diff changeset
84 "test1: not enough frames; got %zu, expected at least 3\n",
kono
parents:
diff changeset
85 data.index);
kono
parents:
diff changeset
86 data.failed = 1;
kono
parents:
diff changeset
87 }
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 check ("test1", 0, all, f3line, "f3", "edtest.c", &data.failed);
kono
parents:
diff changeset
90 check ("test1", 1, all, f2line, "f2", "edtest2_build.c", &data.failed);
kono
parents:
diff changeset
91 check ("test1", 2, all, f1line, "test1", "edtest.c", &data.failed);
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 printf ("%s: backtrace_full alloc stress\n", data.failed ? "FAIL" : "PASS");
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 if (data.failed)
kono
parents:
diff changeset
96 ++failures;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 return failures;
kono
parents:
diff changeset
99 }
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 int
kono
parents:
diff changeset
102 main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
kono
parents:
diff changeset
105 error_callback_create, NULL);
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 // Grab the storage allocation lock prior to doing anything interesting.
kono
parents:
diff changeset
108 // The intent here is to insure that the backtrace_alloc code is forced
kono
parents:
diff changeset
109 // to always call mmap() for new memory as opposed to reusing previously
kono
parents:
diff changeset
110 // allocated memory from the free list. Doing things this way helps
kono
parents:
diff changeset
111 // simulate what you might see in a multithreaded program in which there
kono
parents:
diff changeset
112 // are racing calls to the allocator.
kono
parents:
diff changeset
113 struct backtrace_state *state_internal =
kono
parents:
diff changeset
114 (struct backtrace_state *) state;
kono
parents:
diff changeset
115 state_internal->lock_alloc = 1;
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 // Kick off the test
kono
parents:
diff changeset
118 test1();
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 exit (failures > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
kono
parents:
diff changeset
121 }