Skip to content

Commit

Permalink
Added --test-payload option
Browse files Browse the repository at this point in the history
This commit adds a feature to give the user the option to specify
a custom file as payload to fill netperf's buffers.
Previously, netperf buffers were filled with randomised payload from
the /dev/urandom device file. But now with the --test-payload option
a custom file can also be sent as payload.
Flent will check if the file is readable before passing it to netperf,
and fail the test run if it isn't.
This can be useful in test scenarios where some data needs to be
sent along with the packets when running the provided tests.

Signed-off-by: Hrishikesh Athalye <hathalye7@hotmail.com>
  • Loading branch information
hrishikeshathalye committed Oct 21, 2021
1 parent 5527b18 commit 42e0f29
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
16 changes: 12 additions & 4 deletions flent/runners.py
Expand Up @@ -983,6 +983,7 @@ def check(self):
args.setdefault('send_size',
self.settings.SEND_SIZE[0]
if self.settings.SEND_SIZE else "")
args.setdefault('test_payload', self.settings.TEST_PAYLOAD)

if self.settings.SWAP_UPDOWN:
if self.test == 'TCP_STREAM':
Expand Down Expand Up @@ -1022,12 +1023,19 @@ def check(self):
netperf['-e'] = True

try:
# Sanity check; is /dev/urandom readable? If so, use it to
# If --test-payload option is specified, use data from that file
# else use the default value /dev/urandom.
fill_file = args['test_payload']
# Sanity check; is /dev/urandom or the custom file readable? If so, use it to
# pre-fill netperf's buffers
self.run_simple(['dd', 'if=/dev/urandom', 'of=/dev/null', 'bs=1', 'count=1'], errmsg="Err")
netperf['buffer'] = '-F /dev/urandom'
self.run_simple(['dd', 'if='+fill_file, 'of=/dev/null', 'bs=1', 'count=1'], errmsg="Err")
netperf['buffer'] = '-F '+fill_file
except RunnerCheckError:
netperf['buffer'] = ''
if(fill_file == '/dev/urandom'):
netperf['buffer'] = ''
else:
# If the custom file is not readable, fail noisily
raise RunnerCheckError("The specified test payload file does not exist or is not readable.")

if not self.remote_host:
# only cache values if we're not executing the checks on a
Expand Down
6 changes: 6 additions & 0 deletions flent/settings.py
Expand Up @@ -378,6 +378,12 @@ def __call__(self, parser, namespace, values, option_string=None):
"to decrease the socket buffer size. Can be specified multiple times, "
"with each value corresponding to a stream of a test.")

test_group.add_argument(
"--test-payload",
action="store", type=unicode, dest="TEST_PAYLOAD", default='/dev/urandom',
help="Path to file containing payload to pre-fill the netperf buffers with "
"defaults to randomised payload")

test_group.add_argument(
"--test-parameter",
action=Update, type=keyval, dest="TEST_PARAMETERS", metavar='key=value',
Expand Down
2 changes: 1 addition & 1 deletion flent/testenv.py
Expand Up @@ -57,7 +57,7 @@
# in the code below
STREAM_CONFIG_PARAM_NAMES = ['label', 'ping_label', 'marking',
'control_host', 'local_bind', 'cc_algo',
'udp_bandwidth', 'udp_pktsize', 'send_size']
'udp_bandwidth', 'udp_pktsize', 'send_size', 'test_payload']

# Mapping of test parameters that will be picked up from the global settings if
# they are not set
Expand Down

0 comments on commit 42e0f29

Please sign in to comment.