【问题标题】:Catch testing framework long link time every time每次都赶上测试框架长链接时间
【发布时间】:2019-08-02 10:04:04
【问题描述】:

我目前正在尝试使用 Catch 测试框架。我正在使用 cmake 来构建我的项目,目前我只是将所有 .h 和 .c 文件放在一起。出于测试目的,我取出了我的实际“主要”并将其替换为 Catch 的样本阶乘示例。我有两个文件:

// testmain.cpp

#define CATCH_CONFIG_MAIN

#include <catch2/catch.hpp>

//test.cpp

#include "catch2/catch.hpp"


int Factorial( int number ) {
    return number <= 1 ? number : Factorial( number - 1 ) * number;  // fail
  // return number <= 1 ? 1      : Factorial( number - 1 ) * number;  // pass
}

TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) {
 REQUIRE( Factorial(0) == 1 );
}

TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) {
 REQUIRE( Factorial(1) == 1 );
 REQUIRE( Factorial(2) == 2 );
 REQUIRE( Factorial(3) == 6 );
 REQUIRE( Factorial(10) == 3628800 );
}

现在发生的事情是它花费 3 秒构建和 1 分钟链接。在所有链接(1+分钟)之后,我得到了测试结果。我遵循以下两个教程,其中提到将这两个文件分开。

我阅读了 Catch 教程: https://github.com/catchorg/Catch2/blob/master/docs/tutorial.md

“慢编译”wiki 页面: https://github.com/catchorg/Catch2/blob/master/docs/slow-compiles.md

我不太清楚为什么链接需要这么长时间。有没有人遇到过这样的问题?

更新:

关于我的环境的更多信息:

  • cmake 3.14.0-rc1

  • g++ 8.1.0

【问题讨论】:

  • 这里没有链接问题。 g++ 8.3.1
  • 嗯,我正在使用 g++ 8.1.0 mingw。我想知道这是否导致缓慢。
  • 我遇到的唯一速度问题是在slow compile wiki 页面上描述的。我已经使用 Catch 至少一年了,没有其他速度问题。我已经定期进行 g++ 升级(OpenSuse Tumbleweed 滚动发行版)
  • 这似乎是一个 cmake 问题?每当我关闭调试并启用发布时,它的链接速度都非常快......不过需要更多调查。
  • 显然这是 mingw 和 catch 的一个已知问题:github.com/catchorg/Catch2/issues/1205

标签: c++ unit-testing catch-unit-test


【解决方案1】:

所以从这个已知问题来看:

github.com/catchorg/Catch2/issues/1205

Mingw 在链接时间优化方面真的很糟糕。然而;我偶然发现了一个适合我的解决方案。将 cmake 构建类型设置为

RELWITHDEBINFO

似乎将链接速度提高了 10 倍。

【讨论】:

  • 是的,MinGW 的链接器很旧,当有很多符号要链接时性能很差——Catch2 恰好生成 很多 需要链接的符号。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-14
  • 1970-01-01
  • 2015-11-27
  • 2017-01-16
  • 1970-01-01
相关资源
最近更新 更多