如何在expect脚本中嵌入gcc和gcov命令

发布于 2024-08-09 19:07:21 字数 974 浏览 2 评论 0原文

我想嵌入 gcc 和 gcov 命令作为期望脚本的一部分..

我尝试了..

#!/usr/bin/expect -f
send ":gcc -fprofile-arcs -ftest-coverage c.c\r"

send ":gcov c.c\r"

但它不运行并执行命令。

对此有何见解?谢谢。


我遇到的问题是我不确定如何将命令嵌入到正确的位置。我所知道的是有一个给定的测试用例,如下所示:-

#!/usr/bin/expect -f
spawn $env(SUBJECTS_SRC_DIR)/vim -u $env(HOME)/.vimrc $env(TESTS_SRC)/copy1
expect "copy1"
sleep 1
send ":se lines=24\r"
send ":se columns=80\r"
send ":redir >> move_2.1.1.out\r"
send "$"
send "\007"
send "5h"

send "\007"
send ":redir END\r"

send ":wq\r"
expect
exit -onexit {
interact
}

它包含在名为 testfile.txt 的特定文件中。在 Perl 脚本中执行此测试文件后,就会生成输出。

如下所示:

$IN_DIR/$SCRIPT_FILE;

$outfile = "$OUT_DIR/t$scriptCounter";

我尝试将您之前建议的期望命令放在一个名为的单独文件中,并将其传递给 $IN_DIR 中名为 ...$MY_FILE 的新变量。

然后,我通过了 $IN_DIR/$MY_FILE;

但它没有做任何事情。 .gcno 文件也不会执行,因此 .gcov 文件也不会被执行。

I wanted to embed gcc and gcov command as part of expect script..

I tried as..

#!/usr/bin/expect -f
send ":gcc -fprofile-arcs -ftest-coverage c.c\r"

send ":gcov c.c\r"

But it doesnt run and execute the commands.

Any insights to this? Thanks.


The problem I have is I am not sure how can I embed the command at the right place. All I know was there is a given test cases as below :-

#!/usr/bin/expect -f
spawn $env(SUBJECTS_SRC_DIR)/vim -u $env(HOME)/.vimrc $env(TESTS_SRC)/copy1
expect "copy1"
sleep 1
send ":se lines=24\r"
send ":se columns=80\r"
send ":redir >> move_2.1.1.out\r"
send "$"
send "\007"
send "5h"

send "\007"
send ":redir END\r"

send ":wq\r"
expect
exit -onexit {
interact
}

This is contained in a specific file named testfile. Once this testfile is executed in Perl script, an output is generated.

Something like below:

$IN_DIR/$SCRIPT_FILE;

$outfile = "$OUT_DIR/t$scriptCounter";

I tried to put the expect command which you have suggested earlier in a separate file named and passed to a new variable named...$MY_FILE in $IN_DIR.

And then, i passed $IN_DIR/$MY_FILE;

but it doesnt do anything. The .gcno files are not executed either so thus .gcov.

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

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

发布评论

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

评论(1

随梦而飞# 2024-08-16 19:07:21

Expect 对于交互式程序很有用,而不是命令行实用程序。如果您只想执行 gccgcov 作为 Expect 脚本的一部分,请执行以下操作:

exec gcc -fprofile-arcs -ftest-coverage c.c
exec gcov c.c

顺便说一句,在不先运行可执行文件的情况下运行 gcov 是徒劳的:您需要生成运行时覆盖率数据,然后才能对其进行分析。

Expect is useful for interactive programs, not for command-line utilities. If you want to just execute gcc and gcov as part of expect script, do this:

exec gcc -fprofile-arcs -ftest-coverage c.c
exec gcov c.c

BTW, running gcov without first running the executable is futile: you need to produce the runtime coverage data before you can analyze it.

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