Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion embedded_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* https://en.wikipedia.org/wiki/ANSI_escape_code
*/

#include <stdio.h>
#include <string.h>

#include "embedded_cli.h"
Expand Down
1 change: 1 addition & 0 deletions embedded_cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define EMBEDDED_CLI

#include <stdbool.h>
#include <stddef.h>

#ifndef EMBEDDED_CLI_MAX_LINE
/**
Expand Down
2 changes: 1 addition & 1 deletion examples/posix_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 63 additions & 0 deletions tests/sizes.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF > mock_incl/string.h
#include <stddef.h>
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 <<EOF > 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