• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Author: Ondrej Oprala
5 
6 /// @file
7 ///
8 /// This program tests the annotation capabilities of the library.
9 
10 #include <iostream>
11 #include <cstdlib>
12 #include "abg-tools-utils.h"
13 #include "test-utils.h"
14 
15 using std::cerr;
16 using std::string;
17 using abigail::tests::emit_test_status_and_update_counters;
18 using abigail::tests::emit_test_summary;
19 
20 struct InOutSpec
21 {
22   const char* in_elf_path;
23   const char* in_report_path;
24   const char* out_report_path;
25 };
26 
27 InOutSpec in_out_specs[] =
28 {
29   {
30     "data/test-read-dwarf/test0",
31     "data/test-annotate/test0.abi",
32     "output/test-annotate/test0.abi"
33   },
34   {
35     "data/test-read-dwarf/test1",
36     "data/test-annotate/test1.abi",
37     "output/test-annotate/test1.abi"
38   },
39   {
40     "data/test-read-dwarf/test2.so",
41     "data/test-annotate/test2.so.abi",
42     "output/test-annotate/test2.so.abi"
43   },
44   {
45     "data/test-read-common/test3.so",
46     "data/test-annotate/test3.so.abi",
47     "output/test-annotate/test3.so.abi"
48   },
49   {
50     "data/test-read-common/test4.so",
51     "data/test-annotate/test4.so.abi",
52     "output/test-annotate/test4.so.abi"
53   },
54   {
55     "data/test-read-dwarf/test5.o",
56     "data/test-annotate/test5.o.abi",
57     "output/test-annotate/test5.o.abi"
58   },
59   {
60     "data/test-read-dwarf/test6.so",
61     "data/test-annotate/test6.so.abi",
62     "output/test-annotate/test6.so.abi"
63   },
64   {
65     "data/test-read-dwarf/test7.so",
66     "data/test-annotate/test7.so.abi",
67     "output/test-annotate/test7.so.abi"
68   },
69   {
70     "data/test-read-dwarf/test8-qualified-this-pointer.so",
71     "data/test-annotate/test8-qualified-this-pointer.so.abi",
72     "output/test-annotate/test8-qualified-this-pointer.so.abi"
73   },
74   {
75     "data/test-read-dwarf/test13-pr18894.so",
76     "data/test-annotate/test13-pr18894.so.abi",
77     "output/test-annotate/test13-pr18894.so.abi",
78   },
79   {
80     "data/test-read-dwarf/test14-pr18893.so",
81     "data/test-annotate/test14-pr18893.so.abi",
82     "output/test-annotate/test14-pr18893.so.abi",
83   },
84   {
85     "data/test-read-dwarf/test15-pr18892.so",
86     "data/test-annotate/test15-pr18892.so.abi",
87     "output/test-annotate/test15-pr18892.so.abi",
88   },
89   {
90     "data/test-read-dwarf/test17-pr19027.so",
91     "data/test-annotate/test17-pr19027.so.abi",
92     "output/test-annotate/test17-pr19027.so.abi",
93   },
94   {
95     "data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so",
96     "data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi",
97     "output/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi",
98   },
99   {
100     "data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so",
101     "data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi",
102     "output/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi",
103   },
104   {
105     "data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so",
106     "data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi",
107     "output/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi",
108   },
109   {
110     "data/test-read-dwarf/test21-pr19092.so",
111     "data/test-annotate/test21-pr19092.so.abi",
112     "output/test-annotate/test21-pr19092.so.abi",
113   },
114   {
115     "data/test-read-dwarf/libtest23.so",
116     "data/test-annotate/libtest23.so.abi",
117     "output/test-annotate/libtest23.so.abi",
118   },
119   {
120     "data/test-read-dwarf/libtest24-drop-fns.so",
121     "data/test-annotate/libtest24-drop-fns.so.abi",
122     "output/test-annotate/libtest24-drop-fns.so.abi",
123   },
124   {
125     "data/test-read-dwarf/libtest24-drop-fns.so",
126     "data/test-annotate/libtest24-drop-fns-2.so.abi",
127     "output/test-annotate/libtest24-drop-fns-2.so.abi",
128   },
129   {
130     "data/test-annotate/test-anonymous-members-0.o",
131     "data/test-annotate/test-anonymous-members-0.o.abi",
132     "output/test-annotate/test-anonymous-members-0.o.abi",
133   },
134   {
135     "data/test-read-dwarf/PR29443-missing-xx.o",
136     "data/test-annotate/PR29443-missing-xx.o.annotated.abi",
137     "output/test-annotate/PR29443-missing-xx.o.annotated.abi",
138   },
139   // This should be the last entry.
140   {NULL, NULL, NULL}
141 };
142 
143 int
main()144 main()
145 {
146   using abigail::tests::get_src_dir;
147   using abigail::tests::get_build_dir;
148   using abigail::tools_utils::ensure_parent_dir_created;
149 
150   unsigned int total_count = 0, passed_count = 0, failed_count = 0;
151 
152   string in_elf_path, ref_report_path, out_report_path;
153   string abidw;
154 
155   abidw = string(get_build_dir()) + "/tools/abidw "
156     "--annotate --no-corpus-path --no-architecture";
157   for (InOutSpec* s = in_out_specs; s->in_elf_path; ++s)
158     {
159       bool is_ok = true;
160       in_elf_path = string(get_src_dir()) + "/tests/" + s->in_elf_path;
161       ref_report_path = string(get_src_dir()) + "/tests/" + s->in_report_path;
162       out_report_path =
163 	string(get_build_dir()) + "/tests/" + s->out_report_path;
164       if (!ensure_parent_dir_created(out_report_path))
165 	{
166 	  cerr << "could not create parent directory for "
167 	       << out_report_path;
168 	  is_ok = false;
169 	  continue;
170 	}
171 
172       string cmd = abidw + " " + in_elf_path + " > " + out_report_path;
173 
174       bool abidw_ok = true;
175       if (system(cmd.c_str()))
176 	abidw_ok = false;
177 
178       if (abidw_ok)
179 	{
180 	  string diff_cmd =
181 	    "diff -w -u " + ref_report_path + " " + out_report_path;
182 	  if (system(diff_cmd.c_str()))
183 	    is_ok &=false;
184 	}
185       else
186 	{
187 	  is_ok &= false;
188 	}
189 
190       emit_test_status_and_update_counters(is_ok, cmd, passed_count,
191 					   failed_count, total_count);
192     }
193 
194   emit_test_summary(total_count, passed_count, failed_count);
195 
196   return failed_count;
197 }
198