Skip to content

Instantly share code, notes, and snippets.

@t184256
Created May 22, 2019 10:44
Show Gist options
  • Save t184256/5125329ce880f19fa1f3a681c0922455 to your computer and use it in GitHub Desktop.
Save t184256/5125329ce880f19fa1f3a681c0922455 to your computer and use it in GitHub Desktop.
tooling for sampling-fix-418
import glob
import sys
for fname in glob.glob('scripts/test-*.py'):
print('###', fname)
if !(grep -q sanity_test @(fname)):
if not !(grep -q sanity_tests @(fname)):
patch --verbose @(fname) < sanity_tests_plural.patch or sys.exit(1)
if not !(grep -q ordered_tests @(fname)):
print('skipping')
continue
if !(grep -q islice @(fname)):
if !(grep -q "not 'sanity' in" @(fname)):
patchfile = 'with-islice-manysanity.patch'
elif !(grep -q 'conversations_long' @(fname)):
patchfile = 'with-islice-shortlong.patch'
else:
patchfile = 'with-islice.patch'
else:
patchfile = 'without-islice.patch'
print('patching', fname, 'with', patchfile)
patch --verbose @(fname) < @(patchfile) or sys.exit(1)
diff --git a/scripts/test-x25519.py b/scripts/test-x25519.py
index fb846ca..7a85a1d 100644
--- a/scripts/test-x25519.py
+++ b/scripts/test-x25519.py
@@ -922,2 +922,2 @@ def main():
- sanity_test = ('sanity', conversations['sanity'])
- ordered_tests = chain([sanity_test],
+ sanity_tests = [('sanity', conversations['sanity'])]
+ ordered_tests = chain(sanity_tests,
@@ -926 +926 @@ def main():
- [sanity_test])
+ sanity_tests)
diff --git a/scripts/test-invalid-compression-methods.py b/scripts/test-invalid-compression-methods.py
index 75a7069..ee1d025 100644
--- a/scripts/test-invalid-compression-methods.py
+++ b/scripts/test-invalid-compression-methods.py
@@ -8 +9 @@ import getopt
-from itertools import chain, islice
+from random import sample
@@ -130,4 +131,3 @@ def main():
- ordered_tests = chain(sanity_tests,
- islice(filter(lambda x: not 'sanity' in x[0],
- conversations.items()), num_limit),
- sanity_tests)
+ regular_tests = [(k, v) for k, v in conversations.items()
+ if not k.startswith('sanity')]
+ sampled_tests = sample(regular_tests, min(num_limit, len(regular_tests)))
@@ -135 +134 @@ def main():
- for c_name, c_test in ordered_tests:
+ for c_name, c_test in sanity_tests + sampled_tests + sanity_tests:
diff --git a/scripts/test-rsa-pss-sigs-on-certificate-verify.py b/scripts/test-rsa-pss-sigs-on-certificate-verify.py
index 16ac490..68f1ff3 100644
--- a/scripts/test-rsa-pss-sigs-on-certificate-verify.py
+++ b/scripts/test-rsa-pss-sigs-on-certificate-verify.py
@@ -9 +9 @@ import re
-from itertools import chain, islice
+from random import sample
@@ -601,6 +601,7 @@ def main():
- sanity_tests = [('sanity', conversations['sanity'])]
- ordered_tests = chain(sanity_tests,
- filter(lambda x: x[0] != 'sanity',
- conversations.items()),
- islice(conversations_long.items(), num_limit),
- sanity_tests)
+ sanity_tests = [('sanity', conversations['sanity'])]
+ short_tests = [(k, v) for k, v in conversations.items() if k != 'sanity']
+ long_sampled_tests = sample(list(conversations_long).items()),
+ min(num_limit, len(conversations_long)))
+ ordered_tests = (sanity_tests +
+ short_tests + long_sampled_tests +
+ sanity_tests)
diff --git a/scripts/test-invalid-compression-methods.py b/scripts/test-invalid-compression-methods.py
index 75a7069..ee1d025 100644
--- a/scripts/test-invalid-compression-methods.py
+++ b/scripts/test-invalid-compression-methods.py
@@ -8 +9 @@ import getopt
-from itertools import chain, islice
+from random import sample
@@ -130,4 +131,2 @@ def main():
- ordered_tests = chain(sanity_tests,
- islice(filter(lambda x: x[0] != 'sanity',
- conversations.items()), num_limit),
- sanity_tests)
+ regular_tests = [(k, v) for k, v in conversations.items() if k != 'sanity']
+ sampled_tests = sample(regular_tests, min(num_limit, len(regular_tests)))
@@ -135 +134 @@ def main():
- for c_name, c_test in ordered_tests:
+ for c_name, c_test in sanity_tests + sampled_tests + sanity_tests:
diff --git a/scripts/test-x25519.py b/scripts/test-x25519.py
index fb846ca..b9bddbb 100644
--- a/scripts/test-x25519.py
+++ b/scripts/test-x25519.py
@@ -9 +8,0 @@ import re
-from itertools import chain
@@ -923,4 +922 @@ def main():
- ordered_tests = chain(sanity_tests,
- filter(lambda x: x[0] != 'sanity',
- conversations.items()),
- sanity_tests)
+ regular_tests = [(k, v) for k, v in conversations.items() if k != 'sanity']
@@ -928 +924 @@ def main():
- for c_name, c_test in ordered_tests:
+ for c_name, c_test in sanity_tests + regular_tests + sanity_tests:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment