From 2eff9a99b7b05c0fce0d9a76babbf712dc1aceb0 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Mon, 14 Aug 2023 11:16:33 -0700 Subject: [PATCH] test(maitake): add more stuff to task size test (#459) This makes the test for printing task sizes a bit fancier. --- maitake/src/task/tests/alloc_tests.rs | 62 +++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/maitake/src/task/tests/alloc_tests.rs b/maitake/src/task/tests/alloc_tests.rs index 8c663330..2a54f683 100644 --- a/maitake/src/task/tests/alloc_tests.rs +++ b/maitake/src/task/tests/alloc_tests.rs @@ -40,22 +40,68 @@ fn task_is_valid_for_casts() { /// This test just prints the size (in bytes) of an empty task struct. #[test] fn empty_task_size() { + use core::{ + any::type_name, + mem::{size_of, size_of_val}, + }; + type Future = futures::future::Ready<()>; type EmptyTask = Task; + println!( - "{}: {}B", - core::any::type_name::(), - core::mem::size_of::(), + "---- task size (in {} mode) ----\n", + if cfg!(debug_assertions) { + "debug " + } else { + "release" + } ); + println!("{}: {}B", type_name::(), size_of::(),); + println!("{}: {}B", type_name::(), size_of::(),); println!( - "{}: {}B", - core::any::type_name::(), - core::mem::size_of::(), + "task size: {}B", + size_of::() - size_of::() ); + + let task = Task::::new(futures::future::ready(())); + println!("\nTask {{ // {}B", size_of_val(&task)); println!( - "task size: {}B", - core::mem::size_of::() - core::mem::size_of::() + " schedulable: Schedulable {{ // {}B", + size_of_val(&task.schedulable) + ); + println!( + " header: {{ // {}B", + size_of_val(&task.schedulable.header) + ); + println!( + " run_queue: {}B", + size_of_val(&task.schedulable.header.run_queue) + ); + println!( + " state: {}B", + size_of_val(&task.schedulable.header.state) + ); + println!( + " vtable: {}B", + size_of_val(&task.schedulable.header.vtable) + ); + println!( + " id: {}B", + size_of_val(&task.schedulable.header.id) + ); + println!( + " span: {}B", + size_of_val(&task.schedulable.header.span) + ); + println!(" }}"); + println!( + " scheduler: {}B", + size_of_val(&task.schedulable.scheduler) ); + println!(" }}"); + println!(" inner: {}B", size_of_val(&task.inner)); + println!(" join_waker: {}B", size_of_val(&task.join_waker)); + println!("}}"); } #[test]