blob: 13f83021e7eebfdb073c90405b599d2a8e01c3d3 [file] [log] [blame]
David Benjamin491b9212015-02-11 14:18:45 -05001/* Copyright (c) 2015, Google Inc.
2 *
3 * Permission to use, copy, modify, and/or distribute this software for any
4 * purpose with or without fee is hereby granted, provided that the above
5 * copyright notice and this permission notice appear in all copies.
6 *
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
15package main
16
17import (
18 "bytes"
19 "flag"
20 "fmt"
21 "os"
22 "os/exec"
23 "path"
24 "strings"
25)
26
27// TODO(davidben): Link tests with the malloc shim and port -malloc-test to this runner.
28
29var (
30 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
31 buildDir = flag.String("build-dir", "build", "The build directory to run the tests from.")
32)
33
34type test []string
35
36var tests = []test{
37 {"crypto/base64/base64_test"},
38 {"crypto/bio/bio_test"},
39 {"crypto/bn/bn_test"},
40 {"crypto/bytestring/bytestring_test"},
41 {"crypto/cipher/aead_test", "aes-128-gcm", "crypto/cipher/test/aes_128_gcm_tests.txt"},
42 {"crypto/cipher/aead_test", "aes-128-key-wrap", "crypto/cipher/test/aes_128_key_wrap_tests.txt"},
43 {"crypto/cipher/aead_test", "aes-256-gcm", "crypto/cipher/test/aes_256_gcm_tests.txt"},
44 {"crypto/cipher/aead_test", "aes-256-key-wrap", "crypto/cipher/test/aes_256_key_wrap_tests.txt"},
45 {"crypto/cipher/aead_test", "chacha20-poly1305", "crypto/cipher/test/chacha20_poly1305_tests.txt"},
46 {"crypto/cipher/aead_test", "rc4-md5-tls", "crypto/cipher/test/rc4_md5_tls_tests.txt"},
47 {"crypto/cipher/aead_test", "rc4-sha1-tls", "crypto/cipher/test/rc4_sha1_tls_tests.txt"},
48 {"crypto/cipher/aead_test", "aes-128-cbc-sha1-tls", "crypto/cipher/test/aes_128_cbc_sha1_tls_tests.txt"},
49 {"crypto/cipher/aead_test", "aes-128-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/aes_128_cbc_sha1_tls_implicit_iv_tests.txt"},
50 {"crypto/cipher/aead_test", "aes-128-cbc-sha256-tls", "crypto/cipher/test/aes_128_cbc_sha256_tls_tests.txt"},
51 {"crypto/cipher/aead_test", "aes-256-cbc-sha1-tls", "crypto/cipher/test/aes_256_cbc_sha1_tls_tests.txt"},
52 {"crypto/cipher/aead_test", "aes-256-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/aes_256_cbc_sha1_tls_implicit_iv_tests.txt"},
53 {"crypto/cipher/aead_test", "aes-256-cbc-sha256-tls", "crypto/cipher/test/aes_256_cbc_sha256_tls_tests.txt"},
54 {"crypto/cipher/aead_test", "aes-256-cbc-sha384-tls", "crypto/cipher/test/aes_256_cbc_sha384_tls_tests.txt"},
55 {"crypto/cipher/aead_test", "des-ede3-cbc-sha1-tls", "crypto/cipher/test/des_ede3_cbc_sha1_tls_tests.txt"},
56 {"crypto/cipher/aead_test", "des-ede3-cbc-sha1-tls-implicit-iv", "crypto/cipher/test/des_ede3_cbc_sha1_tls_implicit_iv_tests.txt"},
57 {"crypto/cipher/aead_test", "rc4-md5-ssl3", "crypto/cipher/test/rc4_md5_ssl3_tests.txt"},
58 {"crypto/cipher/aead_test", "rc4-sha1-ssl3", "crypto/cipher/test/rc4_sha1_ssl3_tests.txt"},
59 {"crypto/cipher/aead_test", "aes-128-cbc-sha1-ssl3", "crypto/cipher/test/aes_128_cbc_sha1_ssl3_tests.txt"},
60 {"crypto/cipher/aead_test", "aes-256-cbc-sha1-ssl3", "crypto/cipher/test/aes_256_cbc_sha1_ssl3_tests.txt"},
61 {"crypto/cipher/aead_test", "des-ede3-cbc-sha1-ssl3", "crypto/cipher/test/des_ede3_cbc_sha1_ssl3_tests.txt"},
62 {"crypto/cipher/cipher_test", "crypto/cipher/test/cipher_test.txt"},
63 {"crypto/constant_time_test"},
64 {"crypto/dh/dh_test"},
65 {"crypto/digest/digest_test"},
66 {"crypto/dsa/dsa_test"},
67 {"crypto/ec/ec_test"},
68 {"crypto/ec/example_mul"},
69 {"crypto/ecdsa/ecdsa_test"},
70 {"crypto/err/err_test"},
71 {"crypto/evp/evp_test"},
72 {"crypto/evp/pbkdf_test"},
73 {"crypto/hkdf/hkdf_test"},
74 {"crypto/hmac/hmac_test"},
75 {"crypto/lhash/lhash_test"},
76 {"crypto/modes/gcm_test"},
77 {"crypto/pkcs8/pkcs12_test"},
78 {"crypto/rsa/rsa_test"},
79 {"crypto/x509/pkcs7_test"},
80 {"crypto/x509v3/tab_test"},
81 {"crypto/x509v3/v3name_test"},
82 {"ssl/pqueue/pqueue_test"},
83 {"ssl/ssl_test"},
84}
85
86func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
87 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
88 if dbAttach {
89 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
90 }
91 valgrindArgs = append(valgrindArgs, path)
92 valgrindArgs = append(valgrindArgs, args...)
93
94 return exec.Command("valgrind", valgrindArgs...)
95}
96
97func runTest(test test) (passed bool, err error) {
98 prog := path.Join(*buildDir, test[0])
99 args := test[1:]
100 var cmd *exec.Cmd
101 if *useValgrind {
102 cmd = valgrindOf(false, prog, args...)
103 } else {
104 cmd = exec.Command(prog, args...)
105 }
106 var stdoutBuf bytes.Buffer
107 cmd.Stdout = &stdoutBuf
108 cmd.Stderr = os.Stderr
109
110 if err := cmd.Start(); err != nil {
111 return false, err
112 }
113 if err := cmd.Wait(); err != nil {
114 return false, err
115 }
116
117 // Account for Windows line-endings.
118 stdout := bytes.Replace(stdoutBuf.Bytes(), []byte("\r\n"), []byte("\n"), -1)
119
120 if bytes.HasSuffix(stdout, []byte("PASS\n")) &&
121 (len(stdout) == 5 || stdout[len(stdout)-6] == '\n') {
122 return true, nil
123 }
124 return false, nil
125}
126
127func main() {
128 flag.Parse()
129
130 var failed []test
131 for _, test := range tests {
132 fmt.Printf("%s\n", strings.Join([]string(test), " "))
133 passed, err := runTest(test)
134 if err != nil {
135 fmt.Printf("%s failed to complete: %s\n", test[0], err.Error())
136 failed = append(failed, test)
137 continue
138 }
139 if !passed {
140 fmt.Printf("%s failed to print PASS on the last line.\n", test[0])
141 failed = append(failed, test)
142 }
143 }
144
145 if len(failed) == 0 {
146 fmt.Printf("\nAll tests passed!\n")
147 } else {
148 fmt.Printf("\n%d of %d tests failed:\n", len(failed), len(tests))
149 for _, test := range failed {
150 fmt.Printf("\t%s\n", strings.Join([]string(test), " "))
151 }
152 }
153}