• 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/rand.h>
21 
22 #include "abi_test.h"
23 #include "gtest_main.h"
24 #include "../internal.h"
25 
26 #if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) &&       \
27     !defined(OPENSSL_STATIC_ARMCAP)
28 #include <openssl/arm_arch.h>
29 #define TEST_ARM_CPUS
30 #endif
31 
32 
main(int argc,char ** argv)33 int main(int argc, char **argv) {
34   testing::InitGoogleTest(&argc, argv);
35   bssl::SetupGoogleTest();
36 
37   bool unwind_tests = true;
38   for (int i = 1; i < argc; i++) {
39 #if !defined(OPENSSL_WINDOWS)
40     if (strcmp(argv[i], "--fork_unsafe_buffering") == 0) {
41       RAND_enable_fork_unsafe_buffering(-1);
42     }
43 #endif
44 
45 #if defined(TEST_ARM_CPUS)
46     if (strncmp(argv[i], "--cpu=", 6) == 0) {
47       const char *cpu = argv[i] + 6;
48       uint32_t armcap;
49       if (strcmp(cpu, "none") == 0) {
50         armcap = 0;
51       } else if (strcmp(cpu, "neon") == 0) {
52         armcap = ARMV7_NEON;
53       } else if (strcmp(cpu, "crypto") == 0) {
54         armcap = ARMV7_NEON | ARMV8_AES | ARMV8_SHA1 | ARMV8_SHA256 | ARMV8_PMULL;
55       } else {
56         fprintf(stderr, "Unknown CPU: %s\n", cpu);
57         exit(1);
58       }
59 
60       uint32_t *armcap_ptr = OPENSSL_get_armcap_pointer_for_test();
61       if ((armcap & *armcap_ptr) != armcap) {
62         fprintf(stderr,
63                 "Host CPU does not support features for testing CPU '%s'.\n",
64                 cpu);
65         exit(89);
66       }
67       printf("Simulating CPU '%s'\n", cpu);
68       *armcap_ptr = armcap;
69     }
70 #endif  // TEST_ARM_CPUS
71 
72     if (strcmp(argv[i], "--no_unwind_tests") == 0) {
73       unwind_tests = false;
74     }
75   }
76 
77   if (unwind_tests) {
78     abi_test::EnableUnwindTests();
79   }
80 
81   return RUN_ALL_TESTS();
82 }
83