• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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 "gtest/gtest.h"
16 #include "pw_thread/id.h"
17 #include "pw_thread/yield.h"
18 
19 namespace pw::this_thread {
20 namespace {
21 
22 extern "C" {
23 
24 // Function defined in yield_facade_test_c.c which call the API from C.
25 void pw_this_thread_CallYield();
26 
27 }  // extern "C"
28 
TEST(Yield,CompilesAndRuns)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());
32 
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.
37   yield();
38 }
39 
TEST(Yield,CompilesAndRunsInC)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());
43 
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();
49 }
50 
51 }  // namespace
52 }  // namespace pw::this_thread
53