• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- Mode: C++ -*-
3 //
4 // Copyright (C) 2013-2022 Red Hat, Inc.
5 //
6 // Author: Dodji Seketeli
7 
8 /// @file
9 ///
10 /// This program tests that libabigail can handle alternate debug info
11 /// files as specified by http://www.dwarfstd.org/ShowIssue.php?issue=120604.1.
12 
13 #include <iostream>
14 #include <cstdlib>
15 #include "abg-tools-utils.h"
16 #include "test-utils.h"
17 
18 using std::cerr;
19 using std::string;
20 using abigail::tests::emit_test_status_and_update_counters;
21 using abigail::tests::emit_test_summary;
22 
23 struct InOutSpec
24 {
25   const char* in_elf_path;
26   const char* debug_info_dir_path;
27   const char* abidw_options;
28   const char* in_report_path;
29   const char* out_report_path;
30 };
31 
32 
33 InOutSpec in_out_specs[] =
34 {
35   {
36     "data/test-alt-dwarf-file/libtest0.so",
37     "data/test-alt-dwarf-file/test0-debug-dir",
38     "--check-alternate-debug-info-base-name",
39     "data/test-alt-dwarf-file/test0-report.txt",
40     "output/test-alt-dwarf-file/test0-report.txt"
41   },
42   {
43     "data/test-alt-dwarf-file/libtest0-common.so",
44     "data/test-alt-dwarf-file/test0-debug-dir",
45     "--check-alternate-debug-info-base-name",
46     "data/test-alt-dwarf-file/test0-report.txt",
47     "output/test-alt-dwarf-file/test0-report.txt"
48   },
49   {
50     "data/test-alt-dwarf-file/test1-libgromacs_d.so.0.0.0",
51     "data/test-alt-dwarf-file/test1-libgromacs-debug-dir",
52     "--noout --check-alternate-debug-info",
53     "data/test-alt-dwarf-file/test1-report-0.txt",
54     "output/test-alt-dwarf-file/test1-report-0.txt"
55   },
56   {
57     "data/test-alt-dwarf-file/rhbz1951526/usr/bin/gimp-2.10",
58     "data/test-alt-dwarf-file/rhbz1951526/usr/lib/debug",
59     "--abidiff",
60     "data/test-alt-dwarf-file/rhbz1951526/rhbz1951526-report-0.txt",
61     "output/test-alt-dwarf-file/rhbz1951526/rhbz1951526-report-0.txt"
62   },
63   {
64     "data/test-alt-dwarf-file/libstdc++/usr/lib64/libstdc++.so.6.0.30",
65     "data/test-alt-dwarf-file/libstdc++/usr/lib/debug",
66     "--abidiff",
67     "data/test-alt-dwarf-file/libstdc++/libstdc++-report.txt",
68     "output/test-alt-dwarf-file/libstdc++/libstdc++-report.txt"
69   },
70   {
71     "data/test-alt-dwarf-file/libstdc++/usr/lib64/libstdc++.so.6.0.30",
72     "data/test-alt-dwarf-file/libstdc++/usr/lib/debug",
73     "--check-alternate-debug-info-base-name",
74     "data/test-alt-dwarf-file/libstdc++/libstdc++-report-1.txt",
75     "output/test-alt-dwarf-file/libstdc++/libstdc++-report-1.txt"
76   },
77 
78   // This should always be the last entry
79   {NULL, NULL, NULL, NULL, NULL}
80 };
81 
82 int
main()83 main()
84 {
85   using abigail::tests::get_src_dir;
86   using abigail::tests::get_build_dir;
87   using abigail::tools_utils::ensure_parent_dir_created;
88 
89   unsigned int total_count = 0, passed_count = 0, failed_count = 0;
90 
91   bool is_ok = true;
92   string in_elf_path, ref_report_path, out_report_path, debug_info_dir;
93   string abidw, abidw_options;
94 
95   abidw = string(get_build_dir()) + "/tools/abidw";
96   for (InOutSpec* s = in_out_specs; s->in_elf_path; ++s)
97     {
98       abidw_options = s->abidw_options;
99       in_elf_path = string(get_src_dir()) + "/tests/" + s->in_elf_path;
100       debug_info_dir =
101 	string(get_src_dir()) + "/tests/" + s->debug_info_dir_path;
102       ref_report_path = string(get_src_dir()) + "/tests/" + s->in_report_path;
103       out_report_path =
104 	string(get_build_dir()) + "/tests/" + s->out_report_path;
105       if (!ensure_parent_dir_created(out_report_path))
106 	{
107 	  cerr << "could not create parent directory for "
108 	       << out_report_path;
109 	  is_ok = false;
110 	  continue;
111 	}
112 
113       string cmd = abidw + " --debug-info-dir " + debug_info_dir
114 	+ " " + abidw_options + " " + in_elf_path + " > " + out_report_path;
115 
116       bool abidw_ok = true;
117       if (system(cmd.c_str()))
118 	abidw_ok = false;
119 
120       if (abidw_ok)
121 	{
122 	  string diff_cmd = "diff -u " + ref_report_path + " " + out_report_path;
123 	  if (system(diff_cmd.c_str()))
124 	    is_ok &=false;
125 	}
126       else
127 	is_ok &= false;
128 
129       emit_test_status_and_update_counters(is_ok, cmd, passed_count,
130 					   failed_count, total_count);
131     }
132 
133   emit_test_summary(total_count, passed_count, failed_count);
134   return failed_count;
135 }
136