Unsafe tests for AtomicLong

This commit is contained in:
Volker Berlin 2022-10-16 21:45:58 +02:00
parent 4aa282176e
commit 1d342d8d88

View File

@ -18,6 +18,7 @@ package de.inetsoftware.jwebassembly.runtime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.ClassRule;
import org.junit.runners.Parameterized.Parameters;
@ -45,7 +46,11 @@ public class UnsafeTest extends AbstractBaseTest {
addParam( list, script, "compareAndSwapInt" );
addParam( list, script, "getAndAddInt" );
addParam( list, script, "getAndSetInt" );
addParam( list, script, "lazySet" );
addParam( list, script, "lazySetInt" );
addParam( list, script, "compareAndSwapLong" );
addParam( list, script, "getAndAddLong" );
addParam( list, script, "getAndSetLong" );
addParam( list, script, "lazySetLong" );
}
rule.setTestParameters( list );
return list;
@ -86,10 +91,49 @@ public class UnsafeTest extends AbstractBaseTest {
}
@Export
static int lazySet() {
static int lazySetInt() {
AtomicInteger obj = new AtomicInteger();
obj.lazySet( 42 );
return obj.get();
}
@Export
static long compareAndSwapLong() {
AtomicLong obj = new AtomicLong();
if( obj.compareAndSet( 0, 25 ) ) {
return obj.get();
} else {
return 42;
}
}
@Export
static long getAndAddLong() {
AtomicLong obj = new AtomicLong();
obj.set( 13 );
if( obj.getAndAdd( 25 ) == 13 ) {
return obj.get();
} else {
return 42;
}
}
@Export
static long getAndSetLong() {
AtomicLong obj = new AtomicLong();
obj.set( 13 );
if( obj.getAndSet( 25 ) == 13 ) {
return obj.get();
} else {
return 42;
}
}
@Export
static long lazySetLong() {
AtomicLong obj = new AtomicLong();
obj.lazySet( 42 );
return obj.get();
}
}
}