[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 2/2] add mach_host tests
From: |
Luca Dariz |
Subject: |
[RFC PATCH 2/2] add mach_host tests |
Date: |
Thu, 19 Oct 2023 20:57:47 +0200 |
---
tests/Makefrag.am | 4 +++-
tests/test-mach_host.c | 54 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 tests/test-mach_host.c
diff --git a/tests/Makefrag.am b/tests/Makefrag.am
index c16326e8..cb946bc7 100644
--- a/tests/Makefrag.am
+++ b/tests/Makefrag.am
@@ -146,6 +146,8 @@ debug-%: test-%.iso
TESTS += \
- tests/test-hello
+ tests/test-hello \
+ tests/test-mach_host
+
endif # !PLATFORM_xen
diff --git a/tests/test-mach_host.c b/tests/test-mach_host.c
new file mode 100644
index 00000000..2e9e6989
--- /dev/null
+++ b/tests/test-mach_host.c
@@ -0,0 +1,54 @@
+
+#include <testlib.h>
+
+#include <mach_host.user.h>
+
+void test_kernel_version()
+{
+ int err;
+ kernel_version_t kver;
+ err = host_get_kernel_version(mach_host_self(), kver);
+ ASSERT_RET(err, "host_kernel_info");
+ printf("kernel version: %s\n", kver);
+}
+
+void test_host_info()
+{
+ int err;
+ mach_msg_type_number_t count;
+ mach_port_t thishost = mach_host_self();
+
+ host_basic_info_data_t binfo;
+ count = HOST_BASIC_INFO_COUNT;
+ err = host_info(thishost, HOST_BASIC_INFO, (host_info_t)&binfo, &count);
+ ASSERT_RET(err, "host_basic_info");
+ ASSERT(count == HOST_BASIC_INFO_COUNT);
+
+ const int maxcpus = 255;
+ int proc_slots[maxcpus];
+ count = maxcpus;
+ err = host_info(thishost, HOST_PROCESSOR_SLOTS, (host_info_t)&proc_slots,
&count);
+ ASSERT_RET(err, "host_processor_slots");
+ ASSERT((1 <= count) && (count <= maxcpus));
+
+ host_sched_info_data_t sinfo;
+ count = HOST_SCHED_INFO_COUNT;
+ err = host_info(thishost, HOST_SCHED_INFO, (host_info_t)&sinfo, &count);
+ ASSERT_RET(err, "host_sched_info");
+ ASSERT(count == HOST_SCHED_INFO_COUNT);
+
+ host_load_info_data_t linfo;
+ count = HOST_LOAD_INFO_COUNT;
+ err = host_info(thishost, HOST_LOAD_INFO, (host_info_t)&linfo, &count);
+ ASSERT_RET(err, "host_load_info");
+ ASSERT(count == HOST_LOAD_INFO_COUNT);
+}
+
+// TODO processor sets
+
+int main(int argc, char *argv[], int envc, char *envp[])
+{
+ test_kernel_version();
+ test_host_info();
+ return 0;
+}
--
2.39.2