Il 29/12/23 14:44, Samuel Thibault ha scritto:
Luca Dariz, le jeu. 28 déc. 2023 20:42:50 +0100, a ecrit:
---
tests/test-mach_host.c | 54 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+)
create mode 100644 tests/test-mach_host.c
diff --git a/tests/test-mach_host.c b/tests/test-mach_host.c
new file mode 100644
index 00000000..99fc4aca
--- /dev/null
+++ b/tests/test-mach_host.c
Such files are also non-trivial, and thus deserve a copyright header too.
@@ -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, "");
Perhaps also make some basic checks, such as binfo.avail_cpus <=
binfo.max_cpus.
ok
+ 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, "");
Here you can probably check that the min_* values is smaller than e.g.
1000, to catch randomly-filled values.
ok
Also, it would be useful to compile the tests with
-ftrivial-auto-var-init=pattern so as to fill the structures with random
values before making the gnumach calls.
good idea, I didn't know this feature.
Luca