From patchwork Wed Feb 3 12:37:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 8201881 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 914FCBEEED for ; Wed, 3 Feb 2016 12:40:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 55E3D20266 for ; Wed, 3 Feb 2016 12:40:34 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 65864202BE for ; Wed, 3 Feb 2016 12:40:32 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aQwh3-0008Tl-Gs; Wed, 03 Feb 2016 12:37:57 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aQwh2-0008Tb-2H for xen-devel@lists.xen.org; Wed, 03 Feb 2016 12:37:56 +0000 Received: from [193.109.254.147] by server-14.bemta-14.messagelabs.com id 03/4A-07165-3A4F1B65; Wed, 03 Feb 2016 12:37:55 +0000 X-Env-Sender: prvs=8347a21d9=Ian.Campbell@citrix.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1454503069!21127917!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39889 invoked from network); 3 Feb 2016 12:37:54 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-9.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 3 Feb 2016 12:37:54 -0000 X-IronPort-AV: E=Sophos;i="5.22,390,1449532800"; d="scan'208";a="329390406" From: Ian Campbell To: , Date: Wed, 3 Feb 2016 12:37:33 +0000 Message-ID: <1454503053-17361-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1454336912-28503-5-git-send-email-ian.campbell@citrix.com> References: <1454336912-28503-5-git-send-email-ian.campbell@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Ian Campbell Subject: [Xen-devel] [PATCH OSSTEST 5/5 v3] mg-show-flight-runvars: recurse on buildjobs upon request X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By looping over @rows looking for buildjobs runvars and adding those jobs to the output until nothing changes. The output is resorted by runvar name which is the desired default behaviour. As usual can be piped to sort(1) to sort by flight+job. Signed-off-by: Ian Campbell Acked-by: Ian Jackson --- v2: - Use $jobcond,@jobconfparams to avoid SQL injection - Only recurse if the option was given - Drop synth from ORDER BY - Use a Schwatzian transform for the sort, at the same time allowing retention of the sorting of synth runvars last. v3: - Fixup detection of already handle jobs to cope properly with jobs with now rows. - Iterate over @rows using an index var --- mg-show-flight-runvars | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/mg-show-flight-runvars b/mg-show-flight-runvars index f96539f..c847456 100755 --- a/mg-show-flight-runvars +++ b/mg-show-flight-runvars @@ -46,19 +46,21 @@ for (;;) { die unless @ARGV==1 && $ARGV[0] =~ m/^\w+$/; - our @cols = qw(job name val); our @rows; +our %jobs; + +sub collect ($;$@) { + my ($flight,$jobcond,@jobcondparams) = @_; -sub collect ($) { - my ($flight) = @_; + $jobcond //= "TRUE"; $flight =~ m/^\d+/ or $flight = "'$flight'"; - my $qfrom = "FROM runvars WHERE flight=$flight AND $synthcond"; + my $qfrom = "FROM runvars WHERE flight=$flight AND $synthcond AND $jobcond"; my $q = $dbh_tests->prepare - ("SELECT synth, ".(join ',', @cols)." $qfrom ORDER BY synth, name, job"); - $q->execute(); + ("SELECT synth, ".(join ',', @cols)." $qfrom ORDER BY name, job"); + $q->execute(@jobcondparams); while (my (@row) = $q->fetchrow_array()) { my $synth = shift @row; @@ -70,6 +72,34 @@ sub collect ($) { collect($ARGV[0]); +if ($recurse) { + # collect() appends to @rows, avoiding the need to recurse + # there. However this means we can't use foreach (since that is + # not guaranteed to work if the array is mutated under its feet), + # instead use an index. + for ( my $rowidx = 0; $rowidx < @rows ; $rowidx++ ) { + my $row = $rows[$rowidx]; + + next unless $row->[1] =~ m/^(?:.*_)?([^_]*)buildjob$/; + + # parse this flight and job, which must be in $flight.$job + # form if $recurse is true (see collect()) + my ($tflight, $tjob) = flight_otherjob(undef, $row->[0]); + die "$row->[1]" unless $tflight; + + # parse the buildjob reference and recurse. might be a job in + # this flight, in which case we still recurse since it might + # be a chain from a non-top-level job which hasn't been + # included yet. %jobs will prevent us from duplicating or + # infinite loops. + my ($oflight, $ojob) = flight_otherjob($tflight, $row->[2]); + + next if $jobs{$oflight,$ojob}++; + + collect($oflight, "job = ?", $ojob); + } +} + our @colws; sub max ($$) { $_[$_[0] < $_[1]] } foreach my $row (@rows) { @@ -77,7 +107,11 @@ foreach my $row (@rows) { } $colws[1] += length $synthsufx; -foreach my $row (@rows) { +# Sort by runvar name, then (flight+)job, synth runvars come last. +foreach my $row (map { $_->[0] } + sort { $a->[1] cmp $b->[1] } + map { [ $_, ($_->[1] =~ m/~$/)." $_->[1] $_->[0]" ] } + @rows) { printf "%-*s %-*s %-*s\n", map { $colws[$_], $row->[$_] } qw(0 1 2) or die $!; }