1 // Copyright 2016 The BoringSSL Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include <stdio.h>
16 #include <string.h>
17 
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20 
21 #include <openssl/rand.h>
22 
23 #include "abi_test.h"
24 #include "gtest_main.h"
25 #include "../internal.h"
26 
27 
main(int argc,char ** argv)28 int main(int argc, char **argv) {
29   testing::InitGoogleMock(&argc, argv);
30   bssl::SetupGoogleTest();
31 
32   bool unwind_tests = true;
33   for (int i = 1; i < argc; i++) {
34 #if !defined(OPENSSL_WINDOWS)
35     if (strcmp(argv[i], "--fork_unsafe_buffering") == 0) {
36       RAND_enable_fork_unsafe_buffering(-1);
37     }
38 #endif
39 
40 #if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
41     !defined(OPENSSL_STATIC_ARMCAP)
42     if (strncmp(argv[i], "--cpu=", 6) == 0) {
43       const char *cpu = argv[i] + 6;
44       uint32_t armcap;
45       if (strcmp(cpu, "none") == 0) {
46         armcap = 0;
47       } else if (strcmp(cpu, "neon") == 0) {
48         armcap = ARMV7_NEON;
49       } else if (strcmp(cpu, "crypto") == 0) {
50         armcap = ARMV7_NEON | ARMV8_AES | ARMV8_SHA1 | ARMV8_SHA256 | ARMV8_PMULL;
51       } else {
52         fprintf(stderr, "Unknown CPU: %s\n", cpu);
53         exit(1);
54       }
55 
56       uint32_t *armcap_ptr = OPENSSL_get_armcap_pointer_for_test();
57       if ((armcap & *armcap_ptr) != armcap) {
58         fprintf(stderr,
59                 "Host CPU does not support features for testing CPU '%s'.\n",
60                 cpu);
61         exit(89);
62       }
63       printf("Simulating CPU '%s'\n", cpu);
64       *armcap_ptr = armcap;
65     }
66 #endif  // (ARM || AARCH64) && !STATIC_ARMCAP
67 
68     if (strcmp(argv[i], "--no_unwind_tests") == 0) {
69       unwind_tests = false;
70     }
71   }
72 
73   if (unwind_tests) {
74     abi_test::EnableUnwindTests();
75   }
76 
77   return RUN_ALL_TESTS();
78 }
79