Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Not much can be unit-tested though
- Loading branch information
Showing
11 changed files
with
876 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ documentation.list | |
installroot | ||
build | ||
RPMS | ||
test/coverage/full.gcov | ||
test/coverage/lib.gcov | ||
test/coverage/results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- Mode: makefile-gmake -*- | ||
|
||
cleaner: clean | ||
@rm -f *~ | ||
@rm -f common/*~ | ||
@rm -f coverage/*.gcov | ||
@rm -fr coverage/results | ||
|
||
all: | ||
%: | ||
@$(MAKE) -C test_util $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
# -*- Mode: makefile-gmake -*- | ||
|
||
.PHONY: clean all debug release lib-release lib-debug | ||
|
||
# | ||
# Real test makefile defines EXE (and possibly SRC) and includes this one. | ||
# | ||
|
||
ifndef EXE | ||
${error EXE not defined} | ||
endif | ||
|
||
SRC ?= $(EXE).c | ||
COMMON_SRC ?= test_main.c | ||
|
||
# | ||
# Required packages | ||
# | ||
|
||
PKGS += libglibutil gobject-2.0 glib-2.0 gio-2.0 | ||
|
||
# | ||
# Default target | ||
# | ||
|
||
all: debug release | ||
|
||
# | ||
# Directories | ||
# | ||
|
||
SRC_DIR = . | ||
LIB_DIR = ../.. | ||
COMMON_DIR = ../common | ||
BUILD_DIR = build | ||
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug | ||
RELEASE_BUILD_DIR = $(BUILD_DIR)/release | ||
|
||
# | ||
# Code coverage | ||
# | ||
|
||
ifndef GCOV | ||
GCOV = 0 | ||
endif | ||
|
||
ifneq ($(GCOV),0) | ||
CFLAGS += --coverage | ||
LDFLAGS += --coverage | ||
SUBMAKE_OPTS += GCOV=1 | ||
endif | ||
|
||
# | ||
# Tools and flags | ||
# | ||
|
||
CC = $(CROSS_COMPILE)gcc | ||
LD = $(CC) | ||
WARNINGS = -Wall | ||
INCLUDES = -I$(LIB_DIR)/include -I$(LIB_DIR)/src -I$(COMMON_DIR) | ||
BASE_FLAGS = -fPIC | ||
BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) | ||
BASE_CFLAGS = $(BASE_FLAGS) $(CFLAGS) | ||
FULL_CFLAGS = $(BASE_CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) -MMD -MP \ | ||
$(shell pkg-config --cflags $(PKGS)) | ||
FULL_LDFLAGS = $(BASE_LDFLAGS) | ||
LIBS = $(shell pkg-config --libs $(PKGS)) | ||
QUIET_MAKE = make --no-print-directory | ||
DEBUG_FLAGS = -g | ||
RELEASE_FLAGS = | ||
|
||
ifndef KEEP_SYMBOLS | ||
KEEP_SYMBOLS = 0 | ||
endif | ||
|
||
ifneq ($(KEEP_SYMBOLS),0) | ||
RELEASE_FLAGS += -g | ||
SUBMAKE_OPTS += KEEP_SYMBOLS=1 | ||
endif | ||
|
||
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS) | ||
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS) | ||
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG | ||
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2 | ||
|
||
# | ||
# Files | ||
# | ||
|
||
DEBUG_OBJS = \ | ||
$(COMMON_SRC:%.c=$(DEBUG_BUILD_DIR)/common_%.o) \ | ||
$(SRC:%.c=$(DEBUG_BUILD_DIR)/%.o) | ||
RELEASE_OBJS = \ | ||
$(COMMON_SRC:%.c=$(RELEASE_BUILD_DIR)/common_%.o) \ | ||
$(SRC:%.c=$(RELEASE_BUILD_DIR)/%.o) | ||
|
||
DEBUG_LIB_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_debug_lib) | ||
RELEASE_LIB_FILE := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_release_lib) | ||
DEBUG_LIB_PATH := $(shell $(QUIET_MAKE) -C $(LIB_DIR) print_debug_path) | ||
DEBUG_LIB := $(LIB_DIR)/$(DEBUG_LIB_FILE) | ||
RELEASE_LIB := $(LIB_DIR)/$(RELEASE_LIB_FILE) | ||
|
||
# | ||
# Dependencies | ||
# | ||
|
||
DEPS = $(DEBUG_OBJS:%.o=%.d) $(RELEASE_OBJS:%.o=%.d) | ||
ifneq ($(MAKECMDGOALS),clean) | ||
ifneq ($(strip $(DEPS)),) | ||
-include $(DEPS) | ||
endif | ||
endif | ||
|
||
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) | ||
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) | ||
|
||
# | ||
# Rules | ||
# | ||
|
||
DEBUG_EXE = $(DEBUG_BUILD_DIR)/$(EXE) | ||
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE) | ||
|
||
debug: lib-debug $(DEBUG_EXE) | ||
|
||
release: lib-release $(RELEASE_EXE) | ||
|
||
clean: | ||
rm -f *~ | ||
rm -fr $(BUILD_DIR) | ||
|
||
cleaner: clean | ||
@make -C $(LIB_DIR) clean | ||
|
||
test_banner: | ||
@echo "===========" $(EXE) "=========== " | ||
|
||
test: test_banner debug | ||
@LD_LIBRARY_PATH="$(LIB_DIR)/$(DEBUG_LIB_PATH)" $(DEBUG_EXE) | ||
|
||
valgrind: test_banner debug | ||
@LD_LIBRARY_PATH="$(LIB_DIR)/$(DEBUG_LIB_PATH)" G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no $(DEBUG_EXE) | ||
|
||
$(DEBUG_BUILD_DIR): | ||
mkdir -p $@ | ||
|
||
$(RELEASE_BUILD_DIR): | ||
mkdir -p $@ | ||
|
||
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.c | ||
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ | ||
|
||
$(RELEASE_BUILD_DIR)/%.o : $(SRC_DIR)/%.c | ||
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ | ||
|
||
$(DEBUG_BUILD_DIR)/common_%.o : $(COMMON_DIR)/%.c | ||
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ | ||
|
||
$(RELEASE_BUILD_DIR)/common_%.o : $(COMMON_DIR)/%.c | ||
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@ | ||
|
||
$(DEBUG_EXE): $(DEBUG_LIB) $(DEBUG_BUILD_DIR) $(DEBUG_OBJS) | ||
$(LD) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) $< $(LIBS) -o $@ | ||
|
||
$(RELEASE_EXE): $(RELEASE_LIB) $(RELEASE_BUILD_DIR) $(RELEASE_OBJS) | ||
$(LD) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) $< $(LIBS) -o $@ | ||
ifeq ($(KEEP_SYMBOLS),0) | ||
strip $@ | ||
endif | ||
|
||
lib-debug: | ||
@make $(SUBMAKE_OPTS) -C $(LIB_DIR) debug | ||
|
||
lib-release: | ||
@make $(SUBMAKE_OPTS) -C $(LIB_DIR) release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2016 Jolla Ltd. | ||
* Contact: Slava Monich <slava.monich@jolla.com> | ||
* | ||
* You may use this file under the terms of BSD license as follows: | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. Neither the name of the Jolla Ltd nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software | ||
* without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef TEST_COMMON_H | ||
#define TEST_COMMON_H | ||
|
||
#include <gutil_types.h> | ||
|
||
#define TEST_FLAG_DEBUG (0x01) | ||
|
||
typedef struct test_opt { | ||
int flags; | ||
} TestOpt; | ||
|
||
/* Should be invoked after g_test_init */ | ||
void | ||
test_init( | ||
TestOpt* opt, | ||
int argc, | ||
char* argv[]); | ||
|
||
#endif /* TEST_COMMON_H */ | ||
|
||
/* | ||
* Local Variables: | ||
* mode: C | ||
* c-basic-offset: 4 | ||
* indent-tabs-mode: nil | ||
* End: | ||
*/ |
Oops, something went wrong.