xref: /freebsd/crypto/openssl/test/recipes/20-test_speed.t (revision e7be843b4a162e68651d3911f0357ed464915629)
1*e7be843bSPierre Pronchery#! /usr/bin/env perl
2*e7be843bSPierre Pronchery# Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3*e7be843bSPierre Pronchery#
4*e7be843bSPierre Pronchery# Licensed under the Apache License 2.0 (the "License").  You may not use
5*e7be843bSPierre Pronchery# this file except in compliance with the License.  You can obtain a copy
6*e7be843bSPierre Pronchery# in the file LICENSE in the source distribution or at
7*e7be843bSPierre Pronchery# https://www.openssl.org/source/license.html
8*e7be843bSPierre Pronchery
9*e7be843bSPierre Pronchery
10*e7be843bSPierre Proncheryuse strict;
11*e7be843bSPierre Proncheryuse warnings;
12*e7be843bSPierre Pronchery
13*e7be843bSPierre Proncheryuse File::Spec;
14*e7be843bSPierre Proncheryuse File::Basename;
15*e7be843bSPierre Proncheryuse OpenSSL::Test qw/:DEFAULT with srctop_file bldtop_dir/;
16*e7be843bSPierre Proncheryuse OpenSSL::Test::Utils;
17*e7be843bSPierre Pronchery
18*e7be843bSPierre Proncherysetup("test_speed");
19*e7be843bSPierre Pronchery
20*e7be843bSPierre Proncheryplan tests => 25;
21*e7be843bSPierre Pronchery
22*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode'])),
23*e7be843bSPierre Pronchery       "Simple test of all speed algorithms");
24*e7be843bSPierre Pronchery
25*e7be843bSPierre Pronchery#Test various options to speed. In all cases we use the -testmode option to
26*e7be843bSPierre Pronchery#ensure we don't spend too long in this test. That option also causes the speed
27*e7be843bSPierre Pronchery#app to return an error code if anything unexpectedly goes wrong.
28*e7be843bSPierre Pronchery
29*e7be843bSPierre Pronchery
30*e7be843bSPierre ProncherySKIP: {
31*e7be843bSPierre Pronchery    skip "Multi option is not supported by this OpenSSL build", 1
32*e7be843bSPierre Pronchery       if $^O =~ /^(VMS|MSWin32)$/;
33*e7be843bSPierre Pronchery
34*e7be843bSPierre Pronchery    ok(run(app(['openssl', 'speed', '-testmode', '-multi', 2])),
35*e7be843bSPierre Pronchery           "Test the multi option");
36*e7be843bSPierre Pronchery}
37*e7be843bSPierre Pronchery
38*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-misalign', 1])),
39*e7be843bSPierre Pronchery       "Test the misalign option");
40*e7be843bSPierre Pronchery
41*e7be843bSPierre ProncherySKIP: {
42*e7be843bSPierre Pronchery    skip "Multiblock is not supported by this OpenSSL build", 1
43*e7be843bSPierre Pronchery        if disabled("multiblock")
44*e7be843bSPierre Pronchery           # The AES-128-CBC-HMAC-SHA1 cipher isn't available on all platforms
45*e7be843bSPierre Pronchery           # We test its availability without the "-mb" option. We only do the
46*e7be843bSPierre Pronchery           # multiblock test via "-mb" if the cipher seems to exist.
47*e7be843bSPierre Pronchery           || !run(app(['openssl', 'speed', '-testmode', '-evp',
48*e7be843bSPierre Pronchery                       'AES-128-CBC-HMAC-SHA1']));
49*e7be843bSPierre Pronchery
50*e7be843bSPierre Pronchery    ok(run(app(['openssl', 'speed', '-testmode', '-mb', '-evp',
51*e7be843bSPierre Pronchery                'AES-128-CBC-HMAC-SHA1'])),
52*e7be843bSPierre Pronchery        "Test the EVP and mb options");
53*e7be843bSPierre Pronchery}
54*e7be843bSPierre Pronchery
55*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-kem-algorithms'])),
56*e7be843bSPierre Pronchery       "Test the kem-algorithms option");
57*e7be843bSPierre Pronchery
58*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-signature-algorithms'])),
59*e7be843bSPierre Pronchery       "Test the signature-algorithms option");
60*e7be843bSPierre Pronchery
61*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-primes', 3, 'rsa1024'])),
62*e7be843bSPierre Pronchery       "Test the primes option");
63*e7be843bSPierre Pronchery
64*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-mr'])),
65*e7be843bSPierre Pronchery       "Test the mr option");
66*e7be843bSPierre Pronchery
67*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-decrypt', '-evp', 'aes-128-cbc'])),
68*e7be843bSPierre Pronchery       "Test the decrypt and evp options");
69*e7be843bSPierre Pronchery
70*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-evp', 'sha256'])),
71*e7be843bSPierre Pronchery       "Test the evp option with a digest");
72*e7be843bSPierre Pronchery
73*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-hmac', 'sha256'])),
74*e7be843bSPierre Pronchery       "Test the hmac option");
75*e7be843bSPierre Pronchery
76*e7be843bSPierre ProncherySKIP: {
77*e7be843bSPierre Pronchery    skip "CMAC is not supported by this OpenSSL build", 1
78*e7be843bSPierre Pronchery        if disabled("cmac");
79*e7be843bSPierre Pronchery
80*e7be843bSPierre Pronchery    ok(run(app(['openssl', 'speed', '-testmode', '-cmac', 'aes-128-cbc'])),
81*e7be843bSPierre Pronchery           "Test the cmac option");
82*e7be843bSPierre Pronchery}
83*e7be843bSPierre Pronchery
84*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-aead', '-evp', 'aes-128-gcm'])),
85*e7be843bSPierre Pronchery       "Test the aead and evp options");
86*e7be843bSPierre Pronchery
87*e7be843bSPierre ProncherySKIP: {
88*e7be843bSPierre Pronchery    skip "ASYNC/threads not supported by this OpenSSL build", 1
89*e7be843bSPierre Pronchery        if disabled("async") || disabled("threads");
90*e7be843bSPierre Pronchery
91*e7be843bSPierre Pronchery    ok(run(app(['openssl', 'speed', '-testmode', '-async_jobs', '1'])),
92*e7be843bSPierre Pronchery        "Test the async_jobs option");
93*e7be843bSPierre Pronchery}
94*e7be843bSPierre Pronchery
95*e7be843bSPierre ProncherySKIP: {
96*e7be843bSPierre Pronchery    skip "Mlock option is not supported by this OpenSSL build", 1
97*e7be843bSPierre Pronchery       if $^O !~ /^(linux|MSWin32)$/;
98*e7be843bSPierre Pronchery
99*e7be843bSPierre Pronchery       ok(run(app(['openssl', 'speed', '-testmode', '-mlock'])),
100*e7be843bSPierre Pronchery              "Test the mlock option");
101*e7be843bSPierre Pronchery}
102*e7be843bSPierre Pronchery
103*e7be843bSPierre Pronchery#We don't expect these options to have an effect in testmode but we at least
104*e7be843bSPierre Pronchery#test that the option parsing works ok
105*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-seconds', 1, '-bytes', 16,
106*e7be843bSPierre Pronchery            '-elapsed'])),
107*e7be843bSPierre Pronchery       "Test the seconds, bytes and elapsed options");
108*e7be843bSPierre Pronchery
109*e7be843bSPierre Pronchery#Test that this won't crash on sparc
110*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-testmode', '-seconds', 1, '-bytes', 1,
111*e7be843bSPierre Pronchery            'aes-128-cbc'])),
112*e7be843bSPierre Pronchery       "Test that bad bytes value doesn't make speed to crash");
113*e7be843bSPierre Pronchery
114*e7be843bSPierre Pronchery#No need to -testmode for testing -help. All we're doing is testing the option
115*e7be843bSPierre Pronchery#parsing. We don't sanity check the output
116*e7be843bSPierre Proncheryok(run(app(['openssl', 'speed', '-help'])),
117*e7be843bSPierre Pronchery       "Test the help option");
118*e7be843bSPierre Pronchery
119*e7be843bSPierre Pronchery#Now test some invalid options. The speed app should fail
120*e7be843bSPierre Proncheryok(!run(app(['openssl', 'speed', 'blah'])),
121*e7be843bSPierre Pronchery        "Test an unknwon algorithm");
122*e7be843bSPierre Pronchery
123*e7be843bSPierre Proncheryok(!run(app(['openssl', 'speed', '-evp', 'blah'])),
124*e7be843bSPierre Pronchery        "Test a unknown evp algorithm");
125*e7be843bSPierre Pronchery
126*e7be843bSPierre Proncheryok(!run(app(['openssl', 'speed', '-hmac', 'blah'])),
127*e7be843bSPierre Pronchery        "Test a unknown hmac algorithm");
128*e7be843bSPierre Pronchery
129*e7be843bSPierre Proncheryok(!run(app(['openssl', 'speed', '-cmac', 'blah'])),
130*e7be843bSPierre Pronchery        "Test a unknown cmac algorithm");
131*e7be843bSPierre Pronchery
132*e7be843bSPierre Proncheryok(!run(app(['openssl', 'speed', '-async_jobs', 100000])),
133*e7be843bSPierre Pronchery        "Test an invalid number of async_jobs");
134*e7be843bSPierre Pronchery
135*e7be843bSPierre Proncheryok(!run(app(['openssl', 'speed', '-misalign', 65])),
136*e7be843bSPierre Pronchery        "Test an invalid misalign number");
137*e7be843bSPierre Pronchery
138*e7be843bSPierre ProncherySKIP: {
139*e7be843bSPierre Pronchery    skip "Multiblock is not supported by this OpenSSL build", 1
140*e7be843bSPierre Pronchery        if disabled("multiblock");
141*e7be843bSPierre Pronchery
142*e7be843bSPierre Pronchery    ok(!run(app(['openssl', 'speed', '-testmode', '-mb', '-evp',
143*e7be843bSPierre Pronchery                'AES-128-CBC'])),
144*e7be843bSPierre Pronchery            "Test a non multiblock cipher with -mb");
145*e7be843bSPierre Pronchery}
146