RTXI  2.4
The Real-Time eXperiment Interface Documentation
system_tests.cpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  */
19 
20 #include <system_tests.h>
21 #include <gmock/gmock.h>
22 #include <rt.h>
23 #include <chrono>
24 #include <thread>
25 
26 TEST_F(SystemTest, getInstance)
27 {
28  system = RT::System::getInstance();
29  EXPECT_EQ(system, RT::System::getInstance());
30  EXPECT_EQ(system, system->getInstance());
31 }
32 
33 TEST_F(SystemTest, getPeriod)
34 {
35  // Check with default period
36  auto period = 1000000ll;
37  ASSERT_EQ(period, system->getPeriod());
38 }
39 
41 {
42  auto period = 1000000ll;
43  int retval = system->setPeriod(period);
44  ASSERT_EQ(retval, 0);
45  EXPECT_EQ(period, system->getPeriod());
46  period += period;
47  retval = system->setPeriod(period);
48  EXPECT_EQ(period, system->getPeriod());
49 }
50 
51 TEST_F(SystemTest, postEvent)
52 {
53  MockRTEvent event;
54  EXPECT_CALL(event, callback()).Times(::testing::AtLeast(1));
55  auto retval = system->postEvent(&event, true);
56  EXPECT_EQ(retval, 0);
57 }
58 
59 TEST_F(SystemTest, forEachDevice)
60 {
61  // foreachDevice function is unused by RT::System. This test
62  // however checks whether RT::System is looping through all
63  // devices. Useful for RT Thread testing.
64  using namespace std::chrono_literals;
65  MockRTDevice device;
66  device.setActive(true);
67  EXPECT_CALL(device, read()).Times(::testing::AtLeast(10));
68  EXPECT_CALL(device, write()).Times(::testing::AtLeast(10));
69  std::this_thread::sleep_for(1s);
70 }
71 
72 TEST_F(SystemTest, forEachThread)
73 {
74  // foreachThread function is unused by RT::System. This test
75  // however checks whether RT::System is looping through all
76  // threads. Useful for RT Thread testing.
77  using namespace std::chrono_literals;
78  MockRTThread thread;
79  thread.setActive(true);
80  EXPECT_CALL(thread, execute()).Times(::testing::AtLeast(10));
81  std::this_thread::sleep_for(1s);
82 }
system_tests.h
MockRTEvent
Definition: system_tests.h:40
RT::Thread::setActive
void setActive(bool)
Definition: rt.cpp:152
RT::System::getInstance
static System * getInstance(void)
Definition: rt.cpp:361
MockRTThread
Definition: system_tests.h:53
SystemTest
Definition: system_tests.h:29
RT::OS::setPeriod
int setPeriod(Task, long long)
Definition: rt_os-posix.cpp:152
MockRTDevice
Definition: system_tests.h:46
rt.h
TEST_F
TEST_F(SystemTest, getInstance)
Definition: system_tests.cpp:26
RT::Device::setActive
void setActive(bool)
Definition: rt.cpp:130