]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2539] add --with-randomly to hammer.py
authorAndrei Pavel <andrei@isc.org>
Mon, 5 Sep 2022 16:19:09 +0000 (19:19 +0300)
committerAndrei Pavel <andrei@isc.org>
Fri, 7 Oct 2022 12:06:26 +0000 (15:06 +0300)
For testing both with and without a feature over time, you might want to
enable or disable it non-determinstically for a certain test run. This
can be done with the --with-randomly parameter which has a 50% chance of
enabling a feature and a 50% chance of disabling it.

hammer.py

index 3aa1ed9bc55a973917eda8a430e7a7b08dc27dc3..d8d0b4f472f4b8b3ece3d2c62566b219f53a1ac4 100755 (executable)
--- a/hammer.py
+++ b/hammer.py
@@ -11,6 +11,7 @@
 from __future__ import print_function
 
 import os
+import random
 import re
 import sys
 import glob
@@ -2660,6 +2661,8 @@ def parse_args():
     hlp = hlp % ", ".join(ALL_FEATURES)
     parent_parser2.add_argument('-x', '--without', metavar='FEATURE', nargs='+', default=set(),
                                 action=CollectCommaSeparatedArgsAction, help=hlp)
+    parent_parser2.add_argument('--with-randomly', metavar='FEATURE', nargs='+', default=set(),
+                                action=CollectCommaSeparatedArgsAction, help=hlp)
     parent_parser2.add_argument('-l', '--leave-system', action='store_true',
                                 help='At the end of the command do not destroy vagrant system. Default behavior is '
                                 'destroying the system.')
@@ -2776,6 +2779,12 @@ def destroy_system(path):
     execute('vagrant destroy', cwd=path, interactive=True)
 
 
+def _coin_toss():
+    if random.randint(0, 65535) % 2 == 0:
+        return True
+    return False
+
+
 def _get_features(args):
     features = set(vars(args)['with'])
 
@@ -2792,12 +2801,6 @@ def _get_features(args):
         # distcheck is not compatible with defaults so do not add defaults
         features = features.union(DEFAULT_FEATURES)
 
-    nofeatures = set(args.without)
-    features = features.difference(nofeatures)
-
-    if hasattr(args, 'ccache_dir') and args.ccache_dir:
-        features.add('ccache')
-
     # if we build native packages then some features are required and some not
     if 'native-pkg' in features:
         features.add('docs')
@@ -2812,6 +2815,20 @@ def _get_features(args):
         if args.command == 'build':
             features.discard('unittest')
 
+    nofeatures = set(args.without)
+    features = features.difference(nofeatures)
+
+    for i in args.with_randomly:
+        if _coin_toss():
+            features.add(i)
+            log.info(f'Feature enabled through coin toss: {i}')
+        else:
+            features.discard(i)
+            log.info(f'Feature disabled through coin toss: {i}')
+
+    if hasattr(args, 'ccache_dir') and args.ccache_dir:
+        features.add('ccache')
+
     return sorted(features)