|
35 | 35 | #include "pqos.h" |
36 | 36 | #include "test.h" |
37 | 37 | #include "test_cap.h" |
| 38 | +#ifdef __linux__ |
| 39 | +#include <unistd.h> |
| 40 | +#endif |
38 | 41 |
|
39 | 42 | /* ======== helpers ======= */ |
40 | 43 |
|
@@ -110,6 +113,17 @@ __wrap_getenv(const char *name) |
110 | 113 | return mock_ptr_type(char *); |
111 | 114 | } |
112 | 115 |
|
| 116 | +#ifdef __linux__ |
| 117 | +int |
| 118 | +__wrap_access(const char *pathname, int mode) |
| 119 | +{ |
| 120 | + function_called(); |
| 121 | + check_expected_ptr(pathname); |
| 122 | + check_expected(mode); |
| 123 | + return mock_type(int); |
| 124 | +} |
| 125 | +#endif |
| 126 | + |
113 | 127 | static int log_init_result = LOG_RETVAL_OK; |
114 | 128 | int |
115 | 129 | __wrap_log_init(int fd_log __attribute__((unused)), |
@@ -534,18 +548,68 @@ test_discover_interface_auto_linux(void **state __attribute__((unused))) |
534 | 548 |
|
535 | 549 | disable_check_log_printf(); |
536 | 550 |
|
| 551 | + /* MMIO supported (both ERDT and MRRM present) -> select MMIO */ |
| 552 | + interface = -1; |
| 553 | + expect_function_call(__wrap_getenv); |
| 554 | + will_return(__wrap_getenv, NULL); |
| 555 | + expect_function_call(__wrap_access); |
| 556 | + expect_string(__wrap_access, pathname, |
| 557 | + "/sys/firmware/acpi/tables/ERDT"); |
| 558 | + expect_value(__wrap_access, mode, F_OK); |
| 559 | + will_return(__wrap_access, 0); |
| 560 | + expect_function_call(__wrap_access); |
| 561 | + expect_string(__wrap_access, pathname, |
| 562 | + "/sys/firmware/acpi/tables/MRRM"); |
| 563 | + expect_value(__wrap_access, mode, F_OK); |
| 564 | + will_return(__wrap_access, 0); |
| 565 | + ret = discover_interface(PQOS_INTER_AUTO, &interface); |
| 566 | + assert_int_equal(ret, PQOS_RETVAL_OK); |
| 567 | + assert_int_equal(interface, PQOS_INTER_MMIO); |
| 568 | + |
| 569 | + /* ERDT missing -> fall through to OS if resctrl supported */ |
| 570 | + interface = -1; |
| 571 | + expect_function_call(__wrap_getenv); |
| 572 | + will_return(__wrap_getenv, NULL); |
| 573 | + expect_function_call(__wrap_access); |
| 574 | + expect_string(__wrap_access, pathname, |
| 575 | + "/sys/firmware/acpi/tables/ERDT"); |
| 576 | + expect_value(__wrap_access, mode, F_OK); |
| 577 | + will_return(__wrap_access, -1); |
| 578 | + expect_function_call(__wrap_resctrl_is_supported); |
| 579 | + will_return(__wrap_resctrl_is_supported, PQOS_RETVAL_OK); |
| 580 | + ret = discover_interface(PQOS_INTER_AUTO, &interface); |
| 581 | + assert_int_equal(ret, PQOS_RETVAL_OK); |
| 582 | + assert_int_equal(interface, PQOS_INTER_OS); |
| 583 | + |
| 584 | + /* ERDT present but MRRM missing -> fall through to OS if resctrl */ |
537 | 585 | interface = -1; |
538 | 586 | expect_function_call(__wrap_getenv); |
539 | 587 | will_return(__wrap_getenv, NULL); |
| 588 | + expect_function_call(__wrap_access); |
| 589 | + expect_string(__wrap_access, pathname, |
| 590 | + "/sys/firmware/acpi/tables/ERDT"); |
| 591 | + expect_value(__wrap_access, mode, F_OK); |
| 592 | + will_return(__wrap_access, 0); |
| 593 | + expect_function_call(__wrap_access); |
| 594 | + expect_string(__wrap_access, pathname, |
| 595 | + "/sys/firmware/acpi/tables/MRRM"); |
| 596 | + expect_value(__wrap_access, mode, F_OK); |
| 597 | + will_return(__wrap_access, -1); |
540 | 598 | expect_function_call(__wrap_resctrl_is_supported); |
541 | 599 | will_return(__wrap_resctrl_is_supported, PQOS_RETVAL_OK); |
542 | 600 | ret = discover_interface(PQOS_INTER_AUTO, &interface); |
543 | 601 | assert_int_equal(ret, PQOS_RETVAL_OK); |
544 | 602 | assert_int_equal(interface, PQOS_INTER_OS); |
545 | 603 |
|
| 604 | + /* MMIO not supported, resctrl not supported -> select MSR */ |
546 | 605 | interface = -1; |
547 | 606 | expect_function_call(__wrap_getenv); |
548 | 607 | will_return(__wrap_getenv, NULL); |
| 608 | + expect_function_call(__wrap_access); |
| 609 | + expect_string(__wrap_access, pathname, |
| 610 | + "/sys/firmware/acpi/tables/ERDT"); |
| 611 | + expect_value(__wrap_access, mode, F_OK); |
| 612 | + will_return(__wrap_access, -1); |
549 | 613 | expect_function_call(__wrap_resctrl_is_supported); |
550 | 614 | will_return(__wrap_resctrl_is_supported, PQOS_RETVAL_ERROR); |
551 | 615 | ret = discover_interface(PQOS_INTER_AUTO, &interface); |
|
0 commit comments