1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
extern crate libc;
#[macro_use]
extern crate lazy_static;
extern crate bigint;
extern crate dirs;
extern crate stack_test_progpow_cpu;
#[cfg(feature = "cuda")]
extern crate stack_test_progpow_gpu_cuda as progpow_gpu;
#[cfg(feature = "opencl")]
extern crate stack_test_progpow_gpu_opencl as progpow_gpu;
pub mod hardware;
pub mod types;
#[cfg(test)]
mod test {
use super::*;
use bigint::uint::U256;
use hardware::PpCPU;
use types::PpCompute;
#[test]
fn test_compute_cpu() {
let height: u64 = 20;
let nonce: u64 = 10123012301;
let header_hash: [u8; 32] = [0; 32];
let pp_cpu = PpCPU::new();
let (value, mix) = pp_cpu.verify(&header_hash, height, nonce).unwrap();
assert_eq!(
mix,
[
1067276040, 109748694, 1270962088, 3616890847, 2528371908, 2524623649, 1191460869,
2529877558
]
);
}
#[test]
#[cfg(feature = "gpu")]
fn test_compute_gpu() {
use hardware::PpGPU;
use progpow_gpu::utils::get_gpu_solution;
let header = [20u8; 32];
let epoch: i32 = 0;
let height: u64 = 1;
let boundary: u64 = 100000000;
let mut difficulty: U256 = U256::max_value();
difficulty = difficulty / U256::from(boundary);
let target = difficulty >> 192;
let (nonce, mix) = get_gpu_solution(header.clone(), height, epoch, boundary);
let cpu = PpCPU::new();
let (value, mix_hash) = cpu.verify(&header, height, nonce).unwrap();
let mix32: [u32; 8] = unsafe { ::std::mem::transmute(mix) };
assert_eq!(mix32, mix_hash);
assert!(((value[0] as u64) << 32 | value[1] as u64) < target.low_u64());
}
}