File: test-abicompat.cc

package info (click to toggle)
libabigail 2.2-2
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 881,820 kB
  • sloc: xml: 572,528; cpp: 98,056; sh: 11,779; makefile: 2,951; ansic: 2,913; python: 1,345
file content (291 lines) | stat: -rw-r--r-- 9,633 bytes parent folder | download
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// -*- Mode: C++ -*-
//
// Copyright (C) 2014-2022 Red Hat, Inc.
//
// Author: Dodji Seketeli

/// @file
///
/// Given a program P that links against a library L of version V
/// denoted L(V), this program checks if P is still ABI compatible
/// with a subsequent version of L denoted L(V+N), N being a positive
/// integer.  The result of the check is a report that is compared
/// against a reference report.  This program actually performs these
/// checks for a variety of tuple {P, L(V), L(V+N)}
///
/// The set of input files and reference reports to consider should be
/// present in the source distribution.

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

using std::string;
using std::cerr;
using std::cout;

struct InOutSpec
{
  const char* in_app_path;
  const char* in_lib1_path;
  const char* in_lib2_path;
  const char* suppressions;
  const char* options;
  const char* in_report_path;
  const char* out_report_path;
};

InOutSpec in_out_specs[] =
{
  {
    "data/test-abicompat/test0-fn-changed-app",
    "data/test-abicompat/libtest0-fn-changed-libapp-v0.so",
    "data/test-abicompat/libtest0-fn-changed-libapp-v1.so",
    "",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test0-fn-changed-report-0.txt",
    "output/test-abicompat/test0-fn-changed-report-0.txt",
  },
  {
    "data/test-abicompat/test0-fn-changed-app",
    "data/test-abicompat/libtest0-fn-changed-libapp-v0.so",
    "data/test-abicompat/libtest0-fn-changed-libapp-v1.so",
    "data/test-abicompat/test0-fn-changed-0.suppr",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test0-fn-changed-report-1.txt",
    "output/test-abicompat/test0-fn-changed-report-1.txt",
  },
  { // Previous test, but emitting loc info.
    "data/test-abicompat/test0-fn-changed-app",
    "data/test-abicompat/libtest0-fn-changed-libapp-v0.so",
    "data/test-abicompat/libtest0-fn-changed-libapp-v1.so",
    "",
    "--show-base-names --no-redundant",
    "data/test-abicompat/test0-fn-changed-report-2.txt",
    "output/test-abicompat/test0-fn-changed-report-2.txt",
  },
  {
    "data/test-abicompat/test0-fn-changed-app",
    "data/test-abicompat/libtest0-fn-changed-libapp-v0.so",
    "data/test-abicompat/libtest0-fn-changed-libapp-v1.so",
    "data/test-abicompat/test0-fn-changed-1.suppr",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test0-fn-changed-report-3.txt",
    "output/test-abicompat/test0-fn-changed-report-3.txt",
  },
  {
    "data/test-abicompat/test1-fn-removed-app",
    "data/test-abicompat/libtest1-fn-removed-v0.so",
    "data/test-abicompat/libtest1-fn-removed-v1.so",
    "",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test1-fn-removed-report-0.txt",
    "output/test-abicompat/test1-fn-removed-report-0.txt",
  },
  {
    "data/test-abicompat/test2-var-removed-app",
    "data/test-abicompat/libtest2-var-removed-v0.so",
    "data/test-abicompat/libtest2-var-removed-v1.so",
    "",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test2-var-removed-report-0.txt",
    "output/test-abicompat/test2-var-removed-report-0.txt",
  },
  {
    "data/test-abicompat/test3-fn-removed-app",
    "data/test-abicompat/libtest3-fn-removed-v0.so",
    "data/test-abicompat/libtest3-fn-removed-v1.so",
    "",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test3-fn-removed-report-0.txt",
    "output/test-abicompat/test3-fn-removed-report-0.txt",
  },
  {
    "data/test-abicompat/test4-soname-changed-app",
    "data/test-abicompat/libtest4-soname-changed-v0.so",
    "data/test-abicompat/libtest4-soname-changed-v1.so",
    "",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test4-soname-changed-report-0.txt",
    "output/test-abicompat/test4-soname-changed-report-0.txt",
  },
  {
    "data/test-abicompat/test5-fn-changed-app",
    "data/test-abicompat/libtest5-fn-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --no-show-locs --weak-mode",
    "data/test-abicompat/test5-fn-changed-report-0.txt",
    "output/test-abicompat/test5-fn-changed-report-0.txt",
  },
  { // Previous test, but emitting loc info.
    "data/test-abicompat/test5-fn-changed-app",
    "data/test-abicompat/libtest5-fn-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --weak-mode",
    "data/test-abicompat/test5-fn-changed-report-1.txt",
    "output/test-abicompat/test5-fn-changed-report-1.txt",
  },
  {
    "data/test-abicompat/test6-var-changed-app",
    "data/test-abicompat/libtest6-var-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --no-show-locs --weak-mode",
    "data/test-abicompat/test6-var-changed-report-0.txt",
    "output/test-abicompat/test6-var-changed-report-0.txt",
  },
  { // Previous test, but emitting loc info.
    "data/test-abicompat/test6-var-changed-app",
    "data/test-abicompat/libtest6-var-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --weak-mode",
    "data/test-abicompat/test6-var-changed-report-1.txt",
    "output/test-abicompat/test6-var-changed-report-1.txt",
  },
  {
    "data/test-abicompat/test7-fn-changed-app",
    "data/test-abicompat/libtest7-fn-changed-libapp-v0.so",
    "data/test-abicompat/libtest7-fn-changed-libapp-v1.so",
    "",
    "--show-base-names --no-show-locs --no-redundant",
    "data/test-abicompat/test7-fn-changed-report-0.txt",
    "output/test-abicompat/test7-fn-changed-report-0.txt",
  },
  {
    "data/test-abicompat/test7-fn-changed-app",
    "data/test-abicompat/libtest7-fn-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --no-show-locs --weak-mode",
    "data/test-abicompat/test7-fn-changed-report-1.txt",
    "output/test-abicompat/test7-fn-changed-report-1.txt",
  },
  { // Previous test, but emitting loc info.
    "data/test-abicompat/test7-fn-changed-app",
    "data/test-abicompat/libtest7-fn-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --weak-mode",
    "data/test-abicompat/test7-fn-changed-report-2.txt",
    "output/test-abicompat/test7-fn-changed-report-2.txt",
  },
  {
    "data/test-abicompat/test8-fn-changed-app",
    "data/test-abicompat/libtest8-fn-changed-libapp-v1.so",
    "",
    "",
    "--show-base-names --weak-mode",
    "data/test-abicompat/test8-fn-changed-report-0.txt",
    "output/test-abicompat/test8-fn-changed-report-0.txt",
  },
  {
    "data/test-abicompat/test9-fn-changed-app",
    "data/test-abicompat/libtest9-fn-changed-v1.so ",
    "",
    "",
    "--show-base-names --weak-mode",
    "data/test-abicompat/test9-fn-changed-report-0.txt",
    "output/test-abicompat/test9-fn-changed-report-0.txt",
  },
  // This entry must be the last one.
  {0, 0, 0, 0, 0, 0, 0}
};

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

  unsigned int cnt_total = 0, cnt_passed = 0, cnt_failed = 0;
  string in_app_path, in_lib1_path, in_lib2_path, suppression_path,
    abicompat_options, ref_report_path, out_report_path, abicompat, cmd, diffcmd;

  for (InOutSpec* s = in_out_specs; s->in_app_path; ++s)
    {
      bool is_ok = true;
      in_app_path = string(get_src_dir()) + "/tests/" + s->in_app_path;
      in_lib1_path = string(get_src_dir()) + "/tests/" + s->in_lib1_path;
      if (s->in_lib2_path && strcmp(s->in_lib2_path, ""))
	in_lib2_path = string(get_src_dir()) + "/tests/" + s->in_lib2_path;
      else
	in_lib2_path.clear();
      if (s->suppressions == 0 || !strcmp(s->suppressions, ""))
	suppression_path.clear();
      else
	suppression_path = string(get_src_dir()) + "/tests/" + s->suppressions;
      abicompat_options = s->options;
      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;
	}

      abicompat = string(get_build_dir()) + "/tools/abicompat";
      if (!suppression_path.empty())
	abicompat += " --suppressions " + suppression_path;
      abicompat += " " + abicompat_options;

      cmd = abicompat + " " + in_app_path + " " + in_lib1_path;
      if (!in_lib2_path.empty())
	cmd += string(" ") + in_lib2_path;

      cmd += " > " + out_report_path;

      bool abicompat_ok = true;
      abidiff_status status = static_cast<abidiff_status>(system(cmd.c_str()));
      if (abigail::tools_utils::abidiff_status_has_error(status))
	abicompat_ok = false;

      if (abicompat_ok)
	{
	  diffcmd = "diff -u " + ref_report_path + " " + out_report_path;
	  if (system(diffcmd.c_str()))
	    is_ok = false;
	}
      else
	is_ok = false;

      if (is_ok)
        {
	  cout << BRIGHT_YELLOW_COLOR
               << "Test Passed:"
               << DEFAULT_TERMINAL_COLOR
               << cmd
               << std::endl;
	  cnt_passed++;
	}
      else
        {
	  cout << BRIGHT_RED_COLOR
               << "Test Failed:"
               << DEFAULT_TERMINAL_COLOR
               << cmd
               << std::endl;
	  cnt_failed++;
	}
      cnt_total++;
    }
  cout << "Summary: " << cnt_total << " tested!"
       << " Test Passed: " << cnt_passed
       << ", Test Failed: " << cnt_failed
       << ".\n";

  return cnt_failed;
}