Skip to content

Commit

Permalink
Use properly named constant for "ssh serial read buffer size"
Browse files Browse the repository at this point in the history
Related to os-autoinst#2429
  • Loading branch information
okurz committed Jan 11, 2024
1 parent 5eb8a49 commit f59c01c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion backend/baseclass.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use OpenQA::NamedIOSelect;
use constant FULL_SCREEN_SEARCH_FREQUENCY => $ENV{OS_AUTOINST_FULL_SCREEN_SEARCH_FREQUENCY} // 5;
use constant FULL_UPDATE_REQUEST_FREQUENCY => $ENV{OS_AUTOINST_FULL_UPDATE_REQUEST_FREQUENCY} // 5;
use constant DEFAULT_FFMPEG_CMD => 'ffmpeg -y -hide_banner -nostats -r 24 -f image2pipe -vcodec ppm -i - -pix_fmt yuv420p';
use constant SSH_SERIAL_READ_BUFFER_SIZE => 4096;

# should be a singleton - and only useful in backend process
our $backend;
Expand Down Expand Up @@ -1271,7 +1272,7 @@ sub check_ssh_serial ($self, $fh = undef, $write = undef) {
# read from SSH channel (receiving extended data channel as well via `$chan->ext_data('merge')`)
my $chan = $self->{serial_chan};
my $buffer;
while (defined(my $bytes_read = $chan->read($buffer, 4096))) {
while (defined(my $bytes_read = $chan->read($buffer, SSH_SERIAL_READ_BUFFER_SIZE))) {
return 1 unless $bytes_read > 0;
print $buffer;
open(my $serial, '>>', $self->{serialfile});
Expand Down
4 changes: 2 additions & 2 deletions t/23-baseclass.t
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,12 @@ subtest 'SSH utilities' => sub {
is($ssh->blocking(), 0, 'We run SSH in none blocking mode');

$baseclass->truncate_serial_file();
my $expect_output = "FOO$/" x 4096;
my $expect_output = "FOO$/" x backend::baseclass::SSH_SERIAL_READ_BUFFER_SIZE;
my $channel_read_string = $expect_output;
$chan->mock(read => sub {
my ($self, undef, $max) = @_;
return unless (defined($channel_read_string));
$max //= 4096;
$max //= backend::baseclass::SSH_SERIAL_READ_BUFFER_SIZE;
$_[1] = substr($channel_read_string, 0, $max);
my $ret = length($_[1]);
$channel_read_string = substr($channel_read_string, $ret);
Expand Down

0 comments on commit f59c01c

Please sign in to comment.