]> git.proxmox.com Git - pve-installer.git/blame - test/run-command.pl
sys: command: handle EINTR in run_command()
[pve-installer.git] / test / run-command.pl
CommitLineData
152bbef4
CH
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use File::Temp;
7use Test::More;
8
9use Proxmox::Sys::Command qw(run_command CMD_FINISHED);
10use Proxmox::Sys::File qw(file_read_all);
11use Proxmox::UI;
12
13my $log_file = File::Temp->new();
14Proxmox::Log::init($log_file->filename);
15
16Proxmox::UI::init_stdio();
17
18is(run_command('echo test'), "test\n", 'basic usage');
19
20is(run_command('echo test', undef, undef, 1), 0, 'system()-mode');
21
22my $ret = run_command('bash -c "echo test; sleep 1000; echo test"', sub {
23 my $line = shift;
24 is($line, 'test', 'using CMD_FINISHED - produced correct log line');
25
26 return CMD_FINISHED;
27});
28is($ret, '', 'using CMD_FINISHED');
29
7a95f387
CH
30# https://bugzilla.proxmox.com/show_bug.cgi?id=4872
31my $prev;
32eval {
33 local $SIG{ALRM} = sub { die "timed out!\n" };
34 $prev = alarm(1);
35 $ret = run_command('sleep 5');
36};
37alarm($prev);
38
39is($@, "timed out!\n", 'SIGALRM interaction');
40
152bbef4
CH
41# Check the log for errors/warnings
42my $log = file_read_all($log_file->filename);
43ok($log !~ m/(WARN|ERROR): /, 'no warnings or errors logged');
44print $log if $log =~ m/(WARN|ERROR): /;
45
46done_testing();