1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 #include <unittest/unittest.h>
8 
9 extern bool check_dso_ctor();
10 extern bool check_dso_tlocal_in_thread();
11 extern bool check_dso_tlocal_after_join();
12 
13 template<bool* tlocal_ctor_ran, bool* tlocal_dtor_ran>
14 struct ThreadLocal {
15     bool flag = false;
ThreadLocalThreadLocal16     ThreadLocal() {
17         *tlocal_ctor_ran = true;
18     }
~ThreadLocalThreadLocal19     ~ThreadLocal() {
20         *tlocal_dtor_ran = true;
21     }
check_before_referenceThreadLocal22     static bool check_before_reference() {
23         BEGIN_HELPER;
24         EXPECT_FALSE(*tlocal_ctor_ran);
25         EXPECT_FALSE(*tlocal_dtor_ran);
26         END_HELPER;
27     }
check_after_referenceThreadLocal28     static bool check_after_reference() {
29         BEGIN_HELPER;
30         EXPECT_TRUE(*tlocal_ctor_ran);
31         EXPECT_FALSE(*tlocal_dtor_ran);
32         END_HELPER;
33     }
check_after_joinThreadLocal34     static bool check_after_join() {
35         BEGIN_HELPER;
36         EXPECT_TRUE(*tlocal_ctor_ran);
37         EXPECT_TRUE(*tlocal_dtor_ran);
38         END_HELPER;
39     }
40 };
41