test_ioctl_driver.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>
23 
24 #include <command_line_parser.h>
25 #include <file.h>
26 #include <ioctl.h>
27 #include <ioctl_driver.h>
28 #include <driver_entry_interface.h>
29 
31 
32 static auto operator"" _cve(const char *str, std::size_t len)
33 { (void)str; (void)len; return std::make_shared<bfn::corrupt_vmm_error>(); }
34 
35 static auto operator"" _use(const char *str, std::size_t len)
36 { (void)str; (void)len; return std::make_shared<bfn::unknown_status_error>(); }
37 
38 static auto operator"" _ivse(const char *str, std::size_t len)
39 { (void)str; (void)len; return std::make_shared<bfn::invalid_vmm_state_error>(""); }
40 
41 static auto operator"" _ife(const char *str, std::size_t len)
42 { (void)str; (void)len; return std::make_shared<bfn::ioctl_failed_error>(""); }
43 
44 static file *
45 setup_file(MockRepository &mocks)
46 {
47  auto fil = mocks.Mock<file>();
48 
49  mocks.OnCall(fil, file::read_text).Return(""_s);
50  mocks.OnCall(fil, file::read_binary).Return(file::binary_data());
51  mocks.OnCall(fil, file::write_text);
52  mocks.OnCall(fil, file::write_binary);
53 
54  return fil;
55 }
56 
57 static ioctl *
58 setup_ioctl(MockRepository &mocks, ioctl::status_type status)
59 {
60  auto ctl = mocks.Mock<ioctl>();
61 
62  g_status = status;
63 
64  mocks.OnCall(ctl, ioctl::open);
65  mocks.OnCall(ctl, ioctl::call_ioctl_add_module);
66  mocks.OnCall(ctl, ioctl::call_ioctl_load_vmm);
67  mocks.OnCall(ctl, ioctl::call_ioctl_unload_vmm);
68  mocks.OnCall(ctl, ioctl::call_ioctl_start_vmm);
69  mocks.OnCall(ctl, ioctl::call_ioctl_stop_vmm);
70  mocks.OnCall(ctl, ioctl::call_ioctl_dump_vmm);
71  mocks.OnCall(ctl, ioctl::call_ioctl_vmm_status);
72  mocks.OnCall(ctl, ioctl::call_ioctl_vmcall);
73 
74  mocks.OnCall(ctl, ioctl::call_ioctl_vmm_status).Do([&](gsl::not_null<ioctl::status_pointer> s)
75  { *s = g_status; });
76 
77  return ctl;
78 }
79 
80 static command_line_parser *
81 setup_command_line_parser(MockRepository &mocks, command_line_parser::command_type type)
82 {
83  auto clp = mocks.Mock<command_line_parser>();
84 
85  mocks.OnCall(clp, command_line_parser::cmd).Return(type);
86  mocks.OnCall(clp, command_line_parser::modules).Return(""_s);
87  mocks.OnCall(clp, command_line_parser::cpuid).Return(0);
88  mocks.OnCall(clp, command_line_parser::vcpuid).Return(0);
89  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type{});
90  mocks.OnCall(clp, command_line_parser::ifile).Return(""_s);
91  mocks.OnCall(clp, command_line_parser::ofile).Return(""_s);
92 
93  return clp;
94 }
95 
96 void
97 bfm_ut::test_ioctl_driver_process_invalid_file()
98 {
99  MockRepository mocks;
100 
101  auto &&fil = static_cast<file *>(nullptr);
102  auto &&ctl = mocks.Mock<ioctl>();
103  auto &&clp = mocks.Mock<command_line_parser>();
104 
105  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
106  {
107  this->expect_exception([&]{ ioctl_driver(fil, ctl, clp); }, ""_ut_ffe);
108  });
109 }
110 
111 void
112 bfm_ut::test_ioctl_driver_process_invalid_ioctl()
113 {
114  MockRepository mocks;
115 
116  auto &&fil = mocks.Mock<file>();
117  auto &&ctl = static_cast<ioctl *>(nullptr);
118  auto &&clp = mocks.Mock<command_line_parser>();
119 
120  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
121  {
122  this->expect_exception([&]{ ioctl_driver(fil, ctl, clp); }, ""_ut_ffe);
123  });
124 }
125 
126 void
127 bfm_ut::test_ioctl_driver_process_invalid_command_line_parser()
128 {
129  MockRepository mocks;
130 
131  auto &&fil = mocks.Mock<file>();
132  auto &&ctl = mocks.Mock<ioctl>();
133  auto &&clp = static_cast<command_line_parser *>(nullptr);
134 
135  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
136  {
137  this->expect_exception([&]{ ioctl_driver(fil, ctl, clp); }, ""_ut_ffe);
138  });
139 }
140 
141 void
142 bfm_ut::test_ioctl_driver_process_help()
143 {
144  MockRepository mocks;
145 
146  auto &&fil = setup_file(mocks);
147  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
148  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::help);
149 
150  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
151  {
152  auto &&driver = ioctl_driver(fil, ctl, clp);
153  this->expect_no_exception([&]{ driver.process(); });
154  });
155 }
156 
157 void
158 bfm_ut::test_ioctl_driver_process_load_vmm_running()
159 {
160  MockRepository mocks;
161 
162  auto &&fil = setup_file(mocks);
163  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
164  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
165 
166  mocks.OnCall(fil, file::read_text).Throw(std::runtime_error("error"));
167 
168  mocks.ExpectCall(ctl, ioctl::call_ioctl_stop_vmm);
169  mocks.ExpectCall(ctl, ioctl::call_ioctl_unload_vmm);
170 
171  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
172  {
173  auto &&driver = ioctl_driver(fil, ctl, clp);
174  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
175  });
176 }
177 
178 void
179 bfm_ut::test_ioctl_driver_process_load_vmm_loaded()
180 {
181  MockRepository mocks;
182 
183  auto &&fil = setup_file(mocks);
184  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
185  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
186 
187  mocks.OnCall(fil, file::read_text).Throw(std::runtime_error("error"));
188 
189  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
190  mocks.ExpectCall(ctl, ioctl::call_ioctl_unload_vmm);
191 
192  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
193  {
194  auto &&driver = ioctl_driver(fil, ctl, clp);
195  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
196  });
197 }
198 
199 void
200 bfm_ut::test_ioctl_driver_process_load_vmm_corrupt()
201 {
202  MockRepository mocks;
203 
204  auto &&fil = setup_file(mocks);
205  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
206  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
207 
208  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
209  {
210  auto &&driver = ioctl_driver(fil, ctl, clp);
211  this->expect_exception([&]{ driver.process(); }, ""_cve);
212  });
213 }
214 
215 void
216 bfm_ut::test_ioctl_driver_process_load_vmm_unknown_status()
217 {
218  MockRepository mocks;
219 
220  auto &&fil = setup_file(mocks);
221  auto &&ctl = setup_ioctl(mocks, -1);
222  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
223 
224  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
225  {
226  auto &&driver = ioctl_driver(fil, ctl, clp);
227  this->expect_exception([&]{ driver.process(); }, ""_use);
228  });
229 }
230 
231 void
232 bfm_ut::test_ioctl_driver_process_load_bad_modules_filename()
233 {
234  MockRepository mocks;
235 
236  auto &&fil = setup_file(mocks);
237  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
238  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
239 
240  mocks.OnCall(fil, file::read_text).Throw(std::runtime_error("error"));
241 
242  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
243  mocks.NeverCall(ctl, ioctl::call_ioctl_unload_vmm);
244 
245  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
246  {
247  auto &&driver = ioctl_driver(fil, ctl, clp);
248  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
249  });
250 }
251 
252 void
253 bfm_ut::test_ioctl_driver_process_load_bad_module_filename()
254 {
255  MockRepository mocks;
256 
257  auto &&fil = setup_file(mocks);
258  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
259  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
260 
261  mocks.OnCall(clp, command_line_parser::modules).Return("modules"_s);
262 
263  mocks.OnCall(fil, file::read_text).Do([](auto) -> auto
264  { return "{\"modules\":[\"1\",\"2\",\"3\"]}"_s; });
265 
266  mocks.OnCall(fil, file::read_binary).Throw(std::runtime_error("error"));
267 
268  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
269  {
270  auto &&driver = ioctl_driver(fil, ctl, clp);
271  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
272  });
273 }
274 
275 void
276 bfm_ut::test_ioctl_driver_process_load_add_module_failed()
277 {
278  MockRepository mocks;
279 
280  auto &&fil = setup_file(mocks);
281  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
282  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
283 
284  mocks.OnCall(clp, command_line_parser::modules).Return("modules"_s);
285 
286  mocks.OnCall(fil, file::read_text).Do([](auto) -> auto
287  { return "{\"modules\":[\"1\",\"2\",\"3\"]}"_s; });
288 
289  mocks.OnCall(fil, file::read_binary).Do([](auto) -> auto
290  {
291  return file::binary_data{'g', 'o', 'o', 'd'};
292  });
293 
294  mocks.OnCall(ctl, ioctl::call_ioctl_add_module).Throw(std::runtime_error("error"));
295 
296  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
297  {
298  auto &&driver = ioctl_driver(fil, ctl, clp);
299  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
300  });
301 }
302 
303 void
304 bfm_ut::test_ioctl_driver_process_load_load_failed()
305 {
306  MockRepository mocks;
307 
308  auto &&fil = setup_file(mocks);
309  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
310  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
311 
312  mocks.OnCall(clp, command_line_parser::modules).Return("modules"_s);
313 
314  mocks.OnCall(fil, file::read_text).Do([](auto) -> auto
315  { return "{\"modules\":[\"1\",\"2\",\"3\"]}"_s; });
316 
317  mocks.OnCall(fil, file::read_binary).Do([](auto) -> auto
318  { return file::binary_data{'g', 'o', 'o', 'd'}; });
319 
320  mocks.OnCall(ctl, ioctl::call_ioctl_load_vmm).Throw(std::runtime_error("error"));
321 
322  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
323  {
324  auto &&driver = ioctl_driver(fil, ctl, clp);
325  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
326  });
327 }
328 
329 void
330 bfm_ut::test_ioctl_driver_process_load_success()
331 {
332  MockRepository mocks;
333 
334  auto &&fil = setup_file(mocks);
335  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
336  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::load);
337 
338  mocks.OnCall(clp, command_line_parser::modules).Return("modules"_s);
339 
340  mocks.OnCall(fil, file::read_text).Do([](auto) -> auto
341  { return "{\"modules\":[\"1\",\"2\",\"3\"]}"_s; });
342 
343  mocks.OnCall(fil, file::read_binary).Do([](auto) -> auto
344  { return file::binary_data{'g', 'o', 'o', 'd'}; });
345 
346  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
347  {
348  auto &&driver = ioctl_driver(fil, ctl, clp);
349  this->expect_no_exception([&]{ driver.process(); });
350  });
351 }
352 
353 void
354 bfm_ut::test_ioctl_driver_process_unload_vmm_running()
355 {
356  MockRepository mocks;
357 
358  auto &&fil = setup_file(mocks);
359  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
360  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
361 
362  mocks.ExpectCall(ctl, ioctl::call_ioctl_stop_vmm);
363  mocks.ExpectCall(ctl, ioctl::call_ioctl_unload_vmm);
364 
365  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
366  {
367  auto &&driver = ioctl_driver(fil, ctl, clp);
368  this->expect_no_exception([&]{ driver.process(); });
369  });
370 }
371 
372 void
373 bfm_ut::test_ioctl_driver_process_unload_vmm_loaded()
374 {
375  MockRepository mocks;
376 
377  auto &&fil = setup_file(mocks);
378  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
379  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
380 
381  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
382  mocks.ExpectCall(ctl, ioctl::call_ioctl_unload_vmm);
383 
384  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
385  {
386  auto &&driver = ioctl_driver(fil, ctl, clp);
387  this->expect_no_exception([&]{ driver.process(); });
388  });
389 }
390 
391 void
392 bfm_ut::test_ioctl_driver_process_unload_vmm_unloaded()
393 {
394  MockRepository mocks;
395 
396  auto &&fil = setup_file(mocks);
397  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
398  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
399 
400  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
401  mocks.ExpectCall(ctl, ioctl::call_ioctl_unload_vmm);
402 
403  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
404  {
405  auto &&driver = ioctl_driver(fil, ctl, clp);
406  this->expect_no_exception([&]{ driver.process(); });
407  });
408 }
409 
410 void
411 bfm_ut::test_ioctl_driver_process_unload_vmm_corrupt()
412 {
413  MockRepository mocks;
414 
415  auto &&fil = setup_file(mocks);
416  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
417  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
418 
419  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
420  {
421  auto &&driver = ioctl_driver(fil, ctl, clp);
422  this->expect_exception([&]{ driver.process(); }, ""_cve);
423  });
424 }
425 
426 void
427 bfm_ut::test_ioctl_driver_process_unload_vmm_unknown_status()
428 {
429  MockRepository mocks;
430 
431  auto &&fil = setup_file(mocks);
432  auto &&ctl = setup_ioctl(mocks, -1);
433  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
434 
435  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
436  {
437  auto &&driver = ioctl_driver(fil, ctl, clp);
438  this->expect_exception([&]{ driver.process(); }, ""_use);
439  });
440 }
441 
442 void
443 bfm_ut::test_ioctl_driver_process_unload_unload_failed()
444 {
445  MockRepository mocks;
446 
447  auto &&fil = setup_file(mocks);
448  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
449  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
450 
451  mocks.OnCall(ctl, ioctl::call_ioctl_unload_vmm).Throw(std::runtime_error("error"));
452 
453  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
454  {
455  auto &&driver = ioctl_driver(fil, ctl, clp);
456  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
457  });
458 }
459 
460 void
461 bfm_ut::test_ioctl_driver_process_unload_success()
462 {
463  MockRepository mocks;
464 
465  auto &&fil = setup_file(mocks);
466  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
467  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::unload);
468 
469  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
470  {
471  auto &&driver = ioctl_driver(fil, ctl, clp);
472  this->expect_no_exception([&]{ driver.process(); });
473  });
474 }
475 
476 void
477 bfm_ut::test_ioctl_driver_process_start_vmm_running()
478 {
479  MockRepository mocks;
480 
481  auto &&fil = setup_file(mocks);
482  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
483  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
484 
485  mocks.ExpectCall(ctl, ioctl::call_ioctl_stop_vmm);
486  mocks.ExpectCall(ctl, ioctl::call_ioctl_start_vmm);
487 
488  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
489  {
490  auto &&driver = ioctl_driver(fil, ctl, clp);
491  this->expect_no_exception([&]{ driver.process(); });
492  });
493 }
494 
495 void
496 bfm_ut::test_ioctl_driver_process_start_vmm_loaded()
497 {
498  MockRepository mocks;
499 
500  auto &&fil = setup_file(mocks);
501  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
502  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
503 
504  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
505  mocks.ExpectCall(ctl, ioctl::call_ioctl_start_vmm);
506 
507  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
508  {
509  auto &&driver = ioctl_driver(fil, ctl, clp);
510  this->expect_no_exception([&]{ driver.process(); });
511  });
512 }
513 
514 void
515 bfm_ut::test_ioctl_driver_process_start_vmm_unloaded()
516 {
517  MockRepository mocks;
518 
519  auto &&fil = setup_file(mocks);
520  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
521  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
522 
523  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
524  mocks.NeverCall(ctl, ioctl::call_ioctl_start_vmm);
525 
526  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
527  {
528  auto &&driver = ioctl_driver(fil, ctl, clp);
529  this->expect_exception([&]{ driver.process(); }, ""_ivse);
530  });
531 }
532 
533 void
534 bfm_ut::test_ioctl_driver_process_start_vmm_corrupt()
535 {
536  MockRepository mocks;
537 
538  auto &&fil = setup_file(mocks);
539  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
540  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
541 
542  mocks.NeverCall(ctl, ioctl::call_ioctl_start_vmm);
543 
544  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
545  {
546  auto &&driver = ioctl_driver(fil, ctl, clp);
547  this->expect_exception([&]{ driver.process(); }, ""_cve);
548  });
549 }
550 
551 void
552 bfm_ut::test_ioctl_driver_process_start_vmm_unknown_status()
553 {
554  MockRepository mocks;
555 
556  auto &&fil = setup_file(mocks);
557  auto &&ctl = setup_ioctl(mocks, -1);
558  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
559 
560  mocks.NeverCall(ctl, ioctl::call_ioctl_start_vmm);
561 
562  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
563  {
564  auto &&driver = ioctl_driver(fil, ctl, clp);
565  this->expect_exception([&]{ driver.process(); }, ""_use);
566  });
567 }
568 
569 void
570 bfm_ut::test_ioctl_driver_process_start_start_failed()
571 {
572  MockRepository mocks;
573 
574  auto &&fil = setup_file(mocks);
575  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
576  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
577 
578  mocks.OnCall(ctl, ioctl::call_ioctl_start_vmm).Throw(std::runtime_error("error"));
579 
580  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
581  {
582  auto &&driver = ioctl_driver(fil, ctl, clp);
583  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
584  });
585 }
586 
587 void
588 bfm_ut::test_ioctl_driver_process_start_success()
589 {
590  MockRepository mocks;
591 
592  auto &&fil = setup_file(mocks);
593  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
594  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::start);
595 
596  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
597  {
598  auto &&driver = ioctl_driver(fil, ctl, clp);
599  this->expect_no_exception([&]{ driver.process(); });
600  });
601 }
602 
603 void
604 bfm_ut::test_ioctl_driver_process_stop_vmm_loaded()
605 {
606  MockRepository mocks;
607 
608  auto &&fil = setup_file(mocks);
609  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
610  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::stop);
611 
612  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
613 
614  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
615  {
616  auto &&driver = ioctl_driver(fil, ctl, clp);
617  this->expect_no_exception([&]{ driver.process(); });
618  });
619 }
620 
621 void
622 bfm_ut::test_ioctl_driver_process_stop_vmm_unloaded()
623 {
624  MockRepository mocks;
625 
626  auto &&fil = setup_file(mocks);
627  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
628  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::stop);
629 
630  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
631 
632  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
633  {
634  auto &&driver = ioctl_driver(fil, ctl, clp);
635  this->expect_no_exception([&]{ driver.process(); });
636  });
637 }
638 
639 void
640 bfm_ut::test_ioctl_driver_process_stop_vmm_corrupt()
641 {
642  MockRepository mocks;
643 
644  auto &&fil = setup_file(mocks);
645  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
646  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::stop);
647 
648  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
649 
650  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
651  {
652  auto &&driver = ioctl_driver(fil, ctl, clp);
653  this->expect_exception([&]{ driver.process(); }, ""_cve);
654  });
655 }
656 
657 void
658 bfm_ut::test_ioctl_driver_process_stop_vmm_unknown_status()
659 {
660  MockRepository mocks;
661 
662  auto &&fil = setup_file(mocks);
663  auto &&ctl = setup_ioctl(mocks, -1);
664  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::stop);
665 
666  mocks.NeverCall(ctl, ioctl::call_ioctl_stop_vmm);
667 
668  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
669  {
670  auto &&driver = ioctl_driver(fil, ctl, clp);
671  this->expect_exception([&]{ driver.process(); }, ""_use);
672  });
673 }
674 
675 void
676 bfm_ut::test_ioctl_driver_process_stop_stop_failed()
677 {
678  MockRepository mocks;
679 
680  auto &&fil = setup_file(mocks);
681  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
682  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::stop);
683 
684  mocks.OnCall(ctl, ioctl::call_ioctl_stop_vmm).Throw(std::runtime_error("error"));
685 
686  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
687  {
688  auto &&driver = ioctl_driver(fil, ctl, clp);
689  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
690  });
691 }
692 
693 void
694 bfm_ut::test_ioctl_driver_process_stop_success()
695 {
696  MockRepository mocks;
697 
698  auto &&fil = setup_file(mocks);
699  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
700  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::stop);
701 
702  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
703  {
704  auto &&driver = ioctl_driver(fil, ctl, clp);
705  this->expect_no_exception([&]{ driver.process(); });
706  });
707 }
708 
709 void
710 bfm_ut::test_ioctl_driver_process_dump_vmm_unloaded()
711 {
712  MockRepository mocks;
713 
714  auto &&fil = setup_file(mocks);
715  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
716  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::dump);
717 
718  mocks.NeverCall(ctl, ioctl::call_ioctl_dump_vmm);
719 
720  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
721  {
722  auto &&driver = ioctl_driver(fil, ctl, clp);
723  this->expect_exception([&]{ driver.process(); }, ""_ivse);
724  });
725 }
726 
727 void
728 bfm_ut::test_ioctl_driver_process_dump_vmm_corrupted()
729 {
730  MockRepository mocks;
731 
732  auto &&fil = setup_file(mocks);
733  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
734  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::dump);
735 
736  mocks.NeverCall(ctl, ioctl::call_ioctl_dump_vmm);
737 
738  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
739  {
740  auto &&driver = ioctl_driver(fil, ctl, clp);
741  this->expect_exception([&]{ driver.process(); }, ""_cve);
742  });
743 }
744 
745 void
746 bfm_ut::test_ioctl_driver_process_dump_vmm_unknown_status()
747 {
748  MockRepository mocks;
749 
750  auto &&fil = setup_file(mocks);
751  auto &&ctl = setup_ioctl(mocks, -1);
752  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::dump);
753 
754  mocks.NeverCall(ctl, ioctl::call_ioctl_dump_vmm);
755 
756  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
757  {
758  auto &&driver = ioctl_driver(fil, ctl, clp);
759  this->expect_exception([&]{ driver.process(); }, ""_use);
760  });
761 }
762 
763 void
764 bfm_ut::test_ioctl_driver_process_dump_dump_failed()
765 {
766  MockRepository mocks;
767 
768  auto &&fil = setup_file(mocks);
769  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
770  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::dump);
771 
772  mocks.OnCall(ctl, ioctl::call_ioctl_dump_vmm).Throw(std::runtime_error("error"));
773 
774  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
775  {
776  auto &&driver = ioctl_driver(fil, ctl, clp);
777  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
778  });
779 }
780 
781 void
782 bfm_ut::test_ioctl_driver_process_dump_success_running()
783 {
784  MockRepository mocks;
785 
786  auto &&fil = setup_file(mocks);
787  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
788  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::dump);
789 
790  mocks.OnCall(ctl, ioctl::call_ioctl_dump_vmm).Do([](gsl::not_null<ioctl::drr_pointer> drr, auto)
791  {
792  drr->spos = 0;
793  drr->epos = 3;
794  drr->buf[0] = 'h';
795  drr->buf[1] = 'i';
796  drr->buf[2] = '\n';
797  });
798 
799  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
800  {
801  auto &&driver = ioctl_driver(fil, ctl, clp);
802  this->expect_no_exception([&]{ driver.process(); });
803  });
804 }
805 
806 void
807 bfm_ut::test_ioctl_driver_process_dump_success_loaded()
808 {
809  MockRepository mocks;
810 
811  auto &&fil = setup_file(mocks);
812  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
813  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::dump);
814 
815  mocks.OnCall(ctl, ioctl::call_ioctl_dump_vmm).Do([](gsl::not_null<ioctl::drr_pointer> drr, auto)
816  {
817  drr->spos = 0;
818  drr->epos = 3;
819  drr->buf[0] = 'h';
820  drr->buf[1] = 'i';
821  drr->buf[2] = '\n';
822  });
823 
824  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
825  {
826  auto &&driver = ioctl_driver(fil, ctl, clp);
827  this->expect_no_exception([&]{ driver.process(); });
828  });
829 }
830 
831 void
832 bfm_ut::test_ioctl_driver_process_vmm_status_running()
833 {
834  MockRepository mocks;
835 
836  auto &&fil = setup_file(mocks);
837  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
838  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::status);
839 
840  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
841  {
842  auto &&driver = ioctl_driver(fil, ctl, clp);
843  this->expect_no_exception([&]{ driver.process(); });
844  });
845 }
846 
847 void
848 bfm_ut::test_ioctl_driver_process_vmm_status_loaded()
849 {
850  MockRepository mocks;
851 
852  auto &&fil = setup_file(mocks);
853  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
854  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::status);
855 
856  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
857  {
858  auto &&driver = ioctl_driver(fil, ctl, clp);
859  this->expect_no_exception([&]{ driver.process(); });
860  });
861 }
862 
863 void
864 bfm_ut::test_ioctl_driver_process_vmm_status_unloaded()
865 {
866  MockRepository mocks;
867 
868  auto &&fil = setup_file(mocks);
869  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
870  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::status);
871 
872  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
873  {
874  auto &&driver = ioctl_driver(fil, ctl, clp);
875  this->expect_no_exception([&]{ driver.process(); });
876  });
877 }
878 
879 void
880 bfm_ut::test_ioctl_driver_process_vmm_status_corrupt()
881 {
882  MockRepository mocks;
883 
884  auto &&fil = setup_file(mocks);
885  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
886  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::status);
887 
888  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
889  {
890  auto &&driver = ioctl_driver(fil, ctl, clp);
891  this->expect_no_exception([&]{ driver.process(); });
892  });
893 }
894 
895 void
896 bfm_ut::test_ioctl_driver_process_vmm_status_unknown_status()
897 {
898  MockRepository mocks;
899 
900  auto &&fil = setup_file(mocks);
901  auto &&ctl = setup_ioctl(mocks, -1);
902  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::status);
903 
904  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
905  {
906  auto &&driver = ioctl_driver(fil, ctl, clp);
907  this->expect_exception([&]{ driver.process(); }, ""_use);
908  });
909 }
910 
911 void
912 bfm_ut::test_ioctl_driver_process_vmcall_vmm_unloaded()
913 {
914  MockRepository mocks;
915 
916  auto &&fil = setup_file(mocks);
917  auto &&ctl = setup_ioctl(mocks, VMM_UNLOADED);
918  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
919 
920  mocks.NeverCall(ctl, ioctl::call_ioctl_vmcall);
921 
922  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
923  {
924  auto &&driver = ioctl_driver(fil, ctl, clp);
925  this->expect_exception([&]{ driver.process(); }, ""_ivse);
926  });
927 }
928 
929 void
930 bfm_ut::test_ioctl_driver_process_vmcall_vmm_loaded()
931 {
932  MockRepository mocks;
933 
934  auto &&fil = setup_file(mocks);
935  auto &&ctl = setup_ioctl(mocks, VMM_LOADED);
936  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
937 
938  mocks.NeverCall(ctl, ioctl::call_ioctl_vmcall);
939 
940  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
941  {
942  auto &&driver = ioctl_driver(fil, ctl, clp);
943  this->expect_exception([&]{ driver.process(); }, ""_ivse);
944  });
945 }
946 
947 void
948 bfm_ut::test_ioctl_driver_process_vmcall_vmm_corrupt()
949 {
950  MockRepository mocks;
951 
952  auto &&fil = setup_file(mocks);
953  auto &&ctl = setup_ioctl(mocks, VMM_CORRUPT);
954  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
955 
956  mocks.NeverCall(ctl, ioctl::call_ioctl_vmcall);
957 
958  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
959  {
960  auto &&driver = ioctl_driver(fil, ctl, clp);
961  this->expect_exception([&]{ driver.process(); }, ""_cve);
962  });
963 }
964 
965 void
966 bfm_ut::test_ioctl_driver_process_vmcall_vmm_unknown()
967 {
968  MockRepository mocks;
969 
970  auto &&fil = setup_file(mocks);
971  auto &&ctl = setup_ioctl(mocks, -1);
972  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
973 
974  mocks.NeverCall(ctl, ioctl::call_ioctl_vmcall);
975 
976  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
977  {
978  auto &&driver = ioctl_driver(fil, ctl, clp);
979  this->expect_exception([&]{ driver.process(); }, ""_use);
980  });
981 }
982 
983 void
984 bfm_ut::test_ioctl_driver_process_vmcall_unknown_vmcall()
985 {
986  MockRepository mocks;
987 
988  auto &&fil = setup_file(mocks);
989  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
990  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
991 
992  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
993  {
994  0xBAD,
995  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
996  });
997 
998  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
999  {
1000  auto &&driver = ioctl_driver(fil, ctl, clp);
1001  this->expect_exception([&]{ driver.process(); }, ""_ut_lee);
1002  });
1003 }
1004 
1005 void
1006 bfm_ut::test_ioctl_driver_process_vmcall_versions_ioctl_failed()
1007 {
1008  MockRepository mocks;
1009 
1010  auto &&fil = setup_file(mocks);
1011  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1012  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1013 
1014  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1015  {
1017  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1018  });
1019 
1020  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1021 
1022  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1023  {
1024  auto &&driver = ioctl_driver(fil, ctl, clp);
1025  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1026  });
1027 }
1028 
1029 void
1030 bfm_ut::test_ioctl_driver_process_vmcall_versions_ioctl_return_failed()
1031 {
1032  MockRepository mocks;
1033 
1034  auto &&fil = setup_file(mocks);
1035  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1036  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1037 
1038  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1039  {
1041  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1042  });
1043 
1044  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1045  {
1046  regs->r01 = 1;
1047  });
1048 
1049  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1050  {
1051  auto &&driver = ioctl_driver(fil, ctl, clp);
1052  this->expect_exception([&]{ driver.process(); }, ""_ife);
1053  });
1054 }
1055 
1056 void
1057 bfm_ut::test_ioctl_driver_process_vmcall_versions_protocol_version()
1058 {
1059  MockRepository mocks;
1060 
1061  auto &&fil = setup_file(mocks);
1062  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1063  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1064 
1065  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1066  {
1068  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1069  });
1070 
1071  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1072  {
1073  regs->r01 = 0;
1074  regs->r02 = 0;
1075  regs->r03 = 1;
1076  });
1077 
1078  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1079  {
1080  auto &&driver = ioctl_driver(fil, ctl, clp);
1081  this->expect_no_exception([&]{ driver.process(); });
1082  });
1083 }
1084 
1085 void
1086 bfm_ut::test_ioctl_driver_process_vmcall_versions_bareflank_version()
1087 {
1088  MockRepository mocks;
1089 
1090  auto &&fil = setup_file(mocks);
1091  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1092  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1093 
1094  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1095  {
1097  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1098  });
1099 
1100  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1101  {
1102  regs->r01 = 0;
1103  regs->r02 = 1;
1104  regs->r03 = 1;
1105  regs->r04 = 2;
1106  regs->r05 = 3;
1107  });
1108 
1109  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1110  {
1111  auto &&driver = ioctl_driver(fil, ctl, clp);
1112  this->expect_no_exception([&]{ driver.process(); });
1113  });
1114 }
1115 
1116 void
1117 bfm_ut::test_ioctl_driver_process_vmcall_versions_user_version()
1118 {
1119  MockRepository mocks;
1120 
1121  auto &&fil = setup_file(mocks);
1122  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1123  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1124 
1125  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1126  {
1128  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1129  });
1130 
1131  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1132  {
1133  regs->r01 = 0;
1134  regs->r02 = 10;
1135  regs->r03 = 1;
1136  regs->r04 = 2;
1137  regs->r05 = 3;
1138  });
1139 
1140  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1141  {
1142  auto &&driver = ioctl_driver(fil, ctl, clp);
1143  this->expect_no_exception([&]{ driver.process(); });
1144  });
1145 }
1146 
1147 void
1148 bfm_ut::test_ioctl_driver_process_vmcall_versions_unknown()
1149 {
1150  MockRepository mocks;
1151 
1152  auto &&fil = setup_file(mocks);
1153  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1154  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1155 
1156  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1157  {
1159  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1160  });
1161 
1162  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1163  {
1164  regs->r01 = 0;
1165  regs->r02 = 0x8000000000000000;
1166  regs->r03 = 1;
1167  regs->r04 = 2;
1168  regs->r05 = 3;
1169  });
1170 
1171  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1172  {
1173  auto &&driver = ioctl_driver(fil, ctl, clp);
1174  this->expect_no_exception([&]{ driver.process(); });
1175  });
1176 }
1177 
1178 void
1179 bfm_ut::test_ioctl_driver_process_vmcall_registers_ioctl_failed()
1180 {
1181  MockRepository mocks;
1182 
1183  auto &&fil = setup_file(mocks);
1184  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1185  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1186 
1187  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1188  {
1190  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1191  });
1192 
1193  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1194 
1195  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1196  {
1197  auto &&driver = ioctl_driver(fil, ctl, clp);
1198  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1199  });
1200 }
1201 
1202 void
1203 bfm_ut::test_ioctl_driver_process_vmcall_registers_ioctl_return_failed()
1204 {
1205  MockRepository mocks;
1206 
1207  auto &&fil = setup_file(mocks);
1208  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1209  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1210 
1211  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1212  {
1214  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1215  });
1216 
1217  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1218  {
1219  regs->r01 = 1;
1220  });
1221 
1222  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1223  {
1224  auto &&driver = ioctl_driver(fil, ctl, clp);
1225  this->expect_exception([&]{ driver.process(); }, ""_ife);
1226  });
1227 }
1228 
1229 void
1230 bfm_ut::test_ioctl_driver_process_vmcall_registers_success()
1231 {
1232  MockRepository mocks;
1233 
1234  auto &&fil = setup_file(mocks);
1235  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1236  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1237 
1238  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1239  {
1241  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1242  });
1243 
1244  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1245  {
1246  auto &&driver = ioctl_driver(fil, ctl, clp);
1247  this->expect_no_exception([&]{ driver.process(); });
1248  });
1249 }
1250 
1251 void
1252 bfm_ut::test_ioctl_driver_process_vmcall_unittest_ioctl_failed()
1253 {
1254  MockRepository mocks;
1255 
1256  auto &&fil = setup_file(mocks);
1257  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1258  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1259 
1260  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1261  {
1263  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1264  });
1265 
1266  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1267 
1268  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1269  {
1270  auto &&driver = ioctl_driver(fil, ctl, clp);
1271  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1272  });
1273 }
1274 
1275 void
1276 bfm_ut::test_ioctl_driver_process_vmcall_unittest_ioctl_return_failed()
1277 {
1278  MockRepository mocks;
1279 
1280  auto &&fil = setup_file(mocks);
1281  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1282  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1283 
1284  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1285  {
1287  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1288  });
1289 
1290  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1291  {
1292  regs->r01 = 1;
1293  });
1294 
1295  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1296  {
1297  auto &&driver = ioctl_driver(fil, ctl, clp);
1298  this->expect_exception([&]{ driver.process(); }, ""_ife);
1299  });
1300 }
1301 
1302 void
1303 bfm_ut::test_ioctl_driver_process_vmcall_unittest_success()
1304 {
1305  MockRepository mocks;
1306 
1307  auto &&fil = setup_file(mocks);
1308  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1309  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1310 
1311  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1312  {
1314  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1315  });
1316 
1317  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1318  {
1319  auto &&driver = ioctl_driver(fil, ctl, clp);
1320  this->expect_no_exception([&]{ driver.process(); });
1321  });
1322 }
1323 
1324 void
1325 bfm_ut::test_ioctl_driver_process_vmcall_event_ioctl_failed()
1326 {
1327  MockRepository mocks;
1328 
1329  auto &&fil = setup_file(mocks);
1330  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1331  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1332 
1333  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1334  {
1335  VMCALL_EVENT,
1336  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1337  });
1338 
1339  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1340 
1341  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1342  {
1343  auto &&driver = ioctl_driver(fil, ctl, clp);
1344  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1345  });
1346 }
1347 
1348 void
1349 bfm_ut::test_ioctl_driver_process_vmcall_event_ioctl_return_failed()
1350 {
1351  MockRepository mocks;
1352 
1353  auto &&fil = setup_file(mocks);
1354  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1355  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1356 
1357  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1358  {
1359  VMCALL_EVENT,
1360  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1361  });
1362 
1363  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1364  {
1365  regs->r01 = 1;
1366  });
1367 
1368  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1369  {
1370  auto &&driver = ioctl_driver(fil, ctl, clp);
1371  this->expect_exception([&]{ driver.process(); }, ""_ife);
1372  });
1373 }
1374 
1375 void
1376 bfm_ut::test_ioctl_driver_process_vmcall_event_success()
1377 {
1378  MockRepository mocks;
1379 
1380  auto &&fil = setup_file(mocks);
1381  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1382  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1383 
1384  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1385  {
1386  VMCALL_EVENT,
1387  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1388  });
1389 
1390  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1391  {
1392  auto &&driver = ioctl_driver(fil, ctl, clp);
1393  this->expect_no_exception([&]{ driver.process(); });
1394  });
1395 }
1396 
1397 
1398 
1399 
1400 
1401 
1402 
1403 
1404 
1405 
1406 
1407 
1408 
1409 
1410 void
1411 bfm_ut::test_ioctl_driver_process_vmcall_data_string_unformatted_unknown_data_type()
1412 {
1413  MockRepository mocks;
1414 
1415  auto &&fil = setup_file(mocks);
1416  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1417  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1418 
1419  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1420  {
1421  VMCALL_DATA,
1422  0, 0, 0,
1423  0xBAD,
1424  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1425  });
1426 
1427  mocks.NeverCall(ctl, ioctl::call_ioctl_vmcall);
1428 
1429  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1430  {
1431  auto &&driver = ioctl_driver(fil, ctl, clp);
1432  this->expect_exception([&]{ driver.process(); }, ""_ut_lee);
1433  });
1434 }
1435 
1436 void
1437 bfm_ut::test_ioctl_driver_process_vmcall_data_string_unformatted_ioctl_failed()
1438 {
1439  MockRepository mocks;
1440 
1441  auto &&fil = setup_file(mocks);
1442  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1443  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1444 
1445  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1446  {
1447  VMCALL_DATA,
1448  0, 0, 0,
1450  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1451  });
1452 
1453  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1454 
1455  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1456  {
1457  auto &&driver = ioctl_driver(fil, ctl, clp);
1458  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1459  });
1460 }
1461 
1462 void
1463 bfm_ut::test_ioctl_driver_process_vmcall_data_string_unformatted_ioctl_return_failed()
1464 {
1465  MockRepository mocks;
1466 
1467  auto &&fil = setup_file(mocks);
1468  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1469  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1470 
1471  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1472  {
1473  VMCALL_DATA,
1474  0, 0, 0,
1476  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1477  });
1478 
1479  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1480  {
1481  regs->r01 = 1;
1482  });
1483 
1484  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1485  {
1486  auto &&driver = ioctl_driver(fil, ctl, clp);
1487  this->expect_exception([&]{ driver.process(); }, ""_ife);
1488  });
1489 }
1490 
1491 void
1492 bfm_ut::test_ioctl_driver_process_vmcall_data_string_unformatted_out_of_range()
1493 {
1494  MockRepository mocks;
1495 
1496  auto &&fil = setup_file(mocks);
1497  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1498  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1499 
1500  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1501  {
1502  VMCALL_DATA,
1503  0, 0, 0,
1505  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1506  });
1507 
1508  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1509  {
1510  regs->r07 = VMCALL_DATA_STRING_UNFORMATTED;
1511  regs->r09 = VMCALL_OUT_BUFFER_SIZE + 1;
1512  });
1513 
1514  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1515  {
1516  auto &&driver = ioctl_driver(fil, ctl, clp);
1517  this->expect_exception([&]{ driver.process(); }, ""_ut_ore);
1518  });
1519 }
1520 
1521 void
1522 bfm_ut::test_ioctl_driver_process_vmcall_data_string_unformatted_success_no_return()
1523 {
1524  MockRepository mocks;
1525 
1526  auto &&fil = setup_file(mocks);
1527  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1528  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1529 
1530  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1531  {
1532  VMCALL_DATA,
1533  0, 0, 0,
1535  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1536  });
1537 
1538  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1539  {
1540  regs->r07 = VMCALL_DATA_NONE;
1541  });
1542 
1543  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1544  {
1545  auto &&driver = ioctl_driver(fil, ctl, clp);
1546  this->expect_no_exception([&]{ driver.process(); });
1547  });
1548 }
1549 
1550 void
1551 bfm_ut::test_ioctl_driver_process_vmcall_data_string_unformatted_success_unformatted()
1552 {
1553  MockRepository mocks;
1554 
1555  auto &&fil = setup_file(mocks);
1556  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1557  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1558 
1559  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1560  {
1561  VMCALL_DATA,
1562  0, 0, 0,
1564  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1565  });
1566 
1567  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1568  {
1569  regs->r07 = VMCALL_DATA_STRING_UNFORMATTED;
1570  regs->r09 = 10;
1571  });
1572 
1573  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1574  {
1575  auto &&driver = ioctl_driver(fil, ctl, clp);
1576  this->expect_no_exception([&]{ driver.process(); });
1577  });
1578 }
1579 
1580 void
1581 bfm_ut::test_ioctl_driver_process_vmcall_data_string_json_ioctl_failed()
1582 {
1583  MockRepository mocks;
1584 
1585  auto &&fil = setup_file(mocks);
1586  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1587  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1588 
1589  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1590  {
1591  VMCALL_DATA,
1592  0, 0, 0,
1594  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1595  });
1596 
1597  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1598 
1599  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1600  {
1601  auto &&driver = ioctl_driver(fil, ctl, clp);
1602  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1603  });
1604 }
1605 
1606 void
1607 bfm_ut::test_ioctl_driver_process_vmcall_data_string_json_ioctl_return_failed()
1608 {
1609  MockRepository mocks;
1610 
1611  auto &&fil = setup_file(mocks);
1612  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1613  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1614 
1615  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1616  {
1617  VMCALL_DATA,
1618  0, 0, 0,
1620  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1621  });
1622 
1623  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1624  {
1625  regs->r01 = 1;
1626  });
1627 
1628  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1629  {
1630  auto &&driver = ioctl_driver(fil, ctl, clp);
1631  this->expect_exception([&]{ driver.process(); }, ""_ife);
1632  });
1633 }
1634 
1635 void
1636 bfm_ut::test_ioctl_driver_process_vmcall_data_string_json_out_of_range()
1637 {
1638  MockRepository mocks;
1639 
1640  auto &&fil = setup_file(mocks);
1641  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1642  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1643 
1644  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1645  {
1646  VMCALL_DATA,
1647  0, 0, 0,
1649  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1650  });
1651 
1652  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1653  {
1654  regs->r07 = VMCALL_DATA_STRING_JSON;
1655  regs->r09 = VMCALL_OUT_BUFFER_SIZE + 1;
1656  });
1657 
1658  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1659  {
1660  auto &&driver = ioctl_driver(fil, ctl, clp);
1661  this->expect_exception([&]{ driver.process(); }, ""_ut_ore);
1662  });
1663 }
1664 
1665 void
1666 bfm_ut::test_ioctl_driver_process_vmcall_data_string_json_success_no_return()
1667 {
1668  MockRepository mocks;
1669 
1670  auto &&fil = setup_file(mocks);
1671  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1672  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1673 
1674  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1675  {
1676  VMCALL_DATA,
1677  0, 0, 0,
1679  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1680  });
1681 
1682  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1683  {
1684  regs->r07 = VMCALL_DATA_NONE;
1685  });
1686 
1687  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1688  {
1689  auto &&driver = ioctl_driver(fil, ctl, clp);
1690  this->expect_no_exception([&]{ driver.process(); });
1691  });
1692 }
1693 
1694 void
1695 bfm_ut::test_ioctl_driver_process_vmcall_data_string_json_parse_failure()
1696 {
1697  MockRepository mocks;
1698 
1699  auto &&fil = setup_file(mocks);
1700  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1701  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1702 
1703  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1704  {
1705  VMCALL_DATA,
1706  0, 0, 0,
1708  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1709  });
1710 
1711  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1712  {
1713  auto &&output = "hello world"_s;
1714  __builtin_memcpy(reinterpret_cast<char *>(regs->r08), output.c_str(), output.size());
1715 
1716  regs->r07 = VMCALL_DATA_STRING_JSON;
1717  regs->r09 = output.size();
1718  });
1719 
1720  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1721  {
1722  auto &&driver = ioctl_driver(fil, ctl, clp);
1723  this->expect_exception([&]{ driver.process(); }, ""_ut_iae);
1724  });
1725 }
1726 
1727 void
1728 bfm_ut::test_ioctl_driver_process_vmcall_data_string_json_success_json()
1729 {
1730  MockRepository mocks;
1731 
1732  auto &&fil = setup_file(mocks);
1733  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1734  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1735 
1736  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1737  {
1738  VMCALL_DATA,
1739  0, 0, 0,
1741  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1742  });
1743 
1744  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1745  {
1746  auto &&output = "{\"msg\":\"hello world\"}"_s;
1747  __builtin_memcpy(reinterpret_cast<char *>(regs->r08), output.c_str(), output.size());
1748 
1749  regs->r07 = VMCALL_DATA_STRING_JSON;
1750  regs->r09 = output.size();
1751  });
1752 
1753  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1754  {
1755  auto &&driver = ioctl_driver(fil, ctl, clp);
1756  this->expect_no_exception([&]{ driver.process(); });
1757  });
1758 }
1759 
1760 void
1761 bfm_ut::test_ioctl_driver_process_vmcall_data_binary_unformatted_ifile_failed()
1762 {
1763  MockRepository mocks;
1764 
1765  auto &&fil = setup_file(mocks);
1766  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1767  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1768 
1769  mocks.OnCall(clp, file::read_binary).Throw(std::runtime_error("error"));
1770 
1771  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1772  {
1773  VMCALL_DATA,
1774  0, 0, 0,
1776  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1777  });
1778 
1779  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1780  {
1781  auto &&driver = ioctl_driver(fil, ctl, clp);
1782  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1783  });
1784 }
1785 
1786 void
1787 bfm_ut::test_ioctl_driver_process_vmcall_data_binary_unformatted_ioctl_failed()
1788 {
1789  MockRepository mocks;
1790 
1791  auto &&fil = setup_file(mocks);
1792  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1793  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1794 
1795  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1796  {
1797  VMCALL_DATA,
1798  0, 0, 0,
1800  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1801  });
1802 
1803  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Throw(std::runtime_error("error"));
1804 
1805  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1806  {
1807  auto &&driver = ioctl_driver(fil, ctl, clp);
1808  this->expect_exception([&]{ driver.process(); }, ""_ut_ree);
1809  });
1810 }
1811 
1812 void
1813 bfm_ut::test_ioctl_driver_process_vmcall_data_binary_unformatted_ioctl_return_failed()
1814 {
1815  MockRepository mocks;
1816 
1817  auto &&fil = setup_file(mocks);
1818  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1819  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1820 
1821  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1822  {
1823  VMCALL_DATA,
1824  0, 0, 0,
1826  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1827  });
1828 
1829  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1830  {
1831  regs->r01 = 1;
1832  });
1833 
1834  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1835  {
1836  auto &&driver = ioctl_driver(fil, ctl, clp);
1837  this->expect_exception([&]{ driver.process(); }, ""_ife);
1838  });
1839 }
1840 
1841 void
1842 bfm_ut::test_ioctl_driver_process_vmcall_data_binary_unformatted_out_of_range()
1843 {
1844  MockRepository mocks;
1845 
1846  auto &&fil = setup_file(mocks);
1847  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1848  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1849 
1850  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1851  {
1852  VMCALL_DATA,
1853  0, 0, 0,
1855  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1856  });
1857 
1858  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1859  {
1860  regs->r07 = VMCALL_DATA_BINARY_UNFORMATTED;
1861  regs->r09 = VMCALL_OUT_BUFFER_SIZE + 1;
1862  });
1863 
1864  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1865  {
1866  auto &&driver = ioctl_driver(fil, ctl, clp);
1867  this->expect_exception([&]{ driver.process(); }, ""_ut_ore);
1868  });
1869 }
1870 
1871 void
1872 bfm_ut::test_ioctl_driver_process_vmcall_data_binary_unformatted_success_no_return()
1873 {
1874  MockRepository mocks;
1875 
1876  auto &&fil = setup_file(mocks);
1877  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1878  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1879 
1880  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1881  {
1882  VMCALL_DATA,
1883  0, 0, 0,
1885  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1886  });
1887 
1888  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1889  {
1890  regs->r07 = VMCALL_DATA_NONE;
1891  });
1892 
1893  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1894  {
1895  auto &&driver = ioctl_driver(fil, ctl, clp);
1896  this->expect_no_exception([&]{ driver.process(); });
1897  });
1898 }
1899 
1900 void
1901 bfm_ut::test_ioctl_driver_process_vmcall_data_binary_unformatted_success_unformatted()
1902 {
1903  MockRepository mocks;
1904 
1905  auto &&fil = setup_file(mocks);
1906  auto &&ctl = setup_ioctl(mocks, VMM_RUNNING);
1907  auto &&clp = setup_command_line_parser(mocks, command_line_parser::command_type::vmcall);
1908 
1909  mocks.OnCall(clp, command_line_parser::registers).Return(ioctl::registers_type
1910  {
1911  VMCALL_DATA,
1912  0, 0, 0,
1914  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1915  });
1916 
1917  mocks.ExpectCall(ctl, ioctl::call_ioctl_vmcall).Do([](gsl::not_null<ioctl::registers_pointer> regs, auto)
1918  {
1919  regs->r07 = VMCALL_DATA_BINARY_UNFORMATTED;
1920  regs->r09 = 10;
1921  });
1922 
1923  RUN_UNITTEST_WITH_MOCKS(mocks, [&]
1924  {
1925  auto &&driver = ioctl_driver(fil, ctl, clp);
1926  this->expect_no_exception([&]{ driver.process(); });
1927  });
1928 }
#define expect_exception(f, e)
Definition: unittest.h:162
#define VMM_LOADED
Definition: file.h:35
#define RUN_UNITTEST_WITH_MOCKS(a, b)
Definition: unittest.h:229
virtual void call_ioctl_vmm_status(gsl::not_null< status_pointer > status)
Definition: ioctl.cpp:82
virtual const filename_type & ifile() const noexcept
#define expect_no_exception(f)
Definition: unittest.h:198
virtual void call_ioctl_start_vmm()
Definition: ioctl.cpp:61
virtual cpuid_type cpuid() const noexcept
#define VMCALL_OUT_BUFFER_SIZE
Definition: constants.h:272
void help()
Definition: main.cpp:70
virtual void write_binary(const filename_type &filename, const binary_data &data) const
Definition: file.cpp:69
debug_ring_resources_t * drr
virtual void call_ioctl_stop_vmm()
Definition: ioctl.cpp:68
int64_t status_type
Definition: ioctl.h:57
virtual void call_ioctl_unload_vmm()
Definition: ioctl.cpp:54
virtual command_type cmd() const noexcept
#define VMM_UNLOADED
ioctl::status_type g_status
virtual void call_ioctl_dump_vmm(gsl::not_null< drr_pointer > drr, vcpuid_type vcpuid)
Definition: ioctl.cpp:75
virtual void call_ioctl_load_vmm()
Definition: ioctl.cpp:47
virtual text_data read_text(const filename_type &filename) const
Definition: file.cpp:30
virtual void open()
Definition: ioctl.cpp:30
virtual void write_text(const filename_type &filename, const text_data &data) const
Definition: file.cpp:54
virtual binary_data read_binary(const filename_type &filename) const
Definition: file.cpp:42
#define VMM_RUNNING
virtual const filename_type & ofile() const noexcept
virtual const registers_type & registers() const noexcept
#define VMM_CORRUPT
Definition: ioctl.h:48
std::vector< char > binary_data
Definition: file.h:40
virtual void call_ioctl_vmcall(gsl::not_null< registers_pointer > regs, cpuid_type cpuid)
Definition: ioctl.cpp:89
virtual vcpuid_type vcpuid() const noexcept
virtual const filename_type & modules() const noexcept
virtual void call_ioctl_add_module(const binary_data &module_data)
Definition: ioctl.cpp:37