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 void dejagnu_pass (const char* fmt
, ...);
24 void dejagnu_fail (const char* fmt
, ...);
25 void dejagnu_note (const char* fmt
, ...);
27 /* We now provide our own implementations of "pass"/"fail"/"note", which
28 call the underlying dejagnu implementations, but with a mutex. */
31 pass (const char* fmt
, ...)
37 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
40 pthread_mutex_lock (&dg_mutex
);
41 dejagnu_pass (buffer
);
42 pthread_mutex_unlock (&dg_mutex
);
46 fail (const char* fmt
, ...)
52 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
55 pthread_mutex_lock (&dg_mutex
);
56 dejagnu_fail (buffer
);
57 pthread_mutex_unlock (&dg_mutex
);
61 note (const char* fmt
, ...)
67 vsnprintf (buffer
, sizeof (buffer
), fmt
, ap
);
70 pthread_mutex_lock (&dg_mutex
);
71 dejagnu_note (buffer
);
72 pthread_mutex_unlock (&dg_mutex
);
75 #define MAKE_DEJAGNU_H_THREADSAFE
77 /* We also need to provide our own version of TEST_NAME. */
80 /* We can now include all of the relevant selftests. */
82 #include "all-non-failing-tests.h"
84 #define TEST_PROVIDES_MAIN
85 #define TEST_ESCHEWS_TEST_JIT
87 /* Now construct a test case from all the other test cases.
89 We undefine COMBINED_TEST so that we can now include harness.h
97 void (*m_hook_to_create_code
) (gcc_jit_context
*ctxt
,
99 void (*m_hook_to_verify_code
) (gcc_jit_context
*ctxt
,
100 gcc_jit_result
*result
);
103 const struct testcase testcases
[] = {
105 create_code_accessing_struct
,
106 verify_code_accessing_struct
},
108 create_code_accessing_union
,
109 verify_code_accessing_union
},
111 create_code_arith_overflow
,
112 verify_code_arith_overflow
},
114 create_code_array_as_pointer
,
115 verify_code_array_as_pointer
},
119 {"calling_external_function",
120 create_code_calling_external_function
,
121 verify_code_calling_external_function
},
122 {"calling_function_ptr",
123 create_code_calling_function_ptr
,
124 verify_code_calling_function_ptr
},
126 create_code_dot_product
,
127 verify_code_dot_product
},
129 create_code_expressions
,
130 verify_code_expressions
},
132 create_code_factorial
,
133 verify_code_factorial
},
135 create_code_fibonacci
,
136 verify_code_fibonacci
},
138 create_code_functions
,
139 verify_code_functions
},
141 create_code_hello_world
,
142 verify_code_hello_world
},
144 create_code_linked_list
,
145 verify_code_linked_list
},
147 create_code_long_names
,
148 verify_code_long_names
},
150 create_code_quadratic
,
151 verify_code_quadratic
},
153 create_code_nested_loop
,
154 verify_code_nested_loop
},
156 create_code_reading_struct
,
157 verify_code_reading_struct
},
159 create_code_string_literal
,
160 verify_code_string_literal
},
162 create_code_sum_of_squares
,
163 verify_code_sum_of_squares
},
168 create_code_using_global
,
169 verify_code_using_global
},
171 create_code_volatile
,
172 verify_code_volatile
}
175 const int num_testcases
= (sizeof (testcases
) / sizeof (testcases
[0]));
180 const struct testcase
*m_testcase
;
183 static const char *argv0
;
186 run_threaded_test (void *data
)
188 struct thread_data
*thread
= (struct thread_data
*)data
;
191 for (i
= 0; i
< 5; i
++)
193 gcc_jit_context
*ctxt
;
194 gcc_jit_result
*result
;
196 note ("run_threaded_test: %s iteration: %d",
197 thread
->m_testcase
->m_name
, i
);
199 ctxt
= gcc_jit_context_acquire ();
201 set_options (ctxt
, argv0
);
203 thread
->m_testcase
->m_hook_to_create_code (ctxt
, NULL
);
205 result
= gcc_jit_context_compile (ctxt
);
207 thread
->m_testcase
->m_hook_to_verify_code (ctxt
, result
);
209 gcc_jit_context_release (ctxt
);
211 /* Once we're done with the code, this unloads the built .so file: */
212 gcc_jit_result_release (result
);
219 main (int argc
, char **argv
)
223 snprintf (test
, sizeof (test
),
225 extract_progname (argv
[0]));
229 /* The individual testcases are not thread-safe (some have their own
230 global variables), so we have one thread per test-case. */
231 struct thread_data
*threads
=
232 calloc (num_testcases
, sizeof (struct thread_data
));
234 /* Start a thread per test-case. */
235 for (i
= 0; i
< num_testcases
; i
++)
237 struct thread_data
*thread
= &threads
[i
];
238 thread
->m_testcase
= &testcases
[i
];
239 pthread_create (&thread
->m_tid
,
245 /* Wait for all the threads to be done. */
246 for (i
= 0; i
< num_testcases
; i
++)
248 struct thread_data
*thread
= &threads
[i
];
249 (void)pthread_join (thread
->m_tid
, NULL
);