diff --git a/embedded_cli.c b/embedded_cli.c index a594a39..adcd1b5 100644 --- a/embedded_cli.c +++ b/embedded_cli.c @@ -4,7 +4,6 @@ * https://en.wikipedia.org/wiki/ANSI_escape_code */ -#include #include #include "embedded_cli.h" diff --git a/embedded_cli.h b/embedded_cli.h index c2bc5f6..49c33f9 100644 --- a/embedded_cli.h +++ b/embedded_cli.h @@ -2,6 +2,7 @@ #define EMBEDDED_CLI #include +#include #ifndef EMBEDDED_CLI_MAX_LINE /** diff --git a/examples/posix_demo.c b/examples/posix_demo.c index e500faf..57cc9a8 100644 --- a/examples/posix_demo.c +++ b/examples/posix_demo.c @@ -95,7 +95,7 @@ int main(void) cli_argc = embedded_cli_argc(&cli, &cli_argv); printf("Got %d args\n", cli_argc); for (int i = 0; i < cli_argc; i++) { - printf("Arg %d/%d: [%lu bytes] '%s'\n", i, cli_argc, + printf("Arg %d/%d: [%zu bytes] '%s'\n", i, cli_argc, strlen(cli_argv[i]), cli_argv[i]); } done = cli_argc >= 1 && (strcmp(cli_argv[0], "quit") == 0); diff --git a/tests/sizes.sh b/tests/sizes.sh new file mode 100755 index 0000000..3edceb6 --- /dev/null +++ b/tests/sizes.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# Configuration +CC=arm-none-eabi-gcc +SIZE=arm-none-eabi-size +NM=arm-none-eabi-nm + +# Use -ffreestanding and provide minimal headers to avoid toolchain dependencies +CFLAGS="-mthumb -mcpu=cortex-m3 -Os -I. -std=c99 -ffreestanding" + +# Create a mock include directory +mkdir -p mock_incl + +cat < mock_incl/string.h +#include +void *memset(void *s, int c, size_t n); +char *strncpy(char *dest, const char *src, size_t n); +size_t strlen(const char *s); +int strcmp(const char *s1, const char *s2); +void *memcpy(void *dest, const void *src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +char *strstr(const char *haystack, const char *needle); +EOF + +# Compile embedded_cli.c to object file +$CC $CFLAGS -Imock_incl -c embedded_cli.c -o embedded_cli.o + +if [ $? -ne 0 ]; then + echo "Error: Compilation of embedded_cli.c failed" + rm -rf mock_incl + exit 1 +fi + +echo "Binary sizes (ARM Thumb-2, -Os):" +$SIZE embedded_cli.o + +# Calculate size of the structure +cat < struct_size.c +#include "embedded_cli.h" +struct embedded_cli cli; +EOF + +$CC $CFLAGS -Imock_incl -c struct_size.c -o struct_size.o +if [ $? -ne 0 ]; then + echo "Error: Compilation of struct_size.c failed" + rm -rf mock_incl embedded_cli.o struct_size.c + exit 1 +fi + +# Get size using nm +STRUCT_SIZE_HEX=$($NM -S struct_size.o | grep " cli" | awk '{print $2}') + +if [ -z "$STRUCT_SIZE_HEX" ]; then + echo "Error: Could not find 'cli' symbol in object file" +else + # Convert hex size from nm to decimal + STRUCT_SIZE_DECIMAL=$((16#$STRUCT_SIZE_HEX)) + echo "" + echo "Size of struct embedded_cli: $STRUCT_SIZE_DECIMAL bytes" +fi + +# Cleanup +rm -rf embedded_cli.o struct_size.c struct_size.o mock_incl