pico-sdk/test/pico_sem_test/pico_sem_test.c
Graham Sanderson 672e48e9e9
Add sem_try_acquire(). Fixes #846 (#856)
Co-authored-by: Geoff Simmons <geoff@uplex.de>
2022-06-08 13:23:36 -05:00

30 lines
606 B
C

/**
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include "pico/sem.h"
#include "pico/test.h"
#include "pico/stdio.h"
PICOTEST_MODULE_NAME("SEM", "semaphore test");
int main() {
semaphore_t sem;
stdio_init_all();
sem_init(&sem, 1, 1);
PICOTEST_START();
PICOTEST_START_SECTION("sem_try_acquire");
PICOTEST_CHECK(sem_try_acquire(&sem), "available permit not acquired");
PICOTEST_CHECK(!sem_try_acquire(&sem), "success with no permits");
PICOTEST_END_SECTION();
PICOTEST_END_TEST();
}