]> Git Repo - linux.git/blob - tools/perf/tests/thread-mg-share.c
selinux: Remove security_ops extern
[linux.git] / tools / perf / tests / thread-mg-share.c
1 #include "tests.h"
2 #include "machine.h"
3 #include "thread.h"
4 #include "map.h"
5
6 int test__thread_mg_share(void)
7 {
8         struct machines machines;
9         struct machine *machine;
10
11         /* thread group */
12         struct thread *leader;
13         struct thread *t1, *t2, *t3;
14         struct map_groups *mg;
15
16         /* other process */
17         struct thread *other, *other_leader;
18         struct map_groups *other_mg;
19
20         /*
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).
24          *
25          * thread group (pid: 0, tids: 0, 1, 2, 3)
26          * other  group (pid: 4, tids: 4, 5)
27         */
28
29         machines__init(&machines);
30         machine = &machines.host;
31
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);
37
38         /* and create 1 separated process, without thread leader */
39         other  = machine__findnew_thread(machine, 4, 5);
40
41         TEST_ASSERT_VAL("failed to create threads",
42                         leader && t1 && t2 && t3 && other);
43
44         mg = leader->mg;
45         TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 4);
46
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);
51
52         /*
53          * Verify the other leader was created by previous call.
54          * It should have shared map groups with no change in
55          * refcnt.
56          */
57         other_leader = machine__find_thread(machine, 4, 4);
58         TEST_ASSERT_VAL("failed to find other leader", other_leader);
59
60         other_mg = other->mg;
61         TEST_ASSERT_VAL("wrong refcnt", other_mg->refcnt == 2);
62
63         TEST_ASSERT_VAL("map groups don't match", other_mg == other_leader->mg);
64
65         /* release thread group */
66         thread__delete(leader);
67         TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 3);
68
69         thread__delete(t1);
70         TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 2);
71
72         thread__delete(t2);
73         TEST_ASSERT_VAL("wrong refcnt", mg->refcnt == 1);
74
75         thread__delete(t3);
76
77         /* release other group  */
78         thread__delete(other_leader);
79         TEST_ASSERT_VAL("wrong refcnt", other_mg->refcnt == 1);
80
81         thread__delete(other);
82
83         /*
84          * Cannot call machine__delete_threads(machine) now,
85          * because we've already released all the threads.
86          */
87
88         machines__exit(&machines);
89         return 0;
90 }
This page took 0.037024 seconds and 4 git commands to generate.