|
| 1 | +# Testing examples |
| 2 | + |
| 3 | +Examples are tested using tool [mbedhtrun](https://github.com/ARMmbed/htrun) and templated print log. The templated logs represents expected behaviour of the example. |
| 4 | + |
| 5 | +## How to create templated log |
| 6 | + |
| 7 | +The idea is to check that repeated execution of the example produces serial output that matches expected pattern. An example produces serial output when code contains ```printf``` statements. Serial output may change for legitimate reasons like use of random data or date and time stamps. That's why the log is converted to a template. This means that either the text/lines that differ in every execution are removed or they are converted into regular expressions. See the example below: |
| 8 | + |
| 9 | +``` |
| 10 | +
|
| 11 | + > Using Ethernet LWIP |
| 12 | + |
| 13 | + > Client IP Address is 10.2.203.139 |
| 14 | + |
| 15 | + > Connecting with developer.mbed.org |
| 16 | + |
| 17 | +Starting the TLS handshake... Starting the TLS handshake... |
| 18 | + |
| 19 | + > TLS connection to developer.mbed.org established |
| 20 | + |
| 21 | +Server certificate: Server certificate: |
| 22 | + |
| 23 | + > |
| 24 | + cert. version : 3 |
| 25 | + > |
| 26 | + serial number : 11:21:B8:47:9B:21:6C:B1:C6:AF:BC:5D:0 |
| 27 | + > |
| 28 | + issuer name : C=BE, O=GlobalSign nv-sa, CN=GlobalSi |
| 29 | + > |
| 30 | + subject name : C=GB, ST=Cambridgeshire, L=Cambridge, |
| 31 | + > |
| 32 | + issued on : 2016-03-03 12:26:08 |
| 33 | + > |
| 34 | + expires on : 2017-04-05 10:31:02 |
| 35 | + > |
| 36 | + signed using : RSA with SHA-256 |
| 37 | + > |
| 38 | + RSA key size : 2048 bits |
| 39 | + > |
| 40 | + basic constraints : CA=false |
| 41 | + > |
| 42 | + subject alt name : *.mbed.com, mbed.org, *.mbed.org, mbe |
| 43 | + > |
| 44 | + key usage : Digital Signature, Key Encipherment |
| 45 | + > |
| 46 | + ext key usage : TLS Web Server Authentication, TLS We |
| 47 | +
|
| 48 | +Certificate verification passed Certificate verification passed |
| 49 | + |
| 50 | +
|
| 51 | + |
| 52 | + |
| 53 | + > HTTPS: Received 439 chars from server |
| 54 | + |
| 55 | + > HTTPS: Received 200 OK status ... [OK] |
| 56 | + |
| 57 | +HTTPS: Received 'Hello world!' status ... [OK] HTTPS: Received 'Hello world!' status ... [OK] |
| 58 | + |
| 59 | +HTTPS: Received message: HTTPS: Received message: |
| 60 | + |
| 61 | +
|
| 62 | + |
| 63 | + |
| 64 | + > HTTP/1.1 200 OK |
| 65 | + |
| 66 | + > Server: nginx/1.7.10 |
| 67 | + |
| 68 | + > Date: Thu, 01 Dec 2016 13:56:32 GMT |
| 69 | + |
| 70 | + > Content-Type: text/plain |
| 71 | + |
| 72 | + > Content-Length: 14 |
| 73 | + |
| 74 | + > Connection: keep-alive |
| 75 | + |
| 76 | + > Last-Modified: Fri, 27 Jul 2012 13:30:34 GMT |
| 77 | + |
| 78 | + > Accept-Ranges: bytes |
| 79 | + |
| 80 | + > Cache-Control: max-age=36000 |
| 81 | + |
| 82 | + > Expires: Thu, 01 Dec 2016 23:56:32 GMT |
| 83 | + |
| 84 | + > X-Upstream-L3: 172.17.0.3:80 |
| 85 | + |
| 86 | + > X-Upstream-L2: developer-sjc-indigo-2-nginx |
| 87 | + |
| 88 | + > Strict-Transport-Security: max-age=31536000; includeSubdomain |
| 89 | + |
| 90 | +
|
| 91 | + |
| 92 | + |
| 93 | +Hello world! Hello world! |
| 94 | +
|
| 95 | +``` |
| 96 | + |
| 97 | +Please observe above that all the lines that have data that changes from execution to execution (on right) have been removed enabling htrun to compare these logs. htrun matches lines from the compare log (on left) one by one. It keeps on looking for a line until it matches. Once matched it moves on to match the next line. If it finds all lines from the compare log in the target serial output stream. Then it halts and the test passes. |
| 98 | + |
| 99 | +Another example with regular examples is shown below: |
| 100 | + |
| 101 | +``` |
| 102 | +
|
| 103 | + SHA-256 :\s*\d+ Kb/s,\s*\d+ cycles/byte | SHA-256 : 1922 Kb/s, 61 cycl |
| 104 | + |
| 105 | + SHA-512 :\s*\d+ Kb/s,\s*\d+ cycles/byte | SHA-512 : 614 Kb/s, 191 cycl |
| 106 | + |
| 107 | + AES-CBC-128 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-CBC-128 : 1401 Kb/s, 83 cycl |
| 108 | + |
| 109 | + AES-CBC-192 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-CBC-192 : 1231 Kb/s, 95 cycl |
| 110 | + |
| 111 | + AES-CBC-256 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-CBC-256 : 1097 Kb/s, 106 cycl |
| 112 | + |
| 113 | + AES-GCM-128 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-GCM-128 : 429 Kb/s, 273 cycl |
| 114 | + |
| 115 | + AES-GCM-192 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-GCM-192 : 412 Kb/s, 285 cycl |
| 116 | + |
| 117 | + AES-GCM-256 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-GCM-256 : 395 Kb/s, 297 cycl |
| 118 | + |
| 119 | + AES-CCM-128 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-CCM-128 : 604 Kb/s, 194 cycl |
| 120 | + |
| 121 | + AES-CCM-192 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-CCM-192 : 539 Kb/s, 217 cycl |
| 122 | + |
| 123 | + AES-CCM-256 :\s*\d+ Kb/s,\s*\d+ cycles/byte | AES-CCM-256 : 487 Kb/s, 241 cycl |
| 124 | + |
| 125 | + CTR_DRBG \(NOPR\) :\s*\d+ Kb/s,\s*\d+ cycles/byte | CTR_DRBG (NOPR) : 1145 Kb/s, 102 cycl |
| 126 | + |
| 127 | + CTR_DRBG \(PR\) :\s*\d+ Kb/s,\s*\d+ cycles/byte | CTR_DRBG (PR) : 821 Kb/s, 142 cycl |
| 128 | + |
| 129 | + HMAC_DRBG SHA-256 \(NOPR\) :\s*\d+ Kb/s,\s*\d+ cycles/byte | HMAC_DRBG SHA-256 (NOPR) : 219 Kb/s, 537 cycl |
| 130 | + |
| 131 | + HMAC_DRBG SHA-256 \(PR\) :\s*\d+ Kb/s,\s*\d+ cycles/byte | HMAC_DRBG SHA-256 (PR) : 193 Kb/s, 612 cycl |
| 132 | + |
| 133 | + RSA-2048 :\s*\d+ ms/ public | RSA-2048 : 30 ms/ public |
| 134 | + |
| 135 | + RSA-2048 :\s*\d+ ms/private | RSA-2048 : 1054 ms/private |
| 136 | + |
| 137 | + RSA-4096 :\s*\d+ ms/ public | RSA-4096 : 101 ms/ public |
| 138 | + |
| 139 | + RSA-4096 :\s*\d+ ms/private | RSA-4096 : 5790 ms/private |
| 140 | + |
| 141 | + ECDHE-secp384r1 :\s*\d+ ms/handshake | ECDHE-secp384r1 : 1023 ms/handshake |
| 142 | + |
| 143 | + ECDHE-secp256r1 :\s*\d+ ms/handshake | ECDHE-secp256r1 : 678 ms/handshake |
| 144 | + |
| 145 | + ECDHE-Curve25519 :\s*\d+ ms/handshake | ECDHE-Curve25519 : 580 ms/handshake |
| 146 | + |
| 147 | + ECDH-secp384r1 :\s*\d+ ms/handshake | ECDH-secp384r1 : 503 ms/handshake |
| 148 | + |
| 149 | + ECDH-secp256r1 :\s*\d+ ms/handshake | ECDH-secp256r1 : 336 ms/handshake |
| 150 | + |
| 151 | + ECDH-Curve25519 :\s*\d+ ms/handshake | ECDH-Curve25519 : 300 ms/handshake |
| 152 | +
|
| 153 | +``` |
| 154 | + |
| 155 | +More details about ```htrun``` are [here](https://github.com/ARMmbed/htrun#testing-mbed-os-examples). |
| 156 | + |
0 commit comments