]> git.saurik.com Git - apple/xnu.git/blame - tests/verify_kalloc_config.c
xnu-4903.241.1.tar.gz
[apple/xnu.git] / tests / verify_kalloc_config.c
CommitLineData
a39ff7e2
A
1#include <string.h>
2#include <stdlib.h>
3#include <mach/mach.h>
4#include <mach_debug/mach_debug.h>
5#include <darwintest.h>
6
7T_GLOBAL_META(
8 T_META_NAMESPACE("xnu.vm"),
9 T_META_CHECK_LEAKS(false)
10);
11
12static void run_test(void);
13
14static void run_test(void)
15{
16 kern_return_t kr;
17 uint64_t size, i;
18 mach_zone_name_t *name = NULL;
19 unsigned int nameCnt = 0;
20 mach_zone_info_t *info = NULL;
21 unsigned int infoCnt = 0;
22 mach_memory_info_t *wiredInfo = NULL;
23 unsigned int wiredInfoCnt = 0;
24 const char kalloc_str[] = "kalloc.";
25
26 kr = mach_memory_info(mach_host_self(),
27 &name, &nameCnt, &info, &infoCnt,
28 &wiredInfo, &wiredInfoCnt);
29 T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "mach_memory_info");
30 T_QUIET; T_ASSERT_EQ(nameCnt, infoCnt, "zone name and info counts don't match");
31
32 /* Match the names of the kalloc zones against their element sizes. */
33 for (i = 0; i < nameCnt; i++) {
34 if (strncmp(name[i].mzn_name, kalloc_str, strlen(kalloc_str)) == 0) {
35 size = strtoul(&(name[i].mzn_name[strlen(kalloc_str)]), NULL, 10);
36 T_LOG("ZONE NAME: %-25s ELEMENT SIZE: %llu", name[i].mzn_name, size);
37 T_QUIET; T_ASSERT_EQ(size, info[i].mzi_elem_size, "kalloc zone name and element size don't match");
38 }
39 }
40
41 if ((name != NULL) && (nameCnt != 0)) {
42 kr = vm_deallocate(mach_task_self(), (vm_address_t) name,
43 (vm_size_t) (nameCnt * sizeof *name));
44 T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "vm_deallocate name");
45 }
46
47 if ((info != NULL) && (infoCnt != 0)) {
48 kr = vm_deallocate(mach_task_self(), (vm_address_t) info,
49 (vm_size_t) (infoCnt * sizeof *info));
50 T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "vm_deallocate info");
51 }
52
53 if ((wiredInfo != NULL) && (wiredInfoCnt != 0)) {
54 kr = vm_deallocate(mach_task_self(), (vm_address_t) wiredInfo,
55 (vm_size_t) (wiredInfoCnt * sizeof *wiredInfo));
56 T_QUIET; T_ASSERT_MACH_SUCCESS(kr, "vm_deallocate wiredInfo");
57 }
58
59 T_END;
60}
61
62T_DECL( verify_kalloc_config,
63 "verifies that the kalloc zones are configured correctly",
64 T_META_ASROOT(true))
65{
66 run_test();
67}
68