/* * SPDX-FileCopyrightText: 2019 Gunar Schorcht * SPDX-License-Identifier: LGPL-2.1-only */ /** * @file * @brief Shell-based test application for heap functions * * @author Gunar Schorcht * */ #include #include #include #include "shell.h" static int malloc_cmd(int argc, char **argv) { static void *ptr = 0; if (argc < 2) { printf("usage: %s \n", argv[0]); return 1; } size_t size = atoi(argv[1]); ptr = malloc(size); printf("allocated %p\n", ptr); return 0; } SHELL_COMMAND(malloc, "malloc ", malloc_cmd); static int free_cmd(int argc, char **argv) { if (argc < 2) { printf("usage: %s returned from malloc, e.g., 0x1234\n", argv[0]); return 1; } uintptr_t p = strtoul(argv[1], NULL, 16); void *ptr = (void *)p; printf("freeing %p\n", ptr); free(ptr); return 0; } SHELL_COMMAND(free, "free returned from malloc, e.g., 0x1234", free_cmd); int main(void) { puts("Shell-based test application for heap functions.\n" "Use the 'help' command to get more information on how to use it."); /* define buffer to be used by the shell */ char line_buf[SHELL_DEFAULT_BUFSIZE]; /* define own shell commands */ shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; }