首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >STM8上的cpputest由于多个“主”而失败

STM8上的cpputest由于多个“主”而失败
EN

Stack Overflow用户
提问于 2017-11-08 13:50:47
回答 1查看 384关注 0票数 1

我想在STM8上使用cpputest,并安装它所需的所有工具。我能够在我的简化代码上运行cpputest。在我的主文件中,这是属于硬件的,我当然有主要的功能。但是在测试环境中,我在AllTests.cpp下也有一个主要的功能。当我编译它时,我会得到以下错误:

代码语言:javascript
复制
multiple definition of `main'

我遇到的另一个问题是:我为一个8位处理器编译了代码,我使用了库<stdint.h>,所以我的主文件有行uint8_t main(){。cpputest的编译器一点也不喜欢.

有谁知道怎么解决这个问题吗?

文件:

眨眼:

代码语言:javascript
复制
#ifndef BLINKY_H
#define BLINKY_H

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

uint16_t blink(void);

#endif

blinky.c

代码语言:javascript
复制
#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:

代码语言:javascript
复制
#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:

代码语言:javascript
复制
#include "CppUTest/CommandLineTestRunner.h"

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

Makefile:

代码语言:javascript
复制
#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       :=@$(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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-16 11:01:05

正如赞扬中所建议的那样,没有其他方法可以创建一个只有Controller的主循环并将其与单元测试分离的文件。

我的结构类似于: main.c:-包含来自固件的包含(app.h)和带有run_app() app.c:包含所有固件的main(),并且用cpputest进行了测试。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47181446

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档