History

feat(x86_64): add TLS Local Exec support with tests

Meng Zhuo committed 6 months ago

Commit ea26b851 parent 8443e255 files · +141 −6Browse files

Showing the changes to tests (3 of 5 files). Show all

Unified · Split

3 files
  1. tests/tests2/144_tls.c +50 −0
  2. tests/tests2/144_tls.expect +8 −0
  3. tests/tests2/Makefile +7 −0
tests/tests2/144_tls.c+50−0
@@ -0,0 +1,50 @@
1+#include <stdio.h>
2+#include <pthread.h>
3+
4+__thread int tls_init = 42;
5+__thread int tls_zero;
6+
7+static void *thread_func(void *arg)
8+{
9+ (void)arg;
10+
11+ printf("%d\n", tls_init);
12+ if (tls_init != 42) return (void *)1;
13+
14+ printf("%d\n", tls_zero);
15+ if (tls_zero != 0) return (void *)1;
16+
17+ tls_init = 100;
18+ tls_zero = 200;
19+
20+ printf("%d\n", tls_init);
21+ printf("%d\n", tls_zero);
22+
23+ return (void *)0;
24+}
25+
26+int main()
27+{
28+ pthread_t t;
29+ void *ret;
30+ int errors = 0;
31+
32+ printf("%d\n", tls_init);
33+ if (tls_init != 42) errors = 1;
34+
35+ printf("%d\n", tls_zero);
36+ if (tls_zero != 0) errors = 1;
37+
38+ pthread_create(&t, NULL, thread_func, NULL);
39+ pthread_join(t, &ret);
40+
41+ if (ret) errors = 1;
42+
43+ printf("%d\n", tls_init);
44+ if (tls_init != 42) errors = 1;
45+
46+ printf("%d\n", tls_zero);
47+ if (tls_zero != 0) errors = 1;
48+
49+ return errors;
50+}
tests/tests2/144_tls.expect+8−0
@@ -0,0 +1,8 @@
1+42
2+0
3+42
4+0
5+100
6+200
7+42
8+0
tests/tests2/Makefile+7−0
@@ -19,6 +19,9 @@ ifeq (,$(filter i386 x86_64,$(ARCH))) · 18 unmodified lines
1919 SKIP += 85_asm-outside-function.test # x86 asm
2020 SKIP += 127_asm_goto.test # hardcodes x86 asm
2121 endif
22+ifeq (,$(filter x86_64,$(ARCH)))
23+ SKIP += 144_tls.test # TLS only implemented on x86_64 so far
24+endif
2225 ifeq ($(CONFIG_backtrace),no)
2326 SKIP += 113_btdll.test
2427 CONFIG_bcheck = no
@@ -107,6 +110,10 @@ GEN-ALWAYS = · 82 unmodified lines
107110 # constructor/destructor
108111 108_constructor.test: NORUN = true
109112
113+# TLS needs executable and pthread, not -run
114+144_tls.test: FLAGS += -pthread
115+144_tls.test: NORUN = true
116+
110117 112_backtrace.test: FLAGS += -dt -b
111118 112_backtrace.test 113_btdll.test 126_bound_global.test: FILTER += \
112119 -e 's;[0-9A-Fa-fx]\{5,\};........;g' \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t