开源PSS解析器

本章介绍开源PSS解析工具:

1. 
 PSSTools语法解析器,这个工具仅包含一个语法解析器。

2.  gen-pss,实现了语法解析器,和简单的Test realization,没有约束求解器。

       本文将改造并使用gen-pss来生成C测试用例,改造工具将放在gitee开源网站上。因为gen-pss是使用java实现的一个PSS语法解析器,因此我们需要在系统上安装java JDK。

系统环境:

  • GNU Make 3.82
  • OpenJDK Runtime Environment (build 13.0.2+8)

pss-gen目录构成:

|-- antlr4        // 基于Java开发的开源的语法分析器生成工具

| -- issue        // 问题记录

| -- samples   // 测试用例

| -- src           // 源代码

编译pss-gen:

1.  切换到pss-gen目录下,设置PSS_HOME路径

2. 切换到pss-gen/src目录,并执行make,编译生成java包

$ cd pss-gen
$ export PSS_HOME=$PWD
$ cd src && make
java -jar /home/workspace/pss-gen/antlr4/antlr-4.9.3-complete.jar -no-listener -visitor PSS.g4;
javac --release 13 -classpath /home/handongw/workspace/PSS/pss-tool/pss-gen/src:/home/handongw/workspace/PSS/pss-tool/pss-gen/antlr4/antlr-4.9.3-complete.jar PSS*.java
jar cf pssgen_.jar *.class

运行测试用例:

1. 使用PSS语言进行简单建模

component pss_top {

action sub_a {
  rand int a;
  rand int b;
  constraint {
    a in [100..200];
    b in [100..200];
    (a - b) > 12;
  }

  exec header C = """
#include "sub_a.h"
""";
  exec declaration ASM = """int sub_a;""";
  exec body        ASM = """result = {{a}} - {{b}}""";
  exec run_start   ASM = """sub_a.run_start""";
  exec run_end     ASM = """sub_a.run_end""";
};

action add_a {
  rand int a;
  rand int b;
  constraint {
    a in [0..100];
    b in [0..100];
    (a + b) > 120;
  }

  exec header C = """
#include "add_a.h"
""";
  exec declaration C = """int add_a;""";
  exec body        C = """result = {{a}} + {{b}}""";
  exec run_start   C = """add_a.run_start""";
  exec run_end     C = """add_a.run_end""";
};

action root_a {
  exec header C = """
#include "root_a.h"
""";
  exec declaration C = """int root_a;""";
  exec body        C = """root_a.body""";
  exec run_start   C = """root_a.run_start""";
  exec run_end     C = """root_a.run_end""";

  activity {
    do sub_a;
    do add_a;
  }
};
};

执行make命令生成测试激励

include ../Make.vars

gentarget:
	$(PSSGEN) test.pss -n 1 -root pss_top::root_a || true

测试激励

// header

#include "root_a.h"


#include "sub_a.h"


#include "add_a.h"


// declaration
int root_a;
int sub_a;
int add_a;

void main() {

    // run_start

    root_a.run_start

    sub_a.run_start

    add_a.run_start

    {
        // action pss_top.root_a realization
        root_a.body
    }

    {
        // action pss_top.root_a.sub_a realization
        result = 182 - 150
    }

    {
        // action pss_top.root_a.add_a realization
        result = 33 + 93
    }

    // run_end

    root_a.run_end

    sub_a.run_end

    add_a.run_end

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值