]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | #include <darwintest.h> |
2 | #include <inttypes.h> | |
3 | #include <stdint.h> | |
4 | ||
5 | #include <kperf/kpc.h> | |
6 | ||
7 | T_DECL(fixed_counters, | |
8 | "test that fixed counters return monotonically increasing values", | |
9 | T_META_ASROOT(YES)) | |
10 | { | |
11 | T_SKIP("unimplemented"); | |
12 | } | |
13 | ||
14 | T_DECL(fixed_thread_counters, | |
15 | "test that fixed thread counters return monotonically increasing values", | |
16 | T_META_ASROOT(YES)) | |
17 | { | |
18 | int err; | |
19 | uint32_t ctrs_cnt; | |
20 | uint64_t *ctrs_a; | |
21 | uint64_t *ctrs_b; | |
22 | ||
23 | T_SETUPBEGIN; | |
24 | ||
25 | ctrs_cnt = kpc_get_counter_count(KPC_CLASS_FIXED_MASK); | |
26 | if (ctrs_cnt == 0) { | |
27 | T_SKIP("no fixed counters available"); | |
28 | } | |
29 | T_LOG("device has %" PRIu32 " fixed counters", ctrs_cnt); | |
30 | ||
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), | |
33 | "kpc_set_counting"); | |
34 | T_ASSERT_POSIX_SUCCESS(kpc_set_thread_counting(KPC_CLASS_FIXED_MASK), | |
35 | "kpc_set_thread_counting"); | |
36 | ||
37 | T_SETUPEND; | |
38 | ||
39 | ctrs_a = malloc(ctrs_cnt * sizeof(uint64_t)); | |
40 | T_QUIET; T_ASSERT_NOTNULL(ctrs_a, NULL); | |
41 | ||
42 | err = kpc_get_thread_counters(0, ctrs_cnt, ctrs_a); | |
43 | T_ASSERT_POSIX_SUCCESS(err, "kpc_get_thread_counters"); | |
44 | ||
45 | for (uint32_t i = 0; i < ctrs_cnt; i++) { | |
46 | T_LOG("checking counter %d with value %" PRIu64 " > 0", i, ctrs_a[i]); | |
47 | T_QUIET; | |
48 | T_EXPECT_GT(ctrs_a[i], UINT64_C(0), "counter %d is non-zero", i); | |
49 | } | |
50 | ||
51 | ctrs_b = malloc(ctrs_cnt * sizeof(uint64_t)); | |
52 | T_QUIET; T_ASSERT_NOTNULL(ctrs_b, NULL); | |
53 | ||
54 | err = kpc_get_thread_counters(0, ctrs_cnt, ctrs_b); | |
55 | T_ASSERT_POSIX_SUCCESS(err, "kpc_get_thread_counters"); | |
56 | ||
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]); | |
60 | T_QUIET; | |
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); | |
64 | } | |
65 | ||
66 | free(ctrs_a); | |
67 | free(ctrs_b); | |
68 | } |