detect non-blocking fd EOF by read()==0 following poll(), needed on MacOS.
[platform/upstream/glib.git] / glib / gtester.c
1 /* GLib testing framework runner
2  * Copyright (C) 2007 Sven Herzberg
3  * Copyright (C) 2007 Tim Janik
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 #include <glib.h>
21 #include <gstdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 #include <sys/wait.h>
27 #include <errno.h>
28 #include <signal.h>
29
30 /* the read buffer size in bytes */
31 #define READ_BUFFER_SIZE 4096
32
33 /* --- prototypes --- */
34 static int      main_selftest   (int    argc,
35                                  char **argv);
36 static void     parse_args      (gint           *argc_p,
37                                  gchar        ***argv_p);
38
39 /* --- variables --- */
40 static GIOChannel  *ioc_report = NULL;
41 static gboolean     gtester_quiet = FALSE;
42 static gboolean     gtester_verbose = FALSE;
43 static gboolean     gtester_list_tests = FALSE;
44 static gboolean     gtester_selftest = FALSE;
45 static gboolean     subtest_running = FALSE;
46 static gint         subtest_exitstatus = 0;
47 static gboolean     subtest_io_pending = FALSE;
48 static gboolean     subtest_quiet = TRUE;
49 static gboolean     subtest_verbose = FALSE;
50 static gboolean     subtest_mode_fatal = TRUE;
51 static gboolean     subtest_mode_perf = FALSE;
52 static gboolean     subtest_mode_quick = TRUE;
53 static const gchar *subtest_seedstr = NULL;
54 static gchar       *subtest_last_seed = NULL;
55 static GSList      *subtest_paths = NULL;
56 static GSList      *subtest_args = NULL;
57 static gboolean     testcase_open = FALSE;
58 static guint        testcase_count = 0;
59 static guint        testcase_fail_count = 0;
60 static const gchar *output_filename = NULL;
61 static guint        log_indent = 0;
62 static gint         log_fd = -1;
63
64 /* --- functions --- */
65 static const char*
66 sindent (guint n)
67 {
68   static const char spaces[] = "                                                                                                    ";
69   int l = sizeof (spaces) - 1;
70   n = MIN (n, l);
71   return spaces + l - n;
72 }
73
74 static void G_GNUC_PRINTF (1, 2)
75 test_log_printfe (const char *format,
76                   ...)
77 {
78   char *result;
79   int r;
80   va_list args;
81   va_start (args, format);
82   result = g_markup_vprintf_escaped (format, args);
83   va_end (args);
84   do
85     r = write (log_fd, result, strlen (result));
86   while (r < 0 && errno == EINTR);
87   g_free (result);
88 }
89
90 static void
91 terminate (void)
92 {
93   kill (getpid(), SIGTERM);
94   abort();
95 }
96
97 static void
98 testcase_close (long double duration,
99                 gint        exit_status,
100                 guint       n_forks)
101 {
102   g_return_if_fail (testcase_open > 0);
103   test_log_printfe ("%s<duration>%.6Lf</duration>\n", sindent (log_indent), duration);
104   test_log_printfe ("%s<status exit-status=\"%d\" n-forks=\"%d\" result=\"%s\"/>\n",
105                     sindent (log_indent), exit_status, n_forks,
106                     exit_status ? "failed" : "success");
107   log_indent -= 2;
108   test_log_printfe ("%s</testcase>\n", sindent (log_indent));
109   testcase_open--;
110   if (gtester_verbose)
111     g_print ("%s\n", exit_status ? "FAIL" : "OK");
112   if (exit_status && subtest_last_seed)
113     g_print ("GTester: last random seed: %s\n", subtest_last_seed);
114   if (exit_status)
115     testcase_fail_count += 1;
116   if (subtest_mode_fatal && testcase_fail_count)
117     terminate();
118 }
119
120 static void
121 test_log_msg (GTestLogMsg *msg)
122 {
123   switch (msg->log_type)
124     {
125     case G_TEST_LOG_NONE:
126       break;
127     case G_TEST_LOG_ERROR:
128       g_printerr ("%s\n", msg->strings[0]);
129       break;
130     case G_TEST_LOG_START_BINARY:
131       test_log_printfe ("%s<binary file=\"%s\"/>\n", sindent (log_indent), msg->strings[0]);
132       subtest_last_seed = g_strdup (msg->strings[1]);
133       test_log_printfe ("%s<random-seed>%s</random-seed>\n", sindent (log_indent), subtest_last_seed);
134       break;
135     case G_TEST_LOG_LIST_CASE:
136       g_print ("%s\n", msg->strings[0]);
137       break;
138     case G_TEST_LOG_START_CASE:
139       testcase_count++;
140       if (gtester_verbose)
141         {
142           gchar *sc = g_strconcat (msg->strings[0], ":", NULL);
143           gchar *sleft = g_strdup_printf ("%-68s", sc);
144           g_free (sc);
145           g_print ("%70s ", sleft);
146           g_free (sleft);
147         }
148       g_return_if_fail (testcase_open == 0);
149       testcase_open++;
150       test_log_printfe ("%s<testcase path=\"%s\">\n", sindent (log_indent), msg->strings[0]);
151       log_indent += 2;
152       break;
153     case G_TEST_LOG_SKIP_CASE:
154       if (FALSE && gtester_verbose) // enable to debug test case skipping logic
155         {
156           gchar *sc = g_strconcat (msg->strings[0], ":", NULL);
157           gchar *sleft = g_strdup_printf ("%-68s", sc);
158           g_free (sc);
159           g_print ("%70s SKIPPED\n", sleft);
160           g_free (sleft);
161         }
162       test_log_printfe ("%s<testcase path=\"%s\" skipped=\"1\"/>\n", sindent (log_indent), msg->strings[0]);
163       break;
164     case G_TEST_LOG_STOP_CASE:
165       testcase_close (msg->nums[2], (int) msg->nums[0], (int) msg->nums[1]);
166       break;
167     case G_TEST_LOG_MIN_RESULT:
168     case G_TEST_LOG_MAX_RESULT:
169       test_log_printfe ("%s<performance minimize=\"%d\" maximize=\"%d\" value=\"%.16Lg\">\n",
170                         sindent (log_indent), msg->log_type == G_TEST_LOG_MIN_RESULT, msg->log_type == G_TEST_LOG_MAX_RESULT, msg->nums[0]);
171       test_log_printfe ("%s%s\n", sindent (log_indent + 2), msg->strings[0]);
172       test_log_printfe ("%s</performance>\n", sindent (log_indent));
173       break;
174     case G_TEST_LOG_MESSAGE:
175       test_log_printfe ("%s<message>\n%s\n%s</message>\n", sindent (log_indent), msg->strings[0], sindent (log_indent));
176       break;
177     }
178 }
179
180 static gboolean
181 child_report_cb (GIOChannel  *source,
182                  GIOCondition condition,
183                  gpointer     data)
184 {
185   GTestLogBuffer *tlb = data;
186   GIOStatus status = G_IO_STATUS_NORMAL;
187   gboolean first_read_eof = FALSE, first_read = TRUE;
188   gsize length = 0;
189   do
190     {
191       guint8 buffer[READ_BUFFER_SIZE];
192       GError *error = NULL;
193       status = g_io_channel_read_chars (source, (gchar*) buffer, sizeof (buffer), &length, &error);
194       if (first_read && (condition & G_IO_IN))
195         {
196           /* on some unixes (MacOS) we need to detect non-blocking fd EOF
197            * by an IO_IN select/poll followed by read()==0.
198            */
199           first_read_eof = length == 0;
200         }
201       first_read = FALSE;
202       if (length)
203         {
204           GTestLogMsg *msg;
205           g_test_log_buffer_push (tlb, length, buffer);
206           do
207             {
208               msg = g_test_log_buffer_pop (tlb);
209               if (msg)
210                 {
211                   test_log_msg (msg);
212                   g_test_log_msg_free (msg);
213                 }
214             }
215           while (msg);
216         }
217       g_clear_error (&error);
218       /* ignore the io channel status, which will report intermediate EOFs for non blocking fds */
219       (void) status;
220     }
221   while (length > 0);
222   if (first_read_eof || (condition & (G_IO_ERR | G_IO_HUP)))
223     {
224       /* if there's no data to read and select() reports an error or hangup,
225        * the fd must have been closed remotely
226        */
227       subtest_io_pending = FALSE;
228       return FALSE;
229     }
230   return TRUE; /* keep polling */
231 }
232
233 static void
234 child_watch_cb (GPid     pid,
235                 gint     status,
236                 gpointer data)
237 {
238   g_spawn_close_pid (pid);
239   if (WIFEXITED (status)) /* normal exit */
240     subtest_exitstatus = WEXITSTATUS (status);
241   else /* signal or core dump, etc */
242     subtest_exitstatus = 0xffffffff;
243   subtest_running = FALSE;
244 }
245
246 static gchar*
247 queue_gfree (GSList **slistp,
248              gchar   *string)
249 {
250   *slistp = g_slist_prepend (*slistp, string);
251   return string;
252 }
253
254 static void
255 unset_cloexec_fdp (gpointer fdp_data)
256 {
257   int r, *fdp = fdp_data;
258   do
259     r = fcntl (*fdp, F_SETFD, 0 /* FD_CLOEXEC */);
260   while (r < 0 && errno == EINTR);
261 }
262
263 static gboolean
264 launch_test_binary (const char *binary,
265                     guint       skip_tests)
266 {
267   GTestLogBuffer *tlb;
268   GSList *slist, *free_list = NULL;
269   GError *error = NULL;
270   const gchar *argv[99 + g_slist_length (subtest_args) + g_slist_length (subtest_paths)];
271   GPid pid = 0;
272   gint report_pipe[2] = { -1, -1 };
273   gint i = 0;
274
275   if (pipe (report_pipe) < 0)
276     {
277       if (subtest_mode_fatal)
278         g_error ("Failed to open pipe for test binary: %s: %s", binary, g_strerror (errno));
279       else
280         g_warning ("Failed to open pipe for test binary: %s: %s", binary, g_strerror (errno));
281       return FALSE;
282     }
283
284   /* setup argv */
285   argv[i++] = binary;
286   for (slist = subtest_args; slist; slist = slist->next)
287     argv[i++] = (gchar*) slist->data;
288   // argv[i++] = "--debug-log";
289   if (subtest_quiet)
290     argv[i++] = "--quiet";
291   if (subtest_verbose)
292     argv[i++] = "--verbose";
293   if (!subtest_mode_fatal)
294     argv[i++] = "--keep-going";
295   if (subtest_mode_quick)
296     argv[i++] = "-m=quick";
297   else
298     argv[i++] = "-m=slow";
299   if (subtest_mode_perf)
300     argv[i++] = "-m=perf";
301   if (gtester_list_tests)
302     argv[i++] = "-l";
303   if (subtest_seedstr)
304     argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--seed=%s", subtest_seedstr));
305   argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--GTestLogFD=%u", report_pipe[1]));
306   if (skip_tests)
307     argv[i++] = queue_gfree (&free_list, g_strdup_printf ("--GTestSkipCount=%u", skip_tests));
308   for (slist = subtest_paths; slist; slist = slist->next)
309     argv[i++] = queue_gfree (&free_list, g_strdup_printf ("-p=%s", (gchar*) slist->data));
310   argv[i++] = NULL;
311
312   g_spawn_async_with_pipes (NULL, /* g_get_current_dir() */
313                             (gchar**) argv,
314                             NULL, /* envp */
315                             G_SPAWN_DO_NOT_REAP_CHILD, /* G_SPAWN_SEARCH_PATH */
316                             unset_cloexec_fdp, &report_pipe[1], /* pre-exec callback */
317                             &pid,
318                             NULL,       /* standard_input */
319                             NULL,       /* standard_output */
320                             NULL,       /* standard_error */
321                             &error);
322   g_slist_foreach (free_list, (void(*)(void*,void*)) g_free, NULL);
323   g_slist_free (free_list);
324   free_list = NULL;
325   close (report_pipe[1]);
326
327   if (!gtester_quiet)
328     g_print ("(pid=%lu)\n", (unsigned long) pid);
329
330   if (error)
331     {
332       close (report_pipe[0]);
333       if (subtest_mode_fatal)
334         g_error ("Failed to execute test binary: %s: %s", argv[0], error->message);
335       else
336         g_warning ("Failed to execute test binary: %s: %s", argv[0], error->message);
337       g_clear_error (&error);
338       return FALSE;
339     }
340
341   subtest_running = TRUE;
342   subtest_io_pending = TRUE;
343   tlb = g_test_log_buffer_new();
344   if (report_pipe[0] >= 0)
345     {
346       ioc_report = g_io_channel_unix_new (report_pipe[0]);
347       g_io_channel_set_flags (ioc_report, G_IO_FLAG_NONBLOCK, NULL);
348       g_io_channel_set_encoding (ioc_report, NULL, NULL);
349       g_io_channel_set_buffered (ioc_report, FALSE);
350       g_io_add_watch_full (ioc_report, G_PRIORITY_DEFAULT - 1, G_IO_IN | G_IO_ERR | G_IO_HUP, child_report_cb, tlb, NULL);
351       g_io_channel_unref (ioc_report);
352     }
353   g_child_watch_add_full (G_PRIORITY_DEFAULT + 1, pid, child_watch_cb, NULL, NULL);
354
355   while (subtest_running ||             /* FALSE once child exits */
356          subtest_io_pending ||          /* FALSE once ioc_report closes */
357          g_main_context_pending (NULL)) /* TRUE while idler, etc are running */
358     g_main_context_iteration (NULL, TRUE);
359
360   close (report_pipe[0]);
361   g_test_log_buffer_free (tlb);
362
363   return TRUE;
364 }
365
366 static void
367 launch_test (const char *binary)
368 {
369   gboolean success = TRUE;
370   GTimer *btimer = g_timer_new();
371   gboolean need_restart;
372   testcase_count = 0;
373   testcase_fail_count = 0;
374   if (!gtester_quiet)
375     g_print ("TEST: %s... ", binary);
376
377  retry:
378   test_log_printfe ("%s<testbinary path=\"%s\">\n", sindent (log_indent), binary);
379   log_indent += 2;
380   g_timer_start (btimer);
381   subtest_exitstatus = 0;
382   success &= launch_test_binary (binary, testcase_count);
383   success &= subtest_exitstatus == 0;
384   need_restart = testcase_open != 0;
385   if (testcase_open)
386     testcase_close (0, -256, 0);
387   g_timer_stop (btimer);
388   test_log_printfe ("%s<duration>%.6f</duration>\n", sindent (log_indent), g_timer_elapsed (btimer, NULL));
389   log_indent -= 2;
390   test_log_printfe ("%s</testbinary>\n", sindent (log_indent));
391   g_free (subtest_last_seed);
392   subtest_last_seed = NULL;
393   if (need_restart)
394     {
395       /* restart test binary, skipping processed test cases */
396       goto retry;
397     }
398
399   if (!gtester_quiet)
400     g_print ("%s: %s\n", testcase_fail_count || !success ? "FAIL" : "PASS", binary);
401   g_timer_destroy (btimer);
402   if (subtest_mode_fatal && !success)
403     terminate();
404 }
405
406 static void
407 usage (gboolean just_version)
408 {
409   if (just_version)
410     {
411       g_print ("gtester version %d.%d.%d\n", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
412       return;
413     }
414   g_print ("Usage: gtester [OPTIONS] testprogram...\n");
415   /*        12345678901234567890123456789012345678901234567890123456789012345678901234567890 */
416   g_print ("Options:\n");
417   g_print ("  -h, --help                  show this help message\n");
418   g_print ("  -v, --version               print version informations\n");
419   g_print ("  --g-fatal-warnings          make warnings fatal (abort)\n");
420   g_print ("  -k, --keep-going            continue running after tests failed\n");
421   g_print ("  -l                          list paths of available test cases\n");
422   g_print ("  -m=perf, -m=slow, -m=quick -m=thorough\n");
423   g_print ("                              run test cases in mode perf, slow/thorough or quick (default)\n");
424   g_print ("  -p=TESTPATH                 only start test cases matching TESTPATH\n");
425   g_print ("  --seed=SEEDSTRING           start all tests with random number seed SEEDSTRING\n");
426   g_print ("  -o=LOGFILE                  write the test log to LOGFILE\n");
427   g_print ("  -q, --quiet                 suppress per test binary output\n");
428   g_print ("  --verbose                   report success per testcase\n");
429 }
430
431 static void
432 parse_args (gint    *argc_p,
433             gchar ***argv_p)
434 {
435   guint argc = *argc_p;
436   gchar **argv = *argv_p;
437   guint i, e;
438   /* parse known args */
439   for (i = 1; i < argc; i++)
440     {
441       if (strcmp (argv[i], "--g-fatal-warnings") == 0)
442         {
443           GLogLevelFlags fatal_mask = (GLogLevelFlags) g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
444           fatal_mask = (GLogLevelFlags) (fatal_mask | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
445           g_log_set_always_fatal (fatal_mask);
446           argv[i] = NULL;
447         }
448       else if (strcmp (argv[i], "--gtester-selftest") == 0)
449         {
450           gtester_selftest = TRUE;
451           argv[i] = NULL;
452           break;        // stop parsing regular gtester arguments
453         }
454       else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0)
455         {
456           usage (FALSE);
457           exit (0);
458           argv[i] = NULL;
459         }
460       else if (strcmp (argv[i], "-v") == 0 || strcmp (argv[i], "--version") == 0)
461         {
462           usage (TRUE);
463           exit (0);
464           argv[i] = NULL;
465         }
466       else if (strcmp (argv[i], "--keep-going") == 0 ||
467                strcmp (argv[i], "-k") == 0)
468         {
469           subtest_mode_fatal = FALSE;
470           argv[i] = NULL;
471         }
472       else if (strcmp ("-p", argv[i]) == 0 || strncmp ("-p=", argv[i], 3) == 0)
473         {
474           gchar *equal = argv[i] + 2;
475           if (*equal == '=')
476             subtest_paths = g_slist_prepend (subtest_paths, equal + 1);
477           else if (i + 1 < argc)
478             {
479               argv[i++] = NULL;
480               subtest_paths = g_slist_prepend (subtest_paths, argv[i]);
481             }
482           argv[i] = NULL;
483         }
484       else if (strcmp ("--test-arg", argv[i]) == 0 || strncmp ("--test-arg=", argv[i], 11) == 0)
485         {
486           gchar *equal = argv[i] + 10;
487           if (*equal == '=')
488             subtest_args = g_slist_prepend (subtest_args, equal + 1);
489           else if (i + 1 < argc)
490             {
491               argv[i++] = NULL;
492               subtest_args = g_slist_prepend (subtest_args, argv[i]);
493             }
494           argv[i] = NULL;
495         }
496       else if (strcmp ("-o", argv[i]) == 0 || strncmp ("-o=", argv[i], 3) == 0)
497         {
498           gchar *equal = argv[i] + 2;
499           if (*equal == '=')
500             output_filename = equal + 1;
501           else if (i + 1 < argc)
502             {
503               argv[i++] = NULL;
504               output_filename = argv[i];
505             }
506           argv[i] = NULL;
507         }
508       else if (strcmp ("-m", argv[i]) == 0 || strncmp ("-m=", argv[i], 3) == 0)
509         {
510           gchar *equal = argv[i] + 2;
511           const gchar *mode = "";
512           if (*equal == '=')
513             mode = equal + 1;
514           else if (i + 1 < argc)
515             {
516               argv[i++] = NULL;
517               mode = argv[i];
518             }
519           if (strcmp (mode, "perf") == 0)
520             subtest_mode_perf = TRUE;
521           else if (strcmp (mode, "slow") == 0 || strcmp (mode, "thorough") == 0)
522             subtest_mode_quick = FALSE;
523           else if (strcmp (mode, "quick") == 0)
524             {
525               subtest_mode_quick = TRUE;
526               subtest_mode_perf = FALSE;
527             }
528           else
529             g_error ("unknown test mode: -m %s", mode);
530           argv[i] = NULL;
531         }
532       else if (strcmp ("-q", argv[i]) == 0 || strcmp ("--quiet", argv[i]) == 0)
533         {
534           gtester_quiet = TRUE;
535           gtester_verbose = FALSE;
536           argv[i] = NULL;
537         }
538       else if (strcmp ("--verbose", argv[i]) == 0)
539         {
540           gtester_quiet = FALSE;
541           gtester_verbose = TRUE;
542           argv[i] = NULL;
543         }
544       else if (strcmp ("-l", argv[i]) == 0)
545         {
546           gtester_list_tests = TRUE;
547           argv[i] = NULL;
548         }
549       else if (strcmp ("--seed", argv[i]) == 0 || strncmp ("--seed=", argv[i], 7) == 0)
550         {
551           gchar *equal = argv[i] + 6;
552           if (*equal == '=')
553             subtest_seedstr = equal + 1;
554           else if (i + 1 < argc)
555             {
556               argv[i++] = NULL;
557               subtest_seedstr = argv[i];
558             }
559           argv[i] = NULL;
560         }
561     }
562   /* collapse argv */
563   e = 1;
564   for (i = 1; i < argc; i++)
565     if (argv[i])
566       {
567         argv[e++] = argv[i];
568         if (i >= e)
569           argv[i] = NULL;
570       }
571   *argc_p = e;
572 }
573
574 int
575 main (int    argc,
576       char **argv)
577 {
578   guint ui;
579
580   /* some unices need SA_RESTART for SIGCHLD to return -EAGAIN for io.
581    * we must fiddle with sigaction() *before* glib is used, otherwise
582    * we could revoke signal hanmdler setups from glib initialization code.
583    */
584   if (TRUE)
585     {
586       struct sigaction sa;
587       struct sigaction osa;
588       sa.sa_handler = SIG_DFL;
589       sigfillset (&sa.sa_mask);
590       sa.sa_flags = SA_RESTART;
591       sigaction (SIGCHLD, &sa, &osa);
592     }
593
594   g_set_prgname (argv[0]);
595   parse_args (&argc, &argv);
596   if (gtester_selftest)
597     return main_selftest (argc, argv);
598
599   if (argc <= 1)
600     {
601       usage (FALSE);
602       return 1;
603     }
604
605   if (output_filename)
606     {
607       log_fd = g_open (output_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
608       if (log_fd < 0)
609         g_error ("Failed to open log file '%s': %s", output_filename, g_strerror (errno));
610     }
611
612   test_log_printfe ("<?xml version=\"1.0\"?>\n");
613   test_log_printfe ("%s<gtester>\n", sindent (log_indent));
614   log_indent += 2;
615   for (ui = 1; ui < argc; ui++)
616     {
617       const char *binary = argv[ui];
618       launch_test (binary);
619       /* we only get here on success or if !subtest_mode_fatal */
620     }
621   log_indent -= 2;
622   test_log_printfe ("%s</gtester>\n", sindent (log_indent));
623
624   close (log_fd);
625
626   return 0;
627 }
628
629 static void
630 fixture_setup (guint        *fix,
631                gconstpointer test_data)
632 {
633   g_assert_cmphex (*fix, ==, 0);
634   *fix = 0xdeadbeef;
635 }
636 static void
637 fixture_test (guint        *fix,
638               gconstpointer test_data)
639 {
640   g_assert_cmphex (*fix, ==, 0xdeadbeef);
641   g_test_message ("This is a test message API test message.");
642   g_test_bug_base ("http://www.example.com/bugtracker/");
643   g_test_bug ("123");
644   g_test_bug_base ("http://www.example.com/bugtracker?bugnum=%s;cmd=showbug");
645   g_test_bug ("456");
646 }
647 static void
648 fixture_teardown (guint        *fix,
649                   gconstpointer test_data)
650 {
651   g_assert_cmphex (*fix, ==, 0xdeadbeef);
652 }
653
654 static int
655 main_selftest (int    argc,
656                char **argv)
657 {
658   /* gtester main() for --gtester-selftest invokations */
659   g_test_init (&argc, &argv, NULL);
660   g_test_add ("/gtester/fixture-test", guint, NULL, fixture_setup, fixture_test, fixture_teardown);
661   return g_test_run();
662 }