Skip to content

Commit

Permalink
Merge pull request #20176 from SeroSun/yosun/single_run
Browse files Browse the repository at this point in the history
xfstests: subtest run could rollback
  • Loading branch information
SeroSun authored Sep 24, 2024
2 parents 4ec739a + 58a03ea commit 2085b19
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 195 deletions.
1 change: 0 additions & 1 deletion lib/main_micro_alp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ sub load_xfstests_tests {
boot_hdd_image;
loadtest 'xfstests/partition';
loadtest 'xfstests/run';
loadtest 'xfstests/generate_report';
}
}

Expand Down
60 changes: 48 additions & 12 deletions lib/xfstests_utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ our @EXPORT = qw(
reload_loop_device
umount_xfstests_dev
config_debug_option
test_run_without_heartbeat);
test_run_without_heartbeat
check_bugzilla_status);

=head2 heartbeat_prepare
Expand Down Expand Up @@ -464,13 +465,11 @@ Log: Collect fs runtime status for XFS, Btrfs and Ext4

sub collect_fs_status {
my ($category, $num, $fstype) = @_;
my $cmd = <<END_CMD;
mount \$TEST_DEV \$TEST_DIR &> /dev/null
[ -n "\$SCRATCH_DEV" ] && mount \$SCRATCH_DEV $SCRATCH_FOLDER &> /dev/null
END_CMD
my $cmd;
script_run('mount $TEST_DEV $TEST_DIR &> /dev/null');
script_run("[ -n \"\$SCRATCH_DEV\" ] && mount \$SCRATCH_DEV $SCRATCH_FOLDER &> /dev/null");
if ($fstype eq 'xfs') {
$cmd = <<END_CMD;
$cmd
echo "==> /sys/fs/$fstype/stats/stats <==" > $LOG_DIR/$category/$num.fs_stat
cat /sys/fs/$fstype/stats/stats >> $LOG_DIR/$category/$num.fs_stat
tail -n +1 /sys/fs/$fstype/*/log/* >> $LOG_DIR/$category/$num.fs_stat
Expand All @@ -481,7 +480,6 @@ END_CMD
}
elsif ($fstype eq 'btrfs') {
$cmd = <<END_CMD;
$cmd
tail -n +1 /sys/fs/$fstype/*/allocation/data/[bdft]* >> $LOG_DIR/$category/$num.fs_stat
tail -n +1 /sys/fs/$fstype/*/allocation/metadata/[bdft]* >> $LOG_DIR/$category/$num.fs_stat
tail -n +1 /sys/fs/$fstype/*/allocation/metadata/dup/* >> $LOG_DIR/$category/$num.fs_stat
Expand All @@ -490,12 +488,10 @@ END_CMD
}
elsif ($fstype eq 'ext4') {
$cmd = <<END_CMD;
$cmd
tail -n +1 /sys/fs/$fstype/*/* >> $LOG_DIR/$category/$num.fs_stat
END_CMD
}
$cmd = <<END_CMD;
$cmd
umount \$TEST_DEV &> /dev/null
[ -n "\$SCRATCH_DEV" ] && umount \$SCRATCH_DEV &> /dev/null
END_CMD
Expand Down Expand Up @@ -577,7 +573,7 @@ Run a single test and write log to file but without heartbeat, return log_add ou
=cut

sub test_run_without_heartbeat {
my ($self, $test, $timeout, $fstype, $btrfs_dump, $raw_dump, $scratch_dev, $scratch_dev_pool, $inject_info, $loop_device, $enable_kdump, $virtio_console) = @_;
my ($self, $test, $timeout, $fstype, $btrfs_dump, $raw_dump, $scratch_dev, $scratch_dev_pool, $inject_info, $loop_device, $enable_kdump, $virtio_console, $get_log_content) = @_;
my ($category, $num) = split(/\//, $test);
my $run_options = '';
my $status_num = 1;
Expand All @@ -591,7 +587,6 @@ sub test_run_without_heartbeat {
$test_start = time();
# Send kill signal 3 seconds after sending the default SIGTERM to avoid some tests refuse to stop after timeout
assert_script_run("timeout -k 3 " . ($timeout - 5) . " $TEST_WRAPPER '$test' $run_options $inject_info | tee $LOG_DIR/$category/$num; echo \${PIPESTATUS[0]} > $LOG_DIR/subtest_result_num", $timeout);
$status_num = script_output("tail -n 1 $LOG_DIR/subtest_result_num");
$test_duration = time() - $test_start;
};
if ($@) {
Expand Down Expand Up @@ -620,6 +615,7 @@ sub test_run_without_heartbeat {
reload_loop_device($self, $fstype) if $loop_device;
}
else {
$status_num = script_output("tail -n 1 $LOG_DIR/subtest_result_num");
$status_num =~ s/^\s+|\s+$//g;
if ($status_num == 0) {
$test_status = 'PASSED';
Expand All @@ -633,7 +629,47 @@ sub test_run_without_heartbeat {
}
}
# Add test status to STATUS_LOG file
return log_add($STATUS_LOG, $test, $test_status, $test_duration);
if ($get_log_content) {
return log_add($STATUS_LOG, $test, $test_status, $test_duration);
}
else {
log_add($STATUS_LOG, $test, $test_status, $test_duration);
my $log_content = script_output("cat $LOG_DIR/subtest_result_num");
my $targs = {
name => $test,
status => $test_status,
time => $test_duration,
output => $log_content,
};
return $targs;
}
}

=head2 check_bugzilla_status
A function use in white list, to check bugzilla status and write messages in output
=cut

sub check_bugzilla_status {
my ($entry, $targs) = @_;
if (exists $entry->{bugzilla}) {
my $info = bugzilla_buginfo($entry->{bugzilla});

if (!defined($info) || !exists $info->{bug_status}) {
$targs->{bugzilla} = "Bugzilla error:\n" .
"Failed to query bug #$entry->{bugzilla} status";
return;
}

if ($info->{bug_status} =~ /resolved/i || $info->{bug_status} =~ /verified/i) {
$targs->{bugzilla} = "Bug closed:\n" .
"Bug #$entry->{bugzilla} is closed, ignoring whitelist entry";
return;
}
}
$targs->{status} = 'SOFTFAILED' unless $entry->{keep_fail};
$targs->{failinfo} = $entry->{message};
}

1;
2 changes: 0 additions & 2 deletions products/sle/main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -800,13 +800,11 @@ elsif (get_var('XFSTESTS')) {
else {
loadtest 'xfstests/partition';
loadtest 'xfstests/run';
loadtest 'xfstests/generate_report';
}
}
else {
loadtest 'xfstests/partition';
loadtest 'xfstests/run';
loadtest 'xfstests/generate_report';
}
}
elsif (get_var("BTRFS_PROGS")) {
Expand Down
79 changes: 10 additions & 69 deletions tests/xfstests/generate_report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ use File::Basename;
use testapi;
use serial_terminal 'select_serial_terminal';
use upload_system_log;
use filesystem_utils 'generate_xfstests_list';
use LTP::utils;
use LTP::WhiteList;
use bugzilla;

my $STATUS_LOG = '/opt/status.log';
my $LOG_DIR = '/opt/log';
Expand All @@ -45,28 +41,21 @@ sub upload_subdirs {
my $output = script_output("if [ -d $dir ]; then find $dir -maxdepth 1 -mindepth 1 -type f -or -type d; else echo $dir folder not exist; fi");
if ($output =~ /folder not exist/) { return; }
for my $subdir (split(/\n/, $output)) {
next if ($subdir =~ /subtest_result_num/);
my $tarball = "$subdir.tar.xz";
assert_script_run("ll; tar cJf $tarball -C $dir " . basename($subdir), $timeout);
upload_logs($tarball, timeout => $timeout);
}
}

sub analyze_result {
sub test_summary {
my ($text) = @_;
my $test_num = 0;
my $pass_num = 0;
my $fail_num = 0;
my $skip_num = 0;
my $total_time = 0;
my $test_range = '';
my $whitelist;
my $whitelist_env = prepare_whitelist_environment();
my $whitelist_url = get_var('XFSTESTS_KNOWN_ISSUES');
my $suite = get_required_var('TEST');
my %softfail_list = generate_xfstests_list(get_var('XFSTESTS_SOFTFAIL'));

$whitelist = LTP::WhiteList->new($whitelist_url) if $whitelist_url;

foreach (split("\n", $text)) {
my ($test_name, $test_status, $test_time);
if ($_ =~ /(\S+)\s+\.{3}\s+\.{3}\s+(PASSED|FAILED|SKIPPED)\s+\((\S+)\)/g) {
Expand All @@ -80,36 +69,11 @@ sub analyze_result {
(my $generate_name = $test_name) =~ s/-/\//;
$test_num += 1;
$test_range = $test_range . $generate_name . " ... ... " . $test_status . " ($test_time seconds)" . "\n";
my $test_path = '/opt/log/' . $generate_name;
bmwqemu::fctinfo("$generate_name");
if ($test_status =~ /FAILED|SKIPPED/) {
my $targs = OpenQA::Test::RunArgs->new();
my $whitelist_entry;

$targs->{output} = script_output("if [ -f $test_path ]; then tail -n 200 $test_path | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176'; else echo 'No log in test path, find log in serial0.txt'; fi", 600);
$targs->{name} = $test_name;
$targs->{time} = $test_time;
$targs->{status} = $test_status;

if ($test_status =~ /FAILED/) {
$targs->{outbad} = script_output("if [ -f $test_path.out.bad ]; then tail -n 200 $test_path.out.bad | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176'; else echo '$test_path.out.bad not exist';fi", 600);
$targs->{fullog} = script_output("if [ -f $test_path.full ]; then tail -n 200 $test_path.full | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176'; else echo '$test_path.full not exist'; fi", 600);
$targs->{dmesg} = script_output("if [ -f $test_path.dmesg ]; then tail -n 200 $test_path.dmesg | sed \"s/'//g\" | tr -cd '\\11\\12\\15\\40-\\176'; fi", 600);
$fail_num += 1;

if (exists($softfail_list{$generate_name})) {
$targs->{status} = 'SOFTFAILED';
$targs->{failinfo} = 'XFSTESTS_SOFTFAIL';
}

$whitelist_entry = $whitelist->find_whitelist_entry($whitelist_env, $suite, $generate_name) if defined($whitelist);
check_bugzilla_status($whitelist_entry, $targs) if ($whitelist_entry);
}
else {
$skip_num += 1;
}
# show fail message
autotest::loadtest("tests/xfstests/xfstests_failed.pm", name => $test_name, run_args => $targs);
if ($test_status =~ /FAILED/) {
$fail_num += 1;
}
elsif ($test_status =~ /SKIPPED/) {
$skip_num += 1;
}
else {
$pass_num += 1;
Expand All @@ -120,27 +84,6 @@ sub analyze_result {
record_info('Test Ranges', "$test_range");
}

sub check_bugzilla_status {
my ($entry, $targs) = @_;
if (exists $entry->{bugzilla}) {
my $info = bugzilla_buginfo($entry->{bugzilla});

if (!defined($info) || !exists $info->{bug_status}) {
$targs->{bugzilla} = "Bugzilla error:\n" .
"Failed to query bug #$entry->{bugzilla} status";
return;
}

if ($info->{bug_status} =~ /resolved/i || $info->{bug_status} =~ /verified/i) {
$targs->{bugzilla} = "Bug closed:\n" .
"Bug #$entry->{bugzilla} is closed, ignoring whitelist entry";
return;
}
}
$targs->{status} = 'SOFTFAILED' unless $entry->{keep_fail};
$targs->{failinfo} = $entry->{message};
}

sub run {
select_serial_terminal;
return if get_var('XFSTESTS_NFS_SERVER');
Expand All @@ -158,21 +101,19 @@ sub run {
# Finalize status log and upload it
log_end($STATUS_LOG);
upload_logs($STATUS_LOG, timeout => 60, log_name => $STATUS_LOG);

# Upload test logs
upload_subdirs($LOG_DIR, 1200);

# Upload kdump logs if not set "NO_KDUMP=1"
unless (check_var('NO_KDUMP', '1')) {
upload_subdirs($KDUMP_DIR, 1200);
}

#upload system log
# Upload system log
upload_system_logs();

# Junit xml report
# Summary test range info
my $script_output = script_output("cat $STATUS_LOG", 600);
analyze_result($script_output);
test_summary($script_output);
}

sub test_flags {
Expand Down
Loading

0 comments on commit 2085b19

Please sign in to comment.