mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-09-15 22:59:56 +00:00
Single-threaded test of nominal mutex usage
No negative tests since all forbidden usage has undefined behavior. Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
Mutex usage: init, free
|
||||
mutex_usage_nominal:0
|
||||
|
||||
Mutex usage: lock 1
|
||||
mutex_usage_nominal:1
|
||||
|
||||
Mutex usage: lock 2
|
||||
mutex_usage_nominal:2
|
||||
@@ -0,0 +1,32 @@
|
||||
/* BEGIN_HEADER */
|
||||
/* Basic tests for the threading interface.
|
||||
*/
|
||||
|
||||
#include "mbedtls/threading.h"
|
||||
|
||||
#include "test/threading_helpers.h"
|
||||
|
||||
/* END_HEADER */
|
||||
|
||||
/* BEGIN_DEPENDENCIES
|
||||
* depends_on:MBEDTLS_THREADING_C
|
||||
* END_DEPENDENCIES
|
||||
*/
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mutex_usage_nominal(int lock_cycles)
|
||||
{
|
||||
mbedtls_threading_mutex_t mutex;
|
||||
|
||||
mbedtls_mutex_init(&mutex);
|
||||
|
||||
for (int i = 0; i < lock_cycles; i++) {
|
||||
mbedtls_test_set_step(i);
|
||||
TEST_EQUAL(mbedtls_mutex_lock(&mutex), 0);
|
||||
TEST_EQUAL(mbedtls_mutex_unlock(&mutex), 0);
|
||||
}
|
||||
|
||||
exit:
|
||||
mbedtls_mutex_free(&mutex);
|
||||
}
|
||||
/* END_CASE */
|
||||
Reference in New Issue
Block a user