test_exit_handler_intel_x64_entry.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <test.h>
26 
27 void
28 exit_handler_intel_x64_ut::test_entry_valid()
29 {
30  MockRepository mocks;
31  auto &&eh = mocks.Mock<exit_handler_intel_x64>();
32 
33  mocks.OnCall(eh, exit_handler_intel_x64::halt);
34  mocks.OnCall(eh, exit_handler_intel_x64::dispatch);
35 
36  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
37  {
38  this->expect_no_exception([&]{ exit_handler(eh); });
39  });
40 }
41 
42 void
43 exit_handler_intel_x64_ut::test_entry_throws_general_exception()
44 {
45  MockRepository mocks;
46  auto &&eh = mocks.Mock<exit_handler_intel_x64>();
47 
48  mocks.ExpectCall(eh, exit_handler_intel_x64::halt);
50 
51  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
52  {
53  this->expect_no_exception([&]{ exit_handler(eh); });
54  });
55 }
56 
57 void
58 exit_handler_intel_x64_ut::test_entry_throws_standard_exception()
59 {
60  MockRepository mocks;
61  auto &&eh = mocks.Mock<exit_handler_intel_x64>();
62 
63  mocks.ExpectCall(eh, exit_handler_intel_x64::halt);
64  mocks.OnCall(eh, exit_handler_intel_x64::dispatch).Throw(std::exception());
65 
66  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
67  {
68  this->expect_no_exception([&]{ exit_handler(eh); });
69  });
70 }
71 
72 void
73 exit_handler_intel_x64_ut::test_entry_throws_any_exception()
74 {
75  MockRepository mocks;
76  auto &&eh = mocks.Mock<exit_handler_intel_x64>();
77 
78  mocks.ExpectCall(eh, exit_handler_intel_x64::halt);
79  mocks.OnCall(eh, exit_handler_intel_x64::dispatch).Throw(10);
80 
81  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
82  {
83  this->expect_no_exception([&]{ exit_handler(eh); });
84  });
85 }
#define RUN_UNITTEST_WITH_MOCKS(a, b)
Definition: unittest.h:229
#define expect_no_exception(f)
Definition: unittest.h:198
void exit_handler(exit_handler_intel_x64 *exit_handler) noexcept
virtual void halt() noexcept