<commit_before>#!perl

use strict;
use warnings;

use Data::Dumper;
use Test::More;

no warnings "experimental::signatures";
use feature qw(signatures);

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

init();


my $DIR_SAVE = "/var/lib/libvirt/qemu/save";

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

sub test_crashed($vm, $position) {
    my $domain = create_domain($vm->type);
    $domain->start(user_admin);
    is($domain->is_active,1);
    sleep 2;
    $domain->hibernate(user_admin);

    ok($domain->domain->has_managed_save_image) or return;

    my $file_image =  $DIR_SAVE."/".$domain->name.".save";
    ok ( -e $file_image,"Expecting saved image in file $file_image") or return;

    open my $image, "+<", $file_image or die "$! $file_image";
    seek($image, $position , 0);
    syswrite($image,"garbage");
    close $image;

    eval { $domain->start(user_admin) };
    is(''.$@,'');

    is($domain->is_active,1);

}

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

clean();

use_ok('Ravada');

for my $vm_name ( 'KVM' ) {

    my $vm;
    eval { $vm = rvd_back->search_vm($vm_name) };

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

        diag($msg)      if !$vm;
        skip $msg       if !$vm;

        diag("Testing shutdown on $vm_name");

        for my $position( 128, 1024, 2048, 4096 ) {
            test_crashed($vm, $position);
        }<commit_msg>wip(test): remove machine after test<commit_after>#!perl

use strict;
use warnings;

use Data::Dumper;
use Test::More;

no warnings "experimental::signatures";
use feature qw(signatures);

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

init();


my $DIR_SAVE = "/var/lib/libvirt/qemu/save";

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

sub test_crashed($vm, $position) {
    my $domain = create_domain($vm->type);
    $domain->start(user_admin);
    is($domain->is_active,1);
    sleep 2;
    $domain->hibernate(user_admin);

    ok($domain->domain->has_managed_save_image) or return;

    my $file_image =  $DIR_SAVE."/".$domain->name.".save";
    ok ( -e $file_image,"Expecting saved image in file $file_image") or return;

    open my $image, "+<", $file_image or die "$! $file_image";
    seek($image, $position , 0);
    syswrite($image,"garbage");
    close $image;

    eval { $domain->start(user_admin) };
    is(''.$@,'');

    is($domain->is_active,1);

    $domain->remove(user_admin);
}

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

clean();

use_ok('Ravada');

for my $vm_name ( 'KVM' ) {

    my $vm;
    eval { $vm = rvd_back->search_vm($vm_name) };

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

        diag($msg)      if !$vm;
        skip $msg       if !$vm;

        diag("Testing shutdown on $vm_name");

        for my $position( 128, 1024, 2048, 4096 ) {
            test_crashed($vm, $position);
        }
{'fraction_non_alphanumeric': 0.2564814814814815, 'fraction_numerical': 0.011728395061728396, 'mean_word_length': 3.1392081736909323, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1033559', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1079, 'n_words': 247}