From patchwork Tue Dec 13 06:39:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9471749 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6622E6021C for ; Tue, 13 Dec 2016 03:33:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 596722074F for ; Tue, 13 Dec 2016 03:33:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E25F28156; Tue, 13 Dec 2016 03:33:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=2.0 tests=BAYES_00, DATE_IN_FUTURE_03_06, RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AF5842074F for ; Tue, 13 Dec 2016 03:33:09 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGdnX-0004sm-BM; Tue, 13 Dec 2016 03:30:35 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cGdnV-0004rX-FT for xen-devel@lists.xenproject.org; Tue, 13 Dec 2016 03:30:33 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id CF/69-31715-85B6F485; Tue, 13 Dec 2016 03:30:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeJIrShJLcpLzFFi42LpnVTnqhuR7R9 hcPK4sMX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmvFu3z7GgpmOFdO/bWRtYNxr1MXIxSEkMJFJ 4uDWXSwQzm9GiZkfp7BDOBsZJVauOwbldDNKnO85DeRwcLAJmEi8WeXYxcjJISJgK3GvcTYjS JhZoEhixf86kLCwQLDE5P5L7CA2i4CqxNEDh8FsXgF3iQmT/rGA2BICchLnj/9kBrE5BTwkPi 6/xwQyRgioZs7MJIgSQ4nPG5cyT2DkW8DIsIpRozi1qCy1SNfYQC+pKDM9oyQ3MTNH19DAWC8 3tbg4MT01JzGpWC85P3cTIzBM6hkYGHcwdp7wO8QoycGkJMprHuMfIcSXlJ9SmZFYnBFfVJqT WnyIUYaDQ0mCNz8LKCdYlJqeWpGWmQMMWJi0BAePkgjvxwygNG9xQWJucWY6ROoUozHHtGeLn zJxfDi+5CmTEEtefl6qlDhvGsgkAZDSjNI8uEGwSLrEKCslzMvIwMAgxFOQWpSbWYIq/4pRnI NRSZh3AsgUnsy8Erh9r4BOYQI65fk+b5BTShIRUlINjJn8jNskVS73T3JYZXjqWQDnpbcVzKd Klz161nZWYXrpT4ft6vofFTMs83drXeT5G7vBc1tUXrHz0cXx9gt9V/9ll9wc9WDf6+wHhwXk w1+Hnmm7WiUi2aJYeiHtQcM70cR3TdNO1k4tqux+fXmi9XbTD8sPXhVLWN06tYPpeXej05v58 WfM5yixFGckGmoxFxUnAgBzsdTQnwIAAA== X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-11.tower-31.messagelabs.com!1481599830!44902158!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 40927 invoked from network); 13 Dec 2016 03:30:32 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-11.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 13 Dec 2016 03:30:32 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id uBD3UTqk016408 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Dec 2016 03:30:29 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id uBD3UTZa008115 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Dec 2016 03:30:29 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id uBD3USYb007988; Tue, 13 Dec 2016 03:30:28 GMT Received: from osstest.dumpdata.com (/209.6.196.81) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Dec 2016 19:30:28 -0800 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, Ian.Jackson@eu.citrix.com Date: Tue, 13 Dec 2016 01:39:53 -0500 Message-Id: <1481611195-105372-8-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1481611195-105372-1-git-send-email-konrad.wilk@oracle.com> References: <1481611195-105372-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: ross.lagerwall@citrix.com, Marcos.Matsunaga@oracle.com, Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v2 7/9] ts-livepatch-[install|run]: Install and initial test-cases. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP There are 37 of the test-cases in there. Before we run any of them we verify that the payload files are present in /usr/lib/debug. If so we go through all of the test-cases. Also as a dependency we only install them if xenltpdist.tar.gz exists. Signed-off-by: Konrad Rzeszutek Wilk --- v1: Initial submission. v2: Add ts-livepatch-install Rename ts-livepatch to ts-livepatch-run Use target_cmd_root_status instead of target_cmd_root_rc Use target_cmd_output_status as well Remove tabs, replace with spaces Use Perl for string matching :-) Use subroutines for more complex string testing Use proper style for variable Drop parenthesis on cmd. --- ts-livepatch-install | 37 ++++++++++++ ts-livepatch-run | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100755 ts-livepatch-install create mode 100755 ts-livepatch-run diff --git a/ts-livepatch-install b/ts-livepatch-install new file mode 100755 index 0000000..23c4c20 --- /dev/null +++ b/ts-livepatch-install @@ -0,0 +1,37 @@ +#!/usr/bin/perl -w +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +use strict qw(vars); +use DBI; +use Osstest; +use Osstest::TestSupport; + +tsreadconfig(); + +our ($whhost) = @ARGV; +$whhost ||= 'host'; + +our $ho= selecthost($whhost); + +sub extract () { + my %distpath; + target_extract_jobdistpath($ho, "xen", "path_xenlptdist", + $r{"$ho->{Ident}_xenbuildjob"} // $r{"xenbuildjob"}, + \%distpath); +} + +extract(); diff --git a/ts-livepatch-run b/ts-livepatch-run new file mode 100755 index 0000000..b315d78 --- /dev/null +++ b/ts-livepatch-run @@ -0,0 +1,168 @@ +#!/usr/bin/perl -w +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +use strict qw(vars); +use Osstest; +use POSIX; +use Osstest::TestSupport; + +tsreadconfig(); + +my @livepatch_files = qw(xen_hello_world.livepatch xen_replace_world.livepatch + xen_bye_world.livepatch xen_nop.livepatch); + +my $xen_extra_info; +my $xen_minor_ver; + +sub populate_data { + my @lines = split('\n', $_); + foreach my $line (@lines) { + my ($key, $values) = split /:/, $line; + $values = join("", $values); + chomp($values); + if ($key =~ m/xen_extra/) { + $xen_extra_info = $values; + } + if ($key =~ m/xen_minor/) { + $xen_minor_ver = $values; + } + } + return 1 if $xen_extra_info && $xen_minor_ver; + return 0; +} + +sub check_for_hello_world { + return m/xen_extra/ && m/Hello World/; +} + +sub check_for_stock { + return m/xen_extra/ && m/$xen_extra_info/; +} + +# The NOP test-cases makes xen_minor_ver do nothing. Which means its +# output value should be nothing like before NOPing it. +sub check_versions { + my @lines = split('\n', $_); + foreach my $line (@lines) { + my ($key, $values) = split /:/, $line; + $values = join("", $values); + chomp($values); + if ($key =~ m/xen_minor/) { + if ($values ne $xen_minor_ver ) { + return 1; + } + } + } + return 0; +} + +my @livepatch_tests = ( + # Whether we can actually execute it. + { C => "xen-livepatch list" }, + # And we better have a clean slate.. + { C => "xen-livepatch list", OutputCheck => sub { return !m/xen_/; } }, + # Sets the default values + { C => "xl info", OutputCheck => \&populate_data }, + # Sanity check that populate_data did its job. + { C => "xl info", + OutputCheck => \&check_for_stock }, + # Let it rip! + { C => "xen-livepatch revert xen_hello_world", rc => 256 }, + { C => "xen-livepatch load xen_hello_world.livepatch" }, + { C => "xen-livepatch load xen_hello_world.livepatch", rc => 256 }, + { C => "xen-livepatch list", + OutputCheck => sub { m/xen_hello_world/ } }, + { C => "xl info", + OutputCheck => \&check_for_hello_world }, + { C => "xen-livepatch revert xen_hello_world" }, + { C => "xl info", + OutputCheck => \&check_for_stock }, + { C => "xen-livepatch unload xen_hello_world" }, + { C => "xen-livepatch unload xen_hello_world", rc => 256 }, + { C => "xl info", + OutputCheck => \&check_for_stock }, + { C => "xen-livepatch load xen_hello_world.livepatch" }, + { C => "xl info", + OutputCheck => \&check_for_hello_world }, + { C => "xen-livepatch load xen_bye_world.livepatch" }, + { C => "xl info", + OutputCheck => sub { m/xen_extra/ && m/Bye World/ } }, + { C => "xen-livepatch upload xen_replace xen_replace_world.livepatch" }, + { C => "xen-livepatch replace xen_replace" }, + { C => "xl info", + OutputCheck => sub { m/xen_extra/ && m/Hello Again Wo/ } }, + { C => "xen-livepatch apply xen_hello_world", rc => 256 }, + { C => "xen-livepatch apply xen_bye_world", rc => 256 }, + { C => "xen-livepatch apply xen_replace" }, + { C => "xen-livepatch revert xen_replace" }, + { C => "xen-livepatch unload xen_replace" }, + { C => "xen-livepatch unload xen_hello_world" }, + { C => "xen-livepatch unload xen_bye_world" }, + { C => "xen-livepatch list", + OutputCheck => sub { !m/xen_/ } }, + { C => "xl info", + OutputCheck => \&check_for_stock }, + { C => "xen-livepatch load xen_nop.livepatch" }, + { C => "xen-livepatch revert xen_nop" }, + { C => "xen-livepatch apply xen_nop" }, + { C => "xl info", + OutputCheck => \&check_versions }, + { C => "xen-livepatch unload xen_nop", rc => 256 }, + { C => "xen-livepatch revert xen_nop" }, + { C => "xen-livepatch unload xen_nop" }, + ); + +our $ho = selecthost('host'); + +sub livepatch_test () { + logm "Have ".(scalar @livepatch_tests)." test-cases\n"; + my $rc; + my $output; + + foreach my $test (@livepatch_tests) { + # Default rc is zero. + my $expected_rc = defined($test->{rc}) ? $test->{rc} : 0; + my $cmd = "set -e;cd /usr/lib/debug;$test->{C}"; + my ($rc, $output) = target_cmd_output_root_status($ho, $cmd); + + if ( $rc != $expected_rc ) { + logm "FAILED (got $rc, expected: $expected_rc): \n"; + die $rc; + } + if (defined($test->{OutputCheck})) { + $_ = $output; + $rc=$test->{OutputCheck}->(); + if ($rc ne 1) { + die "FAILED! OutputCheck=$test->{OutputCheck}, input=$output\n"; + } + } + } + return 0; +} + +sub livepatch_check () { + foreach my $file (@livepatch_files) { + if (!target_file_exists($ho, "/usr/lib/debug/$$file")) { + die "$file is missing!\n"; + } + } +} + +livepatch_check(); +my $livepatch_result = livepatch_test(); +logm("Livepatch test returned $livepatch_result"); +exit $livepatch_result;