1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
15 #include "gtest/gtest.h"
16 #include "pw_thread/id.h"
17 #include "pw_thread/yield.h"
19 namespace pw::this_thread {
24 // Function defined in yield_facade_test_c.c which call the API from C.
25 void pw_this_thread_CallYield();
29 TEST(Yield, CompilesAndRuns) {
30 // Ensure we are in a thread context, meaning we are permitted to sleep.
31 ASSERT_NE(get_id(), thread::Id());
33 // Unfortunately we have not thought of a useful way to test yield without
34 // knowing the backend implementation as things like round robin scheduling
35 // may be enabled meaning it may appear like yield is working when it isn't.
36 // For now we just ensure it compiles and we can execute it without a crash.
40 TEST(Yield, CompilesAndRunsInC) {
41 // Ensure we are in a thread context, meaning we are permitted to sleep.
42 ASSERT_NE(get_id(), thread::Id());
44 // Unfortunately we have not thought of a useful way to test yield without
45 // knowing the backend implementation as things like round robin scheduling
46 // may be enabled meaning it may appear like yield is working when it isn't.
47 // For now we just ensure it compiles and we can execute it without a crash.
48 pw_this_thread_CallYield();
52 } // namespace pw::this_thread