3 As per test-combination.c, construct a test case by combining other test
4 cases, to try to shake out state issues. However each test runs in a
11 /* dejagnu.h isn't thread-safe; there's a shared "buffer", and the counts
12 of "passed"/"failed" etc are globals.
14 We get around this by putting a mutex around pass/fail calls.
17 static pthread_mutex_t dg_mutex
= PTHREAD_MUTEX_INITIALIZER
;
19 /* By defining MAKE_DEJAGNU_H_THREADSAFE before we include harness.h,
20 harness.h injects macros before including <dejagnu.h> so that the
21 pass/fail functions become "dejagnu_pass"/"dejagnu_fail" etc. */
23 /* Forward decls of our implementations of pass/fail/note. */
26 pass (const char* fmt
, ...);
29 fail (const char* fmt
, ...);
32 note (const char* fmt
, ...);
34 #define MAKE_DEJAGNU_H_THREADSAFE
36 /* We also need to provide our own version of TEST_NAME. */
39 /* We can now include all of the relevant selftests. */
41 #include "all-non-failing-tests.h"
43 #define TEST_PROVIDES_MAIN
44 #define TEST_ESCHEWS_TEST_JIT
46 /* Now construct a test case from all the other test cases.
48 We undefine COMBINED_TEST so that we can now include harness.h
53 /* We now provide our own implementations of "pass"/"fail"/"note", which
54 call the underlying dejagnu implementations, but with a mutex. */
57 pass (const char* fmt
, ...)
63 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
66 pthread_mutex_lock (&dg_mutex
);
67 dejagnu_pass (buffer
);
68 pthread_mutex_unlock (&dg_mutex
);
72 fail (const char* fmt
, ...)
78 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
81 pthread_mutex_lock (&dg_mutex
);
82 dejagnu_fail (buffer
);
83 pthread_mutex_unlock (&dg_mutex
);
87 note (const char* fmt
, ...)
93 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
96 pthread_mutex_lock (&dg_mutex
);
97 dejagnu_note (buffer
);
98 pthread_mutex_unlock (&dg_mutex
);
104 const struct testcase
*m_testcase
;
107 static const char *argv0
;
110 run_threaded_test (void *data
)
112 struct thread_data
*thread
= (struct thread_data
*)data
;
115 for (i
= 0; i
< 5; i
++)
117 gcc_jit_context
*ctxt
;
118 gcc_jit_result
*result
;
120 note ("run_threaded_test: %s iteration: %d",
121 thread
->m_testcase
->m_name
, i
);
123 ctxt
= gcc_jit_context_acquire ();
125 set_options (ctxt
, argv0
);
127 thread
->m_testcase
->m_hook_to_create_code (ctxt
, NULL
);
129 result
= gcc_jit_context_compile (ctxt
);
131 thread
->m_testcase
->m_hook_to_verify_code (ctxt
, result
);
133 gcc_jit_context_release (ctxt
);
135 /* Once we're done with the code, this unloads the built .so file: */
136 gcc_jit_result_release (result
);
143 main (int argc
, char **argv
)
147 snprintf (test
, sizeof (test
),
149 extract_progname (argv
[0]));
153 /* The individual testcases are not thread-safe (some have their own
154 global variables), so we have one thread per test-case. */
155 struct thread_data
*threads
=
156 calloc (num_testcases
, sizeof (struct thread_data
));
158 /* Start a thread per test-case. */
159 for (i
= 0; i
< num_testcases
; i
++)
161 struct thread_data
*thread
= &threads
[i
];
162 thread
->m_testcase
= &testcases
[i
];
163 pthread_create (&thread
->m_tid
,
169 /* Wait for all the threads to be done. */
170 for (i
= 0; i
< num_testcases
; i
++)
172 struct thread_data
*thread
= &threads
[i
];
173 (void)pthread_join (thread
->m_tid
, NULL
);