folly copyright 2015 -> copyright 2016
[folly.git] / folly / futures / test / CoreTest.cpp
1 /*
2  * Copyright 2016 Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <gtest/gtest.h>
18
19 #include <folly/futures/Future.h>
20 #include <folly/futures/detail/Core.h>
21
22 using namespace folly;
23
24 // On android, we see a different way of memory alignment of this structure.
25 // Adding some extra padding to make it pass.
26 #ifdef __ANDROID_
27 constexpr size_t extraPadding = 8;
28 #else
29 constexpr size_t extraPadding = 0;
30 #endif
31
32 TEST(Core, size) {
33   struct Gold {
34     char lambdaBuf_[8 * sizeof(void*)];
35     folly::Optional<Try<Unit>> result_;
36     std::function<void(Try<Unit>&&)> callback_;
37     detail::FSM<detail::State> fsm_;
38     std::atomic<unsigned char> attached_;
39     std::atomic<bool> active_;
40     std::atomic<bool> interruptHandlerSet_;
41     folly::MicroSpinLock interruptLock_;
42     folly::MicroSpinLock executorLock_;
43     int8_t priority_;
44     Executor* executor_;
45     std::shared_ptr<RequestContext> context_;
46     std::unique_ptr<exception_wrapper> interrupt_;
47     std::function<void(exception_wrapper const&)> interruptHandler_;
48   };
49   // If this number goes down, it's fine!
50   // If it goes up, please seek professional advice ;-)
51   EXPECT_GE(sizeof(Gold) + extraPadding, sizeof(detail::Core<Unit>));
52 }