1 #include <darwintest.h>
3 #include <mach/coalition.h>
5 #include <sys/coalition.h>
6 #include <sys/sysctl.h>
10 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
13 skip_if_monotonic_unsupported(void)
17 size_t supported_size
= sizeof(supported
);
19 r
= sysctlbyname("kern.monotonic.supported", &supported
, &supported_size
,
23 T_SKIP("could not find \"kern.monotonic.supported\" sysctl");
27 T_SKIP("monotonic is not supported on this platform");
31 T_DECL(coalition_resource_info_counters
,
32 "ensure that coalition resource info produces valid counter data")
34 skip_if_monotonic_unsupported();
36 struct proc_pidcoalitioninfo idinfo
= {};
37 int ret
= proc_pidinfo(getpid(), PROC_PIDCOALITIONINFO
, 0,
38 &idinfo
, sizeof(idinfo
));
39 T_ASSERT_POSIX_SUCCESS(ret
, "proc_pidinfo(... PROC_PIDCOALITIONINFO ...)");
41 uint64_t resid
= idinfo
.coalition_id
[COALITION_TYPE_RESOURCE
];
43 struct coalition_resource_usage coalusage
[2] = {};
44 ret
= coalition_info_resource_usage(resid
, &coalusage
[0],
45 sizeof(coalusage
[0]));
46 T_ASSERT_POSIX_SUCCESS(ret
, "coalition_info_resource_usage()");
47 T_EXPECT_GT(coalusage
[0].cpu_instructions
, UINT64_C(0),
48 "instruction count is non-zero");
49 T_EXPECT_GT(coalusage
[0].cpu_cycles
, UINT64_C(0),
50 "cycle count is non-zero");
54 ret
= coalition_info_resource_usage(resid
, &coalusage
[1],
55 sizeof(coalusage
[1]));
56 T_ASSERT_POSIX_SUCCESS(ret
, "coalition_info_resource_usage()");
58 T_EXPECT_GE(coalusage
[1].cpu_instructions
, coalusage
[0].cpu_instructions
,
59 "instruction count is monotonically increasing (+%" PRIu64
")",
60 coalusage
[1].cpu_instructions
- coalusage
[0].cpu_instructions
);
61 T_EXPECT_GE(coalusage
[1].cpu_cycles
, coalusage
[0].cpu_cycles
,
62 "cycle count is monotonically increasing (+%" PRIu64
")",
63 coalusage
[1].cpu_cycles
- coalusage
[0].cpu_cycles
);