• 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   // This should be the last entry.
135   {NULL, NULL, NULL}
136 };
137 
138 int
main()139 main()
140 {
141   using abigail::tests::get_src_dir;
142   using abigail::tests::get_build_dir;
143   using abigail::tools_utils::ensure_parent_dir_created;
144 
145   unsigned int total_count = 0, passed_count = 0, failed_count = 0;
146 
147   string in_elf_path, ref_report_path, out_report_path;
148   string abidw;
149 
150   abidw = string(get_build_dir()) + "/tools/abidw "
151     "--annotate --no-corpus-path";
152   for (InOutSpec* s = in_out_specs; s->in_elf_path; ++s)
153     {
154       bool is_ok = true;
155       in_elf_path = string(get_src_dir()) + "/tests/" + s->in_elf_path;
156       ref_report_path = string(get_src_dir()) + "/tests/" + s->in_report_path;
157       out_report_path =
158 	string(get_build_dir()) + "/tests/" + s->out_report_path;
159       if (!ensure_parent_dir_created(out_report_path))
160 	{
161 	  cerr << "could not create parent directory for "
162 	       << out_report_path;
163 	  is_ok = false;
164 	  continue;
165 	}
166 
167       string cmd = abidw + " " + in_elf_path + " > " + out_report_path;
168 
169       bool abidw_ok = true;
170       if (system(cmd.c_str()))
171 	abidw_ok = false;
172 
173       if (abidw_ok)
174 	{
175 	  string diff_cmd =
176 	    "diff -w -u " + ref_report_path + " " + out_report_path;
177 	  if (system(diff_cmd.c_str()))
178 	    is_ok &=false;
179 	}
180       else
181 	{
182 	  is_ok &= false;
183 	}
184 
185       emit_test_status_and_update_counters(is_ok, cmd, passed_count,
186 					   failed_count, total_count);
187     }
188 
189   emit_test_summary(total_count, passed_count, failed_count);
190 
191   return failed_count;
192 }
193