Skip to content

Commit 56c4dc1

Browse files
Single-threaded test of nominal mutex usage
No negative tests since all forbidden usage has undefined behavior. Signed-off-by: Gilles Peskine <[email protected]>
1 parent e0ef179 commit 56c4dc1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Mutex usage: init, free
2+
mutex_usage_nominal:0
3+
4+
Mutex usage: lock 1
5+
mutex_usage_nominal:1
6+
7+
Mutex usage: lock 2
8+
mutex_usage_nominal:2
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* BEGIN_HEADER */
2+
/* Basic tests for the threading interface.
3+
*/
4+
5+
#include "mbedtls/threading.h"
6+
7+
#include "test/threading_helpers.h"
8+
9+
/* END_HEADER */
10+
11+
/* BEGIN_DEPENDENCIES
12+
* depends_on:MBEDTLS_THREADING_C
13+
* END_DEPENDENCIES
14+
*/
15+
16+
/* BEGIN_CASE */
17+
void mutex_usage_nominal(int lock_cycles)
18+
{
19+
mbedtls_threading_mutex_t mutex;
20+
21+
mbedtls_mutex_init(&mutex);
22+
23+
for (int i = 0; i < lock_cycles; i++) {
24+
mbedtls_test_set_step(i);
25+
TEST_EQUAL(mbedtls_mutex_lock(&mutex), 0);
26+
TEST_EQUAL(mbedtls_mutex_unlock(&mutex), 0);
27+
}
28+
29+
exit:
30+
mbedtls_mutex_free(&mutex);
31+
}
32+
/* END_CASE */

0 commit comments

Comments
 (0)