1*** Settings ***
2Library             Process
3Library             String
4Library             SerialLibrary
5Library             CSVLibrary
6
7Suite Teardown      Terminate All Processes    kill=True
8
9
10*** Variables ***
11${csv_file}         zbus_dyn_benchmark_256kb.csv
12${board}            hifive1@B
13${serial_port}      /dev/ttyACM0
14
15
16*** Tasks ***
17Clear Old CSV File
18    Empty Csv File    ${csv_file}
19
20Zbus Benchmark
21    FOR    ${obs_type}    IN    0    1    2
22        FOR    ${consumers}    IN    1    4    8
23            FOR    ${msg_size}    IN    2    8    32    128    512
24                Benchmark Report For
25                ...    message_size=${msg_size}
26                ...    one_to=${consumers}
27                ...    observer_type=${obs_type}
28            END
29        END
30    END
31
32
33*** Keywords ***
34Run Memory Report
35    [Arguments]    ${type}
36    ${result}    Run Process    west build -t ${type}_report    shell=True
37    Should Be Equal As Integers    ${result.rc}    0
38    ${mem}    Get Substring    ${result.stdout}    -20
39    ${mem}    Strip String    ${mem}
40    ${mem}    Convert To Integer    ${mem}
41    RETURN    ${mem}
42
43Measure Results
44    ${total}    Set Variable    0
45    Add Port    ${serial_port}    timeout=120    baudrate=115200
46    Set Encoding    ascii
47    FOR    ${count}    IN RANGE    3
48        ${result}    Run Process    west flash    shell=True
49        Should Be Equal As Integers    ${result.rc}    0
50        ${val}    Read Until    expected=@    encoding=ascii
51        ${val}    Read Until    encoding=ascii
52        ${val}    Strip String    ${val}
53        ${val}    Convert To Integer    ${val}
54        ${total}    Evaluate    ${total}+${val}
55    END
56    ${duration}    Evaluate    ${total}/3.0
57    RETURN    ${duration}
58    [Teardown]    Delete All Ports
59
60Benchmark
61    [Arguments]    ${message_size}=256    ${one_to}=1    ${observer_type}=LISTENERS
62    ${result}    Run Process
63    ...    west build -b ${board} -p always -- -DCONFIG_BM_MESSAGE_SIZE\=${message_size} -DCONFIG_BM_ONE_TO\=${one_to} -DCONFIG_BM_${observer_type}\=y
64    ...    shell=True
65    Should Be Equal As Integers    ${result.rc}    0
66    ${duration}    Measure Results
67    RETURN    ${duration}
68
69Benchmark Report For
70    [Arguments]    ${message_size}=256    ${one_to}=1    ${observer_type}=0
71
72    ${obs_type_str}    Set Variable    LISTENERS
73    IF    ${observer_type} == 1
74        ${obs_type_str}    Set Variable    SUBSCRIBERS
75    ELSE IF    ${observer_type} == 2
76        ${obs_type_str}    Set Variable    MSG_SUBSCRIBERS
77    END
78
79    ${duration}    Benchmark
80    ...    message_size=${message_size}
81    ...    one_to=${one_to}
82    ...    observer_type=${obs_type_str}
83
84    ${ram_amount}    Run Memory Report    ram
85
86    ${rom_amount}    Run Memory Report    rom
87
88    @{results}    Create List
89    ...    ${obs_type_str}
90    ...    ${one_to}
91    ...    ${message_size}
92    ...    ${duration}
93    ...    ${ram_amount}
94    ...    ${rom_amount}
95
96    Log To Console    \n${results}
97
98    Append To Csv File    ${csv_file}    ${results}
99