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