编写路径覆盖工具

发布于 2024-08-01 18:57:14 字数 644 浏览 4 评论 0原文

目前,我们的一个生产系统由 1986 年至今编写的 3000 多个程序处理。 代码库是用非标准语言编写的,不幸的是缺乏现代测试工具。

为了提高我们的代码质量,我一直在努力整合流程并构建能够改进开发和测试的工具。 我刚刚拥有一个完整的行覆盖工具,以便我们可以在开发过程中帮助识别死代码+未经测试的代码。

现在,我想开始向该工具添加路径覆盖。

我应该如何解决这个问题?

鉴于:

1) 行覆盖工具充当注入代码的预处理器
2)我已经有能力收集我在上述代码中设置的统计数据。

程序执行时我应该记录哪些数据,以及如何解释它?

如何通过 HTML 表示结果?

我已经阅读了问题 如何开始“编写”代码覆盖工具?,这是关于 Java 的,但是没有帮助(包括论文“Branch Coverage for Arbitrary Languages Made Easy”)。

预先感谢您提供的任何指导!

Currently, one of our production systems is handled by over 3000 programs written between 1986 and now . The code base is written in a non-standard language, which unfortunately lacks modern testing tools.

In a bid to improve our code quality moving forward I have been working to incorporate processes and build tools that will improve development and testing. I have just completely a line coverage tool so that we can help identify dead code + untested code during development.

Now, I would like to start work on adding Path Coverage to the tool.

How should I go about this?

Given that:

1) The line coverage tool acts as a pre-processor that injects code
2) I already have the ability to gather stats I set in said code.

What data should I be recording as the program executes, and how do I interpret it?

How can I represent the results via HTML?

I have already read the question How to get started “writing” a code coverage tool?, which was about Java, however it didn't help (including the paper "Branch Coverage for Arbitrary Languages Made Easy").

Thanks in advance for any guidance given!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巾帼英雄 2024-08-08 18:57:15

要进行路径覆盖,您需要以某种方式获取程序控制流。 一个明显的方法是构建一个真实的控制流图,然后遍历它的各个部分以挑选出要在路径覆盖分析中使用的“路径片段”(例如,基本路径)。
(您可以尝试通过字符串破解源代码来做到这一点,但您可能会失败;
解析和流分析太复杂)。

请参阅基本路径覆盖的意义是什么?
有关基本路径的良好 stackoverflow 讨论。

要实现所需的路径覆盖工具,您可能需要真正完全解析完整的遗留语言。 对于 3000 个程序和强烈的测试要求,使用工业强度解析器和基础设施来执行此操作是有意义的。

我们的 DMS 软件重组工具包不仅可用于构建解析器,还可以用于构建解析器。控制流分析收集路径覆盖数据所需的仪器。 (如果您只想收集分支覆盖率数据,“任意语言的分支覆盖率”就说明了这一点,但 DMS 不仅仅只是解析)。
如果需要,DMS 还支持构建控制(和数据流)图,
正如您在本例中显然所做的那样; 请参阅DMS 构建的控制流图

DMS 已用于构建 C、Java 和 COBOL 的控制和数据流分析器,
并已用于为大约 30 多种语言构建解析器。 如果您认真对待这一点,它可以处理您的遗留语言。

编辑 10/31/2011:DMS 现在可以计算 C++ 的控制流,因此它将成为 C++ 路径覆盖工具的良好基础。

To do path coverage, you need to get at the program control flow somehow. An obvious method is to construct a real control flow graph, and then traverse segments of it to pick out "path fragments" (e.g., basis paths) to be used in your path coverage analysis.
(You can attempt to do this by string hacking the source code, but you'll likely fail;
parsing and flow analysis is too complex).

See What's the point of basis path coverage?
for a good stackoverflow discussion on basis paths.

To implement the required path coverage tool, you likely need to really parse the full legacy language completely. For 3000 programs and a strong requirement for testing, using a industrial strength parser and infrastructure to do this would make sense.

Our DMS Software Reengineering Toolkit can be used to construct not only the parser, but the control flow analysis and the instrumentation required to collect path coverage data. (The "Branch Coverage for Arbitrary Languages" made this point if all you wanted to do was collect branch coverage data, but there's more to DMS than just parsing).
DMS also has support for constucting control (and data flow) graphs if you need them,
as you apparantly do in this case; see DMS constructed control flow graphs.

DMS has been used to build control and data flow analyzers for C, Java and COBOL,
and has been used to build parsers for some 30+ langauges. It can handle your legacy language if you are serious about this.

EDIT 10/31/2011: DMS can now compute control flow for C++, so it would be a great foundation for a C++ path coverage tool.

萌无敌 2024-08-08 18:57:15

路径覆盖测量是一个棘手的话题。 首先,您必须首先定义路径的含义。 执行三次循环与执行四次循环的路径是否不同? 如果是这样,你就有无数条路径。 如果没有,即使覆盖了所有路径,也会遗漏测试用例。

下一步可能更好的是分支覆盖:测量每个条件是否都被执行为 true 和 false。 这可以通过记录行号序列来完成。

Path coverage measurement is a tricky subject. First you have to define what you mean by a path in the first place. Is a loop executed three times a different path than a loop executed four times? If so, you have an infinite number of paths. If not, there are test cases missed even if all paths are covered.

It might be that the better next step is branch coverage: measuring whether every conditional is executed both true and false. This can be accomplished by recording sequences of line numbers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文