diff mbox series

[OSSTEST,59/82] runvar access: Provide runvar_glob

Message ID 20201007180024.7932-60-iwj@xenproject.org (mailing list archive)
State New, archived
Headers show
Series Reuse test hosts | expand

Commit Message

Ian Jackson Oct. 7, 2020, 6 p.m. UTC
From: Ian Jackson <ian.jackson@eu.citrix.com>

We will need this because when runvar access is restricted, accessing
via %r directly won't work.  We want to see what patterns the code is
interested in (so that interest in a nonexistent runvar is properly
tracked).

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
 Osstest/TestSupport.pm | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index b1eca0a9..6403e52b 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -53,7 +53,7 @@  BEGIN {
                       store_runvar get_runvar get_runvar_maybe
                       get_runvar_default need_runvars
                       unique_incrementing_runvar next_unique_name
-                      stashfilecontents runvar_is_synth
+                      stashfilecontents runvar_is_synth runvar_glob
 
                       target_cmd_root_status target_cmd_output_root_status
                       target_cmd_root target_cmd target_cmd_build
@@ -3187,6 +3187,20 @@  sub runvar_access_check ($$) {
     Carp::cluck $m;
 }
 
+sub runvar_glob {
+    my $monitor = tied %r;
+    my $realr = $monitor || \%r;
+    my @out;
+    foreach my $pat (@_) {
+	if ($monitor) { runvar_access_check($pat, 'scan') }
+	foreach my $key (sort keys %$realr) {
+	    next unless fnmatch $pat, $key;
+	    push @out, $key;
+	}
+    }
+    @out;
+}
+
 package RunvarMonitor;
 use Carp;
 use Osstest;