首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印输出使用Promela和自旋?

打印输出使用Promela和自旋?
EN

Stack Overflow用户
提问于 2014-03-08 08:35:00
回答 1查看 2K关注 0票数 4

我是一个初学者尝试使用Promela和旋转。在开发一些简单的Promela规范时,我希望使用printf()检查程序中变量的值。我读过这个手册页,并试图运行一个简单的hello world程序,但我没有看到任何输出文本。下面是示例hello world文件:

代码语言:javascript
复制
init {
    printf("MSC: passed first test!\n")
}

用于编译和运行的步骤包括

代码语言:javascript
复制
spin -a hello.pml
cc -o run pan.c
./run

运行的输出是

代码语言:javascript
复制
hint: this search is more efficient if pan.c is compiled -DSAFETY
(Spin Version 4.2.6 -- 27 October 2005)
        + Partial Order Reduction

Full statespace search for:
        never claim             - (none specified)
        assertion violations    +
        acceptance   cycles     - (not selected)
        invalid end states      +

State-vector 12 byte, depth reached 2, errors: 0
       3 states, stored
       0 states, matched
       3 transitions (= stored+matched)
       0 atomic steps
hash conflicts: 0 (resolved)

4.879   memory usage (Mbyte)

unreached in proctype :init:
        (0 of 2 states)

那么,我在哪里可以从printf语句中找到我的输出呢?我已经在更复杂的promela文件中尝试了printf语句,但是很明显,我想让它首先在简单的情况下工作。任何洞察力都将不胜感激。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-08 15:48:04

运行SPIN验证时,没有打印输出;只显示是否找到错误(以及其他性能信息)。请注意,由于您是初学者,所以当您使用'spin -a…‘调用SPIN时,您会“运行自旋验证”。然后运行编译后的代码。

查看输出有两种方法。首先,利用spin hello.pml在仿真模式下使用自旋。例如:

代码语言:javascript
复制
$ cat >hello.pml <<EOF
> init { printf ("hello world\n"); }
> EOF
$ spin hello.pml 
      hello world
1 process created

其次,在验证模式中使用SPIN,但在程序中注入一个错误。发生错误后,检查跟踪文件。例如:

代码语言:javascript
复制
$ cat >hello.pml <<EOF
> init { printf ("hello world\n"); assert (0); }
> EOF
$ spin -a hello.pml
$ gcc -o hello pan.c
$ ./hello
hint: this search is more efficient if pan.c is compiled -DSAFETY
pan:1: assertion violated 0 (at depth 0)
pan: wrote hello.pml.trail
...
State-vector 12 byte, depth reached 0, errors: 1
...
pan: elapsed time 0 seconds
$ spin -p -t hello.pml
using statement merging
      hello world
  1:    proc  0 (:init:) hello.pml:1 (state 1)  [printf('hello world\\n')]
spin: hello.pml:1, Error: assertion violated
spin: text of failed assertion: assert(0)
  1:    proc  0 (:init:) hello.pml:1 (state 2)  [assert(0)]
spin: trail ends after 1 steps
#processes: 1
  1:    proc  0 (:init:) hello.pml:1 (state 3) <valid end state>
1 process created

您可以在上面的spin -p -t hello.pml后面找到“你好世界”

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22267054

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档