Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / native_client / tests / toolchain / thread_cpp11.cc
1 /*
2  * Copyright (c) 2013 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /*
8  * This test ensures that the PNaCl backends can deal with C++11's
9  * <thread> header.
10  */
11
12 #include <inttypes.h>
13 #include <stdint.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <thread>
17
18
19 #define STR_(A) #A
20 #define STR(A) STR_(A)
21
22 #define CHECK_NE(LHS, RHS, MSG) do {            \
23     printf("\t" MSG ":\t" STR(LHS) "=%" PRIu64  \
24            " and " STR(RHS) "=%" PRIu64 "\n",   \
25            (uint64_t)(LHS), (uint64_t)(RHS));   \
26     if ((LHS) == (RHS)) {                       \
27       fprintf(stderr, "ERROR: " MSG ": `"       \
28               STR(LHS) " == " STR(RHS) "` "     \
29               "\n");                            \
30       exit(1);                                  \
31     }                                           \
32   } while (0)
33
34 // std::thread::hardware_concurrency returns 0 if not computable or not
35 // well defined, and a hint about the number of hardware thread contexts
36 // otherwise.
37 void test_hardware_concurrency() {
38   CHECK_NE(std::thread::hardware_concurrency(), 0,
39            "NaCl should know the platform's hardware concurrency");
40 }
41
42 // TODO(jfb) Test the rest of C++11 <thread>.
43
44 int main() {
45   test_hardware_concurrency();
46   return 0;
47 }