2017-11-08 19 views
0

STM8でcpputestを使用し、そのために必要なすべてのツールをインストールしたいと考えています。 私は簡単なコードでcpputestを実行することができます。 私のメインファイルには、私はもちろん主な機能を持っているハードウェアに属しています。しかし、テスト環境では、私はAllTests.cppの下でも主な機能を持っています。私はそれをコンパイルするとき、私はエラーを取得:STM8のcpputestが複数の 'main'のために失敗しました

multiple definition of `main' 

私はに実行し、さらに問題がある:私は、8ビットプロセッサ用のコードをコンパイルし、私のメインのファイルが行uint8_t main(){を持っているので、私は、ライブラリ<stdint.h>を使用しています。 cpputestのコンパイラはまったく好きではありません...

これを修正する方法を知っている人はいますか?

ファイル:

blinky.h:

#ifndef BLINKY_H 
#define BLINKY_H 

#include "stm8l.h" 
#include <stdint.h> 

uint16_t blink(void); 

#endif 

blinky.c

#include "blinky.h" 


uint16_t blink(){ 
    PD_DDR = 0x1; 
    PD_CR1 = 0x1; 
    return 1; 
} 
uint8_t main() { 
    // Configure pins 
    while(1){ 
    // Loop 
    blink(); 
    } 
} 

ます。test.cpp:

#include "CppUTest/TestHarness.h" 

extern "C" 
{ 
#include "blinky.h" 
} 

TEST_GROUP(FirstTestGroup) 
{ 
    void setup() 
    { 
    } 

    void teardown() 
    { 
    } 
}; 

TEST(FirstTestGroup, test1) 
{ 
    LONGS_EQUAL(1, blink()); 
} 

AllTest.cpp:

#include "CppUTest/CommandLineTestRunner.h" 

int main(int ac, char** av) 
{ 
    return CommandLineTestRunner::RunAllTests(ac, av); 
} 

のMakefile:

#Set this to @ to keep the makefile quiet 
SILENCE = @ 

#---- Outputs ----# 
COMPONENT_NAME = blinky 

#--- Inputs ----# 
PROJECT_HOME_DIR = . 
ifeq "$(CPPUTEST_HOME)" "" 
    CPPUTEST_HOME = ~/tools/cpputest 
endif 

# --- SRC_FILES --- 
# Use SRC_FILES to specifiy individual production 
# code files. 
# These files are compiled and put into the 
# ProductionCode library and links with the test runner 
SRC_FILES = src/blinky.c 

# --- SRC_DIRS --- 
# Use SRC_DIRS to specifiy production directories 
# code files. 
# These files are compiled and put into a the 
# ProductionCode library and links with the test runner 
SRC_DIRS = \ 
    platform 

# --- TEST_SRC_FILES --- 
# TEST_SRC_FILES specifies individual test files to build. Test 
# files are always included in the build and they 
# pull in production code from the library 
TEST_SRC_FILES = \ 

# --- TEST_SRC_DIRS --- 
# Like TEST_SRC_FILES, but biulds everyting in the directory 
TEST_SRC_DIRS = \ 
    tests \ 
    #tests/blinky \ 
    #tests/io-cppumock \ 
    #tests/exploding-fakes \ 
    #tests \ 
    #tests/example-fff \ 
    #tests/fff \ 
# --- MOCKS_SRC_DIRS --- 
# MOCKS_SRC_DIRS specifies a directories where you can put your 
# mocks, stubs and fakes. You can also just put them 
# in TEST_SRC_DIRS 
MOCKS_SRC_DIRS = \ 

# Turn on CppUMock 
CPPUTEST_USE_EXTENSIONS = Y 

INCLUDE_DIRS =\ 
    .\ 
    $(CPPUTEST_HOME)/include/ \ 
    $(CPPUTEST_HOME)/include/Platforms/Gcc \ 
    platform \ 
    src \ 
    include \ 
    #example-fff \ 
    #test/exploding-fakes \ 
    #tests/fff 


#STM8DIR 

#SDCC_DIR :=$(CPPUTEST_HOME)/../sdcc/ 
#CC  :[email protected]$(SDCC_DIR)/bin/sdcc 
# --- CPPUTEST_OBJS_DIR --- 
# if you have to use "../" to get to your source path 
# the makefile will put the .o and .d files in surprising 
# places. 
# To make up for each level of "../", add place holder 
# sub directories in CPPUTEST_OBJS_DIR 
# each "../". It is kind of a kludge, but it causes the 
# .o and .d files to be put under objs. 
# e.g. if you have "../../src", set to "test-objs/1/2" 
# This is set no "../" in the source path. 
CPPUTEST_OBJS_DIR = test-obj 

CPPUTEST_LIB_DIR = test-lib 
CPPUTEST_WARNINGFLAGS += -Wall 
CPPUTEST_WARNINGFLAGS += -Werror 
CPPUTEST_WARNINGFLAGS += -Wswitch-default 
CPPUTEST_WARNINGFLAGS += -Wfatal-errors 
CPPUTEST_CXXFLAGS = -Wno-c++14-compat 
CPPUTEST_CFLAGS = -std=c99 
CPPUTEST_CXXFLAGS += $(CPPUTEST_PLATFORM_CXXFLAGS) 
CPPUTEST_CFLAGS += -Wno-missing-prototypes 
CPPUTEST_CXXFLAGS += -Wno-missing-variable-declarations 
# --- LD_LIBRARIES -- Additional needed libraries can be added here. 
# commented out example specifies math library 
#LD_LIBRARIES += -lm 

# Look at $(CPPUTEST_HOME)/build/MakefileWorker.mk for more controls 

include $(CPPUTEST_HOME)/build/MakefileWorker.mk 
+2

あなたは2つの 'main'関数を持つことができないので、**それらのうちの1つを削除する**を持っています。別の名前を使うことは一つの選択肢のようです。 'blink()'関数を置くことは、別の.cファイルです。 –

+0

少なくとも、私はそれを私のハードウェアにデプロイするときに、それを主な関数として指定する必要がありますか、ここで何か完全に間違っていますか? – K0ertis

+1

はい、各ビルドにちょうど1つの 'main'関数を持たなければなりません。したがって、ファイルを別の方法で整理する必要があるかもしれません。 'blinky.c'を2つのファイルに分割し、テストビルドでそれらのファイルを1つだけ使用します。 –

答えて

0

表彰で示唆したように、唯一のコントローラのメインループを使用してファイルを作成し、ユニットテストからそれを分離する他の方法はなかったです。

私の構造は次のようになります。 のmain.c: - ファームウェア(app.h)とメイン(から含まれて含まれている)run_appと() app.c: はすべてのファームウェアが含まれ、テストされていますcpputestを使って

関連する問題