/* * Copyright (C) 2019 Gunar Schorcht * * 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. */ /** * @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; } 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; } unsigned int p = strtoul(argv[1], NULL, 16); void *ptr = (void *)p; printf("freeing %p\n", ptr); free(ptr); return 0; } static const shell_command_t shell_commands[] = { { "malloc", "malloc ", malloc_cmd }, { "free", "free returned from malloc, e.g., 0x1234", free_cmd }, { NULL, NULL, NULL } }; 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(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); return 0; }