The ROme OpTimistic Simulator
3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
test_main.c
Go to the documentation of this file.
1
11
#include <
test.h
>
12
13
#include <
arch/thread.h
>
14
16
struct
stub_arguments
{
18
int (*
test_fnc
)(void);
20
rid_t
tid
;
21
};
22
28
static
thr_ret_t THREAD_CALL_CONV
test_run_stub
(
void
*arg)
29
{
30
struct
stub_arguments
*args = arg;
31
rid
= args->
tid
;
32
int
ret = args->
test_fnc
();
33
return
ret ? THREAD_RET_FAILURE : THREAD_RET_SUCCESS;
34
}
35
36
int
main
(
int
argc,
char
**argv)
37
{
38
(void)argc; (void)argv;
39
int
ret = 0;
40
thr_id_t threads[
test_config
.
threads_count
];
41
struct
stub_arguments
args[
test_config
.threads_count];
42
43
if
(
test_config
.
test_init_fnc
&& (ret =
test_config
.
test_init_fnc
())) {
44
printf(
"Test initialization failed with code %d\n"
, ret);
45
return
ret;
46
}
47
48
for
(
unsigned
i = 0; i <
test_config
.
threads_count
; ++i) {
49
args[i].
test_fnc
=
test_config
.
test_fnc
;
50
args[i].
tid
= i;
51
if
(
thread_start
(&threads[i],
test_run_stub
, &args[i]))
52
return
TEST_BAD_FAIL_EXIT_CODE
;
53
}
54
55
for
(
unsigned
i = 0; i <
test_config
.
threads_count
; ++i) {
56
thr_ret_t thr_ret;
57
if
(
thread_wait
(threads[i], &thr_ret))
58
return
TEST_BAD_FAIL_EXIT_CODE
;
59
60
if
(thr_ret) {
61
printf(
"Thread %u failed the test\n"
, i);
62
return
-1;
63
}
64
}
65
66
if
(
test_config
.
test_fini_fnc
&& (ret =
test_config
.
test_fini_fnc
())) {
67
printf(
"Test finalization failed with code %d\n"
, ret);
68
return
ret;
69
}
70
71
return
0;
72
}
stub_arguments::test_fnc
int(* test_fnc)(void)
The actual entry point defined by the test configuration.
Definition:
test_main.c:18
TEST_BAD_FAIL_EXIT_CODE
#define TEST_BAD_FAIL_EXIT_CODE
The exit code of tests when something fails horribly.
Definition:
test.h:19
rid_t
unsigned rid_t
Used to identify in a node the computing resources (threads at the moment)
Definition:
core.h:77
test_config::test_init_fnc
int(* test_init_fnc)(void)
The test initialization function.
Definition:
test.h:25
test_run_stub
static thr_ret_t THREAD_CALL_CONV test_run_stub(void *arg)
The entry point of the test threads.
Definition:
test_main.c:28
test_config::test_fini_fnc
int(* test_fini_fnc)(void)
The test finalization function.
Definition:
test.h:28
thread_wait
int thread_wait(thr_id_t thr, thr_ret_t *ret)
Wait for specified thread to complete execution.
test_config
A complete test configuration.
Definition:
test.h:22
rid
__thread rid_t rid
The identifier of the thread.
Definition:
core.c:16
test.h
Test framework header.
stub_arguments::tid
rid_t tid
The thread identifier which is set upon thread startup.
Definition:
test_main.c:20
test_config::test_fnc
int(* test_fnc)(void)
The core test function.
Definition:
test.h:31
thread_start
int thread_start(thr_id_t *thr_p, thr_run_fnc t_fnc, void *t_fnc_arg)
Creates a thread.
test_config::threads_count
unsigned threads_count
test_fnc is executed with that many cores
Definition:
test.h:33
main
int main(int argc, char **argv)
The main entry point of the custom compiler.
Definition:
test_main.c:36
stub_arguments
The arguments passed to test threads.
Definition:
test_main.c:16
thread.h
Generic architecture management facilities.
test
test_main.c
Generated by
1.8.17