Skip to content

Commit

Permalink
Integrate duplicated PoW testing code into a file
Browse files Browse the repository at this point in the history
The selected hardware acceleration are added by user-defined macro.
$ make check output message:
*** Validating build/test-trinary ***
        [ Verified ]
*** Validating build/test-curl ***
        [ Verified ]
*** Validating build/test-dcurl ***
        [ Verified ]
*** Validating build/test-multi-pow ***
        [ Verified ]
*** Validating build/test-pow ***
CPU - SSE
Success.
        [ Verified ]

Close #60.
  • Loading branch information
marktwtn committed Sep 12, 2018
1 parent 9c9b126 commit 0bea478
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 372 deletions.
25 changes: 2 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,13 @@ TESTS = \
trinary \
curl \
dcurl \
multi-pow

ifeq ("$(BUILD_AVX)","1")
TESTS += \
pow_avx
else
ifeq ("$(BUILD_SSE)","1")
TESTS += \
pow_sse
else
TESTS += \
pow_c
endif
endif

ifeq ("$(BUILD_GPU)","1")
TESTS += \
pow_cl
endif
multi-pow \
pow

ifeq ("$(BUILD_COMPAT)", "1")
TESTS += ccurl-multi_pow
endif

ifeq ("$(BUILD_FPGA_ACCEL)","1")
TESTS += pow_fpga_accel
endif

TESTS := $(addprefix $(OUT)/test-, $(TESTS))

LIBS = libdcurl.so
Expand Down
10 changes: 6 additions & 4 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
#define Depth 3
#define Radix 3

#define HASH_LENGTH 243 // trits
#define NONCE_LENGTH 81 // trits
#define STATE_LENGTH 3 * HASH_LENGTH // trits
#define TRANSACTION_LENGTH 2673 * 3 // trits
#define TRANSACTION_TRYTES_LENGTH 2673

#define HASH_LENGTH 243 // trits
#define NONCE_LENGTH 81 // trits
#define STATE_LENGTH 3 * HASH_LENGTH // trits
#define TRANSACTION_LENGTH (TRANSACTION_TRYTES_LENGTH * 3) // trits

#define SignatureMessageFragmentTrinaryOffset 0
#define SignatureMessageFragmentTrinarySize 6561
Expand Down
110 changes: 85 additions & 25 deletions tests/test-pow_fpga_accel.c → tests/test-pow.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
/* Test program for pow_fpga_accel */
/* Test program for pow_*.c */
#include "common.h"
#include "implcontext.h"

#if defined(ENABLE_AVX)
extern ImplContext PoWAVX_Context;
#elif defined(ENABLE_SSE)
extern ImplContext PoWSSE_Context;
#else
extern ImplContext PoWC_Context;
#endif

#if defined(ENABLE_OPENCL)
extern ImplContext PoWCL_Context;
#endif

#if defined(ENABLE_FPGA_ACCEL)
extern ImplContext PoWFPGAAccel_Context;
#endif

const char *description[ ] = {
#if defined(ENABLE_AVX)
"CPU - AVX",
#elif defined(ENABLE_SSE)
"CPU - SSE",
#else
"CPU - pure C",
#endif

#if defined(ENABLE_OPENCL)
"GPU - OpenCL",
#endif

#if defined(ENABLE_FPGA_ACCEL)
"FPGA",
#endif
};

int main()
{
Expand Down Expand Up @@ -49,31 +81,59 @@ int main()

int mwm = 14;

/* test implementation of the PoW FPGA accelerator with mwm = 14 */
initializeImplContext(&PoWFPGAAccel_Context);
void *pow_ctx =
getPoWContext(&PoWFPGAAccel_Context, (int8_t *) trytes, mwm);
assert(pow_ctx);
doThePoW(&PoWFPGAAccel_Context, pow_ctx);
int8_t *ret_trytes = getPoWResult(&PoWFPGAAccel_Context, pow_ctx);
assert(ret_trytes);
freePoWContext(&PoWFPGAAccel_Context, pow_ctx);

Trytes_t *trytes_t = initTrytes(ret_trytes, 2673);
assert(trytes_t);
Trytes_t *hash_trytes = hashTrytes(trytes_t);
assert(hash_trytes);

/* Validation */
Trits_t *ret_trits = trits_from_trytes(hash_trytes);
for (int i = 243 - 1; i >= 243 - mwm; i--) {
assert(ret_trits->data[i] == 0);
}
ImplContext ImplContextArr[ ] = {
#if defined(ENABLE_AVX)
PoWAVX_Context,
#elif defined(ENABLE_SSE)
PoWSSE_Context,
#else
PoWC_Context,
#endif

#if defined(ENABLE_OPENCL)
PoWCL_Context,
#endif

#if defined(ENABLE_FPGA_ACCEL)
PoWFPGAAccel_Context,
#endif
};

free(ret_trytes);
freeTrobject(trytes_t);
freeTrobject(hash_trytes);
freeTrobject(ret_trits);

for (int idx = 0; idx < sizeof(ImplContextArr) / sizeof(ImplContext); idx++) {
printf("%s\n",description[idx]);

ImplContext *PoW_Context_ptr = &ImplContextArr[idx];

/* test implementation with mwm = 14 */
initializeImplContext(PoW_Context_ptr);
void *pow_ctx = getPoWContext(PoW_Context_ptr, (int8_t *) trytes, mwm);
assert(pow_ctx);
doThePoW(PoW_Context_ptr, pow_ctx);
int8_t *ret_trytes = getPoWResult(PoW_Context_ptr, pow_ctx);
assert(ret_trytes);
freePoWContext(PoW_Context_ptr, pow_ctx);
destroyImplContext(PoW_Context_ptr);

Trytes_t *trytes_t = initTrytes(ret_trytes, TRANSACTION_TRYTES_LENGTH);
assert(trytes_t);
Trytes_t *hash_trytes = hashTrytes(trytes_t);
assert(hash_trytes);
Trits_t *ret_trits = trits_from_trytes(hash_trytes);
assert(ret_trits);

/* Validation */
for (int i = HASH_LENGTH - 1; i >= HASH_LENGTH - mwm; i--) {
assert(ret_trits->data[i] == 0);
}

free(ret_trytes);
freeTrobject(trytes_t);
freeTrobject(hash_trytes);
freeTrobject(ret_trits);

printf("Success.\n");
}

return 0;
}
79 changes: 0 additions & 79 deletions tests/test-pow_avx.c

This file was deleted.

84 changes: 0 additions & 84 deletions tests/test-pow_c.c

This file was deleted.

Loading

0 comments on commit 0bea478

Please sign in to comment.