File: test-annotate.cc

package info (click to toggle)
libabigail 2.9-2
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,021,756 kB
  • sloc: xml: 572,663; cpp: 110,945; sh: 11,868; ansic: 4,329; makefile: 3,486; python: 1,684; ada: 62
file content (203 lines) | stat: -rw-r--r-- 5,766 bytes parent folder | download | duplicates (2)
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- Mode: C++ -*-
//
// Author: Ondrej Oprala

/// @file
///
/// This program tests the annotation capabilities of the library.

#include <iostream>
#include <cstdlib>
#include "abg-tools-utils.h"
#include "test-utils.h"

using std::cerr;
using std::string;
using abigail::tests::emit_test_status_and_update_counters;
using abigail::tests::emit_test_summary;

struct InOutSpec
{
  const char* in_elf_path;
  const char* in_report_path;
  const char* out_report_path;
};

InOutSpec in_out_specs[] =
{
  {
    "data/test-read-dwarf/test0",
    "data/test-annotate/test0.abi",
    "output/test-annotate/test0.abi"
  },
  {
    "data/test-read-dwarf/test1",
    "data/test-annotate/test1.abi",
    "output/test-annotate/test1.abi"
  },
  {
    "data/test-read-dwarf/test2.so",
    "data/test-annotate/test2.so.abi",
    "output/test-annotate/test2.so.abi"
  },
  {
    "data/test-read-common/test3.so",
    "data/test-annotate/test3.so.abi",
    "output/test-annotate/test3.so.abi"
  },
  {
    "data/test-read-common/test4.so",
    "data/test-annotate/test4.so.abi",
    "output/test-annotate/test4.so.abi"
  },
  {
    "data/test-read-dwarf/test5.o",
    "data/test-annotate/test5.o.abi",
    "output/test-annotate/test5.o.abi"
  },
  {
    "data/test-read-dwarf/test6.so",
    "data/test-annotate/test6.so.abi",
    "output/test-annotate/test6.so.abi"
  },
  {
    "data/test-read-dwarf/test7.so",
    "data/test-annotate/test7.so.abi",
    "output/test-annotate/test7.so.abi"
  },
  {
    "data/test-read-dwarf/test8-qualified-this-pointer.so",
    "data/test-annotate/test8-qualified-this-pointer.so.abi",
    "output/test-annotate/test8-qualified-this-pointer.so.abi"
  },
  {
    "data/test-read-dwarf/test13-pr18894.so",
    "data/test-annotate/test13-pr18894.so.abi",
    "output/test-annotate/test13-pr18894.so.abi",
  },
  {
    "data/test-read-dwarf/test14-pr18893.so",
    "data/test-annotate/test14-pr18893.so.abi",
    "output/test-annotate/test14-pr18893.so.abi",
  },
  {
    "data/test-read-dwarf/test15-pr18892.so",
    "data/test-annotate/test15-pr18892.so.abi",
    "output/test-annotate/test15-pr18892.so.abi",
  },
  {
    "data/test-read-dwarf/test17-pr19027.so",
    "data/test-annotate/test17-pr19027.so.abi",
    "output/test-annotate/test17-pr19027.so.abi",
  },
  {
    "data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so",
    "data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi",
    "output/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi",
  },
  {
    "data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so",
    "data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi",
    "output/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi",
  },
  {
    "data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so",
    "data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi",
    "output/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi",
  },
  {
    "data/test-read-dwarf/test21-pr19092.so",
    "data/test-annotate/test21-pr19092.so.abi",
    "output/test-annotate/test21-pr19092.so.abi",
  },
  {
    "data/test-read-dwarf/libtest23.so",
    "data/test-annotate/libtest23.so.abi",
    "output/test-annotate/libtest23.so.abi",
  },
  {
    "data/test-read-dwarf/libtest24-drop-fns.so",
    "data/test-annotate/libtest24-drop-fns.so.abi",
    "output/test-annotate/libtest24-drop-fns.so.abi",
  },
  {
    "data/test-read-dwarf/libtest24-drop-fns.so",
    "data/test-annotate/libtest24-drop-fns-2.so.abi",
    "output/test-annotate/libtest24-drop-fns-2.so.abi",
  },
  {
    "data/test-annotate/test-anonymous-members-0.o",
    "data/test-annotate/test-anonymous-members-0.o.abi",
    "output/test-annotate/test-anonymous-members-0.o.abi",
  },
  {
    "data/test-read-dwarf/PR29443-missing-xx.o",
    "data/test-annotate/PR29443-missing-xx.o.annotated.abi",
    "output/test-annotate/PR29443-missing-xx.o.annotated.abi",
  },
  {
    "data/test-read-dwarf/test-pointer-to-member-1.o",
    "data/test-annotate/test-pointer-to-member-1.o.annotated.abi",
    "output/test-annotate/test-pointer-to-member-1.o.annotated.abi",
  },
  // This should be the last entry.
  {NULL, NULL, NULL}
};

int
main()
{
  using abigail::tests::get_src_dir;
  using abigail::tests::get_build_dir;
  using abigail::tools_utils::ensure_parent_dir_created;

  unsigned int total_count = 0, passed_count = 0, failed_count = 0;

  string in_elf_path, ref_report_path, out_report_path;
  string abidw;

  abidw = string(get_build_dir()) + "/tools/abidw "
    "--annotate --no-corpus-path --no-architecture "
    "--no-load-undefined-interfaces --no-parameter-names";
  for (InOutSpec* s = in_out_specs; s->in_elf_path; ++s)
    {
      bool is_ok = true;
      in_elf_path = string(get_src_dir()) + "/tests/" + s->in_elf_path;
      ref_report_path = string(get_src_dir()) + "/tests/" + s->in_report_path;
      out_report_path =
	string(get_build_dir()) + "/tests/" + s->out_report_path;
      if (!ensure_parent_dir_created(out_report_path))
	{
	  cerr << "could not create parent directory for "
	       << out_report_path;
	  is_ok = false;
	  continue;
	}

      string cmd = abidw + " " + in_elf_path + " > " + out_report_path;

      bool abidw_ok = true;
      if (system(cmd.c_str()))
	abidw_ok = false;

      if (abidw_ok)
	{
	  string diff_cmd =
	    "diff -w -u " + ref_report_path + " " + out_report_path;
	  if (system(diff_cmd.c_str()))
	    is_ok &=false;
	}
      else
	{
	  is_ok &= false;
	}

      emit_test_status_and_update_counters(is_ok, cmd, passed_count,
					   failed_count, total_count);
    }

  emit_test_summary(total_count, passed_count, failed_count);

  return failed_count;
}