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 9extern bool check_dso_ctor(); 10extern bool check_dso_tlocal_in_thread(); 11extern bool check_dso_tlocal_after_join(); 12 13template<bool* tlocal_ctor_ran, bool* tlocal_dtor_ran> 14struct ThreadLocal { 15 bool flag = false; 16 ThreadLocal() { 17 *tlocal_ctor_ran = true; 18 } 19 ~ThreadLocal() { 20 *tlocal_dtor_ran = true; 21 } 22 static bool check_before_reference() { 23 BEGIN_HELPER; 24 EXPECT_FALSE(*tlocal_ctor_ran); 25 EXPECT_FALSE(*tlocal_dtor_ran); 26 END_HELPER; 27 } 28 static bool check_after_reference() { 29 BEGIN_HELPER; 30 EXPECT_TRUE(*tlocal_ctor_ran); 31 EXPECT_FALSE(*tlocal_dtor_ran); 32 END_HELPER; 33 } 34 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