jwgrenning / cpputest-starter-project

gcc cpputest starter project, with instructions to help get your legacy code into cpputest for the first time
MIT License
111 stars 56 forks source link

Getting the starter kit to work for 32bit executable #11

Open alastairtree opened 2 years ago

alastairtree commented 2 years ago

Thanks for the awesome tools!

I am targeting a 32bit embedded system and so wanted my tests to have a similar setup. I spent a while trying to get this starter project and cpputest to work together but in 32bit rather than 64.

I managed it by changing the docker image from gcc to debian with the dockerfile below, reconfiguring cpputest for 32bit and installing gcc and multilib myself:

FROM debian:bullseye

RUN apt-get update \
 && apt-get install --assume-yes --no-install-recommends --quiet \
         build-essential \
         gcc-multilib \
         g++-multilib \
         git \
         autoconf \
         automake \
         libtool

RUN apt-get install --assume-yes --reinstall ca-certificates

WORKDIR /home/cpputest

RUN git clone --depth 1 --branch v4.0 https://github.com/cpputest/cpputest.git .
RUN autoreconf . -i
RUN ./configure CFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 --build=x86_64-pc-linux-gnu --host=i686-pc-linux-gnu
RUN make install

ENV CPPUTEST_HOME=/home/cpputest

WORKDIR /home/legacy-build
RUN git clone https://github.com/jwgrenning/legacy-build.git .
RUN git submodule update --init
RUN bash test/all-tests.sh

WORKDIR /home/src

In the makefile I needed to pass the appropriate m32 args to the compiler and linker via the cpputest make variables:

CPPUTEST_CFLAGS += -m32
CPPUTEST_LDFLAGS += -m32
CPPUTEST_CXXFLAGS += -m32
CPPUTEST_CPPFLAGS += -m32

Is there an easier way I am missing? If not then maybe this can be turned into some docs somewhere and might help others.

Thanks