Skip to content

Commit

Permalink
integration-tests: Expand use of TLS in rust integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlattimore committed Jun 27, 2024
1 parent 54d07d6 commit 514f1d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
14 changes: 14 additions & 0 deletions wild/tests/sources/rdyn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ thread_local! {
pub static TLS1: Cell<i32> = const { Cell::new(1) };
}

thread_local! {
pub static TLS2: Cell<i32> = const { Cell::new(2) };
}

#[no_mangle]
pub extern fn get_tls1() -> i32 {
TLS1.get()
Expand All @@ -24,3 +28,13 @@ pub extern fn get_tls1() -> i32 {
pub extern fn set_tls1(value: i32) {
TLS1.set(value);
}

#[no_mangle]
pub extern fn get_tls2() -> i32 {
TLS2.get()
}

#[no_mangle]
pub extern fn set_tls2(value: i32) {
TLS2.set(value);
}
24 changes: 21 additions & 3 deletions wild/tests/sources/rust-integration-dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
//#CompArgs:-C debuginfo=2
//#Shared:rdyn1.rs

extern {
extern "C" {
fn foo() -> i32;
fn bar() -> i32;
fn get_tls1() -> i32;
fn set_tls1(value: i32);
fn get_tls2() -> i32;
fn set_tls2(value: i32);
}

fn main() {
Expand All @@ -21,10 +23,26 @@ fn main() {
std::process::exit(101);
}

unsafe { set_tls1(88); }
if unsafe { get_tls1() } != 88 {
if unsafe { get_tls1() } != 1 {
std::process::exit(102);
}
if unsafe { get_tls2() } != 2 {
std::process::exit(103);
}

unsafe {
set_tls1(88);
}
unsafe {
set_tls2(55);
}

if unsafe { get_tls1() } != 88 {
std::process::exit(104);
}
if unsafe { get_tls2() } != 55 {
std::process::exit(105);
}

std::process::exit(42);
}

0 comments on commit 514f1d5

Please sign in to comment.