2017-11-08 22 views
0

STM8에서 cpputest를 사용하고 이에 필요한 모든 도구를 설치하려고합니다. 간체 코드로 cpputest를 실행할 수 있습니다. 하드웨어에 속한 주요 파일에는 물론 주요 기능이 있습니다. 하지만 Test 환경에는 AllTests.cpp 아래에 주요 기능이 있습니다. 나는 그것을 컴파일 할 때이 오류가 발생합니다 :STM8에 cpputest가 여러 개의 'main'으로 인해 실패했습니다

multiple definition of `main' 

내가으로 실행하는 또 다른 문제가 있습니다 : 나는 8 비트 프로세서에 대한 코드를 컴파일하고 난 도서관 <stdint.h>을 사용하기 때문에 내 주요 파일이 라인 uint8_t main(){ 있습니다. 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); 
} 

메이크 :

추천 해에 제시된 바와 같이
#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' 함수를 가질 수 없기 때문에 ** 그것들 중 하나를 제거 할 수 있습니다 **. 다른 이름을 사용하는 것은 하나의 옵션처럼 보입니다. 'blink()'함수를 두는 것은 또 다른 .c 파일이다. –

+0

하지만 적어도 내 하드웨어에 배포 할 때 주 기능으로 이름을 지정해야합니까? 아니면 여기에 완전히 잘못 되었습니까? – K0ertis

+1

예, 각 빌드에는 정확하게 하나의'main' 함수가 있어야합니다. 따라서 파일을 다른 방식으로 구성해야 할 수도 있습니다. 'blinky.c'를 두 파일로 나누고 테스트 빌드에서 그것들 중 하나만 사용하는 것. –

답변

0

만 컨트롤러의 메인 루프 파일을 작성하고, 유닛 테스트에서 분리하는 다른 방법이 없었다. 을 main.c :

내 구조처럼 보인다 -가 run_app와 펌웨어 (APP_H,)와 주()에서 포함 포함() 가 APP.C : 모든 펌웨어를 포함하고 테스트 cpputest와 함께