本章介绍开源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.varsgentarget:$(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_startroot_a.run_startsub_a.run_startadd_a.run_start{// action pss_top.root_a realizationroot_a.body}{// action pss_top.root_a.sub_a realizationresult = 182 - 150}{// action pss_top.root_a.add_a realizationresult = 33 + 93}// run_endroot_a.run_endsub_a.run_endadd_a.run_end}