Pull in gtest for unit tests.

This commit is contained in:
Christian Speckner 2024-07-11 00:57:16 +02:00
parent a606d294a4
commit 2fff5ec118
6 changed files with 104 additions and 2 deletions

2
.gitignore vendored
View File

@ -10,7 +10,9 @@ src/**/*.tlog
out out
out.pgo out.pgo
out.pgen out.pgen
out.test
stella stella
stella-test
stella-pgo stella-pgo
stella-pgo-generate stella-pgo-generate
*.diff *.diff

View File

@ -47,17 +47,38 @@ else
CFLAGS:= -O2 CFLAGS:= -O2
endif endif
ifndef CXXFLAGS_TEST
CXXFLAGS_TEST := $(CXXFLAGS)
endif
ifndef CFLAGS_TEST
CFLAGS_TEST := $(CFLAGS)
endif
ifndef LDFLAGS_TEST
LDFLAGS_TEST := $(LDFLAGS)
endif
CXXFLAGS+= -Wall -Wextra -Wno-unused-parameter CXXFLAGS+= -Wall -Wextra -Wno-unused-parameter
CFLAGS+= -Wall -Wextra -Wno-unused-parameter CFLAGS+= -Wall -Wextra -Wno-unused-parameter
CXXFLAGS_TEST+= -Wall -Wextra -Wno-unused-parameter
CFLAGS_TEST+= -Wall -Wextra -Wno-unused-parameter
ifdef HAVE_GCC ifdef HAVE_GCC
CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20 CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20
CFLAGS+= -Wno-multichar -Wunused CFLAGS+= -Wno-multichar -Wunused
CXXFLAGS_TEST+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20
CFLAGS_TEST+= -Wno-multichar -Wunused
endif endif
ifdef HAVE_CLANG ifdef HAVE_CLANG
CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20 CXXFLAGS+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20
CFLAGS+= -Wno-multichar -Wunused CFLAGS+= -Wno-multichar -Wunused
CXXFLAGS_TEST+= -Wno-multichar -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -std=c++20
CFLAGS_TEST+= -Wno-multichar -Wunused
endif endif
ifdef CLANG_WARNINGS ifdef CLANG_WARNINGS
@ -70,6 +91,9 @@ ifdef CLANG_WARNINGS
CXXFLAGS+= $(EXTRA_WARN) CXXFLAGS+= $(EXTRA_WARN)
CFLAGS+= $(EXTRA_WARN) CFLAGS+= $(EXTRA_WARN)
CXXFLAGS_TEST+= $(EXTRA_WARN)
CFLAGS_TEST+= $(EXTRA_WARN)
endif endif
ifdef PROFILE ifdef PROFILE
@ -108,12 +132,14 @@ ifdef STELLA_BUILD_ROOT
else else
OBJECT_ROOT := out OBJECT_ROOT := out
endif endif
OBJECT_ROOT_TEST := out.test
OBJECT_ROOT_PROFILE_GENERERATE := out.pgen OBJECT_ROOT_PROFILE_GENERERATE := out.pgen
OBJECT_ROOT_PROFILE_USE := out.pgo OBJECT_ROOT_PROFILE_USE := out.pgo
EXECUTABLE := stella$(EXEEXT) EXECUTABLE := stella$(EXEEXT)
EXECUTABLE_PROFILE_GENERATE := stella-pgo-generate$(EXEEXT) EXECUTABLE_PROFILE_GENERATE := stella-pgo-generate$(EXEEXT)
EXECUTABLE_PROFILE_USE := stella-pgo$(EXEEXT) EXECUTABLE_PROFILE_USE := stella-pgo$(EXEEXT)
EXECUTABLE_TEST := stella-test$(EXEEXT)
PROFILE_DIR = $(CURDIR)/test/roms/profile PROFILE_DIR = $(CURDIR)/test/roms/profile
PROFILE_OUT = $(PROFILE_DIR)/out PROFILE_OUT = $(PROFILE_DIR)/out
@ -154,6 +180,9 @@ all: $(EXECUTABLE)
pgo: $(EXECUTABLE_PROFILE_USE) pgo: $(EXECUTABLE_PROFILE_USE)
test: $(EXECUTABLE_TEST)
./$(EXECUTABLE_TEST)
###################################################################### ######################################################################
# Various minor settings # Various minor settings
###################################################################### ######################################################################
@ -195,6 +224,7 @@ DEPDIRS = $(addsuffix /$(DEPDIR),$(MODULE_DIRS))
DEPFILES = DEPFILES =
OBJ=$(addprefix $(OBJECT_ROOT)/,$(OBJS)) OBJ=$(addprefix $(OBJECT_ROOT)/,$(OBJS))
OBJ_TEST=$(addprefix $(OBJECT_ROOT_TEST)/,$(OBJS_TEST))
OBJ_PROFILE_GENERATE=$(addprefix $(OBJECT_ROOT_PROFILE_GENERERATE)/,$(OBJS)) OBJ_PROFILE_GENERATE=$(addprefix $(OBJECT_ROOT_PROFILE_GENERERATE)/,$(OBJS))
OBJ_PROFILE_USE=$(addprefix $(OBJECT_ROOT_PROFILE_USE)/,$(OBJS)) OBJ_PROFILE_USE=$(addprefix $(OBJECT_ROOT_PROFILE_USE)/,$(OBJS))
@ -202,6 +232,9 @@ OBJ_PROFILE_USE=$(addprefix $(OBJECT_ROOT_PROFILE_USE)/,$(OBJS))
$(EXECUTABLE): $(OBJ) $(EXECUTABLE): $(OBJ)
$(LD) $(LDFLAGS) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) $(PROF) -o $@ $(LD) $(LDFLAGS) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) $(PROF) -o $@
$(EXECUTABLE_TEST): $(OBJ_TEST)
$(LD) $(LDFLAGS_TEST) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) -lgtest -lgtest_main -o $@
$(EXECUTABLE_PROFILE_GENERATE): $(OBJ_PROFILE_GENERATE) $(EXECUTABLE_PROFILE_GENERATE): $(OBJ_PROFILE_GENERATE)
$(LD) $(LDFLAGS_PROFILE_GENERATE) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) $(PROF) -o $@ $(LD) $(LDFLAGS_PROFILE_GENERATE) $(PRE_OBJS_FLAGS) $+ $(POST_OBJS_FLAGS) $(LIBS) $(PROF) -o $@
@ -216,7 +249,7 @@ clean:
-$(RM) -fr \ -$(RM) -fr \
$(OBJECT_ROOT) $(OBJECT_ROOT_PROFILE_GENERERATE) $(OBJECT_ROOT_PROFILE_USE) \ $(OBJECT_ROOT) $(OBJECT_ROOT_PROFILE_GENERERATE) $(OBJECT_ROOT_PROFILE_USE) \
$(EXECUTABLE) $(EXECUTABLE_PROFILE_GENERATE) $(EXECUTABLE_PROFILE_USE) \ $(EXECUTABLE) $(EXECUTABLE_PROFILE_GENERATE) $(EXECUTABLE_PROFILE_USE) \
$(PROFILE_OUT) $(PROFILE_STAMP) $(OBJECT_ROOT_TEST) $(PROFILE_OUT) $(PROFILE_STAMP)
.PHONY: all clean dist distclean .PHONY: all clean dist distclean
@ -244,6 +277,16 @@ $(OBJECT_ROOT)/%.o: %.cxx
$(merge_dep) $(merge_dep)
$(OBJECT_ROOT)/%.o: %.c $(OBJECT_ROOT)/%.o: %.c
$(create_dir)
$(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS_TEST) $(CPPFLAGS) -c $(<) -o $@
$(merge_dep)
$(OBJECT_ROOT_TEST)/%.o: %.cxx
$(create_dir)
$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS_TEST) $(CPPFLAGS) -c $(<) -o $@
$(merge_dep)
$(OBJECT_ROOT_TEST)/%.o: %.c
$(create_dir) $(create_dir)
$(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $@ $(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $@
$(merge_dep) $(merge_dep)
@ -281,6 +324,14 @@ $(OBJECT_ROOT)/%.o: %.c
$(create_dir) $(create_dir)
$(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $@ $(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS) $(CPPFLAGS) -c $(<) -o $@
$(OBJECT_ROOT_TEST)/%.o: %.cxx
$(create_dir)
$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS_TEST) $(CPPFLAGS) -c $(<) -o $@
$(OBJECT_ROOT_TEST)/%.o: %.c
$(create_dir)
$(CC) $(CXX_UPDATE_DEP_FLAG) $(CFLAGS_TEST) $(CPPFLAGS) -c $(<) -o $@
$(OBJECT_ROOT_PROFILE_GENERERATE)/%.o: %.cxx $(OBJECT_ROOT_PROFILE_GENERERATE)/%.o: %.cxx
$(create_dir) $(create_dir)
$(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS_PROFILE_GENERATE) $(CPPFLAGS) -c $(<) -o $@ $(CXX) $(CXX_UPDATE_DEP_FLAG) $(CXXFLAGS_PROFILE_GENERATE) $(CPPFLAGS) -c $(<) -o $@

View File

@ -4,7 +4,9 @@
# contains the module name, a trick we use so we can keep multiple different # contains the module name, a trick we use so we can keep multiple different
# module object lists, one for each module. # module object lists, one for each module.
MODULE_OBJS-$(MODULE) := $(MODULE_OBJS) MODULE_OBJS-$(MODULE) := $(MODULE_OBJS)
MODULE_TEST_OBJS-$(MODULE) := $(MODULE_TEST_OBJS)
# If not building as a plugin, add the object files to the main OBJS list # If not building as a plugin, add the object files to the main OBJS list
#OBJS += $(MODULE_LIB-$(MODULE)) #OBJS += $(MODULE_LIB-$(MODULE))
OBJS += $(MODULE_OBJS) OBJS += $(MODULE_OBJS)
OBJS_TEST := $(MODULE_TEST_OBJS)

23
configure vendored
View File

@ -13,6 +13,16 @@
# use environment vars if set # use environment vars if set
CXXFLAGS="$CXXFLAGS $CPPFLAGS" CXXFLAGS="$CXXFLAGS $CPPFLAGS"
if test -n "$CXXFLAGS_TEST"; then
CXXFLAGS_TEST="$CXXFLAGS_TEST $CPPFLAGS"
else
CXXFLAGS_TEST="$CXXFLAGS"
fi
if test -z "$LDFLAGS_TEST"; then
LDFLAGS_TEST="$LDFLAGS"
fi
# default option behaviour yes/no # default option behaviour yes/no
_build_gui=yes _build_gui=yes
_build_windowed=yes _build_windowed=yes
@ -225,6 +235,7 @@ Optional Libraries:
--with-sdl-prefix=DIR Prefix where the sdl2-config script is installed (optional) --with-sdl-prefix=DIR Prefix where the sdl2-config script is installed (optional)
--with-libpng-prefix=DIR Prefix where libpng is installed (optional) --with-libpng-prefix=DIR Prefix where libpng is installed (optional)
--with-zlib-prefix=DIR Prefix where zlib is installed (optional) --with-zlib-prefix=DIR Prefix where zlib is installed (optional)
--with-gtest-prefix=DIR Prefix where googletest is installed (optional)
Some influential environment variables: Some influential environment variables:
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
@ -233,6 +244,8 @@ Some influential environment variables:
CXXFLAGS C++ compiler flags CXXFLAGS C++ compiler flags
CPPFLAGS C++ preprocessor flags, e.g. -I<include dir> if you have CPPFLAGS C++ preprocessor flags, e.g. -I<include dir> if you have
headers in a nonstandard directory <include dir> headers in a nonstandard directory <include dir>
LDFLAGS_TEST linker flags for unit tests
CXXFLAGS_TEST C++ compiler flags for unit tests
EOF EOF
exit 0 exit 0
@ -280,6 +293,11 @@ for ac_option in $@; do
_prefix=`echo $ac_option | cut -d '=' -f 2` _prefix=`echo $ac_option | cut -d '=' -f 2`
ZLIB_CFLAGS="-I$_prefix/include" ZLIB_CFLAGS="-I$_prefix/include"
ZLIB_LIBS="-L$_prefix/lib" ZLIB_LIBS="-L$_prefix/lib"
;;
--with-gtest-prefix=*)
_prefix=`echo $ac_option | cut -d '=' -f 2`
CXXFLAGS_TEST="$CXXFLAGS_TEST -I$_prefix/include"
LDFLAGS_TEST="$LDFLAGS_TEST -L$_prefix/lib"
;; ;;
--host=*) --host=*)
_host=`echo $ac_option | cut -d '=' -f 2` _host=`echo $ac_option | cut -d '=' -f 2`
@ -841,6 +859,9 @@ case $_host_os in
INCLUDES="$INCLUDES -I$SRC_OS/unix" INCLUDES="$INCLUDES -I$SRC_OS/unix"
if test "$have_clang" == yes; then if test "$have_clang" == yes; then
CXXFLAGS="$CXXFLAGS -Wno-poison-system-directories" CXXFLAGS="$CXXFLAGS -Wno-poison-system-directories"
if test -n "$CXXFLAGS_TEST"; then
CXXFLAGS_TEST="$CXXFLAGS_TEST -Wno-poison-system-directories"
fi
fi fi
_libsqlite3=no _libsqlite3=no
;; ;;
@ -954,6 +975,7 @@ cat > config.mak << EOF
CC := $CC CC := $CC
CXX := $CXX CXX := $CXX
CXXFLAGS := $CXXFLAGS CXXFLAGS := $CXXFLAGS
CXXFLAGS_TEST := $CXXFLAGS_TEST
LD := $LD LD := $LD
LIBS += $LIBS LIBS += $LIBS
RANLIB := $_ranlib RANLIB := $_ranlib
@ -991,6 +1013,7 @@ INCLUDES += $INCLUDES
OBJS += $OBJS OBJS += $OBJS
DEFINES += $DEFINES DEFINES += $DEFINES
LDFLAGS += $LDFLAGS LDFLAGS += $LDFLAGS
LDFLAGS_TEST += $LDFLAGS_TEST
$_config_mk_data $_config_mk_data
EOF EOF

View File

@ -0,0 +1,20 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2024 by Bradford W. Mott, Stephen Anthony
// and the Stella Team
//
// See the file "License.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//============================================================================
#include <gtest/gtest.h>
TEST(HelloWorld, Passes) {}

View File

@ -5,8 +5,12 @@ MODULE_OBJS = \
src/emucore/elf/ElfLinker.o \ src/emucore/elf/ElfLinker.o \
src/emucore/elf/ElfUtil.o src/emucore/elf/ElfUtil.o
MODULE_TEST_OBJS = \
src/emucore/elf/ElfUtil.o \
src/emucore/elf/EncodingTest.o
MODULE_DIRS += \ MODULE_DIRS += \
src/emucore/elf src/emucore/elf/EncodingTest.o
# Include common rules # Include common rules
include $(srcdir)/common.rules include $(srcdir)/common.rules