summaryrefslogtreecommitdiffstats
path: root/tests/btparser/backtrace.at
blob: d0b1467c76fef690602669eeba91c6b52ca659c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Checking the btparser. -*- Autotest -*-

AT_BANNER([Backtraces])

## --------------------------------------- ##
## btp_backtrace_remove_threads_except_one ##
## --------------------------------------- ##
AT_TESTFUN([btp_backtrace_remove_threads_except_one],
[[
#include <backtrace.h>
#include <thread.h>
#include <assert.h>
#include <stdlib.h>

int main(void)
{
  /* Delete the thread except the middle one. */
  struct btp_thread *thread2 = btp_thread_new();
  struct btp_thread *thread1 = btp_thread_new();
  thread1->next = thread2;
  struct btp_thread *thread0 = btp_thread_new();
  thread0->next = thread1;
  struct btp_backtrace *backtrace = btp_backtrace_new();
  backtrace->threads = thread0;
  btp_backtrace_remove_threads_except_one(backtrace, thread1);
  assert(backtrace->threads == thread1);
  assert(NULL == backtrace->threads->next);

  /* Delete all threads except one when there is only one. */
  btp_backtrace_remove_threads_except_one(backtrace, thread1);
  assert(backtrace->threads == thread1);
  assert(NULL == backtrace->threads->next);

  /* Delete all threads except the first one. */
  thread0 = btp_thread_new();
  backtrace->threads = thread0;
  thread0->next = thread1; // already exists
  thread2 = btp_thread_new();
  thread1->next = thread2;
  btp_backtrace_remove_threads_except_one(backtrace, thread0);
  assert(backtrace->threads == thread0);
  assert(NULL == backtrace->threads->next);

  /* Delete all threads except the last one. */
  thread1 = btp_thread_new();
  thread0->next = thread1;
  thread2 = btp_thread_new();
  thread1->next = thread2;
  btp_backtrace_remove_threads_except_one(backtrace, thread2);
  assert(backtrace->threads == thread2);
  assert(NULL == backtrace->threads->next);

  btp_backtrace_free(backtrace);
  return 0;
}
]])

## ------------------------------- ##
## btp_backtrace_find_crash_thread ##
## ------------------------------- ##
AT_TESTFUN([btp_backtrace_find_crash_thread],
[[
#include <backtrace.h>
#include <thread.h>
#include <frame.h>
#include <location.h>
#include <utils.h>
#include <assert.h>

int main(void)
{
  /* Load the backtrace from Red Hat Bugzilla bug #621492. */
  struct btp_location location;
  btp_location_init(&location);
  char *full_input = btp_file_to_string("../../btparser/backtraces/621492.bt");
  assert(full_input);
  char *input = full_input;
  struct btp_backtrace *backtrace = btp_backtrace_parse(&input, &location);
  assert(backtrace);

  /* Check that the crash thread is found. */
  struct btp_thread *crash_thread = btp_backtrace_find_crash_thread(backtrace);
  assert(crash_thread);
  assert(0 == strcmp(crash_thread->frames->function_name, "raise"));
  btp_backtrace_free(backtrace);
  return 0;
}
]])

## ------------------------------- ##
## btp_backtrace_limit_frame_depth ##
## ------------------------------- ##
AT_TESTFUN([btp_backtrace_limit_frame_depth],
[[
#include <backtrace.h>
#include <thread.h>
#include <location.h>
#include <utils.h>
#include <assert.h>

int main(void)
{
  /* Load the backtrace from Red Hat Bugzilla bug #621492. */
  struct btp_location location;
  btp_location_init(&location);
  char *full_input = btp_file_to_string("../../btparser/backtraces/621492.bt");
  assert(full_input);
  char *input = full_input;
  struct btp_backtrace *backtrace = btp_backtrace_parse(&input, &location);
  assert(backtrace);

  /* Check the frame depth limit. */
  btp_backtrace_limit_frame_depth(backtrace, 5);
  assert(11 == btp_backtrace_get_thread_count(backtrace));
  struct btp_thread *thread = backtrace->threads;
  while (thread)
  {
    assert(5 == btp_thread_get_frame_count(thread));
    thread = thread->next;
  }

  btp_backtrace_free(backtrace);
  return 0;
}
]])

## ----------------------------- ##
## btp_backtrace_quality_complex ##
## ----------------------------- ##
AT_TESTFUN([btp_backtrace_quality_complex],
[[
#include <backtrace.h>
#include <thread.h>
#include <location.h>
#include <utils.h>
#include <assert.h>

int main(void)
{
  /* Load the backtrace from Red Hat Bugzilla bug #621492. */
  struct btp_location location;
  btp_location_init(&location);
  char *full_input = btp_file_to_string("../../btparser/backtraces/621492.bt");
  assert(full_input);
  char *input = full_input;
  struct btp_backtrace *backtrace = btp_backtrace_parse(&input, &location);
  assert(backtrace);
  assert(1.0f == btp_backtrace_quality_complex(backtrace));
  btp_backtrace_free(backtrace);
  return 0;
}
]])