]>
git.saurik.com Git - apple/xnu.git/blob - tests/kpc.c
1 #include <darwintest.h>
8 "test that fixed counters return monotonically increasing values",
11 T_SKIP("unimplemented");
14 T_DECL(fixed_thread_counters
,
15 "test that fixed thread counters return monotonically increasing values",
25 ctrs_cnt
= kpc_get_counter_count(KPC_CLASS_FIXED_MASK
);
27 T_SKIP("no fixed counters available");
29 T_LOG("device has %" PRIu32
" fixed counters", ctrs_cnt
);
31 T_QUIET
; T_ASSERT_POSIX_SUCCESS(kpc_force_all_ctrs_set(1), NULL
);
32 T_ASSERT_POSIX_SUCCESS(kpc_set_counting(KPC_CLASS_FIXED_MASK
),
34 T_ASSERT_POSIX_SUCCESS(kpc_set_thread_counting(KPC_CLASS_FIXED_MASK
),
35 "kpc_set_thread_counting");
39 ctrs_a
= malloc(ctrs_cnt
* sizeof(uint64_t));
40 T_QUIET
; T_ASSERT_NOTNULL(ctrs_a
, NULL
);
42 err
= kpc_get_thread_counters(0, ctrs_cnt
, ctrs_a
);
43 T_ASSERT_POSIX_SUCCESS(err
, "kpc_get_thread_counters");
45 for (uint32_t i
= 0; i
< ctrs_cnt
; i
++) {
46 T_LOG("checking counter %d with value %" PRIu64
" > 0", i
, ctrs_a
[i
]);
48 T_EXPECT_GT(ctrs_a
[i
], UINT64_C(0), "counter %d is non-zero", i
);
51 ctrs_b
= malloc(ctrs_cnt
* sizeof(uint64_t));
52 T_QUIET
; T_ASSERT_NOTNULL(ctrs_b
, NULL
);
54 err
= kpc_get_thread_counters(0, ctrs_cnt
, ctrs_b
);
55 T_ASSERT_POSIX_SUCCESS(err
, "kpc_get_thread_counters");
57 for (uint32_t i
= 0; i
< ctrs_cnt
; i
++) {
58 T_LOG("checking counter %d with value %" PRIu64
59 " > previous value %" PRIu64
, i
, ctrs_b
[i
], ctrs_a
[i
]);
61 T_EXPECT_GT(ctrs_b
[i
], UINT64_C(0), "counter %d is non-zero", i
);
62 T_QUIET
; T_EXPECT_LT(ctrs_a
[i
], ctrs_b
[i
],
63 "counter %d is increasing", i
);