P158 Schooner 优化
优化之前问题
- csv 过于臃肿,如果牵扯到调整ERS循环的情况,那真的就是
一行代码
改一天- Yaml文件问题
testParameters
不同;actions:
只有某一项或者多项参数不同,其余均相同。但是还是需要根据testParameters
编写Yaml,导致大量冗余代码testParameters
不同;inputs
是需要从外界传入find.output(...)
只有某一项或者多项参数不同,其余均相同,但是还是需要根据testParameters
编写Yaml,导致大量冗余代码
CSV优化
参考 Demo readme
- 根据ERS 分步编写CSV
- CSV中定义部分逻辑,
Yaml优化
1. 参数抽取
以Calibration.yaml
为例
-
优化前
优化前的代码可以参考
v1.9
分支commit: 253682fc7b67b893440e13cec235cc2e5be35269
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67- #ReadADCcalfromDSMStoretoPDCA
technology: Calibration
coverage: ReadADCcalfromDSMStoretoPDCA
testParameters: "*"
outputs:
result:
lookup: [sendCommand_action]
sequence:
actions:
- sendCommand_action:
filename: DutSendCommand.lua
args:
- "calib adc_get"
- #CALIINV64GAIN
technology: Calibration
coverage: "ReadADCcalfromDSMStoretoPDCA"
testParameters: "&CALIINV64GAIN"
outputs:
IINV64GAIN:
lookup: [paras_action]
inputs:
result: 'find.output("Calibration", "ReadADCcalfromDSMStoretoPDCA", "", "result")'
sequence:
actions:
- paras_action:
filename: RegexGroup.lua
args:
- lookup: [inputs, result]
- "i_inv_64_gain=(.*) i_inv_64_offset"
- RunEvalCalculate_action:
filename: CalculatePuckADCValue.lua
args:
- lookup: [paras_action]
- record_action:
filename: CreateRecord.lua
args:
- lookup: [RunEvalCalculate_action]
- #&CALIINV64OFFSET
technology: Calibration
coverage: "ReadADCcalfromDSMStoretoPDCA"
testParameters: "&CALIINV64OFFSET"
outputs:
IINV64OFFSET:
lookup: [paras_action]
inputs:
result: 'find.output("Calibration", "ReadADCcalfromDSMStoretoPDCA", "", "result")'
sequence:
actions:
- paras_action:
filename: RegexGroup.lua
args:
- lookup: [inputs, result]
- "i_inv_64_offset=(.*) i_inv_16_gain"
- RunEvalCalculate_action:
filename: CalculatePuckADCValue.lua
args:
- lookup: [paras_action]
- record_action:
filename: CreateRecord.lua
args:
- lookup: [RunEvalCalculate_action]
#...omit..
# total code line number is 313观察上述代码可以发现 除却第一个配置,后续12个yaml 基本都是重复的,除了
testParameters
和paras_action
中第二个参数不一样之外,其他都一样, -
优化后:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44- #ReadADCcalfromDSMStoretoPDCA
technology: Calibration
coverage: ReadADCcalfromDSMStoretoPDCA
testParameters: ""
outputs:
result:
lookup: [sendCommand_action]
sequence:
actions:
- sendCommand_action:
filename: DutSendCommand.lua
args:
- "calib adc_get"
- #FetchCalibrationValue
technology: Calibration
coverage: "ReadADCcalfromDSMStoretoPDCA"
testParameters: "*"
outputs:
result:
lookup: [paras_action]
inputs:
result: 'find.output("Calibration", "ReadADCcalfromDSMStoretoPDCA", "", "result")'
category: testParameters
sequence:
actions:
- fecth_Regex_pattern_Action:
filename: FetchRegexPattern.lua
args:
- lookup: [inputs, category]
- paras_action:
filename: RegexGroup.lua
args:
- lookup: [inputs, result]
- lookup: [fecth_Regex_pattern_Action]
- RunEvalCalculate_action:
filename: CalculatePuckADCValue.lua
args:
- lookup: [paras_action]
- record_action:
filename: CreateRecord.lua
args:
- lookup: [RunEvalCalculate_action]
# total line is 43
优化之后最直观的表现是 yaml 文件中仅有43行代码;
优化后的思路是:
-
将
testParameters
通过参数传入, 观察第 24行代码category: testParameters
-
定义一个方法
fecth_Regex_pattern_Action
用来获取对应的正则,内部的部分代码如下1
2
3
4
5
6
7
8
9
10
11function main(category)
local pattern = ""
if category:find("CALIINV64GAIN") then
pattern = "i_inv_64_gain=(.*) i_inv_64_offset"
elseif category:find("CALIINV64OFFSET") then
pattern = "i_inv_64_offset=(.*) i_inv_16_gain"
elseif category:find("CALIINV16GAIN") then
pattern = "i_inv_16_gain=(.*) i_inv_16_offset"
-- omit others
return pattern
end
2. 编译器优化
参考DEMO P158 分支:lx_analyze
, HF_before.yaml
和 LF_before.yaml
两个文件是优化之前的,HF.yaml
和 LF.yaml
是优化之后的
-
优化前的部分代码
1
2
3
4
5
6
7
8technology: LF
coverage: CalculateDCEfficiency
testParameters: "&LF_EFF_21_290mA_DCDC_EFF"
inputs:
vrect_fixture: 'find.output("Common", "RecordVrectFixture", "&LF_EFF_21_290mA_VRECT_FIXTURE", "vrect_fixture")'
imain_fixture: 'find.output("Common", "RecordImainFixture", "&LF_EFF_21_290mA_IMAIN_FIXTURE", "imain_fixture")'
vpwr_adc: 'find.output("Common", "ReadVPWRAdc", "&LF_EFF_21_290mA_VPWR_ADC", "vpwr_adc")'
ibus_fixture: 'find.output("Common", "RecordIbusFixture", "&LF_EFF_21_290mA_IBUS_FIXTURE", "ibus_fixture")'能够看到
inputs
的四个参数中,负载值(21_290) 跟testParameters
一直。但是Schooner 并没有 参数化传递"find.output(...)"
的方法,所以这部分ERS循环n次就需要编辑n次,导致冗余代码过多,后期维护修改及其繁琐,而且容易漏改
解决方法: 定制化编译工具. 在 Atlas2/Modules/Schooner/Compiler/Compiler.lua
文件中的function M.checkInputs(testDef, conditionTable, dependentTests)
的方法里添加,我们需要格式化 yaml 参数的部分
1 |
|
ALE.CompilerCustom
是我们需要定制化的逻辑,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function CompilerCustom.transformArgsString(sourceTestDef, argsString)
-- NOTE: 这个pattern 不能改的!!! 除非跟定义时候一致,否则会出错
local pattern = "{(.-)}"
for matchLogic in argsString:gmatch(pattern) do
local pattern_tp, duty, load_mA = "", "" ,""
local testParameters = sourceTestDef.testParameters
if string.find(testParameters, "&LF_EFF_") ~= nil then
pattern_tp = "_(%d+)_([%d]+)mA"
elseif string.find(testParameters, "&HF_EFF_") then
pattern_tp = "_(%d+)mV_([%d]+)mA"
end
duty, load_mA = sourceTestDef.testParameters:match(pattern_tp)
if matchLogic == "duty" then
argsString = argsString:gsub("{duty}",duty)
elseif matchLogic == "load" then
argsString = argsString:gsub("{load}",load_mA)
end
end
return argsString
end
优化后的yaml文件里的写法
1 |
|
因此,后续就不惧ERS如何更新。
综上,用程式生成的CSV和Ymal的输入参数格式化,在ERS繁多的情况下,会大大提升开发效率。