Repository: randombit/botan
Pull request #2262 (2020-02-09 14:16:54)

Add more tests for speed util

codecov-io: # [Codecov](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=h1) Report
> Merging [#2262](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=desc) into [master](https://codecov.io/gh/randombit/botan/commit/072869a5e448a37e18f4fa87bb4bb07324a0e015?src=pr&el=desc) will **increase** coverage by `0.08%`.
> The diff coverage is `0%`.

[![Impacted file tree graph](https://codecov.io/gh/randombit/botan/pull/2262/graphs/tree.svg?width=650&token=VR6iYmSPH8&height=150&src=pr)](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master    #2262      +/-   ##
==========================================
+ Coverage    92.5%   92.59%   +0.08%     
==========================================
  Files         555      555              
  Lines       60611    60610       -1     
  Branches     6427     6427              
==========================================
+ Hits        56067    56119      +52     
+ Misses       4544     4491      -53
```


| [Impacted Files](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/cli/speed.cpp](https://codecov.io/gh/randombit/botan/pull/2262/diff?src=pr&el=tree#diff-c3JjL2NsaS9zcGVlZC5jcHA=) | `95.7% <0%> (+4.7%)` | :arrow_up: |
| [src/lib/pubkey/mce/mceliece\_key.cpp](https://codecov.io/gh/randombit/botan/pull/2262/diff?src=pr&el=tree#diff-c3JjL2xpYi9wdWJrZXkvbWNlL21jZWxpZWNlX2tleS5jcHA=) | `85.39% <0%> (-1.13%)` | :arrow_down: |
| [src/lib/pbkdf/bcrypt\_pbkdf/bcrypt\_pbkdf.cpp](https://codecov.io/gh/randombit/botan/pull/2262/diff?src=pr&el=tree#diff-c3JjL2xpYi9wYmtkZi9iY3J5cHRfcGJrZGYvYmNyeXB0X3Bia2RmLmNwcA==) | `91.66% <0%> (ø)` | :arrow_up: |
| [src/lib/pubkey/dl\_group/dl\_group.cpp](https://codecov.io/gh/randombit/botan/pull/2262/diff?src=pr&el=tree#diff-c3JjL2xpYi9wdWJrZXkvZGxfZ3JvdXAvZGxfZ3JvdXAuY3Bw) | `93.3% <0%> (+1.18%)` | :arrow_up: |
| [src/cli/cli.cpp](https://codecov.io/gh/randombit/botan/pull/2262/diff?src=pr&el=tree#diff-c3JjL2NsaS9jbGkuY3Bw) | `79.13% <0%> (+3.59%)` | :arrow_up: |
| [src/cli/cli\_exceptions.h](https://codecov.io/gh/randombit/botan/pull/2262/diff?src=pr&el=tree#diff-c3JjL2NsaS9jbGlfZXhjZXB0aW9ucy5o) | `63.63% <0%> (+18.18%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=footer). Last update [072869a...9208753](https://codecov.io/gh/randombit/botan/pull/2262?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp
index 0593fc1b5..b33dfc157 100644
--- a/src/cli/speed.cpp
+++ b/src/cli/speed.cpp
@@ -1617,8 +1617,7 @@ class Speed final : public Command
 
                if(!ok)
                   {
-                  error_output() << "Generated prime " << p
-                                 << " which then failed primality test";
+                  error_output() << "Generated prime " << p << " which failed a primality test";
                   }
 
                // Now test p+2, p+4, ... which may or may not be prime
diff --git a/src/configs/pylint.rc b/src/configs/pylint.rc
index 14020880b..54d448a10 100644
--- a/src/configs/pylint.rc
+++ b/src/configs/pylint.rc
@@ -255,7 +255,7 @@ callbacks=cb_,_cb
 [FORMAT]
 
 # Maximum number of characters on a single line.
-max-line-length=120
+max-line-length=180
 
 # Regexp for a line that is allowed to be longer than the limit.
 ignore-long-lines=^\s*(# )?<?https?://\S+>?$


Test patch:
diff --git a/src/scripts/test_cli.py b/src/scripts/test_cli.py
index 3b986dad6..a3241a722 100755
--- a/src/scripts/test_cli.py
+++ b/src/scripts/test_cli.py
@@ -89,6 +89,9 @@ def test_cli(cmd, cmd_options, expected_output=None, cmd_input=None, expected_st
         else:
             if stderr != expected_stderr:
                 logging.error("Got output on stderr %s which did not match expected value %s", stderr, expected_stderr)
+    else:
+        if expected_stderr is not None:
+            logging.error('Expected output on stderr but got nothing')
 
     output = stdout.decode('ascii').strip()
 
@@ -138,7 +141,7 @@ def cli_version_tests(_tmp_dir):
         logging.error("Unexpected version output %s" % (output))
 
     output = test_cli("version", ["--full"], None, None)
-    version_full_re = re.compile(r'Botan [0-9]\.[0-9]+\.[0-9] \(.* revision .*, distribution .*\)')
+    version_full_re = re.compile(r'Botan [0-9]\.[0-9]+\.[0-9] \(.* revision .*, distribution .*\)$')
     if not version_full_re.match(output):
         logging.error("Unexpected version output %s" % (output))
 
@@ -1146,6 +1149,62 @@ def cli_speed_pbkdf_tests(_tmp_dir):
             if format_re.match(line) is None:
                 logging.error("Unexpected line %s", line)
 
+def cli_speed_table_tests(_tmp_dir):
+    msec = 1
+
+    version_re = re.compile(r'^Botan 2\.[0-9]+\.[0-9] \(.*, revision .*, distribution .*\)')
+    cpuid_re = re.compile(r'^CPUID: [a-z_0-9 ]*$')
+    format_re = re.compile(r'^AES-128 .* buffer size [0-9]+ bytes: [0-9]+\.[0-9]+ MiB\/sec .*\([0-9]+\.[0-9]+ MiB in [0-9]+\.[0-9]+ ms\)')
+    tbl_hdr_re = re.compile(r'^algo +operation +1024 bytes$')
+    tbl_val_re = re.compile(r'^AES-128 +(encrypt|decrypt) +[0-9]+(\.[0-9]{2})$')
+
+    output = test_cli("speed", ["--format=table", "--provider=base", "--msec=%d" % (msec), "AES-128"], None).split('\n')
+
+    if len(output) != 11:
+        logging.error('Unexpected number of lines from table output')
+
+    if version_re.match(output[0]) is None:
+        logging.error("Unexpected version line %s", output[0])
+
+    if output[1] != '':
+        if cpuid_re.match(output[1]) is None:
+            logging.error("Unexpected cpuid line %s", output[1])
+    elif output[2] != '':
+        logging.error("Expected newline got %s", output[2])
+
+    if format_re.match(output[3]) is None:
+        logging.error("Unexpected line %s", output[3])
+    if format_re.match(output[4]) is None:
+        logging.error("Unexpected line %s", output[4])
+    if output[5] != '':
+        logging.error("Expected newline got %s", output[5])
+
+    if tbl_hdr_re.match(output[6]) is None:
+        logging.error("Unexpected table header %s", output[6])
+    if tbl_val_re.match(output[7]) is None:
+        logging.error("Unexpected table header %s", output[7])
+    if tbl_val_re.match(output[8]) is None:
+        logging.error("Unexpected table header %s", output[8])
+    if output[9] != '':
+        logging.error("Expected newline got %s", output[9])
+    if output[10].find('results are the number of 1000s bytes processed per second') < 0:
+        logging.error("Unexpected trailing message got %s", output[10])
+
+def cli_speed_invalid_option_tests(_tmp_dir):
+    speed_usage = b"Usage: speed --msec=500 --format=default --ecc-groups= --provider= --buf-size=1024 --clear-cpuid= --cpu-clock-speed=0 --cpu-clock-ratio=1.0 *algos\n"
+
+    test_cli("speed", ["--buf-size=0", "--msec=1", "AES-128"],
+             expected_stderr=b"Usage error: Cannot have a zero-sized buffer\n%s" % (speed_usage))
+
+    test_cli("speed", ["--buf-size=F00F", "--msec=1", "AES-128"],
+             expected_stderr=b"Usage error: Invalid integer value 'F00F' for option buf-size\n%s" % (speed_usage))
+
+    test_cli("speed", ["--buf-size=90000000", "--msec=1", "AES-128"],
+             expected_stderr=b"Usage error: Specified buffer size is too large\n%s" % (speed_usage))
+
+    test_cli("speed", ["--clear-cpuid=goku", "--msec=1", "AES-128"],
+             expected_stderr=b"Warning don't know CPUID flag 'goku'\n")
+
 def cli_speed_math_tests(_tmp_dir):
     msec = 1
     # these all have a common output format
@@ -1283,6 +1342,8 @@ def main(args=None):
         cli_speed_pk_tests,
         cli_speed_math_tests,
         cli_speed_pbkdf_tests,
+        cli_speed_table_tests,
+        cli_speed_invalid_option_tests,
         cli_xmss_sign_tests,
 
         cli_argon2_tests,