我正在使用 gcov 来衡量我贡献的 c++ 库的测试覆盖率。出于某种原因,gcov 没有将许多文件中的行识别为可执行文件。在给定文件的 160 多行中,它会说其中 40 行是可执行的。例如:
-: 0:Source:../evo/NK.h
-: 0:Graph:test_driver.gcno
-: 0:Data:test_driver.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:// This file is part of Empirical, https://github.com/devosoft/Empirical
-: 2:// Copyright (C) Michigan State University, 2016.
-: 3:// Released under the MIT Software license; see doc/LICENSE
-: 4://
-: 5://
-: 6:// This file provides code to build NK-based algorithms.
-: 7:
-: 8:#ifndef EMP_EVO_NK_H
-: 9:#define EMP_EVO_NK_H
-: 10:
-: 11:#include <array>
-: 12:
-: 13:#include "../tools/BitVector.h"
-: 14:#include "../tools/const_utils.h"
-: 15:#include "../tools/Random.h"
-: 16:#include "../tools/vector.h"
-: 17:
-: 18:namespace emp {
-: 19:namespace evo {
-: 20:
-: 21: class NKLandscape {
-: 22: private:
-: 23: const uint32_t N;
-: 24: const uint32_t K;
-: 25: const uint32_t state_count;
-: 26: const uint32_t total_count;
-: 27: emp::vector< emp::vector<double> > landscape;
-: 28:
-: 29: public:
-: 30: NKLandscape() = delete;
-: 31: NKLandscape(const NKLandscape &) = delete;
-: 32: NKLandscape(int _N, int _K, emp::Random & random)
-: 33: : N(_N), K(_K)
-: 34: , state_count(emp::constant::IntPow<uint32_t>(2,K+1))
-: 35: , total_count(N * state_count)
-: 36: , landscape(N)
-: 37: {
-: 38: for ( auto & ltable : landscape) {
-: 39: ltable.resize(state_count);
-: 40: for (double & pos : ltable) {
-: 41: pos = random.GetDouble();
-: 42: }
-: 43: }
-: 44: }
-: 45: ~NKLandscape() { ; }
-: 46: NKLandscape & operator=(const NKLandscape &) = delete;
-: 47:
-: 48: int GetN() const { return N; }
-: 49: int GetK() const { return K; }
-: 50: int GetStateCount() const { return state_count; }
-: 51: int GetTotalCount() const { return total_count; }
-: 52:
-: 53: double GetFitness(int n, uint32_t state) const {
-: 54: emp_assert(state < state_count, state, state_count);
-: 55: return landscape[n][state];
-: 56: }
-: 57: double GetFitness( std::vector<uint32_t> states ) const {
-: 58: emp_assert(states.size() == N);
-: 59: double total = landscape[0][states[0]];
-: 60: for (int i = 1; i < N; i++) total += GetFitness(i,states[i]);
-: 61: return total;
-: 62: }
-: 63: double GetFitness(BitVector genome) const {
-: 64: emp_assert(genome.GetSize() == N);
-: 65:
-: 66: // Use a double-length genome to easily handle wrap-around.
-: 67: genome.Resize(N*2);
-: 68: genome |= (genome << N);
-: 69:
-: 70: double total = 0.0;
-: 71: uint32_t mask = emp::constant::MaskLow<uint32_t>(K+1);
-: 72: for (int i = 0; i < N; i++) {
-: 73: const uint32_t cur_val = (genome >> i).GetUInt(0) & mask;
-: 74: const double cur_fit = GetFitness(i, cur_val);
-: 75: total += cur_fit;
-: 76: }
-: 77: return total;
-: 78: }
-: 79: };
-: 80:
-: 81:}
3: 82:}
-: 83:
-: 84:#endif
在这里,gcov 将文件中的几乎所有行都标记为不可执行,但会跟踪第 82 行的 3 次执行:单个右括号。
这对我来说毫无意义,我无法在网上找到有关此问题的任何信息。任何帮助将不胜感激。