diff options
author | Ian Lance Taylor <iant@google.com> | 2007-10-07 17:10:10 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@google.com> | 2007-10-07 17:10:10 +0000 |
commit | 6eee141ff6d84d39ca9e364eb98818431162d6df (patch) | |
tree | cf13d55adff30ab67d0ab5a0e296007fc02521f7 /gold/testsuite/tls_test.cc | |
parent | 46cf9fa27e13491561a643178d5ffd2b086183fb (diff) | |
download | gdb-6eee141ff6d84d39ca9e364eb98818431162d6df.zip gdb-6eee141ff6d84d39ca9e364eb98818431162d6df.tar.gz gdb-6eee141ff6d84d39ca9e364eb98818431162d6df.tar.bz2 |
Add a TLS test case.
Diffstat (limited to 'gold/testsuite/tls_test.cc')
-rw-r--r-- | gold/testsuite/tls_test.cc | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/gold/testsuite/tls_test.cc b/gold/testsuite/tls_test.cc new file mode 100644 index 0000000..a666433 --- /dev/null +++ b/gold/testsuite/tls_test.cc @@ -0,0 +1,137 @@ +// tls_test.cc -- test TLS variables for gold + +// Copyright 2006, 2007 Free Software Foundation, Inc. +// Written by Ian Lance Taylor <iant@google.com>. + +// This file is part of gold. + +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +// MA 02110-1301, USA. + +// This provides a set of test functions for TLS variables. The +// functions are called by a main function in tls_test_main.cc. This +// lets us test TLS access from a shared library. We currently don't +// bother to test TLS access between two different files, on the +// theory that that is no more complicated than ordinary variable +// access between files. + +// We start two threads, and stop the second one. Then we run the +// first thread through the following cases. Then we let the second +// thread continue, and run it through the same set of cases. All the +// actual thread manipulation is in tls_test_main.cc. + +// 1 Access to an uninitialized global thread variable. +// 2 Access to an uninitialized static thread variable. +// 3 Access to an initialized global thread variable. +// 4 Access to an initialized static thread variable. +// 5 Taking the address of a global thread variable. +// 6 Taking the address of a static thread variable. +// 7 Verify that the above tests left the variables set correctly. + +#include "tls_test.h" + +__thread int v1; +static __thread int v2; +__thread int v3 = 3; +static __thread int v4 = 4; +__thread int v5; +static __thread int v6; + +bool +t1() +{ + if (v1 != 0) + return false; + v1 = 10; + return true; +} + +bool +t2() +{ + if (v2 != 0) + return false; + v2 = 20; + return true; +} + +bool +t3() +{ + if (v3 != 3) + return false; + v3 = 30; + return true; +} + +bool +t4() +{ + if (v4 != 4) + return false; + v4 = 40; + return true; +} + +// For test 5 the main function calls f5b(f5a()), then calls t5(). + +int* +f5a() +{ + return &v5; +} + +void +f5b(int* p) +{ + *p = 50; +} + +bool +t5() +{ + return v5 == 50; +} + +// For test 5 the main function calls f6b(f6a()), then calls t6(). + +int* +f6a() +{ + return &v6; +} + +void +f6b(int* p) +{ + *p = 60; +} + +bool +t6() +{ + return v6 == 60; +} + +bool +t7() +{ + return (v1 == 10 + && v2 == 20 + && v3 == 30 + && v4 == 40 + && v5 == 50 + && v6 == 60); +} |