diff --git a/tests/bench_sizeof_coretypes/Makefile b/tests/bench_sizeof_coretypes/Makefile new file mode 100644 index 0000000000..c3cb1b3e01 --- /dev/null +++ b/tests/bench_sizeof_coretypes/Makefile @@ -0,0 +1,17 @@ +include ../Makefile.tests_common + +# Modules that will have an impact on the size of the TCB (thread_t): +# +# disabled by default, enable on demand: +ifneq (,$(USE_FLAGS)) + USEMODULE += core_thread_flags +endif +# +# enabled by default, disable on demand: +ifneq (,$(NO_MSG)) + DISABLE_MODULE += core_msg +endif + +TEST_ON_CI_WHITELIST += all + +include $(RIOTBASE)/Makefile.include diff --git a/tests/bench_sizeof_coretypes/README.md b/tests/bench_sizeof_coretypes/README.md new file mode 100644 index 0000000000..6e921bb70f --- /dev/null +++ b/tests/bench_sizeof_coretypes/README.md @@ -0,0 +1,6 @@ +# Measure Size of Core Types + +This application simply list the size of all significant types defined by the +RIOT core. Its purpose is to provide a base for tracking the memory requirements +of those types over time and to provide a simple way to judge the impacts of +future core changes on memory usage. diff --git a/tests/bench_sizeof_coretypes/main.c b/tests/bench_sizeof_coretypes/main.c new file mode 100644 index 0000000000..eaf5f07b0d --- /dev/null +++ b/tests/bench_sizeof_coretypes/main.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2014 René Kijewski + * 2018 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Print size of core types + * + * @author René Kijewski + * @author Hauke Petersen + * + * @} + */ + +#include + +#include "cib.h" +#include "clist.h" +#include "panic.h" +#include "kernel_types.h" +#include "list.h" +#include "mbox.h" +#include "msg.h" +#include "mutex.h" +#include "priority_queue.h" +#include "ringbuffer.h" +#include "rmutex.h" +#ifdef MODULE_CORE_THREAD_FLAGS +#include "thread_flags.h" +#endif +#include "thread.h" + + +#define P(NAME) printf(" tcb->%-11s %3u %3u\n", #NAME, \ + (unsigned)sizeof(((thread_t *) 0)->NAME), \ + (unsigned)offsetof(thread_t, NAME)) + +int main(void) +{ + puts("Sizeof RIOT core types\n"); + + puts(" size"); + + printf("sizeof(cib_t): %3u\n", + (unsigned)sizeof(cib_t)); + printf("sizeof(clist_node_t): %3u\n", + (unsigned)sizeof(clist_node_t)); + printf("sizeof(core_panic_t): %3u\n", + (unsigned)sizeof(core_panic_t)); + printf("sizeof(kernel_pid_t): %3u\n", + (unsigned)sizeof(kernel_pid_t)); + printf("sizeof(list_node_t): %3u\n", + (unsigned)sizeof(list_node_t)); + printf("sizeof(mbox_t): %3u\n", + (unsigned)sizeof(mbox_t)); +#ifdef MODULE_CORE_MSG + printf("sizeof(msg_t): %3u\n", + (unsigned)sizeof(msg_t)); +#else + puts("sizeof(msg_t): 0 (not enabled)"); +#endif + printf("sizeof(mutex_t): %3u\n", + (unsigned)sizeof(mutex_t)); + printf("sizeof(priority_queue_node_t): %3u\n", + (unsigned)sizeof(priority_queue_node_t)); + printf("sizeof(priority_queue_t): %3u\n", + (unsigned)sizeof(priority_queue_t)); + printf("sizeof(ringbuffer_t): %3u\n", + (unsigned)sizeof(ringbuffer_t)); + printf("sizeof(rmutex_t): %3u\n", + (unsigned)sizeof(rmutex_t)); +#ifdef MODULE_CORE_THREAD_FLAGS + printf("sizeof(thread_flags_t): %3u\n", + (unsigned)sizeof(thread_flags_t)); +#else + puts("sizeof(thread_flags_t): 0 (not enabled)"); +#endif + printf("\nTCB (thread_t) details: size offset\n"); + printf("sizeof(thread_t): %3u -\n", + (unsigned)sizeof(thread_t)); + P(sp); + P(status); + P(priority); + P(pid); +#ifdef MODULE_CORE_THREAD_FLAGS + P(flags); +#endif + P(rq_entry); +#ifdef MODULE_CORE_MSG + P(wait_data); + P(msg_waiters); + P(msg_queue); + P(msg_array); +#endif +#ifdef DEVELHELP + P(name); +#endif +#if defined(DEVELHELP) || defined(SCHED_TEST_STACK) || defined(MODULE_MPU_STACK_GUARD) + P(stack_start); +#endif + + puts("\n[SUCCESS]"); + return 0; +} diff --git a/tests/bench_sizeof_coretypes/tests/01-run.py b/tests/bench_sizeof_coretypes/tests/01-run.py new file mode 100755 index 0000000000..b6b4d4d367 --- /dev/null +++ b/tests/bench_sizeof_coretypes/tests/01-run.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2018 Freie Universität Berlin +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import os +import sys + + +def testfunc(child): + child.expect_exact('[SUCCESS]') + + +if __name__ == "__main__": + sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) + from testrunner import run + sys.exit(run(testfunc))