blob: c8f6eaa24b6a43cde0c808c9c1f7ec2c6d1680e5 [file] [log] [blame]
Ewout van Bekkumf0106062021-05-06 14:08:33 -07001// Copyright 2020 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#include <chrono>
16
17#include "gtest/gtest.h"
18#include "pw_sync/thread_notification.h"
19
20namespace pw::sync {
21namespace {
22
23TEST(ThreadNotification, EmptyInitialState) {
24 ThreadNotification notification;
25 EXPECT_FALSE(notification.try_acquire());
26}
27
28// TODO(pwbug/291): Add real concurrency tests.
29
30TEST(ThreadNotification, Release) {
31 ThreadNotification notification;
32 notification.release();
33 notification.release();
34 notification.acquire();
35 // Ensure it fails when empty.
36 EXPECT_FALSE(notification.try_acquire());
37}
38
39ThreadNotification empty_initial_notification;
40TEST(ThreadNotification, EmptyInitialStateStatic) {
41 EXPECT_FALSE(empty_initial_notification.try_acquire());
42}
43
44ThreadNotification raise_notification;
45TEST(ThreadNotification, ReleaseStatic) {
46 raise_notification.release();
47 raise_notification.release();
48 raise_notification.acquire();
49 // Ensure it fails when empty.
50 EXPECT_FALSE(raise_notification.try_acquire());
51}
52
53} // namespace
54} // namespace pw::sync