|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * vim: set ts=8 sts=4 et sw=4 tw=99: |
|
3 * |
|
4 * This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #ifndef gdb_gdb_tests_h |
|
9 #define gdb_gdb_tests_h |
|
10 |
|
11 // Support for C++ fragments to be used by Python unit tests for SpiderMonkey's |
|
12 // GDB support. |
|
13 // |
|
14 // That is: |
|
15 // - js/src/gdb/mozilla holds the actual GDB SpiderMonkey support code. |
|
16 // - Each '.py' file in js/src/gdb/tests is a unit test for the above. |
|
17 // - Each '.cpp' file in js/src/gdb/tests is C++ code for one of the unit tests |
|
18 // to run. |
|
19 // |
|
20 // (So the .cpp files are two steps removed from being anything one would |
|
21 // actually run.) |
|
22 |
|
23 #include "NamespaceImports.h" |
|
24 |
|
25 void breakpoint(); |
|
26 |
|
27 struct GDBFragment { |
|
28 GDBFragment() { |
|
29 next = allFragments; |
|
30 allFragments = this; |
|
31 } |
|
32 |
|
33 // The name of this fragment. gdb-tests.cpp runs the fragments whose names |
|
34 // are passed to it on the command line. |
|
35 virtual const char *name() = 0; |
|
36 |
|
37 // Run the fragment code. |argv| is a reference to the pointer into the |
|
38 // command-line argument vector, referring to the argument immediately |
|
39 // following this fragment's name. The fragment can consume arguments and |
|
40 // advance argv if it wishes. |
|
41 virtual void run(JSContext *cx, const char **&argv) = 0; |
|
42 |
|
43 // We declare one instance of this type for each fragment to run. The |
|
44 // constructor adds each instance to a linked list, of which this is |
|
45 // the head. |
|
46 static GDBFragment *allFragments; |
|
47 |
|
48 // The link in the list of all instances. |
|
49 GDBFragment *next; |
|
50 }; |
|
51 |
|
52 // Macro for declaring a C++ fragment for some Python unit test to call. Usage: |
|
53 // |
|
54 // FRAGMENT(<category>, <name>) { <body of fragment function> } |
|
55 // |
|
56 // where <category> and <name> are identifiers. The gdb-tests executable |
|
57 // takes a series of fragment names as command-line arguments and runs them in |
|
58 // turn; each fragment is named <category>.<name> on the command line. |
|
59 // |
|
60 // The body runs in a scope where 'cx' is a usable JSContext *. |
|
61 |
|
62 #define FRAGMENT(category, subname) \ |
|
63 class FRAGMENT_CLASS_NAME(category, subname): public GDBFragment { \ |
|
64 void run(JSContext *cx, const char **&argv); \ |
|
65 const char *name() { return FRAGMENT_STRING_NAME(category, subname); } \ |
|
66 static FRAGMENT_CLASS_NAME(category, subname) singleton; \ |
|
67 }; \ |
|
68 FRAGMENT_CLASS_NAME(category, subname) FRAGMENT_CLASS_NAME(category, subname)::singleton; \ |
|
69 void FRAGMENT_CLASS_NAME(category, subname)::run(JSContext *cx, const char **&argv) |
|
70 |
|
71 #define FRAGMENT_STRING_NAME(category, subname) (#category "." #subname) |
|
72 #define FRAGMENT_CLASS_NAME(category, subname) Fragment_ ## category ## _ ## subname |
|
73 |
|
74 #endif /* gdb_gdb_tests_h */ |