6 int test__thread_mg_share(void)
8 struct machines machines
;
9 struct machine
*machine
;
12 struct thread
*leader
;
13 struct thread
*t1
, *t2
, *t3
;
14 struct map_groups
*mg
;
17 struct thread
*other
, *other_leader
;
18 struct map_groups
*other_mg
;
21 * This test create 2 processes abstractions (struct thread)
22 * with several threads and checks they properly share and
23 * maintain map groups info (struct map_groups).
25 * thread group (pid: 0, tids: 0, 1, 2, 3)
26 * other group (pid: 4, tids: 4, 5)
29 machines__init(&machines
);
30 machine
= &machines
.host
;
32 /* create process with 4 threads */
33 leader
= machine__findnew_thread(machine
, 0, 0);
34 t1
= machine__findnew_thread(machine
, 0, 1);
35 t2
= machine__findnew_thread(machine
, 0, 2);
36 t3
= machine__findnew_thread(machine
, 0, 3);
38 /* and create 1 separated process, without thread leader */
39 other
= machine__findnew_thread(machine
, 4, 5);
41 TEST_ASSERT_VAL("failed to create threads",
42 leader
&& t1
&& t2
&& t3
&& other
);
45 TEST_ASSERT_VAL("wrong refcnt", mg
->refcnt
== 4);
47 /* test the map groups pointer is shared */
48 TEST_ASSERT_VAL("map groups don't match", mg
== t1
->mg
);
49 TEST_ASSERT_VAL("map groups don't match", mg
== t2
->mg
);
50 TEST_ASSERT_VAL("map groups don't match", mg
== t3
->mg
);
53 * Verify the other leader was created by previous call.
54 * It should have shared map groups with no change in
57 other_leader
= machine__find_thread(machine
, 4, 4);
58 TEST_ASSERT_VAL("failed to find other leader", other_leader
);
61 TEST_ASSERT_VAL("wrong refcnt", other_mg
->refcnt
== 2);
63 TEST_ASSERT_VAL("map groups don't match", other_mg
== other_leader
->mg
);
65 /* release thread group */
66 thread__delete(leader
);
67 TEST_ASSERT_VAL("wrong refcnt", mg
->refcnt
== 3);
70 TEST_ASSERT_VAL("wrong refcnt", mg
->refcnt
== 2);
73 TEST_ASSERT_VAL("wrong refcnt", mg
->refcnt
== 1);
77 /* release other group */
78 thread__delete(other_leader
);
79 TEST_ASSERT_VAL("wrong refcnt", other_mg
->refcnt
== 1);
81 thread__delete(other
);
84 * Cannot call machine__delete_threads(machine) now,
85 * because we've already released all the threads.
88 machines__exit(&machines
);