From c644b90762e9cdda8b5a925c5f41577020055f4e Mon Sep 17 00:00:00 2001 From: Luca Dariz Date: Thu, 11 Jan 2024 22:09:06 +0100 Subject: add basic task tests Message-ID: <20240111210907.419689-10-luca@orpolo.org> --- tests/test-task.c | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/user-qemu.mk | 3 +- 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 tests/test-task.c (limited to 'tests') diff --git a/tests/test-task.c b/tests/test-task.c new file mode 100644 index 00000000..cbc75e23 --- /dev/null +++ b/tests/test-task.c @@ -0,0 +1,171 @@ +/* + * Copyright (C) 2024 Free Software Foundation + * + * This program is free software ; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation ; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY ; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with the program ; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + + +void test_task() +{ + mach_port_t ourtask = mach_task_self(); + mach_msg_type_number_t count; + int err; + + struct task_basic_info binfo; + count = TASK_BASIC_INFO_COUNT; + err = task_info(ourtask, TASK_BASIC_INFO, (task_info_t)&binfo, &count); + ASSERT_RET(err, "TASK_BASIC_INFO"); + ASSERT(binfo.virtual_size > binfo.resident_size, "wrong memory counters"); + + struct task_events_info einfo; + count = TASK_EVENTS_INFO_COUNT; + err = task_info(ourtask, TASK_EVENTS_INFO, (task_info_t)&einfo, &count); + ASSERT_RET(err, "TASK_EVENTS_INFO"); + printf("msgs sent %llu received %llu\n", + einfo.messages_sent, einfo.messages_received); + + struct task_thread_times_info ttinfo; + count = TASK_THREAD_TIMES_INFO_COUNT; + err = task_info(ourtask, TASK_THREAD_TIMES_INFO, (task_info_t)&ttinfo, &count); + ASSERT_RET(err, "TASK_THREAD_TIMES_INFO"); + printf("run user %lld system %lld\n", + ttinfo.user_time64.seconds, ttinfo.user_time64.nanoseconds); +} + + +void dummy_thread(void *arg) +{ + printf("started dummy thread\n"); + while (1) + ; +} + +void check_threads(thread_t *threads, mach_msg_type_number_t nthreads) +{ + for (int tid=0; tid