libabigail
test-read-common.h
Go to the documentation of this file.
1 // -*- Mode: C++ -*-
2 //
3 
4 /// @file
5 ///
6 /// This file declares the common functionality for tests in
7 /// CTF and DWARF readers, it declares abstractions for `act` test
8 /// stage.
9 
10 #ifndef __TEST_READ_COMMON_H__
11 #define __TEST_READ_COMMON_H__
12 
13 #include <cstring>
14 #include <string>
15 #include "abg-ir.h"
16 #include "abg-corpus.h"
17 #include "abg-workers.h"
18 #include "abg-writer.h"
19 #include "test-utils.h"
20 #include "abg-tools-utils.h"
21 
22 using std::string;
23 
25 using abigail::ir::corpus_sptr;
26 
27 namespace abigail
28 {
29 namespace tests
30 {
31 namespace read_common
32 {
33 
34 /// This is an aggregate that specifies where a test shall get its
35 /// input from, and where it shall write its output to.
36 struct InOutSpec
37 {
38  const char* in_elf_path;
39  const char* in_suppr_spec_path;
40  const char* in_public_headers_path;
41  type_id_style_kind type_id_style;
42  const char* in_abi_path;
43  const char* out_abi_path;
44  const char* options;
45 };// end struct InOutSpec
46 
47 /// The task that performs the tests.
49 {
50  bool is_ok;
51  InOutSpec spec;
52  string error_message;
53  string out_abi_base;
54  string in_elf_base;
55  string in_abi_base;
56 
57  string in_elf_path;
58  string in_abi_path;
59  string in_suppr_spec_path;
60  string in_public_headers_path;
61  string in_options;
62  string out_abi_path;
63 
64 
65  /// A setter for `in_elf_path` field.
66  /// The `in_elf_path` is the full path for input object
67  /// in the tests container @ref
68  /// abigail::tests::read_common::InOutSpec.
69  void
71  {
72  in_elf_path = in_elf_base + spec.in_elf_path;
73  }
74 
75  /// A setter for `in_suppr_spec_path` field.
76  /// The `in_suppr_spec_path` is the full path for suppression
77  /// entry in the tests container @ref
78  /// abigail::tests::read_common::InOutSpec.
79  void
81  {
82  if (spec.in_suppr_spec_path && strcmp(spec.in_suppr_spec_path, ""))
83  in_suppr_spec_path = in_elf_base + spec.in_suppr_spec_path;
84  else
85  in_suppr_spec_path.clear();
86  }
87 
88  /// A setter for `in_public_headers_path` field.
89  /// The `in_public_headers_path` is the full path for headers
90  /// entry in the tests container @ref
91  /// abigail::tests::read_common::InOutSpec.
92  void
94  {
95  in_public_headers_path.clear();
96  if (spec.in_public_headers_path)
97  in_public_headers_path = spec.in_public_headers_path;
98  if (!in_public_headers_path.empty())
99  in_public_headers_path = in_elf_base + spec.in_public_headers_path;
100  }
101 
102  /// A setter for the in_options field.
103  ///
104  /// The in_options is the additional option to be passed to the
105  /// abidw command at run time.
106  void
108  {
109  in_options.clear();
110  if (spec.options)
111  in_options = spec.options;
112  }
113 
114  /// A setter for `out_abi_path` field.
115  /// The `out_abi_path` is the full path for output of abixml file.
116  /// @return true if `out_abi_path` is a valid directory.
117  bool
119  {
120  if (!spec.out_abi_path)
121  // No output abi path was specified in the spec, so get out.
122  return false;
123 
124  out_abi_path = out_abi_base + spec.out_abi_path;
126  {
127  error_message =
128  string("Could not create parent directory for ") + out_abi_path;
129  return false;
130  }
131  return true;
132  }
133 
134  /// A setter for `in_abi_path` field.
135  /// The `in_abi_path` is the full path for the expected abixml file.
136  void
138  {
139  in_abi_path = in_abi_base + spec.in_abi_path;
140  }
141 
142  test_task(const InOutSpec &s,
143  string& a_out_abi_base,
144  string& a_in_elf_base,
145  string& a_in_abi_base);
146  bool
147  serialize_corpus(const string& out_abi_path,
148  corpus_sptr corp);
149  bool
150  run_abidw(const string& extargs = "");
151 
152  bool
153  run_diff();
154 
155  virtual
156  ~test_task()
157  {}
158 }; // end struct test_task
159 
160 typedef shared_ptr<test_task> test_task_sptr;
161 
162 /// An abstraction for valid test options.
163 struct options
164 {
165  // saves a wrong option string passed to test-harness.
166  string wrong_option;
167  // parallel test execution.
168  bool parallel;
169 
170  options()
171  : parallel(true)
172  {}
173 
174  ~options()
175  {
176  }
177 }; // end struct options
178 
179 void
180 display_usage(const string& prog_name, ostream& out);
181 
182 bool
183 parse_command_line(int argc, char* argv[], options& opts);
184 
185 /// A convenience typedef for a callback to create_new_test
186 /// instances.
187 typedef test_task* (*create_new_test)(const InOutSpec* s,
188  string& a_out_abi_base,
189  string& a_in_elf_base,
190  string& a_in_abi_base);
191 bool
192 run_tests(const size_t num_test, const InOutSpec* specs,
193  const options& opts, create_new_test new_test);
194 
195 }//end namespace read_common
196 }//end namespace tests
197 }//end namespace abigail
198 
199 #endif //__TEST_READ_COMMON_H__
This file contains the declarations of the entry points to de-serialize an instance of abigail::trans...
type_id_style_kind
The style of type id the XML writer will output.
Definition: abg-writer.h:27
bool set_out_abi_path()
A setter for `out_abi_path` field. The `out_abi_path` is the full path for output of abixml file...
test_task(const InOutSpec &s, string &a_out_abi_base, string &a_in_elf_base, string &a_in_abi_base)
Constructor.
bool run_abidw(const string &extargs="")
Spawn `abidw –abidiff` tool appending extargs argument.
void set_in_suppr_spec_path()
A setter for `in_suppr_spec_path` field. The `in_suppr_spec_path` is the full path for suppression en...
Toplevel namespace for libabigail.
This file declares an interface for the worker threads (or thread pool) design pattern. It aims at performing a set of tasks in parallel, using the multi-threading capabilities of the underlying processor(s).
void set_in_options()
A setter for the in_options field.
Types of the main internal representation of libabigail.
bool run_diff()
Spawn external `diff` command.
This represents a task to be performed.
Definition: abg-workers.h:42
void set_in_abi_path()
A setter for `in_abi_path` field. The `in_abi_path` is the full path for the expected abixml file...
The task that performs the tests.
void set_in_elf_path()
A setter for `in_elf_path` field. The `in_elf_path` is the full path for input object in the tests co...
An abstraction for valid test options.
void set_in_public_headers_path()
A setter for `in_public_headers_path` field. The `in_public_headers_path` is the full path for header...
This is an aggregate that specifies where a test shall get its input from, and where it shall write i...
bool ensure_parent_dir_created(const string &path)
Ensures that the parent directory of #path is created.
bool serialize_corpus(const string &out_abi_path, corpus_sptr corp)
Serialize the abixml out_abi_path file.