File: throughput_tests.py

package info (click to toggle)
fastdds 3.1.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 58,132 kB
  • sloc: cpp: 779,516; xml: 15,119; python: 4,356; sh: 190; makefile: 93; ansic: 12
file content (325 lines) | stat: -rw-r--r-- 9,867 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import os
import subprocess


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )
    parser.add_argument(
        '-x',
        '--xml_file',
        help='A Fast DDS XML configuration file',
        required=False
    )
    parser.add_argument(
        '-t',
        '--test_duration',
        help='The duration of test iteration [s]',
        required=False,
        default='1'
    )
    parser.add_argument(
        '-r',
        '--recoveries_file',
        help='A CSV file with maxima sleep time between bursts [ms]',
        required=False,
        default=None
    )
    parser.add_argument(
        '-f',
        '--demands_file',
        help='Filename of the demands configuration file',
        required=False,
        default=None
    )
    parser.add_argument(
        '-s',
        '--security',
        action='store_true',
        help='Enables security (Defaults: disable)',
        required=False
    )
    parser.add_argument(
        '-i',
        '--interprocess',
        action='store_true',
        help='Publisher and subscribers in separate processes. Defaults:False',
        required=False
    )
    parser.add_argument(
        '-d',
        '--data_sharing',
        choices=['on', 'off'],
        help='Explicitly enable/disable data sharing. (Defaults: Fast DDS default settings)',
        required=False
    )
    parser.add_argument(
        '-l',
        '--data_loans',
        action='store_true',
        help='Enable the use of the loan sample API (Defaults: disable)',
        required=False
    )
    parser.add_argument(
        '-R',
        '--reliability',
        action='store_true',
        help='Run with RELIABLE reliability (Defaults: disable)',
        required=False
    )
    parser.add_argument(
        '--shared_memory',
        choices=['on', 'off'],
        help='Explicitly enable/disable shared memory transport. (Defaults: Fast DDS default settings)',
        required=False
        )

    # Parse arguments
    args = parser.parse_args()
    xml_file = args.xml_file
    security = args.security
    interprocess = args.interprocess
    recoveries_file = args.recoveries_file

    if security and not interprocess:
        print('Intra-process delivery NOT supported with security')
        exit(1)  # Exit with error

    # Check that test_duration is positive
    if str.isdigit(args.test_duration) and int(args.test_duration) > 0:
        test_duration = str(args.test_duration)
    else:
        print(
            '"test_duration" must be a positive integer, NOT {}'.format(
                args.test_duration
            )
        )
        exit(1)  # Exit with error

    # XML options
    filename_options = 'default'
    xml_options = []
    if xml_file:
        if not os.path.isfile(xml_file):
            print('XML file "{}" is NOT a file'.format(xml_file))
            exit(1)  # Exit with error
        else:
            xml_options = ['--xml', xml_file]
            # Get reliability from XML
            filename_options = xml_file.split('/')[-1].split('\\')[-1]
            filename_options = filename_options.split('.')[-2].split('_')[1:]
            filename_options = '_'.join(filename_options)

    # Data sharing and loans options
    # modify output file names
    if args.data_sharing and 'on' == args.data_sharing and args.data_loans:
        filename_options += '_data_loans_and_sharing'
    elif args.data_sharing and 'on' == args.data_sharing:
        filename_options += '_data_sharing'
    elif args.data_loans:
        filename_options += '_data_loans'

    # Demands files options
    demands_options = []
    if args.demands_file:
        if not os.path.isfile(args.demands_file):
            print('Demands file "{}" is NOT a file'.format(args.demands_file))
            exit(1)  # Exit with error
        else:
            demands_options = [
                '--file',
                args.demands_file,
            ]

    # add flags to the command line
    data_options = []

    if args.data_sharing:
        if 'on' == args.data_sharing:
            data_options += ['--data_sharing=on']
        else:
            data_options += ['--data_sharing=off']

    if args.data_loans:
        data_options += ['--data_loans']

    reliability_options = []
    if args.reliability:
        reliability_options = ['--reliability=reliable']
    else:
        reliability_options = ['--reliability=besteffort']

    if args.shared_memory:
        if 'on' == args.shared_memory:
            data_options += ['--shared_memory=on']
        else:
            data_options += ['--shared_memory=off']

    # Recoveries files options
    recoveries_options = []
    if args.recoveries_file:
        if not os.path.isfile(args.recoveries_file):
            print(
                'Recoveries file "{}" is NOT a file'.format(
                    args.recoveries_file
                )
            )
            exit(1)  # Exit with error
        else:
            recoveries_options = [
                '--recoveries_file',
                args.recoveries_file,
            ]

    # Environment variables
    executable = os.environ.get('THROUGHPUT_TEST_BIN')
    certs_path = os.environ.get('CERTS_PATH')

    # Check that executable exists
    if executable:
        if not os.path.isfile(executable):
            print('THROUGHPUT_TEST_BIN does NOT specify a file')
            exit(1)  # Exit with error
    else:
        print('THROUGHPUT_TEST_BIN is NOT set')
        exit(1)  # Exit with error

    # Security
    security_options = []
    if security is True:
        if certs_path:
            if os.path.isdir(certs_path):
                security_options = ['--security=true', '--certs=' + certs_path]
            else:
                print('CERTS_PATH does NOT specify a directory')
                exit(1)  # Exit with error
        else:
            print('Cannot find CERTS_PATH environment variable')
            exit(1)  # Exit with error

    # Domain must be under 100 to prevent windows multicast issues
    domain = str(os.getpid() % 100)
    domain_options = ['--domain', domain]

    if interprocess is True:
        # Base of test command for publisher agent
        pub_command = [
            executable,
            'publisher',
            '--time',
            test_duration,
            '--export_csv',
        ]
        # Base of test command for subscriber agent
        sub_command = [
            executable,
            'subscriber',
        ]

        # Manage security
        if security is True:
            pub_command.append(
                './measurements_interprocess_{}_security.csv'.format(
                    filename_options
                )
            )
            pub_command += security_options
            sub_command += security_options
        else:
            pub_command.append(
                './measurements_interprocess_{}.csv'.format(
                    filename_options
                )
            )

        pub_command += demands_options
        pub_command += recoveries_options
        pub_command += domain_options
        pub_command += xml_options
        pub_command += data_options
        pub_command += reliability_options

        sub_command += domain_options
        sub_command += xml_options
        sub_command += data_options
        sub_command += reliability_options

        print('Publisher command: {}'.format(
            ' '.join(element for element in pub_command)),
            flush=True
        )
        print('Subscriber command: {}'.format(
            ' '.join(element for element in sub_command)),
            flush=True
        )

        # Spawn processes
        publisher = subprocess.Popen(pub_command)
        subscriber = subprocess.Popen(sub_command)
        # Wait until finish
        subscriber.communicate()
        publisher.communicate()

        if subscriber.returncode != 0:
            exit(subscriber.returncode)
        elif publisher.returncode != 0:
            exit(publisher.returncode)
    else:
        # Base of test command to execute
        command = [
            executable,
            'both',
            '--time',
            test_duration,
            '--export_csv',
        ]

        # Manage security
        if security is True:
            command.append(
                './measurements_intraprocess_{}_security.csv'.format(
                    filename_options,
                )
            )
            command += security_options
        else:
            command.append(
                './measurements_intraprocess_{}.csv'.format(
                    filename_options,
                )
            )

        command += demands_options
        command += recoveries_options
        command += domain_options
        command += xml_options
        command += data_options
        command += reliability_options

        print('Executable command: {}'.format(
            ' '.join(element for element in command)),
            flush=True
        )

        # Spawn process
        both = subprocess.Popen(command)
        # Wait until finish
        both.communicate()
        exit(both.returncode)
    exit(0)