Skip to content

Commit

Permalink
modify unit test randomx flags to JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasMLK committed Dec 8, 2022
1 parent 1884adf commit 31f9f83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions src/test/java/io/xdag/crypto/randomx/RandomXJNATest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ public class RandomXJNATest {

@Test
public void testRandomx_get_flags() {
int flagsValue = INSTANCE.randomx_get_flags();
assertNotEquals(0, flagsValue);
int flags = INSTANCE.randomx_get_flags();
assertNotEquals(0, flags);
}

@Test
public void testRandomx_alloc_cache() {
int flagsValue = 0;
PointerByReference newCache = INSTANCE.randomx_alloc_cache(flagsValue);
int flags = RandomXFlag.JIT.getValue();
PointerByReference newCache = INSTANCE.randomx_alloc_cache(flags);
assertNotNull("randomx alloc cache ", newCache);
}

@Test
public void testRandomx_init_cache() {
int flagsValue = 0;
int length = 32;
PointerByReference newCache = INSTANCE.randomx_alloc_cache(flagsValue);
int flags = RandomXFlag.JIT.getValue();
PointerByReference newCache = INSTANCE.randomx_alloc_cache(flags);
assertNotNull("randomx alloc cache ", newCache);

byte[] buffer = new byte[length];
Expand All @@ -62,9 +62,9 @@ public void testRandomx_init_cache() {

@Test
public void testRandomx_release_cache() {
int flagsValue = 0;
int length = 32;
PointerByReference newCache = INSTANCE.randomx_alloc_cache(flagsValue);
int flags = RandomXFlag.JIT.getValue();
PointerByReference newCache = INSTANCE.randomx_alloc_cache(flags);
assertNotNull("randomx alloc cache ", newCache);

byte[] buffer = new byte[length];
Expand All @@ -77,44 +77,44 @@ public void testRandomx_release_cache() {
@Test
public void testRandomx_create_vm() {
int length = 32;
int flagsValue = RandomXJNA.INSTANCE.randomx_get_flags();
assertNotEquals(0, flagsValue);
int flags = RandomXFlag.JIT.getValue();
assertNotEquals(0, flags);

PointerByReference cache = INSTANCE.randomx_alloc_cache(flagsValue);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flagsValue);
PointerByReference cache = INSTANCE.randomx_alloc_cache(flags);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flags);

byte[] buffer = new byte[length];
Memory memory = new Memory(length);
memory.write(0, buffer, 0, length);
INSTANCE.randomx_init_cache(cache, memory, new NativeSize(length));
RandomXWrapper randomXWrapper = RandomXWrapper.builder().build();
RandomXVM vm = new RandomXVM(RandomXJNA.INSTANCE.randomx_create_vm(flagsValue, cache, dataset), randomXWrapper);
RandomXVM vm = new RandomXVM(RandomXJNA.INSTANCE.randomx_create_vm(flags, cache, dataset), randomXWrapper);
assertNotNull(vm);
}

@Test
public void testRandomx_destroy_vm() {
int length = 32;
int flagsValue = RandomXJNA.INSTANCE.randomx_get_flags();
assertNotEquals(0, flagsValue);
int flags = RandomXFlag.JIT.getValue();
assertNotEquals(0, flags);

PointerByReference cache = INSTANCE.randomx_alloc_cache(flagsValue);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flagsValue);
PointerByReference cache = INSTANCE.randomx_alloc_cache(flags);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flags);

byte[] buffer = new byte[length];
Memory memory = new Memory(length);
memory.write(0, buffer, 0, length);
INSTANCE.randomx_init_cache(cache, memory, new NativeSize(length));
RandomXWrapper randomXWrapper = RandomXWrapper.builder().build();
RandomXVM vm = new RandomXVM(RandomXJNA.INSTANCE.randomx_create_vm(flagsValue, cache, dataset), randomXWrapper);
RandomXVM vm = new RandomXVM(RandomXJNA.INSTANCE.randomx_create_vm(flags, cache, dataset), randomXWrapper);
assertNotNull(vm);

INSTANCE.randomx_destroy_vm(vm.getPointer());
}

@Test
public void testRandomx_vm_set_cache() {
int flags = RandomXJNA.INSTANCE.randomx_get_flags();
int flags = RandomXFlag.JIT.getValue();
PointerByReference cache = INSTANCE.randomx_alloc_cache(flags);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flags);

Expand All @@ -131,8 +131,8 @@ public void testRandomx_calculate_hash() {
byte[] key1Bytes = key1.getBytes();
byte[] key2Bytes = key2.getBytes();

//int flags = INSTANCE.randomx_get_flags() + RandomXWrapper.Flag.LARGE_PAGES.getValue() + RandomXWrapper.Flag.FULL_MEM.getValue();
int flags = INSTANCE.randomx_get_flags();
// int flags = INSTANCE.randomx_get_flags() + RandomXFlag.LARGE_PAGES.getValue() + RandomXFlag.FULL_MEM.getValue();
int flags = RandomXFlag.JIT.getValue();

PointerByReference cache = INSTANCE.randomx_alloc_cache(flags);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flags);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/xdag/crypto/randomx/RandomXVMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void testGetHash() {
byte[] key1Bytes = key1.getBytes();
byte[] key2Bytes = key2.getBytes();

int flags = INSTANCE.randomx_get_flags();
int flags = RandomXFlag.JIT.getValue();

PointerByReference cache = INSTANCE.randomx_alloc_cache(flags);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flags);
Expand All @@ -59,7 +59,7 @@ public void testGetHash() {

@Test
public void testDestroy() {
int flags = RandomXJNA.INSTANCE.randomx_get_flags();
int flags = RandomXFlag.JIT.getValue();
PointerByReference cache = INSTANCE.randomx_alloc_cache(flags);
PointerByReference dataset = RandomXJNA.INSTANCE.randomx_alloc_dataset(flags);

Expand Down

0 comments on commit 31f9f83

Please sign in to comment.