• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2016, 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 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include <gtest/gtest.h>
19 
20 #include <openssl/cpu.h>
21 #include <openssl/rand.h>
22 
23 #include "abi_test.h"
24 #include "gtest_main.h"
25 #include "../internal.h"
26 
27 #if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) &&       \
28     !defined(OPENSSL_STATIC_ARMCAP)
29 #include <openssl/arm_arch.h>
30 #define TEST_ARM_CPUS
31 #endif
32 
33 
main(int argc,char ** argv)34 int main(int argc, char **argv) {
35   testing::InitGoogleTest(&argc, argv);
36   bssl::SetupGoogleTest();
37 
38   bool unwind_tests = true;
39   for (int i = 1; i < argc; i++) {
40 #if !defined(OPENSSL_WINDOWS)
41     if (strcmp(argv[i], "--fork_unsafe_buffering") == 0) {
42       RAND_enable_fork_unsafe_buffering(-1);
43     }
44 #endif
45 
46 #if defined(TEST_ARM_CPUS)
47     if (strncmp(argv[i], "--cpu=", 6) == 0) {
48       const char *cpu = argv[i] + 6;
49       uint32_t armcap;
50       if (strcmp(cpu, "none") == 0) {
51         armcap = 0;
52       } else if (strcmp(cpu, "neon") == 0) {
53         armcap = ARMV7_NEON;
54       } else if (strcmp(cpu, "crypto") == 0) {
55         armcap = ARMV7_NEON | ARMV8_AES | ARMV8_SHA1 | ARMV8_SHA256 | ARMV8_PMULL;
56       } else {
57         fprintf(stderr, "Unknown CPU: %s\n", cpu);
58         exit(1);
59       }
60 
61       uint32_t *armcap_ptr = OPENSSL_get_armcap_pointer_for_test();
62       if ((armcap & *armcap_ptr) != armcap) {
63         fprintf(stderr,
64                 "Host CPU does not support features for testing CPU '%s'.\n",
65                 cpu);
66         exit(89);
67       }
68       printf("Simulating CPU '%s'\n", cpu);
69       *armcap_ptr = armcap;
70     }
71 #endif  // TEST_ARM_CPUS
72 
73     if (strcmp(argv[i], "--no_unwind_tests") == 0) {
74       unwind_tests = false;
75     }
76   }
77 
78   if (unwind_tests) {
79     abi_test::EnableUnwindTests();
80   }
81 
82   // Run the entire test suite under an ABI check. This is less effective than
83   // testing the individual assembly functions, but will catch issues with
84   // rarely-used registers.
85   abi_test::Result abi;
86   int ret = abi_test::Check(&abi, RUN_ALL_TESTS);
87   if (!abi.ok()) {
88     fprintf(stderr, "ABI failure in test suite:\n");
89     for (const auto &error : abi.errors) {
90       fprintf(stderr, "    %s\n", error.c_str());
91     }
92     exit(1);
93   }
94   return ret;
95 }
96