gcov报告未显示在boost :: asio :: io_service线程内调用的函数的覆盖范围

问题描述 投票:0回答:1

我正在使用boost :: asio :: io_service调用std :: thread,如下所示。功能:

      91           0 : void start_tcp( std::shared_ptr<mapping_t> m_mapping, l_publisher& ll_publisher,
      92             :                 reg_publisher& reg_publisher, std::mutex& mtx, bool debug, const string& host,
      93             :                 uint16_t port, uint16_t maximum_number_of_connections ) {
      94             :     spdlog::info( "start_tcp debug:{} host:{} port:{} max_connections:{}", debug, host, port,
      95           0 :                   maximum_number_of_connections );
      96           0 :     modbus_t* ctx = nullptr;
      97           0 :     if( host == "0.0.0.0" ) {
      98           0 :         ctx = new_tcp( NULL, port ); 
      99             :     } else {
     100           0 :         ctx = new_tcp( host.c_str(), port );
     101             :     }

**Above function calling from thread insdie main.cpp:**
           :             std::thread tcp_thread{start_tcp,
     424             :                                    m_mapping,
     425           0 :                                    std::ref( l_publisher ),
     426           0 :                                    std::ref( reg_publisher ),
     427           0 :                                    std::ref( mtx ),
     428             :                                    debug_mode,
     429           0 :                                    input_file["bindAddress"].as<string>(),
     430           0 :                                    input_file["port"].as<unsigned>(),
     431           0 :                                    config["maximum-connections"].as<unsigned>()};
     432           0 :             io_service->run();

我编译时可以看到。gcno文件已生成。这意味着,我正确设置了-g -O0 --coverage编译器标志,然后设置了-lgcov链接器标志。而且,在测试运行之后,生成<.gcda>文件。但是,即使函数start_tcp被执行,也没有显示覆盖率。执行测试后,我可以看到以下内容已打印到控制台。这意味着将执行此功能。但是报道没有显示任何东西。spdlog::info( "start_tcp debug:{} host:{} port:{} max_connections:{}", debug,

摘录自测试输出:

[2020-03-21 10:41:48.268] [信息] start_tcp调试:false主机:127.0.0.1端口:1502 max_connections:50 \ n'测试不是单元测试,而是用python编写的功能测试(使用python子进程),它可以验证从源代码构建的可执行文件的命令行选项。

有人可以帮我解决这个问题。我是在做错什么还是对于增强线程,是否需要其他一些特殊标志以获取正确的覆盖率报告?

我正在使用boost :: asio :: io_service调用std :: thread,如下所示。.函数:91 0:void start_tcp(std :: shared_ptr

m_mapping,l_publisher&ll_publisher,...

c++ boost code-coverage gcov
1个回答
0
投票
我解决了这个问题。与线程无关。测试使用从源构建的可执行文件。测试已经使用pythons子进程从可执行文件中产生了该进程,并且在测试结束时,该进程正在使用sigterm终止。但是可执行文件不处理sigterm。因此,如此处所述,未创建.gcda文件...
© www.soinside.com 2019 - 2024. All rights reserved.