Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / test_arch.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph distributed storage system
5  *
6  * Copyright (C) 2014 Red Hat <contact@redhat.com>
7  *
8  * Author: Loic Dachary <loic@dachary.org>
9  *
10  *  This library is free software; you can redistribute it and/or
11  *  modify it under the terms of the GNU Lesser General Public
12  *  License as published by the Free Software Foundation; either
13  *  version 2.1 of the License, or (at your option) any later version.
14  *
15  */
16
17 #include <stdio.h>
18
19 #include "arch/probe.h"
20 #include "arch/intel.h"
21 #include "arch/arm.h"
22 #include "global/global_context.h"
23 #include "gtest/gtest.h"
24
25
26 #define FLAGS_SIZE 4096
27
28 TEST(Arch, all)
29 {
30   ceph_arch_probe();
31   EXPECT_TRUE(ceph_arch_probed);
32   
33 #if (__arm__ || __aarch64__ || __x86_64__) && __linux__
34   char flags[FLAGS_SIZE];
35   FILE *f = popen("grep '^\\(flags\\|Features\\)[        ]*:' "
36                   "/proc/cpuinfo | head -1", "r");
37   if(f == NULL || fgets(flags, FLAGS_SIZE - 1, f) == NULL) {
38     // silently do nothing if /proc/cpuinfo does exist, is not
39     // readable or does not contain the expected information
40     if (f)
41       pclose(f);
42     return;
43   }
44   pclose(f);
45   flags[strlen(flags) - 1] = ' ';
46
47   int expected;
48
49 #if (__arm__ || __aarch64__)
50
51   expected = (strstr(flags, " neon ") || strstr(flags, " asimd ")) ? 1 : 0;
52   EXPECT_EQ(expected, ceph_arch_neon);
53
54 #endif
55 #if (__aarch64__)
56
57   expected = strstr(flags, " crc32 ") ? 1 : 0;
58   EXPECT_EQ(expected, ceph_arch_aarch64_crc32);
59
60 #endif
61 #if (__x86_64__)
62
63   expected = strstr(flags, " pclmulqdq ") ? 1 : 0;
64   EXPECT_EQ(expected, ceph_arch_intel_pclmul);
65
66   expected = strstr(flags, " sse4_2 ") ? 1 : 0;
67   EXPECT_EQ(expected, ceph_arch_intel_sse42);
68
69   expected = strstr(flags, " sse4_1 ") ? 1 : 0;
70   EXPECT_EQ(expected, ceph_arch_intel_sse41);
71
72   expected = (strstr(flags, " sse3 ") || strstr(flags, " ssse3 ")) ? 1 : 0;
73   EXPECT_EQ(expected, ceph_arch_intel_sse3);
74
75   expected = strstr(flags, " ssse3 ") ? 1 : 0;
76   EXPECT_EQ(expected, ceph_arch_intel_ssse3);
77
78   expected = strstr(flags, " sse2 ") ? 1 : 0;
79   EXPECT_EQ(expected, ceph_arch_intel_sse2);
80
81 #endif
82
83 #endif
84 }
85
86
87 /*
88  * Local Variables:
89  * compile-command: "cd .. ; make -j4 &&
90  *   make unittest_arch &&
91  *   valgrind --tool=memcheck ./unittest_arch --gtest_filter=*.*"
92  * End:
93  */