~vcs-imports-ii/dejagnu/master

« back to all changes in this revision

Viewing changes to dejagnu.h

  • Committer: Jacob Bachmeyer
  • Date: 2022-12-01 04:52:25 UTC
  • Revision ID: git-v1:cc2dcde3edb178434be6ce74fdd12322a35fcfb5
Revise generation of "END" messages in dejagnu.h

The "END" message is now produced upon normal exit, without requiring that
the totals() function or method be called.  The C++ API now emits totals
only when the last TestState object in the program is destroyed, instead
of every time a TestState object is destroyed.  This required adding code
to track the number of live TestState objects.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <stdio.h>
24
24
#include <stdarg.h>
 
25
#include <stdlib.h>
25
26
#include <string.h>
26
27
 
27
28
/* If you have problems with DejaGnu dropping failed, untested, or
38
39
  int untested;
39
40
  int unresolved;
40
41
  int unsupported;
 
42
  /**/
 
43
  int endmsg_registered;
 
44
  int TestState_count;  /* number of live TestState objects in C++ */
41
45
} DG__status = { 0 };
42
46
 
43
47
static inline void
 
48
DG__endmsg (void)
 
49
{ puts ("\tEND: done"); }
 
50
 
 
51
static inline void
 
52
DG__init (void)
 
53
{
 
54
  if (DG__status.endmsg_registered) return;
 
55
 
 
56
  if (atexit (DG__endmsg) == 0)
 
57
    DG__status.endmsg_registered = 1;
 
58
}
 
59
 
 
60
static inline void
44
61
pass (const char* fmt, ...)
45
62
{
46
63
  va_list ap;
47
64
 
48
65
  DG__status.pass++;
 
66
  DG__init ();
49
67
 
50
68
  flockfile (stdout);
51
69
  fputs ("\tPASSED: ", stdout);
60
78
  va_list ap;
61
79
 
62
80
  DG__status.xpass++;
 
81
  DG__init ();
63
82
 
64
83
  flockfile (stdout);
65
84
  fputs ("\tXPASSED: ", stdout);
74
93
  va_list ap;
75
94
 
76
95
  DG__status.fail++;
 
96
  DG__init ();
77
97
 
78
98
  flockfile (stdout);
79
99
  fputs ("\tFAILED: ", stdout);
88
108
  va_list ap;
89
109
 
90
110
  DG__status.xfail++;
 
111
  DG__init ();
91
112
 
92
113
  flockfile (stdout);
93
114
  fputs ("\tXFAILED: ", stdout);
102
123
  va_list ap;
103
124
 
104
125
  DG__status.untested++;
 
126
  DG__init ();
105
127
 
106
128
  flockfile (stdout);
107
129
  fputs ("\tUNTESTED: ", stdout);
116
138
  va_list ap;
117
139
 
118
140
  DG__status.unresolved++;
 
141
  DG__init ();
119
142
 
120
143
  flockfile (stdout);
121
144
  fputs ("\tUNRESOLVED: ", stdout);
130
153
  va_list ap;
131
154
 
132
155
  DG__status.unsupported++;
 
156
  DG__init ();
133
157
 
134
158
  flockfile (stdout);
135
159
  fputs ("\tUNSUPPORTED: ", stdout);
143
167
{
144
168
  va_list ap;
145
169
 
 
170
  DG__init ();
 
171
 
146
172
  flockfile (stdout);
147
173
  fputs ("\tNOTE: ", stdout);
148
174
  va_start (ap, fmt); vfprintf (stdout, fmt, ap); va_end (ap);
166
192
    printf ("\t#unresolved:\t\t%d\n", DG__status.unresolved);
167
193
  if (DG__status.unsupported)
168
194
    printf ("\t#unsupported:\t\t%d\n", DG__status.unsupported);
169
 
  printf ("\tEND: done\n");
170
195
}
171
196
 
172
197
#ifdef __cplusplus
200
225
      DG__status.untested = 0;
201
226
      DG__status.unresolved = 0;
202
227
      DG__status.unsupported = 0;
203
 
    }
204
 
 
205
 
  ~TestState (void) { totals(); }
 
228
 
 
229
      /* C++ object destruction will substitute for atexit(). */
 
230
      DG__status.endmsg_registered = 1;
 
231
      DG__status.TestState_count++;
 
232
    }
 
233
 
 
234
  ~TestState (void)
 
235
    {
 
236
      DG__status.TestState_count--;
 
237
 
 
238
      if (DG__status.TestState_count > 0) return;
 
239
 
 
240
      /* The last TestState object is being destroyed. */
 
241
      totals ();
 
242
      std::cout << "\tEND: done" << std::endl;
 
243
    }
206
244
 
207
245
  void testrun (bool b, std::string s)
208
246
    {
297
335
        if (DG__status.unsupported)
298
336
          std::cout << "\t#unsupported:\t\t"
299
337
                    << DG__status.unsupported << std::endl;
300
 
 
301
 
        std::cout << "\tEND: done" << std::endl;
302
338
      }
303
339
 
304
340
    // This is so this class can be printed in an ostream.