This is an automated email from the ASF dual-hosted git repository. vipulrahane pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push: new f3e4103 crypto_test: add a mutex to serialize prints new cf32a48 Merge pull request #2328 from nkaje/crypto_test_add_mutex_for_prints f3e4103 is described below commit f3e41033afdfc6258243e6c79aa979d2f2a4549a Author: Naveen Kaje <naveen.k...@juul.com> AuthorDate: Thu Jul 9 13:54:37 2020 -0500 crypto_test: add a mutex to serialize prints The concurrency test output is garbled and difficult to read when the lines don't get printed completely. Avoid this by using a mutex. Signed-off-by: Naveen Kaje <naveen.k...@juul.com> --- apps/crypto_test/src/main.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/crypto_test/src/main.c b/apps/crypto_test/src/main.c index bc8fcf5..81ba892 100755 --- a/apps/crypto_test/src/main.c +++ b/apps/crypto_test/src/main.c @@ -44,6 +44,8 @@ struct test_vectors { struct vector_data vectors[]; }; +static struct os_mutex mtx; + /* * Test vectors from "NIST Special Publication 800-38A" */ @@ -348,6 +350,24 @@ run_ctr_bench(struct crypto_dev *crypto, uint8_t iter) } #endif /* MYNEWT_VAL(CRYPTOTEST_BENCHMARK) */ +static void +lock(void) +{ + int rc; + + rc = os_mutex_pend(&mtx, OS_TIMEOUT_NEVER); + assert(rc == 0); +} + +static void +unlock(void) +{ + int rc; + + rc = os_mutex_release(&mtx); + assert(rc == 0); +} + #if MYNEWT_VAL(CRYPTOTEST_CONCURRENCY) static void concurrency_test_handler(void *arg) @@ -372,7 +392,9 @@ concurrency_test_handler(void *arg) os_time_delay(1); } + lock(); printf("%s [%d fails / %d ok] done\n", t->t_name, fail, ok); + unlock(); while (1) { os_time_delay(OS_TICKS_PER_SEC); @@ -671,12 +693,16 @@ main(void) int iterations; #endif int i; + int rc; sysinit(); crypto = (struct crypto_dev *) os_dev_open("crypto", OS_TIMEOUT_NEVER, NULL); assert(crypto); + rc = os_mutex_init(&mtx); + assert(rc == 0); + printf("=== Test vectors ===\n"); for (i = 0; all_tests[i] != NULL; i++) { run_test_vectors(crypto, all_tests[i]);