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.
  • Loading branch information
marktwtn committed Sep 11, 2018
1 parent 9c9b126 commit aac53bb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 368 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
109 changes: 84 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,58 @@ 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);

Trytes_t *trytes_t = initTrytes(ret_trytes, 2673);
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 = 243 - 1; i >= 243 - 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 aac53bb

Please sign in to comment.