c10_cpu_usage.t 1.04 KB
Newer Older
Francesc Guasch's avatar
Francesc Guasch committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use warnings;
use strict;

use Carp qw(confess);
use Data::Dumper;
use IPC::Run3;
use Test::More;

use lib 't/lib';
use Test::Ravada;

use_ok('Ravada');

my @VMS = vm_names();
Francesc Guasch's avatar
Francesc Guasch committed
15
init();
Francesc Guasch's avatar
Francesc Guasch committed
16
17
18
19
20
21
22
my $USER = create_user("foo","bar", 1);

####################################################################################

sub test_get_cpu_usage {
	chomp(my $cpu_count = `grep -c -P '^processor\\s+:' /proc/cpuinfo`);
	#warn $cpu_count;
23
24
	open(my $stat,"<", '/proc/loadavg') or die "WTF: $!";
	my @cpu = split /\s+/, <$stat>;
Francesc Guasch's avatar
Francesc Guasch committed
25
	warn $cpu[1]/$cpu_count;
26
	close $stat;
Francesc Guasch's avatar
Francesc Guasch committed
27
28
29
30

}

####################################################################################
31
32
33
34
35
if ($>)  {
    diag("SKIPPED: Test must run as root");
    done_testing();
    exit;
}
Francesc Guasch's avatar
Francesc Guasch committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

clean();

my $vm_name = 'KVM';
my $vm = rvd_back->search_vm($vm_name);


SKIP: {

    my $msg = "SKIPPED: No virtual managers found";
    if ($vm && $vm_name =~ /kvm/i && $>) {
        $msg = "SKIPPED: Test must run as root";
        $vm = undef;
    }

    skip($msg,10)   if !$vm;

    test_get_cpu_usage();
}

56
end();
Francesc Guasch's avatar
Francesc Guasch committed
57
done_testing();