Skip to content

Commit

Permalink
Merge pull request #6 from jserv/simplify-testcase
Browse files Browse the repository at this point in the history
Simplify test case I/O operations
  • Loading branch information
WEI, CHEN committed Mar 16, 2018
2 parents 0a04574 + 5fde0ee commit b815223
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 51 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ $(OUT)/libdcurl.so: $(OBJS)
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS)

$(OUT)/test_%.done: $(OUT)/test_%
$(Q)./$< && $(PRINTF) "*** $< *** $(PASS_COLOR)[ Verified ]$(NO_COLOR)\n"
$(Q)$(PRINTF) "*** Validating $< ***\n"
$(Q)./$< && $(PRINTF) "\t$(PASS_COLOR)[ Verified ]$(NO_COLOR)\n"
check: $(addsuffix .done, $(TESTS))

clean:
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ $ make DISABLE_GPU=1 DISABLE_JNI=1

```$ make check ```

* Expected Result
* Expected Results

```
Trinary Test Passed!
*** build/test_trinary *** [ Verified ]
Curl Test Passed!
*** build/test_curl *** [ Verified ]
*** build/test_trinary ***
[ Verified ]
*** build/test_curl ***
[ Verified ]
Testing SSE Implementation with mwm = 14...
Result: KJQEILJFZJYJZBNBTYXNBSNCCMHZDYZXTCHXADBMNPKHFOHNLWJLIGTUHPFEKRZEQ9DZHBJIUJRO99999
Pow SSE Test Success
*** build/test_pow_sse *** [ Verified ]
*** build/test_pow_sse ***
[ Verified ]
Testing OpenCL Implementation with mwm = 14...
Result: KJQEILJFZJYJZBNBTYXNBSNCCMHZDYZXTCHXADBMNPKHFOHNLWJLIGTUHPFEKRZEQ9DZHBJIUJRO99999
Pow OpenCL Test Success
*** build/test_pow_cl *** [ Verified ]
*** build/test_pow_cl ***
[ Verified ]
```

# Tuning
Expand Down
21 changes: 21 additions & 0 deletions test/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef TEST_COMMON_H
#define TEST_COMMON_H

#include "../src/trinary/trinary.h"
#include "../src/hash/curl.h"

/* FIXME: conditional inclusion of architecture-specific headers */
#include "../src/pow_sse.h"

#if defined(BUILD_OPENCL)
#include "../src/pow_cl.h"
#endif

#include <stdlib.h>

#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>

#endif
13 changes: 3 additions & 10 deletions test/test_curl.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include "../src/hash/curl.h"
#include "../src/trinary/trinary.h"
#include "common.h"

int main()
{
Expand Down Expand Up @@ -58,11 +55,7 @@ int main()
freeTrobject(trytes);
freeTrobject(ret_trytes);

if (!ret) {
printf("Curl Test Failed!\n");
return -1;
}

printf("Curl Test Passed!\n");
assert(ret != 0);

return 0;
}
17 changes: 5 additions & 12 deletions test/test_pow_cl.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Test program for pow_sse & pow_cl */
#include <stdio.h>
#include "../src/pow_cl.h"
#include "../src/trinary/trinary.h"
/* Test program for pow_cl */
#include "common.h"

int main()
{
Expand Down Expand Up @@ -49,28 +47,23 @@ int main()
Trytes_t *trytes = initTrytes((signed char *) txt, 2673);
int mwm = 14;

printf("Testing OpenCL Implementation with mwm = %d...\n", mwm);
/* test OpenCL Implementation with mwm = 14 */
pwork_ctx_init(1);
Trytes_t *ret_trytes = PowCL(trytes, mwm, 0);
pwork_ctx_destroy(1);

Trytes_t *hash_trytes = hashTrytes(ret_trytes);
printf("Result: %s\n", hash_trytes->data);

/* Validation */
Trits_t *ret_trits = trits_from_trytes(hash_trytes);
for (int i = 243 - 1; i >= 243 - mwm; i--) {
if (ret_trits->data[i] != 0) {
printf("Pow OpenCL Test failed\n");
return -1;
}
assert(ret_trits->data[i] == 0);
}

freeTrobject(trytes);
freeTrobject(ret_trytes);
freeTrobject(hash_trytes);
freeTrobject(ret_trits);

printf("Pow OpenCL Test Success\n");
return 0;
}
}
15 changes: 4 additions & 11 deletions test/test_pow_sse.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Test program for pow_sse & pow_cl */
#include <stdio.h>
#include "../src/pow_sse.h"
#include "../src/trinary/trinary.h"
/* Test program for pow_sse */
#include "common.h"

int main()
{
Expand Down Expand Up @@ -49,28 +47,23 @@ int main()
Trytes_t *trytes = initTrytes((signed char *) txt, 2673);
int mwm = 14;

printf("Testing SSE Implementation with mwm = %d...\n", mwm);
/* test SSE Implementation with mwm = 14 */
pow_sse_init(1);
Trytes_t *ret_trytes = PowSSE(trytes, mwm, 0);
pow_sse_destroy();

Trytes_t *hash_trytes = hashTrytes(ret_trytes);
printf("Result: %s\n", hash_trytes->data);

/* Validation */
Trits_t *ret_trits = trits_from_trytes(hash_trytes);
for (int i = 243 - 1; i >= 243 - mwm; i--) {
if (ret_trits->data[i] != 0) {
printf("Pow SSE Test failed\n");
return -1;
}
assert(ret_trits->data[i] == 0);
}

freeTrobject(trytes);
freeTrobject(ret_trytes);
freeTrobject(hash_trytes);
freeTrobject(ret_trits);

printf("Pow SSE Test Success\n");
return 0;
}
10 changes: 2 additions & 8 deletions test/test_trinary.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <stdio.h>
#include <stdlib.h>
#include "../src/trinary/trinary.h"
#include "common.h"

int main()
{
Expand All @@ -20,11 +18,7 @@ int main()
freeTrobject(trits);
freeTrobject(ret_trytes);

if (!ret) {
printf("Trinary Test Failed!\n");
return -1;
}
assert(ret != 0);

printf("Trinary Test Passed!\n");
return 0;
}

0 comments on commit b815223

Please sign in to comment.