[iwlwifi] Enable all driver tests
This enabled all unit tests, except:
- fw_test
- mvm_test
- pcie_test
- rcu_manager_test
- task_test
Most of these are blocked due to dependency on libraries such as
fake-pci, fake-bti and async-testing, which are not available via the
sdk.
Change-Id: Id8007111f6b7921753b14ca5b34a8b2727abe8b8
Reviewed-on: https://fuchsia-review.googlesource.com/c/drivers/wlan/intel/iwlwifi/+/650525
Fuchsia-Auto-Submit: Sakthi Vignesh Radhakrishnan <rsakthi@google.com>
Reviewed-by: Renato Mangini Dias <mangini@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
diff --git a/README.md b/README.md
index d699b28..43c7169 100644
--- a/README.md
+++ b/README.md
@@ -127,6 +127,7 @@
3. Execute the tests
+ Example,
```
tools/ffx test run fuchsia-pkg://fuchsiadrivers.com/test_hello_pkg#meta/driver_inspector_test.cm
```
diff --git a/third_party/iwlwifi/iwl-drv.c b/third_party/iwlwifi/iwl-drv.c
index 32b13ad..2dcdbc1 100644
--- a/third_party/iwlwifi/iwl-drv.c
+++ b/third_party/iwlwifi/iwl-drv.c
@@ -1934,7 +1934,7 @@
size_t i;
mtx_init(&iwlwifi_opmode_table_mtx, mtx_plain);
-
+
for (i = 0; i < ARRAY_SIZE(iwlwifi_opmode_table); i++) {
list_initialize(&iwlwifi_opmode_table[i].drv);
}
diff --git a/third_party/iwlwifi/iwl-trans.h b/third_party/iwlwifi/iwl-trans.h
index fb33e0e..ebb093c 100644
--- a/third_party/iwlwifi/iwl-trans.h
+++ b/third_party/iwlwifi/iwl-trans.h
@@ -36,10 +36,6 @@
#ifndef SRC_CONNECTIVITY_WLAN_DRIVERS_THIRD_PARTY_INTEL_IWLWIFI_IWL_TRANS_H_
#define SRC_CONNECTIVITY_WLAN_DRIVERS_THIRD_PARTY_INTEL_IWLWIFI_IWL_TRANS_H_
-// ToDo(rsakthi): war sinde defines isnt working in bazel.
-#define CPTCFG_IWLMVM 1
-#define CPTCFG_IWL_TIMEOUT_FACTOR 1
-
#include "third_party/iwlwifi/fw/img.h"
#include "third_party/iwlwifi/iwl-config.h"
#include "third_party/iwlwifi/iwl-debug.h"
diff --git a/third_party/iwlwifi/platform/BUILD.bazel b/third_party/iwlwifi/platform/BUILD.bazel
index ee5152a..7db8690 100644
--- a/third_party/iwlwifi/platform/BUILD.bazel
+++ b/third_party/iwlwifi/platform/BUILD.bazel
@@ -91,6 +91,11 @@
"@fuchsia_sdk//fidl/fuchsia.wlan.mlme:fuchsia.wlan.mlme_cc",
"@fuchsia_sdk//fidl/fuchsia.hardware.wlan.associnfo:fuchsia.hardware.wlan.associnfo_banjo_cc",
],
+
+ defines = [
+ "CPTCFG_IWL_TIMEOUT_FACTOR=1",
+ "CPTCFG_IWLMVM=1",
+ ],
)
# Support for RCU synchronization.
@@ -143,10 +148,4 @@
],
copts = ["-Ithird_party/iwlwifi"],
-
- # This doesn't seem to be taking effect.
- defines = [
- "CPTCFG_IWL_TIMEOUT_FACTOR=1",
- "CPTCFG_IWLMVM=1",
- ],
)
diff --git a/third_party/iwlwifi/test/BUILD.bazel b/third_party/iwlwifi/test/BUILD.bazel
index b91f7cb..1bb4661 100644
--- a/third_party/iwlwifi/test/BUILD.bazel
+++ b/third_party/iwlwifi/test/BUILD.bazel
@@ -53,6 +53,7 @@
],
deps = [
+ ":mock-ddk",
"//third_party/iwlwifi:core",
"//third_party/iwlwifi/fw:api",
"//third_party/iwlwifi/mvm",
@@ -76,11 +77,54 @@
)
cc_library(
- name = "stub_mvm",
- srcs = ["stub-mvm.cc"],
+ name = "no_ddk",
+ srcs = [ "no_ddk.cc" ],
+ deps = [
+ "@fuchsia_sdk//pkg/fdio",
+ "@fuchsia_sdk//pkg/ddk",
+ ]
)
-# Test for the driver inspector.
+cc_library(
+ name = "mock-ddk",
+ srcs = [
+ "libdriver-api.cc",
+ "mock-device.cc",
+ ],
+ hdrs = [ "mock-device.h", ],
+ deps = [
+ "@fuchsia_sdk//pkg/fdio",
+ "@fuchsia_sdk//pkg/ddk",
+ "@fuchsia_sdk//pkg/async",
+ "@fuchsia_sdk//pkg/sync",
+ ],
+)
+
+cc_library(
+ name = "mock_function",
+ hdrs = [ "mock-function.h", ],
+ deps = [ "@com_google_googletest//:gtest_main", ],
+)
+
+cc_library(
+ name = "stub_mvm",
+ srcs = [ "stub-mvm.cc" ],
+ hdrs = [ "test.h" ],
+)
+
+# Dummy code for developer to start a new test.
+cc_test(
+ name = "dummy_test",
+ size = "small",
+ srcs = [ "dummy-test.cc" ],
+ deps = [
+ ":sim_library",
+ ":no_ddk",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "dummy_test" ]
+
cc_test(
name = "driver_inspector_test",
size = "small",
@@ -92,19 +136,250 @@
"//third_party/iwlwifi/platform:driver_inspector",
],
)
-_tests += [ "driver_inspector_test", ]
+_tests += [ "driver_inspector_test" ]
-# Dummy code for developer to start a new test.
cc_test(
- name = "dummy_test",
+ name = "fw_test",
size = "small",
- srcs = [ "dummy-test.cc" ],
+ srcs = [ "fw-test.cc" ],
deps = [
":sim_library",
"@com_google_googletest//:gtest_main",
+ "//third_party/iwlwifi:core",
+ "//third_party/iwlwifi/mvm",
],
)
-_tests += [ "dummy_test", ]
+_tests += [ "fw_test" ]
+
+cc_test(
+ name = "fw_dbg_test",
+ size = "small",
+ srcs = [ "fw-dbg-test.cc" ],
+ deps = [
+ ":sim_library",
+ "//third_party/iwlwifi/fw",
+ "//third_party/iwlwifi/platform:driver_inspector",
+ "@fuchsia_sdk//pkg/inspect",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "fw_dbg_test" ]
+
+cc_test(
+ name = "iwl_phy_db_test",
+ size = "small",
+ srcs = [ "iwl-phy-db-test.cc" ],
+ deps = [
+ ":stub_mvm",
+ ":no_ddk",
+ "//third_party/iwlwifi:core",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "iwl_phy_db_test" ]
+
+cc_test(
+ name = "mac80211_test",
+ size = "small",
+ srcs = [ "mac80211-test.cc" ],
+ deps = [
+ ":sim_library",
+ ":mock_function",
+ "@com_google_googletest//:gtest_main",
+ "//third_party/iwlwifi/mvm",
+ ],
+)
+_tests += [ "mac80211_test" ]
+
+cc_test(
+ name = "mac_ctxt_test",
+ size = "small",
+ srcs = [ "mac-ctxt-test.cc" ],
+ deps = [
+ ":sim_library",
+ "//third_party/iwlwifi/mvm",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "mac_ctxt_test" ]
+
+cc_test(
+ name = "mvm_test",
+ size = "small",
+ srcs = [ "mvm-test.cc" ],
+ deps = [
+ ":sim_library",
+ ":mock_function",
+ "//third_party/iwlwifi/mvm",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "mvm_test" ]
+
+cc_test(
+ name = "notif_wait_test",
+ size = "small",
+ srcs = [ "notif-wait-test.cc" ],
+ deps = [
+ ":stub_mvm",
+ ":no_ddk",
+ "//third_party/iwlwifi/fw",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "notif_wait_test" ]
+
+cc_test(
+ name = "nvm_test",
+ size = "small",
+ srcs = [ "nvm-test.cc" ],
+ deps = [
+ ":sim_library",
+ "//third_party/iwlwifi:core",
+ "//third_party/iwlwifi/mvm",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "nvm_test" ]
+
+cc_test(
+ name = "pcie_test",
+ size = "small",
+ srcs = [ "pcie-test.cc" ],
+ deps = [
+ ":sim_library",
+ ":mock-ddk",
+ ":mock_function",
+ "//third_party/iwlwifi:core",
+ "//third_party/iwlwifi/fw:api",
+ "//third_party/iwlwifi/pcie",
+ "//third_party/iwlwifi/platform:fuchsia_device",
+ "@fuchsia_sdk//pkg/async-loop-cpp",
+ "@fuchsia_sdk//pkg/async-loop-default",
+ "@fuchsia_sdk//pkg/sync",
+ "@com_google_googletest//:gtest_main",
+
+ #"//src/devices/pci/testing:pci-protocol-fake",
+ #"//src/devices/testing/fake-bti",
+ ],
+)
+_tests += [ "pcie_test" ]
+
+cc_test(
+ name = "phy_ctxt_test",
+ size = "small",
+ srcs = [ "phy-ctxt-test.cc" ],
+ deps = [
+ ":sim_library",
+ "//third_party/iwlwifi/mvm",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "phy_ctxt_test" ]
+
+cc_test(
+ name = "platform_test",
+ size = "small",
+ srcs = [ "platform-test.cc" ],
+ deps = [
+ ":stub_mvm",
+ ":no_ddk",
+ "//third_party/iwlwifi/platform",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "platform_test" ]
+
+cc_test(
+ name = "rcu_manager_test",
+ size = "small",
+ srcs = [ "rcu-manager-test.cc" ],
+ deps = [
+ "//third_party/iwlwifi/platform:rcu_manager",
+ "@com_google_googletest//:gtest_main",
+ "@fuchsia_sdk//pkg/async",
+ "@fuchsia_sdk//pkg/sync",
+
+ #"//zircon/system/ulib/async-testing",
+ ],
+)
+_tests += [ "rcu_manager_test" ]
+
+cc_test(
+ name = "sta_test",
+ size = "small",
+ srcs = [ "sta-test.cc" ],
+ deps = [
+ ":sim_library",
+ ":mock_function",
+ "//third_party/iwlwifi/mvm",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "sta_test" ]
+
+cc_test(
+ name = "task_test",
+ size = "small",
+ srcs = [ "task-test.cc" ],
+ deps = [
+ ":stub_mvm",
+ ":no_ddk",
+ "//third_party/iwlwifi/platform",
+ "@com_google_googletest//:gtest_main",
+
+ #"//zircon/system/ulib/async-testing",
+ ],
+)
+_tests += [ "task_test" ]
+
+cc_test(
+ name = "utils_test",
+ size = "small",
+ srcs = [ "utils-test.cc" ],
+ deps = [
+ ":no_ddk",
+ "//third_party/iwlwifi/mvm",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "utils_test" ]
+
+cc_test(
+ name = "wlan_softmac_device_test",
+ size = "small",
+ srcs = [ "wlan-softmac-device-test.cc" ],
+ deps = [
+ ":sim_library",
+ ":mock_function",
+ "//third_party/iwlwifi/mvm",
+ "//third_party/iwlwifi:core",
+ "//third_party/iwlwifi/platform:fuchsia_device",
+ "@com_google_googletest//:gtest_main",
+ "@fuchsia_sdk//fidl/fuchsia.hardware.wlan.softmac:fuchsia.hardware.wlan.softmac_banjo_cc",
+ "@fuchsia_sdk//fidl/fuchsia.hardware.wlan.associnfo:fuchsia.hardware.wlan.associnfo_banjo_cc",
+ "@fuchsia_sdk//fidl/fuchsia.wlan.ieee80211:fuchsia.wlan.ieee80211_cc",
+ ],
+)
+_tests += [ "wlan_softmac_device_test" ]
+
+
+cc_test(
+ name = "wlanphy_impl_device_test",
+ size = "small",
+ srcs = [ "wlanphy-impl-device-test.cc" ],
+ deps = [
+ ":sim_library",
+ "//third_party/iwlwifi/mvm",
+ "//third_party/iwlwifi/platform:fuchsia_device",
+ "@fuchsia_sdk//fidl/fuchsia.wlan.common:fuchsia.wlan.common_banjo_cc",
+ "@fuchsia_sdk//fidl/fuchsia.wlan.internal:fuchsia.wlan.internal_banjo_cc",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+_tests += [ "wlanphy_impl_device_test" ]
+
+
# Create component for all the test binaries
[fuchsia_unittest_component(
@@ -125,7 +400,24 @@
visibility = ["//visibility:public"],
# How to auto genrate this dep list?
deps = [
+ ":dummy_test_component",
":driver_inspector_test_component",
- # ":dummy_test_component", # Requires mock and fake-ddk.
+ ":fw_test_component", # Doesn't work, some issue in paging.
+ ":fw_dbg_test_component",
+ ":iwl_phy_db_test_component",
+ ":mac80211_test_component",
+ ":mac_ctxt_test_component",
+ ":mvm_test_component", # Issue with memory allocation.
+ ":notif_wait_test_component",
+ ":nvm_test_component",
+ ":pcie_test_component", # commented out bti, fake-pci etc to compile, and tests fail but compiles.
+ ":phy_ctxt_test_component",
+ ":platform_test_component",
+ # ":rcu_manager_test_component", # Requires async-testing loop.
+ ":sta_test_component",
+ #":task_test_component", # Requires async-testing loop.
+ ":utils_test_component",
+ ":wlan_softmac_device_test_component",
+ ":wlanphy_impl_device_test_component",
],
)
diff --git a/third_party/iwlwifi/test/fake-ucode-test.cc b/third_party/iwlwifi/test/fake-ucode-test.cc
index cc8f955..0da9a91 100644
--- a/third_party/iwlwifi/test/fake-ucode-test.cc
+++ b/third_party/iwlwifi/test/fake-ucode-test.cc
@@ -17,8 +17,7 @@
FakeUcodeTest::FakeUcodeTest(uint32_t capa_index, uint32_t capa_val, uint32_t api_index,
uint32_t api_val)
- // : fake_parent_(MockDevice::FakeRootParent()), sim_trans_(fake_parent_.get()) {
- : sim_trans_(nullptr) {
+ : fake_parent_(MockDevice::FakeRootParent()), sim_trans_(fake_parent_.get()) {
// Add a default MVM firmware to the fake DDK.
TlvFwBuilder fw_builder;
@@ -42,7 +41,7 @@
(6 << FW_PHY_CFG_RX_CHAIN_POS)); // Rx antenna 2 and 1.
fw_builder.AddValue(IWL_UCODE_TLV_PHY_SKU, &ucode_phy_sku, sizeof(ucode_phy_sku));
- //fake_parent_->SetFirmware(fw_builder.GetBinary());
+ fake_parent_->SetFirmware(fw_builder.GetBinary());
zx_status_t status = sim_trans_.Init();
ZX_ASSERT_MSG(ZX_OK == status, "Transportation initialization failed: %s",
diff --git a/third_party/iwlwifi/test/fake-ucode-test.h b/third_party/iwlwifi/test/fake-ucode-test.h
index dd4f10d..409b6cd 100644
--- a/third_party/iwlwifi/test/fake-ucode-test.h
+++ b/third_party/iwlwifi/test/fake-ucode-test.h
@@ -10,7 +10,7 @@
#include <gtest/gtest.h>
#include "third_party/iwlwifi/test/sim-trans.h"
-//#include "src/devices/testing/mock-ddk/mock-device.h"
+#include "third_party/iwlwifi/test/mock-device.h"
namespace wlan::testing {
@@ -36,7 +36,7 @@
~FakeUcodeTest() = default;
protected:
- //std::shared_ptr<MockDevice> fake_parent_;
+ std::shared_ptr<MockDevice> fake_parent_;
SimTransport sim_trans_;
};
diff --git a/third_party/iwlwifi/test/fw-dbg-test.cc b/third_party/iwlwifi/test/fw-dbg-test.cc
index f1b4928..663c82c 100644
--- a/third_party/iwlwifi/test/fw-dbg-test.cc
+++ b/third_party/iwlwifi/test/fw-dbg-test.cc
@@ -7,8 +7,6 @@
#include <algorithm>
#include <memory>
-#include <gtest/gtest.h>
-
extern "C" {
#include "third_party/iwlwifi/fw/dbg.h"
#include "third_party/iwlwifi/fw/error-dump.h"
@@ -17,6 +15,7 @@
#include "third_party/iwlwifi/platform/driver-inspector.h"
#include "third_party/iwlwifi/test/single-ap-test.h"
+#include "third_party/iwlwifi/test/test.h"
namespace wlan::testing {
namespace {
diff --git a/third_party/iwlwifi/test/libdriver-api.cc b/third_party/iwlwifi/test/libdriver-api.cc
new file mode 100644
index 0000000..c417466
--- /dev/null
+++ b/third_party/iwlwifi/test/libdriver-api.cc
@@ -0,0 +1,260 @@
+// Copyright 2021 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <lib/ddk/debug.h>
+#include <lib/syslog/logger.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <zircon/assert.h>
+#include <zircon/errors.h>
+#include <zircon/types.h>
+
+#include <utility>
+
+#include "third_party/iwlwifi/test/mock-device.h"
+
+namespace mock_ddk {
+
+fx_log_severity_t kMinLogSeverity = FX_LOG_INFO;
+
+} // namespace mock_ddk
+
+// Checks to possibly keep:
+// InitReply:
+// If the init fails, the device should be automatically unbound and removed.
+// AsyncRemove
+// We should not call unbind until the init hook has been replied to.
+
+__EXPORT
+zx_status_t device_add_from_driver(zx_driver_t* drv, zx_device_t* parent, device_add_args_t* args,
+ zx_device_t** out) {
+ return MockDevice::Create(args, parent, out);
+}
+
+// These calls are not supported by root parent devices:
+__EXPORT
+void device_async_remove(zx_device_t* device) {
+ if (!device) {
+ zxlogf(ERROR, "Error: %s passed an null device\n", __func__);
+ return;
+ }
+ if (device->IsRootParent()) {
+ zxlogf(ERROR, "Error: Mock parent device does not support %s\n", __func__);
+ return;
+ }
+ device->RecordAsyncRemove(ZX_OK);
+}
+
+__EXPORT
+void device_init_reply(zx_device_t* device, zx_status_t status,
+ const device_init_reply_args_t* args) {
+ if (!device) {
+ zxlogf(ERROR, "Error: %s passed an null device\n", __func__);
+ return;
+ }
+ if (device->IsRootParent()) {
+ zxlogf(ERROR, "Error: Mock parent device does not support %s\n", __func__);
+ return;
+ }
+ device->RecordInitReply(status);
+}
+
+__EXPORT
+void device_unbind_reply(zx_device_t* device) {
+ if (!device) {
+ zxlogf(ERROR, "Error: %s passed an null device\n", __func__);
+ return;
+ }
+ if (device->IsRootParent()) {
+ zxlogf(ERROR, "Error: Mock parent device does not support %s\n", __func__);
+ return;
+ }
+ device->RecordUnbindReply(ZX_OK);
+}
+
+__EXPORT void device_suspend_reply(zx_device_t* device, zx_status_t status, uint8_t out_state) {
+ if (!device) {
+ zxlogf(ERROR, "Error: %s passed an null device\n", __func__);
+ return;
+ }
+ if (device->IsRootParent()) {
+ zxlogf(ERROR, "Error: Mock parent device does not support %s\n", __func__);
+ return;
+ }
+ device->RecordSuspendReply(status);
+}
+
+__EXPORT void device_resume_reply(zx_device_t* device, zx_status_t status, uint8_t out_power_state,
+ uint32_t out_perf_state) {
+ if (!device) {
+ zxlogf(ERROR, "Error: %s passed an null device\n", __func__);
+ return;
+ }
+ if (device->IsRootParent()) {
+ zxlogf(ERROR, "Error: Mock parent device does not support %s\n", __func__);
+ return;
+ }
+ device->RecordResumeReply(status);
+}
+
+// These functions TODO(will be) supported by devices created as root parents:
+__EXPORT
+zx_status_t device_get_protocol(const zx_device_t* device, uint32_t proto_id, void* protocol) {
+ if (!device) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ return device->GetProtocol(proto_id, protocol);
+}
+
+__EXPORT
+zx_status_t device_add_metadata(zx_device_t* device, uint32_t type, const void* data,
+ size_t length) {
+ device->SetMetadata(type, data, length);
+ return ZX_OK;
+}
+
+__EXPORT
+zx_status_t device_get_metadata(zx_device_t* device, uint32_t type, void* buf, size_t buflen,
+ size_t* actual) {
+ return device->GetMetadata(type, buf, buflen, actual);
+}
+
+__EXPORT
+zx_status_t device_get_metadata_size(zx_device_t* device, uint32_t type, size_t* out_size) {
+ return device->GetMetadataSize(type, out_size);
+}
+
+__EXPORT zx_status_t device_get_fragment_protocol(zx_device_t* device, const char* name,
+ uint32_t proto_id, void* protocol) {
+ if (!device) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ return device->GetProtocol(proto_id, protocol, name);
+}
+
+__EXPORT
+zx_status_t device_get_fragment_metadata(zx_device_t* device, const char* name, uint32_t type,
+ void* buf, size_t buflen, size_t* actual) {
+ if (!device) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ return device_get_metadata(device, type, buf, buflen, actual);
+}
+
+__EXPORT zx_status_t device_connect_fidl_protocol(zx_device_t* device, const char* protocol_name,
+ zx_handle_t request) {
+ if (!device) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ return device->ConnectToFidlProtocol(protocol_name, zx::channel(request));
+}
+
+__EXPORT zx_status_t device_connect_fragment_fidl_protocol(zx_device_t* device,
+ const char* fragment_name,
+ const char* protocol_name,
+ zx_handle_t request) {
+ if (!device) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ return device->ConnectToFidlProtocol(protocol_name, zx::channel(request), fragment_name);
+}
+
+__EXPORT async_dispatcher_t* device_get_dispatcher(zx_device_t* device) {
+ return device->dispatcher();
+}
+
+// Unsupported calls:
+__EXPORT
+zx_status_t device_open_protocol_session_multibindable(const zx_device_t* dev, uint32_t proto_id,
+ void* protocol) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT
+zx_off_t device_get_size(zx_device_t* device) { return device->GetSize(); }
+
+__EXPORT
+zx_status_t device_get_profile(zx_device_t* device, uint32_t priority, const char* name,
+ zx_handle_t* out_profile) {
+ // This is currently a no-op.
+ *out_profile = ZX_HANDLE_INVALID;
+ return ZX_OK;
+}
+
+__EXPORT
+zx_status_t device_get_deadline_profile(zx_device_t* device, uint64_t capacity, uint64_t deadline,
+ uint64_t period, const char* name,
+ zx_handle_t* out_profile) {
+ // This is currently a no-op.
+ *out_profile = ZX_HANDLE_INVALID;
+ return ZX_OK;
+}
+
+__EXPORT
+void device_fidl_transaction_take_ownership(fidl_txn_t* txn, device_fidl_txn_t* new_txn) {
+ // auto fidl_txn = mock_ddk::FromDdkInternalTransaction(ddk::internal::Transaction::FromTxn(txn));
+
+ // ZX_ASSERT_MSG(std::holds_alternative<fidl::Transaction*>(fidl_txn),
+ // "Can only take ownership of transaction once\n");
+
+ // auto result = std::get<fidl::Transaction*>(fidl_txn)->TakeOwnership();
+ // We call this to mimic what devhost does.
+ // result->EnableNextDispatch();
+ // auto new_ddk_txn = mock_ddk::MakeDdkInternalTransaction(std::move(result));
+ // *new_txn = *new_ddk_txn.DeviceFidlTxn();
+}
+
+__EXPORT __WEAK zx_status_t load_firmware_from_driver(zx_driver_t* drv, zx_device_t* device,
+ const char* path, zx_handle_t* fw,
+ size_t* size) {
+ if (!device) {
+ zxlogf(ERROR, "Error: %s passed an null device\n", __func__);
+ return ZX_ERR_INVALID_ARGS;
+ }
+ return device->LoadFirmware(path, fw, size);
+}
+
+__EXPORT zx_status_t device_get_variable(zx_device_t* device, const char* name, char* out,
+ size_t out_size, size_t* size_actual) {
+ return device->GetVariable(name, out, out_size, size_actual);
+}
+
+__EXPORT
+zx_status_t device_rebind(zx_device_t* device) { return ZX_ERR_NOT_SUPPORTED; }
+
+__EXPORT
+zx_handle_t get_root_resource() { return ZX_HANDLE_INVALID; }
+
+__EXPORT zx_status_t driver_log_set_tags_internal(const zx_driver_t* drv, const char* const* tags,
+ size_t num_tags) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+extern "C" bool driver_log_severity_enabled_internal(const zx_driver_t* drv,
+ fx_log_severity_t flag) {
+ return flag >= mock_ddk::kMinLogSeverity;
+}
+
+extern "C" void driver_logvf_internal(const zx_driver_t* drv, fx_log_severity_t flag,
+ const char* tag, const char* file, int line, const char* msg,
+ va_list args) {
+ vfprintf(stdout, msg, args);
+ putchar('\n');
+ fflush(stdout);
+}
+
+extern "C" void driver_logf_internal(const zx_driver_t* drv, fx_log_severity_t flag,
+ const char* tag, const char* file, int line, const char* msg,
+ ...) {
+ va_list args;
+ va_start(args, msg);
+ driver_logvf_internal(drv, flag, tag, file, line, msg, args);
+ va_end(args);
+}
+
+__EXPORT
+__WEAK zx_driver_rec __zircon_driver_rec__ = {
+ .ops = {},
+ .driver = {},
+};
diff --git a/third_party/iwlwifi/test/mac-ctxt-test.cc b/third_party/iwlwifi/test/mac-ctxt-test.cc
index 2a0b3ab..b7a4034 100644
--- a/third_party/iwlwifi/test/mac-ctxt-test.cc
+++ b/third_party/iwlwifi/test/mac-ctxt-test.cc
@@ -6,13 +6,12 @@
#include <zircon/compiler.h>
-#include <gtest/gtest.h>
-
extern "C" {
#include "third_party/iwlwifi/mvm/mvm.h"
}
#include "third_party/iwlwifi/test/single-ap-test.h"
+#include "third_party/iwlwifi/test/test.h"
namespace wlan::testing {
namespace {
diff --git a/third_party/iwlwifi/test/mac80211-test.cc b/third_party/iwlwifi/test/mac80211-test.cc
index 64e9012..495e824 100644
--- a/third_party/iwlwifi/test/mac80211-test.cc
+++ b/third_party/iwlwifi/test/mac80211-test.cc
@@ -4,20 +4,19 @@
// Used to test mvm/mac80211.c
-#include <lib/mock-function/mock-function.h>
#include <zircon/compiler.h>
#include <iterator>
-#include <gtest/gtest.h>
-
extern "C" {
#include "third_party/iwlwifi/mvm/mvm.h"
}
+#include "third_party/iwlwifi/test/test.h"
#include "third_party/iwlwifi/test/fake-ucode-test.h"
#include "third_party/iwlwifi/test/mock-trans.h"
#include "third_party/iwlwifi/test/single-ap-test.h"
+#include "third_party/iwlwifi/test/mock-function.h"
namespace wlan::testing {
namespace {
@@ -46,15 +45,15 @@
.primary = 35,
};
uint16_t phy_ctxt_id;
- ASSERT_EQ(ZX_OK, iwl_mvm_add_chanctx(mvm_, &chandef, &phy_ctxt_id));
+ EXPECT_EQ(ZX_OK, iwl_mvm_add_chanctx(mvm_, &chandef, &phy_ctxt_id));
mvmvif_.phy_ctxt = &mvm_->phy_ctxts[phy_ctxt_id];
// Assign the AP sta info.
- ASSERT_EQ(fuchsia_wlan_ieee80211_TIDS_MAX + 1, std::size(ap_sta_.txq));
+ EXPECT_EQ(fuchsia_wlan_ieee80211_TIDS_MAX + 1, std::size(ap_sta_.txq));
for (size_t i = 0; i < std::size(ap_sta_.txq); i++) {
ap_sta_.txq[i] = &txqs_[i];
}
- ASSERT_EQ(ZX_OK, iwl_mvm_mac_sta_state(&mvmvif_, &ap_sta_, IWL_STA_NOTEXIST, IWL_STA_NONE));
+ EXPECT_EQ(ZX_OK, iwl_mvm_mac_sta_state(&mvmvif_, &ap_sta_, IWL_STA_NOTEXIST, IWL_STA_NONE));
// Set it to associated.
mvmvif_.bss_conf.assoc = true;
diff --git a/third_party/iwlwifi/test/mock-device.cc b/third_party/iwlwifi/test/mock-device.cc
new file mode 100644
index 0000000..101a82b
--- /dev/null
+++ b/third_party/iwlwifi/test/mock-device.cc
@@ -0,0 +1,358 @@
+// Copyright 2021 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "third_party/iwlwifi/test/mock-device.h"
+
+#include <algorithm>
+
+MockDevice::MockDevice(device_add_args_t* args, MockDevice* parent)
+ : parent_(parent), ops_(args->ops), ctx_(args->ctx), name_(args->name) {
+ if (args->proto_id && args->proto_ops) {
+ AddProtocol(args->proto_id, args->proto_ops, ctx_);
+ }
+ if (args->props) {
+ props_.insert(props_.begin(), args->props, args->props + args->prop_count);
+ }
+ if (args->str_props) {
+ str_props_.insert(str_props_.begin(), args->str_props, args->str_props + args->str_prop_count);
+ }
+ if (args->metadata_list && args->metadata_count > 0) {
+ for (size_t i = 0; i < args->metadata_count; ++i) {
+ SetMetadata(args->metadata_list[i].type, args->metadata_list[i].data,
+ args->metadata_list[i].length);
+ }
+ }
+
+ if (args->client_remote) {
+ client_remote_ = zx::channel(args->client_remote);
+ }
+ inspect_ = zx::vmo(args->inspect_vmo);
+}
+
+// static
+std::shared_ptr<MockDevice> MockDevice::FakeRootParent() {
+ // Using `new` to access a non-public constructor.
+ return std::shared_ptr<MockDevice>(new MockDevice());
+}
+
+// Static member function.
+zx_status_t MockDevice::Create(device_add_args_t* args, MockDevice* parent, MockDevice** out_dev) {
+ // We only check the minimum requirements to make sure the mock does not crash:
+ if (!parent || !args || !args->name) {
+ return ZX_ERR_INVALID_ARGS;
+ }
+
+ // Using `new` to access a non-public constructor.
+ auto new_device = std::shared_ptr<MockDevice>(new MockDevice(args, parent));
+ if (out_dev) {
+ *out_dev = new_device.get();
+ }
+ parent->children_.emplace_back(std::move(new_device));
+ // PropagateMetadata to last child:
+ for (const auto& [key, value] : parent->metadata_) {
+ parent->children().back()->metadata_[key] = value;
+ }
+ parent->children().back()->PropagateMetadata();
+ return ZX_OK;
+}
+
+MockDevice* MockDevice::GetLatestChild() {
+ if (child_count()) {
+ return children_.back().get();
+ }
+ return nullptr;
+}
+
+// Templates that dispatch the protocol operations if they were set.
+// If they were not set, the second parameter is returned to the caller
+// (usually ZX_ERR_NOT_SUPPORTED)
+template <typename RetType, typename... ArgTypes>
+RetType Dispatch(void* ctx, RetType (*op)(void* ctx, ArgTypes...), RetType fallback,
+ ArgTypes... args) {
+ return op ? (*op)(ctx, args...) : fallback;
+}
+
+template <typename... ArgTypes>
+void Dispatch(void* ctx, void (*op)(void* ctx, ArgTypes...), ArgTypes... args) {
+ if (op) {
+ (*op)(ctx, args...);
+ }
+}
+
+void MockDevice::InitOp() { Dispatch(ctx_, ops_->init); }
+
+zx_status_t MockDevice::OpenOp(zx_device_t** dev_out, uint32_t flags) {
+ return Dispatch(ctx_, ops_->open, ZX_OK, dev_out, flags);
+}
+
+zx_status_t MockDevice::CloseOp(uint32_t flags) {
+ return Dispatch(ctx_, ops_->close, ZX_OK, flags);
+}
+
+void MockDevice::UnbindOp() { Dispatch(ctx_, ops_->unbind); }
+
+void MockDevice::ReleaseOp() {
+ Dispatch(ctx_, ops_->release);
+ // Make parent release child now
+ for (auto it = parent_->children_.begin(); it != parent_->children_.end(); ++it) {
+ if (it->get() == this) {
+ parent_->children_.erase(it);
+ return;
+ }
+ }
+ // Print error: we did not find ourselves!
+}
+
+MockDevice::~MockDevice() {
+ while (!children_.empty()) {
+ // This should remove the first child device from children_:
+ children_.front()->ReleaseOp();
+ }
+}
+
+void MockDevice::SuspendNewOp(uint8_t requested_state, bool enable_wake, uint8_t suspend_reason) {
+ Dispatch(ctx_, ops_->suspend, requested_state, enable_wake, suspend_reason);
+}
+
+zx_status_t MockDevice::SetPerformanceStateOp(uint32_t requested_state, uint32_t* out_state) {
+ return Dispatch(ctx_, ops_->set_performance_state, ZX_ERR_NOT_SUPPORTED, requested_state,
+ out_state);
+}
+
+zx_status_t MockDevice::ConfigureAutoSuspendOp(bool enable, uint8_t requested_state) {
+ return Dispatch(ctx_, ops_->configure_auto_suspend, ZX_ERR_NOT_SUPPORTED, enable,
+ requested_state);
+}
+
+void MockDevice::ResumeNewOp(uint32_t requested_state) {
+ Dispatch(ctx_, ops_->resume, requested_state);
+}
+
+zx_status_t MockDevice::ReadOp(void* buf, size_t count, zx_off_t off, size_t* actual) {
+ return Dispatch(ctx_, ops_->read, ZX_ERR_NOT_SUPPORTED, buf, count, off, actual);
+}
+
+zx_status_t MockDevice::WriteOp(const void* buf, size_t count, zx_off_t off, size_t* actual) {
+ return Dispatch(ctx_, ops_->write, ZX_ERR_NOT_SUPPORTED, buf, count, off, actual);
+}
+
+zx_off_t MockDevice::GetSizeOp() { return Dispatch(ctx_, ops_->get_size, 0lu); }
+
+zx_status_t MockDevice::MessageOp(fidl_incoming_msg_t* msg, fidl_txn_t* txn) {
+ return Dispatch(ctx_, ops_->message, ZX_ERR_NOT_SUPPORTED, msg, txn);
+}
+
+void MockDevice::ChildPreReleaseOp(void* child_ctx) {
+ Dispatch(ctx_, ops_->child_pre_release, child_ctx);
+}
+
+void MockDevice::SetSize(size_t size) { size_ = size; }
+
+zx_off_t MockDevice::GetSize() {
+ if (size_ == 0) {
+ size_ = GetSizeOp();
+ }
+ return size_;
+}
+
+void MockDevice::SetMetadata(uint32_t type, const void* data, size_t data_length) {
+ std::vector<uint8_t> owned(data_length);
+ memcpy(owned.data(), data, data_length);
+ metadata_[type] = std::move(owned);
+ PropagateMetadata();
+}
+
+void MockDevice::SetVariable(const char* name, const char* data) {
+ if (data) {
+ std::string owned(data);
+ variables_[name] = std::move(owned);
+ } else {
+ auto itr = variables_.find(name);
+ if (itr != variables_.end()) {
+ variables_.erase(itr);
+ }
+ }
+}
+
+zx_status_t MockDevice::GetMetadata(uint32_t type, void* buf, size_t buflen, size_t* actual) {
+ auto itr = metadata_.find(type);
+ if (itr != metadata_.end()) {
+ auto& metadata = itr->second;
+ *actual = metadata.size();
+ if (buflen < metadata.size()) {
+ return ZX_ERR_BUFFER_TOO_SMALL;
+ }
+
+ memcpy(buf, metadata.data(), metadata.size());
+ return ZX_OK;
+ }
+ return ZX_ERR_NOT_FOUND;
+}
+
+zx_status_t MockDevice::GetMetadataSize(uint32_t type, size_t* out_size) {
+ auto itr = metadata_.find(type);
+ if (itr != metadata_.end()) {
+ auto metadata = itr->second;
+ *out_size = metadata.size();
+ return ZX_OK;
+ }
+ return ZX_ERR_BAD_STATE;
+}
+
+zx_status_t MockDevice::GetVariable(const char* name, char* out, size_t size, size_t* actual) {
+ auto itr = variables_.find(name);
+ if (itr == variables_.end()) {
+ return ZX_ERR_NOT_FOUND;
+ }
+
+ auto& variable = itr->second;
+ if (actual) {
+ *actual = variable.size();
+ }
+ if (size < variable.size()) {
+ return ZX_ERR_BUFFER_TOO_SMALL;
+ }
+
+ strncpy(out, variable.data(), size);
+ return ZX_OK;
+}
+
+void MockDevice::PropagateMetadata() {
+ for (auto& child : children_) {
+ for (const auto& [key, value] : metadata_) {
+ child->metadata_[key] = value;
+ }
+ child->PropagateMetadata();
+ }
+}
+
+void MockDevice::AddProtocol(uint32_t id, const void* ops, void* ctx, const char* fragment_name) {
+ protocols_[fragment_name].push_back(mock_ddk::ProtocolEntry{id, {ops, ctx}});
+}
+
+void MockDevice::AddFidlProtocol(const char* protocol_name, mock_ddk::ConnectCallback callback,
+ const char* name) {
+ fidl_protocols_.try_emplace(name, std::unordered_map<std::string, mock_ddk::ConnectCallback>());
+ fidl_protocols_[name][protocol_name] = std::move(callback);
+}
+
+void MockDevice::SetFirmware(std::vector<uint8_t> firmware, std::string_view path) {
+ firmware_[path] = std::move(firmware);
+}
+
+void MockDevice::SetFirmware(std::string firmware, std::string_view path) {
+ std::vector<uint8_t> vec(firmware.begin(), firmware.end());
+ SetFirmware(vec, path);
+}
+
+zx_status_t MockDevice::LoadFirmware(std::string_view path, zx_handle_t* fw, size_t* size) {
+ auto firmware = firmware_.find(path);
+ // If a match is not found to 'path', check if there is a firmware that was loaded with
+ // path == nullptr:
+ if (firmware == firmware_.end()) {
+ firmware = firmware_.find("");
+ }
+ if (firmware == firmware_.end()) {
+ return ZX_ERR_NOT_FOUND;
+ }
+ zx_status_t status = ZX_OK;
+ zx_handle_t vmo = ZX_HANDLE_INVALID;
+ if ((status = zx_vmo_create(firmware->second.size(), 0, &vmo)) != ZX_OK) {
+ return status;
+ }
+ if ((status = zx_vmo_write(vmo, firmware->second.data(), 0, firmware->second.size())) != ZX_OK) {
+ return status;
+ }
+
+ *fw = vmo;
+ *size = firmware->second.size();
+ return ZX_OK;
+}
+
+zx_status_t MockDevice::GetProtocol(uint32_t proto_id, void* protocol,
+ const char* fragment_name) const {
+ // Check if there are protocols for the fragment/device:
+ auto protocol_set = protocols_.find(fragment_name);
+ if (protocol_set == protocols_.end()) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ auto out = reinterpret_cast<mock_ddk::Protocol*>(protocol);
+ // First we check if the user has added protocols:
+ for (const auto& proto : protocol_set->second) {
+ if (proto_id == proto.id) {
+ out->ops = proto.proto.ops;
+ out->ctx = proto.proto.ctx;
+ return ZX_OK;
+ }
+ }
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+zx_status_t MockDevice::ConnectToFidlProtocol(const char* protocol_name, zx::channel request,
+ const char* fragment_name) {
+ // Check if there are protocols for the fragment/device:
+ auto protocol_set = fidl_protocols_.find(fragment_name);
+ if (protocol_set == fidl_protocols_.end()) {
+ return ZX_ERR_NOT_SUPPORTED;
+ }
+ auto callback = protocol_set->second.find(protocol_name);
+ if (callback == protocol_set->second.end()) {
+ return ZX_ERR_NOT_FOUND;
+ }
+ return callback->second(std::move(request));
+}
+
+size_t MockDevice::descendant_count() const {
+ size_t count = child_count();
+ for (auto& child : children_) {
+ count += child->descendant_count();
+ }
+ return count;
+}
+
+void MockDevice::SetDispatcher(async_dispatcher_t* dispatcher) {
+ ZX_ASSERT_MSG(dispatcher_ == nullptr, "Dispatcher for '%s' cannot be changed after it is set.",
+ name());
+ dispatcher_ = dispatcher;
+}
+
+// helper functions:
+namespace {
+
+zx_status_t ProcessDeviceRemoval(MockDevice* device) {
+ device->UnbindOp();
+ // deleting children, so use a while loop:
+ while (!device->children().empty()) {
+ auto status = ProcessDeviceRemoval(device->children().back().get());
+ if (status != ZX_OK) {
+ return status;
+ }
+ }
+ if (device->HasUnbindOp()) {
+ zx_status_t status = device->WaitUntilUnbindReplyCalled();
+ if (status != ZX_OK) {
+ return status;
+ }
+ }
+ device->ReleaseOp();
+ return ZX_OK;
+}
+} // anonymous namespace
+
+zx_status_t mock_ddk::ReleaseFlaggedDevices(MockDevice* device) {
+ if (device->AsyncRemoveCalled()) {
+ return ProcessDeviceRemoval(device);
+ }
+ // Make a vector of the child device pointers, because we might delete the child:
+ std::vector<MockDevice*> children;
+ std::transform(device->children().begin(), device->children().end(), std::back_inserter(children),
+ [](std::shared_ptr<MockDevice> c) -> MockDevice* { return c.get(); });
+ for (auto child : children) {
+ auto ret = ReleaseFlaggedDevices(child);
+ if (ret != ZX_OK) {
+ return ret;
+ }
+ }
+ return ZX_OK;
+}
diff --git a/third_party/iwlwifi/test/mock-device.h b/third_party/iwlwifi/test/mock-device.h
new file mode 100644
index 0000000..81d87c5
--- /dev/null
+++ b/third_party/iwlwifi/test/mock-device.h
@@ -0,0 +1,336 @@
+// Copyright 2021 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SRC_DEVICES_TESTING_MOCK_DDK_MOCK_DEVICE_H_
+#define SRC_DEVICES_TESTING_MOCK_DDK_MOCK_DEVICE_H_
+
+#include <lib/ddk/binding_priv.h>
+#include <lib/ddk/device.h>
+#include <lib/ddk/driver.h>
+#include <lib/fit/function.h>
+#include <lib/stdcompat/span.h>
+#include <lib/sync/completion.h>
+#include <lib/zx/channel.h>
+#include <lib/zx/time.h>
+#include <lib/zx/vmo.h>
+#include <zircon/assert.h>
+
+#include <list>
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <vector>
+
+#include "lib/async/dispatcher.h"
+//#include "lib/fidl/llcpp/wire_messaging.h"
+
+// Allow redefining the zx_device_t struct. MockDevice cannot be in the mock_ddk namespace.
+#define MockDevice zx_device
+
+namespace mock_ddk {
+// Generic protocol.
+struct Protocol {
+ const void* ops;
+ void* ctx;
+};
+
+struct ProtocolEntry {
+ uint32_t id;
+ Protocol proto;
+};
+
+using ConnectCallback = fit::function<zx_status_t(zx::channel)>;
+} // namespace mock_ddk
+
+// MockDevice is an implementation of the opaque type zx_device which mocks much of
+// device host functionality.
+// Mock devices are created in one of two ways:
+// 1) Calling FakeRootParent.
+// 2) Calling device_add_from_driver (which may be done indirectly by DdkAdd)
+//
+// Since device_add_from_driver takes zx_device_t* parent as an argument, FakeRootParent()
+// must be called before adding any other devices.
+// MockDevice does not use any global variables, so multiple fake parents can exist without
+// interfering with each other.
+// The FakeRootParent is limited in functionality, but protocols and metadata can be added to it
+// to facilitate a child device's needs.
+//
+// The fake root parent is also important because it controls the lifecycle of its descendants.
+// Unlike the device host, the parent of each MockDevice holds the MockDevice's refptr.
+// This allows drivers to "leak" the pointer to the device like normal during bind.
+// However, it means that tests using MockDevices must retain the reference to the fake root parent,
+// or all the descendent devices will be deleted, because
+// the root parent will recursively release all of its children upon destruction.
+// When this happens, the release() op will be called on the device, allowing it to delete
+// any context it created.
+//
+// Importantly, this is a mock implementation, not a fake. Any libDriver calls will be
+// recorded, but the mock will not take any automatic action. This may result in unexpected
+// behavior during device initialization and removal.
+// Initialization:
+// The init() op is not automatically called on newly added devices. It can be manually called
+// by calling MockDevice::InitOp().
+// Removal:
+// When attempting to remove dynamically devices, device_async_remove will not result in
+// device removal.
+// To process device removal, a helper function is provided below:
+// ReleaseFlaggedDevices recursively searches the device tree and calls unbind and release
+// on any device that has had device_async_remove called on it.
+// Calling ReleaseOp() on a MockDevice will also cause it to be deleted.
+//
+// Things that this MockDevice does not handle (yet)
+// Rebinding
+// Composite devices
+// Fidl messages
+// Any automatic responses from the DDK
+// The following libdriver calls:
+// device_open_protocol_session_multibindable
+// device_get_profile
+// device_get_deadline_profile
+// device_fidl_transaction_take_ownership
+// get_root_resource
+// device_rebind
+// This needs to be a struct, not a class, to match the public definition
+struct MockDevice : public std::enable_shared_from_this<MockDevice> {
+ public:
+ // Create a Root Parent. This device has limited functionality.
+ static std::shared_ptr<MockDevice> FakeRootParent();
+
+ ~MockDevice();
+
+ // Calls for tracking libdriver calls made that reference this device:
+ // The Register calls below create 4 functions each:
+ // REGISTER_CALL_TRACKER( InitReply ) creates:
+ // void WaitUntilInitReplyCalled(); <-- Blocking wait until InitReply is called
+ // void RecordInitReply(); <-- Records the InitReply call
+ // bool InitReplyCalled(); <-- Returns true if InitReply has been called.
+ // zx_status_t InitReplyCallStatus(); <-- Returns the status that was passed to InitReply
+ //
+ // The WaitUntil* functions are useful if you expect the reply/remove/etc to be called
+ // in a different thread.
+#define REGISTER_CALL_TRACKER(varname) \
+ private: \
+ bool varname##_call_made_ = false; \
+ zx_status_t varname##_call_status_ = ZX_ERR_BAD_STATE; \
+ sync_completion_t varname##_call_made_sync_; \
+ \
+ public: \
+ void Record##varname(zx_status_t status) { \
+ varname##_call_status_ = status; \
+ varname##_call_made_ = true; \
+ sync_completion_signal(&varname##_call_made_sync_); \
+ } \
+ zx_status_t WaitUntil##varname##Called(zx::time deadline = zx::time::infinite()) { \
+ return sync_completion_wait_deadline(&varname##_call_made_sync_, deadline.get()); \
+ } \
+ bool varname##Called() { return varname##_call_made_; } \
+ zx_status_t varname##CallStatus() { return varname##_call_status_; }
+
+ REGISTER_CALL_TRACKER(InitReply)
+ REGISTER_CALL_TRACKER(AsyncRemove)
+ REGISTER_CALL_TRACKER(UnbindReply)
+ REGISTER_CALL_TRACKER(SuspendReply)
+ REGISTER_CALL_TRACKER(ResumeReply)
+ REGISTER_CALL_TRACKER(Remove)
+#undef REGISTER_CALL_TRACKER
+
+ // Functions for calling into the driver.
+ // These are functions that the DDK normally calls, but are exposed here for testing purposes.
+ void InitOp();
+ zx_status_t OpenOp(zx_device_t** dev_out, uint32_t flags);
+ zx_status_t CloseOp(uint32_t flags);
+ void UnbindOp();
+ void ReleaseOp();
+ void SuspendNewOp(uint8_t requested_state, bool enable_wake, uint8_t suspend_reason);
+ zx_status_t SetPerformanceStateOp(uint32_t requested_state, uint32_t* out_state);
+ zx_status_t ConfigureAutoSuspendOp(bool enable, uint8_t requested_state);
+ void ResumeNewOp(uint32_t requested_state);
+ zx_status_t ReadOp(void* buf, size_t count, zx_off_t off, size_t* actual);
+ zx_status_t WriteOp(const void* buf, size_t count, zx_off_t off, size_t* actual);
+ zx_off_t GetSizeOp();
+ zx_status_t MessageOp(fidl_incoming_msg_t* msg, fidl_txn_t* txn);
+ void ChildPreReleaseOp(void* child_ctx);
+ bool HasUnbindOp() { return ops_->unbind != nullptr; }
+
+ cpp20::span<const zx_device_prop_t> GetProperties() const { return props_; }
+ cpp20::span<const zx_device_str_prop_t> GetStringProperties() const { return str_props_; }
+
+ const zx::vmo& GetInspectVmo() const { return inspect_; }
+
+ // Size is often set for the parent of a device, to be available when the device
+ // calls device_get_size
+ void SetSize(size_t size);
+
+ // Metadata is often set for the parent of a device, to be available when the device
+ // calls device_get_metadata
+ void SetMetadata(uint32_t type, const void* data, size_t data_length);
+
+ // Variables are often set for the parent of a device, to be available when the device
+ // calls device_get_variable.
+ // Passing in nullptr for |data| will unset the variable.
+ void SetVariable(const char* name, const char* data);
+
+ // device_get_protocol is usually called by child devices to get their parent protocols.
+ // You can add protocols here to your device or your parent device.
+ // if you want to add a protocol to a fragment, add the fragment's name as 'name'.
+ void AddProtocol(uint32_t id, const void* ops, void* ctx, const char* name = "");
+
+ // You can add FIDL protocols here to your device or your parent device.
+ // if you want to add a protocol to a fragment, add the fragment's name as 'name'.
+ // Devices will use `device_connect_fidl_protocol` or
+ // `device_connect_fragment_fidl_protocol` to connect to these protocols
+ void AddFidlProtocol(const char* protocol_name, mock_ddk::ConnectCallback callback,
+ const char* name = "");
+
+ // This struct can also be a root parent device, with reduced functionality.
+ // This allows the parent to store protocols that can be accessed by a child device.
+ // If IsRootParent returns true, only the following calls may target this device:
+ // device_get_protocol
+ // device_get_metadata_size
+ // device_get_metadata
+ // These calls will be able to target this type of device soon:
+ // device_get_fragment
+ // device_get_fragments
+ // device_get_fragment_count
+ bool IsRootParent() const { return parent_ == nullptr; }
+ const char* name() const { return name_.c_str(); }
+
+ size_t child_count() const { return children_.size(); }
+
+ // Count all the descendants of this device.
+ size_t descendant_count() const;
+
+ std::list<std::shared_ptr<MockDevice>>& children() { return children_; }
+ // Gets the child that was added to this parent most recently.
+ // Returns nullptr if no children exist.
+ MockDevice* GetLatestChild();
+
+ // Access the Device class that created this MockDevice (for example, devices which
+ // inherit from ddk::Device create a MockDevice when they call DdkAdd.)
+ template <class DeviceType>
+ DeviceType* GetDeviceContext() {
+ return static_cast<DeviceType*>(ctx_);
+ }
+
+ // load_firmware support
+ // First, set firmware by calling SetFirmware on a device.
+ // Then, when the device calls load_firmware, a vmo will be created with the
+ // firmware that was set.
+ // SetFirmware can store any number of path:firmware pairs.
+ // If path is empty, the firmware is stored in a way that will match any path
+ // that has not also been provided to SetFirmware to store another firmware blob.
+ void SetFirmware(std::vector<uint8_t> firmware, std::string_view path = {});
+ // Convenience version which takes string:
+ void SetFirmware(std::string firmware, std::string_view path = {});
+
+ // device_get_dispatcher support.
+ async_dispatcher_t* dispatcher() { return dispatcher_; }
+ // Set the dispatcher for this device. The mock ddk does not take ownership of the dispatcher. The
+ // caller is responsible for shutting down the async loop appropriately.
+ void SetDispatcher(async_dispatcher_t* dispatcher);
+
+ zx::channel&& TakeClientRemote() { return std::move(client_remote_); }
+
+ private:
+ constexpr static zx_protocol_device_t kDefaultOps = {};
+ // |ctx| must outlive |*out_dev|. This is managed in the full binary by creating
+ // the DriverHostContext in main() (having essentially a static lifetime).
+ MockDevice(device_add_args_t* args, MockDevice* parent);
+
+ // Calls make by the libdriver api:
+ // device_add_from_driver calls Create:
+ static zx_status_t Create(device_add_args_t* args, MockDevice* parent, MockDevice** out_dev);
+ // Allow device_add_from_driver to access the Create function
+ friend zx_status_t device_add_from_driver(zx_driver_t* drv, zx_device_t* parent,
+ device_add_args_t* args, zx_device_t** out);
+
+ // load_firmware_from_driver calls LoadFirmware:
+ zx_status_t LoadFirmware(std::string_view path, zx_handle_t* fw, size_t* size);
+ friend zx_status_t load_firmware_from_driver(zx_driver_t* drv, zx_device_t* device,
+ const char* path, zx_handle_t* fw, size_t* size);
+
+ // device_get_protocol and device_get_fragment_protocol call GetProtocol.
+ // Get protocol can get the normal protocols for the device, if fragment_name = "".
+ // Otherwise, it gets protocols associated with the fragment identified by fragment_name.
+ zx_status_t GetProtocol(uint32_t proto_id, void* protocol, const char* fragment_name = "") const;
+ friend zx_status_t device_get_protocol(const zx_device_t* device, uint32_t proto_id,
+ void* protocol);
+ friend zx_status_t device_get_fragment_protocol(zx_device_t* device, const char* fragment_name,
+ uint32_t proto_id, void* protocol);
+
+ zx_status_t ConnectToFidlProtocol(const char* protocol_name, zx::channel request,
+ const char* fragment_name = "");
+ friend zx_status_t device_connect_fidl_protocol(zx_device_t* device, const char* protocol_name,
+ zx_handle_t request);
+ friend zx_status_t device_connect_fragment_fidl_protocol(zx_device_t* device,
+ const char* fragment_name,
+ const char* protocol_name,
+ zx_handle_t request);
+
+ zx_off_t GetSize();
+ friend zx_off_t device_get_size(zx_device_t* device);
+
+ // device_get_metadata calls GetMetadata:
+ zx_status_t GetMetadata(uint32_t type, void* buf, size_t buflen, size_t* actual);
+ friend zx_status_t device_get_metadata(zx_device_t* device, uint32_t type, void* buf,
+ size_t buflen, size_t* actual);
+
+ // device_get_metadata_size calls GetMetadataSize:
+ zx_status_t GetMetadataSize(uint32_t type, size_t* out_size);
+ friend zx_status_t device_get_metadata_size(zx_device_t* device, uint32_t type, size_t* out_size);
+
+ // device_get_varaible calls GetVariable:
+ zx_status_t GetVariable(const char* name, char* out, size_t size, size_t* size_actual);
+ friend zx_status_t device_get_variable(zx_device_t* device, const char* name, char* out,
+ size_t size, size_t* size_actual);
+
+ // Default constructor for making root parent:
+ explicit MockDevice() {}
+
+ // Copies this device's metadata to all descendants.
+ void PropagateMetadata();
+
+ // list of this device's children in the device tree
+ std::list<std::shared_ptr<MockDevice>> children_;
+ // Stores the normal protocols under the key "", fragment protocols under their name.
+ std::unordered_map<std::string, std::list<mock_ddk::ProtocolEntry>> protocols_;
+ std::unordered_map<std::string, std::unordered_map<std::string, mock_ddk::ConnectCallback>>
+ fidl_protocols_;
+ std::unordered_map<std::string_view, std::vector<uint8_t>> firmware_;
+
+ size_t size_ = 0;
+
+ // Map of metadata set by SetMetadata.
+ std::unordered_map<uint32_t, std::vector<uint8_t>> metadata_;
+ // Map of variables set by SetVariable.
+ std::unordered_map<std::string, std::string> variables_;
+
+ // parent in the device tree
+ MockDevice* parent_ = nullptr; // This will default to a nullptr, for the root parent.
+
+ const zx_protocol_device_t* ops_ = &kDefaultOps;
+ // reserved for driver use; will not be touched by MockDevice
+ void* ctx_ = nullptr;
+
+ std::string name_;
+
+ std::vector<zx_device_prop_t> props_;
+ std::vector<zx_device_str_prop_t> str_props_;
+ zx::vmo inspect_;
+ async_dispatcher_t* dispatcher_ = nullptr;
+ zx::channel client_remote_;
+};
+
+namespace mock_ddk {
+// Helper function:
+// Performs the unbind and release of any device below the input device that
+// has had device_async_remove called on it.
+// returns an error if there was a problem waiting for UnbindReply to be called.
+// This function will call unbind devices that are to be removed, and block
+// until device_unbind_reply is called.
+zx_status_t ReleaseFlaggedDevices(MockDevice* device);
+
+} // namespace mock_ddk
+
+#endif // SRC_DEVICES_TESTING_MOCK_DDK_MOCK_DEVICE_H_
diff --git a/third_party/iwlwifi/test/mock-function.h b/third_party/iwlwifi/test/mock-function.h
new file mode 100644
index 0000000..2d1c565
--- /dev/null
+++ b/third_party/iwlwifi/test/mock-function.h
@@ -0,0 +1,202 @@
+// Copyright 2019 The Fuchsia Authors. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef LIB_MOCK_FUNCTION_MOCK_FUNCTION_H_
+#define LIB_MOCK_FUNCTION_MOCK_FUNCTION_H_
+
+#include <memory>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace mock_function {
+
+// This class mocks a single function. The Expect*() functions are used by the test to set
+// expectations, and Call() is used by the code under test. There are three variants:
+//
+// * ExpectCall(return_value, arg1, arg2, ...) sets the expectation that the call will be made with
+// arguments `arg1`, `arg2`, etc., each compared using operator==. `return_value` will be returned
+// unconditionally, or is omitted if the function returns void.
+// * ExpectCallWithMatcher(matcher) uses a `matcher` validate the arguments. The matcher will be
+// called with the arguments to the mocked function call, and the call will return the matcher's
+// return value.
+// * ExpectNoCall() expects that the function will not be called.
+//
+// Example:
+//
+// class SomeClassTest : SomeClass {
+// public:
+// zx_status_t CallsSomeMethod();
+//
+// mock_function::MockFunction<zx_status_t, uint32_t, uint32_t>& mock_SomeMethod() {
+// return mock_some_method_;
+// }
+//
+// private:
+// zx_status_t SomeMethod(uint32_t a, uint32_t b) override {
+// return mock_some_method_.Call(a, b);
+// }
+//
+// mock_function::MockFunction<zx_status_t, uint32_t, uint32_t> mock_some_method_;
+// };
+//
+// TEST(SomeDriver, SomeTest) {
+// SomeClassTest test;
+// test.mock_SomeMethod().ExpectCall(ZX_OK, 100, 30);
+// test.mock_SomeMethod().ExpectCallWithMatcher([](uint32_t a, uint32_t b) {
+// EXPECT_EQ(200, a);
+// EXPECT_EQ(60, b);
+// return ZX_OK;
+// });
+//
+// EXPECT_OK(test.CallsSomeMethod(100, 30));
+// EXPECT_OK(test.CallsSomeMethod(200, 60));
+//
+// test.mock_SomeMethod().VerifyAndClear();
+// }
+
+template <typename R, typename... Ts>
+class MockFunction {
+ public:
+ template <typename... As>
+ MockFunction& ExpectCall(R retval, As&&... args) {
+ static_assert(sizeof...(As) == sizeof...(Ts), "wrong number of arguments to ExpectCall");
+ using ArgsTuple = std::tuple<typename std::decay<Ts>::type...>;
+ expectations_.emplace_back(MakeExpectation(
+ [return_value = std::move(retval),
+ expected_args = ArgsTuple(std::forward<As>(args)...)](const Ts&... actual_args) mutable {
+ EXPECT_EQ(expected_args, std::tie(actual_args...));
+ return std::move(return_value);
+ }));
+ has_expectations_ = true;
+ return *this;
+ }
+
+ template <typename M>
+ MockFunction& ExpectCallWithMatcher(M matcher) {
+ expectations_.emplace_back(MakeExpectation<M>(std::move(matcher)));
+ has_expectations_ = true;
+ return *this;
+ }
+
+ MockFunction& ExpectNoCall() {
+ has_expectations_ = true;
+ return *this;
+ }
+
+ R Call(Ts... args) {
+ std::unique_ptr<Expectation> exp;
+ CallHelper(&exp);
+ return exp->Match(std::move(args)...);
+ }
+
+ bool HasExpectations() const { return has_expectations_; }
+
+ void VerifyAndClear() {
+ EXPECT_EQ(expectation_index_, expectations_.size());
+ expectations_.clear();
+ expectation_index_ = 0;
+ }
+
+ private:
+ struct Expectation {
+ virtual ~Expectation() = default;
+ virtual R Match(Ts&&... actual_args) = 0;
+ };
+
+ template <typename M>
+ std::unique_ptr<Expectation> MakeExpectation(M matcher) {
+ struct ExpectationWithMatcher : public Expectation {
+ explicit ExpectationWithMatcher(M matcher) : matcher(std::move(matcher)) {}
+ R Match(Ts&&... actual_args) override { return matcher(std::forward<Ts>(actual_args)...); }
+ M matcher;
+ };
+
+ return std::make_unique<ExpectationWithMatcher>(std::move(matcher));
+ }
+
+ void CallHelper(std::unique_ptr<Expectation>* exp) {
+ const bool enough_expectations_were_set = expectation_index_ < expectations_.size();
+ ZX_ASSERT(enough_expectations_were_set);
+ *exp = std::move(expectations_[expectation_index_++]);
+ }
+
+ bool has_expectations_ = false;
+ std::vector<std::unique_ptr<Expectation>> expectations_;
+ size_t expectation_index_ = 0;
+};
+
+template <typename... Ts>
+class MockFunction<void, Ts...> {
+ public:
+ template <typename... As>
+ MockFunction& ExpectCall(As&&... args) {
+ static_assert(sizeof...(As) == sizeof...(Ts), "wrong number of arguments to ExpectCall");
+ using ArgsTuple = std::tuple<typename std::decay<Ts>::type...>;
+ expectations_.emplace_back(MakeExpectation(
+ [expected_args = ArgsTuple(std::forward<As>(args)...)](const Ts&... actual_args) {
+ EXPECT_EQ(expected_args, std::tie(actual_args...));
+ }));
+ has_expectations_ = true;
+ return *this;
+ }
+
+ template <typename M>
+ MockFunction& ExpectCallWithMatcher(M matcher) {
+ expectations_.emplace_back(MakeExpectation<M>(std::move(matcher)));
+ has_expectations_ = true;
+ return *this;
+ }
+
+ MockFunction& ExpectNoCall() {
+ has_expectations_ = true;
+ return *this;
+ }
+
+ void Call(Ts... args) {
+ std::unique_ptr<Expectation> exp;
+ CallHelper(&exp);
+ exp->Match(std::move(args)...);
+ }
+
+ bool HasExpectations() const { return has_expectations_; }
+
+ void VerifyAndClear() {
+ ASSERT_EQ(expectation_index_, expectations_.size());
+ expectations_.clear();
+ expectation_index_ = 0;
+ }
+
+ private:
+ struct Expectation {
+ virtual ~Expectation() = default;
+ virtual void Match(Ts&&... actual_args) = 0;
+ };
+
+ template <typename M>
+ std::unique_ptr<Expectation> MakeExpectation(M matcher) {
+ struct ExpectationWithMatcher : public Expectation {
+ explicit ExpectationWithMatcher(M matcher) : matcher(std::move(matcher)) {}
+ void Match(Ts&&... actual_args) override { matcher(std::forward<Ts>(actual_args)...); }
+ M matcher;
+ };
+
+ return std::make_unique<ExpectationWithMatcher>(std::move(matcher));
+ }
+
+ void CallHelper(std::unique_ptr<Expectation>* exp) {
+ const bool enough_expectations_were_set = expectation_index_ < expectations_.size();
+ ZX_ASSERT(enough_expectations_were_set);
+ *exp = std::move(expectations_[expectation_index_++]);
+ }
+
+ bool has_expectations_ = false;
+ std::vector<std::unique_ptr<Expectation>> expectations_;
+ size_t expectation_index_ = 0;
+};
+
+} // namespace mock_function
+
+#endif // LIB_MOCK_FUNCTION_MOCK_FUNCTION_H_
diff --git a/third_party/iwlwifi/test/mvm-test.cc b/third_party/iwlwifi/test/mvm-test.cc
index ad1033b..d017baa 100644
--- a/third_party/iwlwifi/test/mvm-test.cc
+++ b/third_party/iwlwifi/test/mvm-test.cc
@@ -2,14 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <lib/mock-function/mock-function.h>
#include <zircon/compiler.h>
#include <iterator>
#include <memory>
-#include <gtest/gtest.h>
-
extern "C" {
#include "third_party/iwlwifi/mvm/mvm.h"
#include "third_party/iwlwifi/mvm/time-event.h"
@@ -22,6 +19,9 @@
#include "third_party/iwlwifi/test/sim-time-event.h"
#include "third_party/iwlwifi/test/single-ap-test.h"
#include "third_party/iwlwifi/test/wlan-pkt-builder.h"
+#include "third_party/iwlwifi/test/mock-function.h"
+#include "third_party/iwlwifi/test/test.h"
+
namespace wlan {
namespace testing {
@@ -49,7 +49,7 @@
public:
explicit TestRxcb(struct device* dev, void* pkt_data, size_t pkt_len) {
struct iwl_iobuf* io_buf = nullptr;
- ASSERT_OK(iwl_iobuf_allocate_contiguous(dev, pkt_len + sizeof(struct iwl_rx_packet), &io_buf));
+ EXPECT_OK(iwl_iobuf_allocate_contiguous(dev, pkt_len + sizeof(struct iwl_rx_packet), &io_buf));
_iobuf = io_buf;
_offset = 0;
@@ -772,7 +772,7 @@
mvm_->fw_id_to_mac_id[0] = &sta_;
for (size_t i = 0; i < std::size(sta_.txq); ++i) {
sta_.txq[i] = reinterpret_cast<struct iwl_mvm_txq*>(calloc(1, sizeof(struct iwl_mvm_txq)));
- ASSERT_NE(nullptr, sta_.txq[i]);
+ EXPECT_NE(nullptr, sta_.txq[i]);
}
}
diff --git a/third_party/iwlwifi/test/no_ddk.cc b/third_party/iwlwifi/test/no_ddk.cc
new file mode 100644
index 0000000..c942570
--- /dev/null
+++ b/third_party/iwlwifi/test/no_ddk.cc
@@ -0,0 +1,167 @@
+// Copyright 2020 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <lib/ddk/device.h>
+#include <lib/ddk/driver.h>
+#include <lib/syslog/logger.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <zircon/errors.h>
+#include <zircon/syscalls/log.h>
+#include <zircon/types.h>
+
+namespace no_ddk {
+
+fx_log_severity_t kMinLogSeverity = FX_LOG_INFO;
+size_t kFakeFWSize = 0x1000;
+
+} // namespace no_ddk
+
+__EXPORT
+zx_status_t device_add_from_driver(zx_driver_t* drv, zx_device_t* parent, device_add_args_t* args,
+ zx_device_t** out) {
+ return ZX_OK;
+}
+
+__EXPORT
+void device_async_remove(zx_device_t* device) {}
+
+__EXPORT
+void device_init_reply(zx_device_t* device, zx_status_t status,
+ const device_init_reply_args_t* args) {}
+
+__EXPORT
+void device_unbind_reply(zx_device_t* device) {}
+
+__EXPORT void device_suspend_reply(zx_device_t* dev, zx_status_t status, uint8_t out_state) {}
+
+__EXPORT void device_resume_reply(zx_device_t* dev, zx_status_t status, uint8_t out_power_state,
+ uint32_t out_perf_state) {}
+
+__EXPORT
+zx_status_t device_add_metadata(zx_device_t* device, uint32_t type, const void* data,
+ size_t length) {
+ return ZX_OK;
+}
+
+__EXPORT
+zx_status_t device_get_protocol(const zx_device_t* device, uint32_t proto_id, void* protocol) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+__EXPORT
+zx_status_t device_open_protocol_session_multibindable(const zx_device_t* dev, uint32_t proto_id,
+ void* protocol) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT
+zx_off_t device_get_size(zx_device_t* device) { return 0; }
+
+__EXPORT
+zx_status_t device_get_metadata(zx_device_t* device, uint32_t type, void* buf, size_t buflen,
+ size_t* actual) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT
+zx_status_t device_get_metadata_size(zx_device_t* device, uint32_t type, size_t* out_size) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT zx_status_t device_get_fragment_protocol(zx_device_t* device, const char* name,
+ uint32_t proto_id, void* protocol) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT
+zx_status_t device_get_fragment_metadata(zx_device_t* device, const char* name, uint32_t type,
+ void* buf, size_t buflen, size_t* actual) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT
+zx_status_t device_get_profile(zx_device_t* device, uint32_t priority, const char* name,
+ zx_handle_t* out_profile) {
+ // This is currently a no-op.
+ *out_profile = ZX_HANDLE_INVALID;
+ return ZX_OK;
+}
+
+__EXPORT
+zx_status_t device_get_deadline_profile(zx_device_t* device, uint64_t capacity, uint64_t deadline,
+ uint64_t period, const char* name,
+ zx_handle_t* out_profile) {
+ // This is currently a no-op.
+ *out_profile = ZX_HANDLE_INVALID;
+ return ZX_OK;
+}
+
+__EXPORT
+zx_status_t device_set_profile_by_role(zx_device_t* device, zx_handle_t thread, const char* role,
+ size_t role_size) {
+ // This is currently a no-op.
+ return ZX_OK;
+}
+
+__EXPORT __WEAK zx_status_t load_firmware_from_driver(zx_driver_t* drv, zx_device_t* dev,
+ const char* path, zx_handle_t* fw,
+ size_t* size) {
+ // This is currently a no-op.
+ *fw = ZX_HANDLE_INVALID;
+ *size = no_ddk::kFakeFWSize;
+ return ZX_OK;
+}
+
+__EXPORT
+zx_status_t device_rebind(zx_device_t* device) { return ZX_OK; }
+
+__EXPORT uint32_t device_get_fragment_count(zx_device_t* dev) { return 0; }
+
+__EXPORT void device_get_fragments(zx_device_t* dev, composite_device_fragment_t* comp_list,
+ size_t comp_count, size_t* comp_actual) {}
+
+__EXPORT
+void device_fidl_transaction_take_ownership(fidl_txn_t* txn, device_fidl_txn_t* new_txn) {}
+
+// Please do not use get_root_resource() in new code. See ZX-1467.
+__EXPORT
+zx_handle_t get_root_resource() { return ZX_HANDLE_INVALID; }
+
+__EXPORT zx_status_t device_get_variable(zx_device_t* device, const char* name, char* out,
+ size_t out_size, size_t* size_actual) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+__EXPORT zx_status_t driver_log_set_tags_internal(const zx_driver_t* drv, const char* const* tags,
+ size_t num_tags) {
+ return ZX_ERR_NOT_SUPPORTED;
+}
+
+extern "C" bool driver_log_severity_enabled_internal(const zx_driver_t* drv,
+ fx_log_severity_t flag) {
+ return flag >= no_ddk::kMinLogSeverity;
+}
+
+extern "C" void driver_logvf_internal(const zx_driver_t* drv, fx_log_severity_t flag,
+ const char* tag, const char* file, int line, const char* msg,
+ va_list args) {
+ vfprintf(stdout, msg, args);
+ putchar('\n');
+}
+
+extern "C" void driver_logf_internal(const zx_driver_t* drv, fx_log_severity_t flag,
+ const char* tag, const char* file, int line, const char* msg,
+ ...) {
+ va_list args;
+ va_start(args, msg);
+ driver_logvf_internal(drv, flag, tag, file, line, msg, args);
+ va_end(args);
+}
+
+__EXPORT
+__WEAK zx_driver_rec __zircon_driver_rec__ = {
+ .ops = {},
+ .driver = {},
+};
diff --git a/third_party/iwlwifi/test/nvm-test.cc b/third_party/iwlwifi/test/nvm-test.cc
index 355057d..2114b08 100644
--- a/third_party/iwlwifi/test/nvm-test.cc
+++ b/third_party/iwlwifi/test/nvm-test.cc
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <gtest/gtest.h>
-
#include "third_party/iwlwifi/test/sim-nvm.h"
extern "C" {
@@ -12,6 +10,7 @@
#include "third_party/iwlwifi/iwl-drv.h"
#include "third_party/iwlwifi/test/fake-ucode-test.h"
+#include "third_party/iwlwifi/test/test.h"
namespace wlan::testing {
namespace {
diff --git a/third_party/iwlwifi/test/pcie-test.cc b/third_party/iwlwifi/test/pcie-test.cc
index 793a4f8..46f09c6 100644
--- a/third_party/iwlwifi/test/pcie-test.cc
+++ b/third_party/iwlwifi/test/pcie-test.cc
@@ -16,8 +16,7 @@
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
-#include <lib/fake-bti/bti.h>
-#include <lib/mock-function/mock-function.h>
+//#include <lib/fake-bti/bti.h>
#include <lib/sync/completion.h>
#include <lib/zx/bti.h>
#include <zircon/listnode.h>
@@ -26,10 +25,6 @@
#include <string>
#include <thread>
-#include <gtest/gtest.h>
-
-//#include "src/devices/testing/mock-ddk/mock-device.h"
-
extern "C" {
#include "third_party/iwlwifi/fw/api/commands.h"
#include "third_party/iwlwifi/iwl-csr.h"
@@ -43,13 +38,18 @@
#include "third_party/iwlwifi/platform/memory.h"
#include "third_party/iwlwifi/platform/pcie-device.h"
#include "third_party/iwlwifi/test/wlan-pkt-builder.h"
-#include "src/devices/pci/testing/pci_protocol_fake.h"
+#include "third_party/iwlwifi/test/mock-function.h"
+#include "third_party/iwlwifi/test/test.h"
+#include "third_party/iwlwifi/test/mock-device.h"
+
+//#include "src/devices/pci/testing/pci_protocol_fake.h"
namespace {
-constexpr int kTestDeviceId = 0x095a;
-constexpr int kTestSubsysDeviceId = 0x9e10;
+//constexpr int kTestDeviceId = 0x095a;
+//constexpr int kTestSubsysDeviceId = 0x9e10;
+#if 0
TEST(MockDdkTesterPci, DeviceLifeCycle) {
auto parent = MockDevice::FakeRootParent();
@@ -94,6 +94,7 @@
mock_ddk::ReleaseFlaggedDevices(pcie_device.get());
}
+#endif
class PcieTest;
@@ -153,12 +154,12 @@
public:
PcieTest() {
task_loop_ = std::make_unique<::async::Loop>(&kAsyncLoopConfigNoAttachToCurrentThread);
- ASSERT_OK(task_loop_->StartThread("iwlwifi-test-task-worker", nullptr));
+ EXPECT_OK(task_loop_->StartThread("iwlwifi-test-task-worker", nullptr));
irq_loop_ = std::make_unique<::async::Loop>(&kAsyncLoopConfigNoAttachToCurrentThread);
- ASSERT_OK(irq_loop_->StartThread("iwlwifi-test-irq-worker", nullptr));
+ EXPECT_OK(irq_loop_->StartThread("iwlwifi-test-irq-worker", nullptr));
pci_dev_.dev.task_dispatcher = task_loop_->dispatcher();
pci_dev_.dev.irq_dispatcher = irq_loop_->dispatcher();
- fake_bti_create(&pci_dev_.dev.bti);
+ //fake_bti_create(&pci_dev_.dev.bti);
trans_ops_.write8 = write8_wrapper;
trans_ops_.write32 = write32_wrapper;
@@ -175,7 +176,7 @@
cfg_.base_params = &base_params_;
trans_ =
iwl_trans_alloc(sizeof(struct iwl_trans_pcie_wrapper), &pci_dev_.dev, &cfg_, &trans_ops_);
- ASSERT_NE(trans_, nullptr);
+ EXPECT_NE(trans_, nullptr);
auto wrapper = reinterpret_cast<iwl_trans_pcie_wrapper*>(IWL_TRANS_GET_PCIE_TRANS(trans_));
wrapper->test = this;
trans_pcie_ = &wrapper->trans_pcie;
@@ -414,7 +415,7 @@
trans_pcie_->rx_buf_size = IWL_AMSDU_2K;
// This is the value we get when we call io_buffer_phys() in the fake environment.
- const size_t kFakePhys = FAKE_BTI_PHYS_ADDR;
+ const size_t kFakePhys = 0x00; //FAKE_BTI_PHYS_ADDR;
// Set expectation for register accesses.
mock_write_prph_.ExpectCall(RFH_RXF_DMA_CFG, 0);
diff --git a/third_party/iwlwifi/test/sim-trans.cc b/third_party/iwlwifi/test/sim-trans.cc
index b1a3019..c4ea084 100644
--- a/third_party/iwlwifi/test/sim-trans.cc
+++ b/third_party/iwlwifi/test/sim-trans.cc
@@ -37,7 +37,7 @@
#include "third_party/iwlwifi/platform/mvm-mlme.h"
#include "third_party/iwlwifi/platform/rcu-manager.h"
#include "third_party/iwlwifi/platform/wlanphy-impl-device.h"
-//#include "src/devices/testing/mock-ddk/mock-device.h"
+#include "third_party/iwlwifi/test/mock-device.h"
using wlan::testing::IWL_TRANS_GET_SIM_TRANS;
using wlan::testing::sim_trans_priv;
@@ -328,7 +328,7 @@
SimTransport::~SimTransport() {
if (sim_device_) {
sim_device_->DdkAsyncRemove();
- //mock_ddk::ReleaseFlaggedDevices(sim_device_->zxdev());
+ mock_ddk::ReleaseFlaggedDevices(sim_device_->zxdev());
}
zx_handle_close(device_.bti);
}
diff --git a/third_party/iwlwifi/test/single-ap-test.cc b/third_party/iwlwifi/test/single-ap-test.cc
index 4223102..839af55 100644
--- a/third_party/iwlwifi/test/single-ap-test.cc
+++ b/third_party/iwlwifi/test/single-ap-test.cc
@@ -17,8 +17,7 @@
//const common::MacAddr SingleApTest::default_macaddr_(kApAddr);
SingleApTest::SingleApTest()
-// : fake_parent_(MockDevice::FakeRootParent()), sim_trans_(fake_parent_.get()) {
- : sim_trans_(nullptr) {
+ : fake_parent_(MockDevice::FakeRootParent()), sim_trans_(fake_parent_.get()) {
// Add a default MVM firmware to the fake DDK.
TlvFwBuilder fw_builder;
@@ -34,7 +33,7 @@
(6 << FW_PHY_CFG_RX_CHAIN_POS)); // Rx antenna 2 and 1.
fw_builder.AddValue(IWL_UCODE_TLV_PHY_SKU, &ucode_phy_sku, sizeof(ucode_phy_sku));
- //fake_parent_->SetFirmware(fw_builder.GetBinary());
+ fake_parent_->SetFirmware(fw_builder.GetBinary());
zx_status_t status = sim_trans_.Init();
ZX_ASSERT_MSG(ZX_OK == status, "Transportation initialization failed: %s",
diff --git a/third_party/iwlwifi/test/single-ap-test.h b/third_party/iwlwifi/test/single-ap-test.h
index 392c6b3..7320942 100644
--- a/third_party/iwlwifi/test/single-ap-test.h
+++ b/third_party/iwlwifi/test/single-ap-test.h
@@ -12,7 +12,7 @@
#include <gtest/gtest.h>
#include "third_party/iwlwifi/test/sim-trans.h"
-//#include "src/devices/testing/mock-ddk/mock-device.h"
+#include "third_party/iwlwifi/test/mock-device.h"
namespace wlan::testing {
@@ -35,7 +35,7 @@
//static const common::MacAddr default_macaddr_;
- //std::shared_ptr<MockDevice> fake_parent_;
+ std::shared_ptr<MockDevice> fake_parent_;
SimTransport sim_trans_;
};
diff --git a/third_party/iwlwifi/test/sta-test.cc b/third_party/iwlwifi/test/sta-test.cc
index e478d86..c67ba5e 100644
--- a/third_party/iwlwifi/test/sta-test.cc
+++ b/third_party/iwlwifi/test/sta-test.cc
@@ -4,8 +4,6 @@
// Used to test mvm/sta.c
-#include <lib/mock-function/mock-function.h>
-
#include <gtest/gtest.h>
extern "C" {
@@ -15,6 +13,7 @@
#include "third_party/iwlwifi/test/mock-trans.h"
#include "third_party/iwlwifi/test/single-ap-test.h"
+#include "third_party/iwlwifi/test/mock-function.h"
namespace wlan::testing {
namespace {
diff --git a/third_party/iwlwifi/test/test.h b/third_party/iwlwifi/test/test.h
index 0d5dbef..2286db0 100644
--- a/third_party/iwlwifi/test/test.h
+++ b/third_party/iwlwifi/test/test.h
@@ -9,4 +9,6 @@
#define EXPECT_OK(val) EXPECT_EQ(ZX_OK, (val))
#define EXPECT_NOT_NULL(val) EXPECT_NE(nullptr, (val))
#define EXPECT_BYTES_EQ(src1, src2, sz) EXPECT_EQ(0, std::memcmp((src1), (src2), (sz)))
-#define ASSERT_NOT_NULL(val) EXPECT_NE(nullptr, (val))
+#define ASSERT_NOT_NULL(val) ASSERT_NE(nullptr, (val))
+#define ASSERT_OK(val) ASSERT_EQ(ZX_OK, (val))
+#define ASSERT_NULL(val) ASSERT_EQ(nullptr, (val))
diff --git a/third_party/iwlwifi/test/wlan-pkt-builder.cc b/third_party/iwlwifi/test/wlan-pkt-builder.cc
index e6b64f3..94ea532 100644
--- a/third_party/iwlwifi/test/wlan-pkt-builder.cc
+++ b/third_party/iwlwifi/test/wlan-pkt-builder.cc
@@ -15,9 +15,9 @@
wlan_pkt_(std::make_unique<wlan_tx_packet_t>()),
buf_(new uint8_t[len]),
len_(len) {
- ASSERT_NOT_NULL(mac_pkt_);
- ASSERT_NOT_NULL(wlan_pkt_);
- ASSERT_NOT_NULL(buf_);
+ EXPECT_NOT_NULL(mac_pkt_);
+ EXPECT_NOT_NULL(wlan_pkt_);
+ EXPECT_NOT_NULL(buf_);
std::memcpy(&*buf_, buf, len);
*mac_pkt_ = {};
diff --git a/third_party/iwlwifi/test/wlan-softmac-device-test.cc b/third_party/iwlwifi/test/wlan-softmac-device-test.cc
index 58c8faa..6f29dbb 100644
--- a/third_party/iwlwifi/test/wlan-softmac-device-test.cc
+++ b/third_party/iwlwifi/test/wlan-softmac-device-test.cc
@@ -8,8 +8,7 @@
#include <fuchsia/hardware/wlan/associnfo/cpp/banjo.h>
#include <fuchsia/hardware/wlan/softmac/cpp/banjo.h>
#include <fuchsia/wlan/common/c/banjo.h>
-#include <fuchsia/wlan/ieee80211/c/fidl.h>
-#include <lib/mock-function/mock-function.h>
+#include <fuchsia/wlan/ieee80211/c/banjo.h>
#include <lib/zx/channel.h>
#include <stdlib.h>
#include <zircon/errors.h>
@@ -33,6 +32,7 @@
#include "third_party/iwlwifi/test/mock-trans.h"
#include "third_party/iwlwifi/test/single-ap-test.h"
#include "third_party/iwlwifi/test/wlan-pkt-builder.h"
+#include "third_party/iwlwifi/test/mock-function.h"
namespace wlan::testing {
namespace {
@@ -264,8 +264,8 @@
MacInterfaceTest() : ifc_{ .ops = &proto_ops_, } , proto_ops_{ .recv = recv_wrapper, } {
zx_handle_t wlanphy_impl_channel = mvmvif_->mlme_channel;
zx::channel mlme_channel;
- ASSERT_EQ(ZX_OK, device_->WlanSoftmacStart(&ifc_, &mlme_channel));
- ASSERT_EQ(wlanphy_impl_channel, mlme_channel);
+ EXPECT_EQ(ZX_OK, device_->WlanSoftmacStart(&ifc_, &mlme_channel));
+ EXPECT_EQ(wlanphy_impl_channel, mlme_channel);
// Add the interface to MVM instance.
mvmvif_->mvm->mvmvif[0] = mvmvif_.get();
@@ -409,7 +409,7 @@
it++) {
printf(" ==> 0x%04x\n", it->cmd_id_);
}
- ASSERT_TRUE(expected_cmd_ids.empty(), "The expected command set is not empty.");
+ EXPECT_TRUE(expected_cmd_ids.empty());
mock_tx_.VerifyAndClear();
}
@@ -880,14 +880,14 @@
// Default cipher configuration for WPA2/3 PTK. This is data frame protection, required for
// WPA2/3.
- key_config->cipher_type = fuchsia_wlan_ieee80211_CipherSuiteType_CCMP_128;
+ key_config->cipher_type = CIPHER_SUITE_TYPE_CCMP_128;
key_config->key_type = WLAN_KEY_TYPE_PAIRWISE;
key_config->key_idx = 0;
ASSERT_EQ(ZX_OK, SetKey(key_config));
// Default cipher configuration for WPA2/3 IGTK. This is management frame protection, optional
// for WPA2 and required for WPA3.
- key_config->cipher_type = fuchsia_wlan_ieee80211_CipherSuiteType_BIP_CMAC_128;
+ key_config->cipher_type = CIPHER_SUITE_TYPE_BIP_CMAC_128;
key_config->key_type = WLAN_KEY_TYPE_IGTK;
key_config->key_idx = 1;
ASSERT_EQ(ZX_OK, SetKey(key_config));
diff --git a/third_party/iwlwifi/test/wlanphy-impl-device-test.cc b/third_party/iwlwifi/test/wlanphy-impl-device-test.cc
index 0da8b58..54177b5 100644
--- a/third_party/iwlwifi/test/wlanphy-impl-device-test.cc
+++ b/third_party/iwlwifi/test/wlanphy-impl-device-test.cc
@@ -111,14 +111,14 @@
ASSERT_NE(mvmvif, nullptr);
ASSERT_EQ(mvmvif->mac_role, WLAN_MAC_ROLE_CLIENT);
// Count includes phy device in addition to the newly created mac device.
- //ASSERT_EQ(fake_parent_->descendant_count(), 2);
+ ASSERT_EQ(fake_parent_->descendant_count(), 2);
device_->parent()->GetLatestChild()->InitOp();
// Remove interface
ASSERT_EQ(device_->WlanphyImplDestroyIface(0), ZX_OK);
- //mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
+ mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
ASSERT_EQ(mvm->mvmvif[iface_id], nullptr);
- //ASSERT_EQ(fake_parent_->descendant_count(), 1);
+ ASSERT_EQ(fake_parent_->descendant_count(), 1);
}
TEST_F(WlanphyImplDeviceTest, PhyCreateDestroyMultipleInterfaces) {
@@ -134,7 +134,7 @@
ASSERT_EQ(device_->WlanphyImplCreateIface(&req, &iface_id), ZX_OK);
ASSERT_EQ(iface_id, 0);
ASSERT_EQ(mvm->mvmvif[iface_id]->mac_role, WLAN_MAC_ROLE_CLIENT);
- //ASSERT_EQ(fake_parent_->descendant_count(), 2);
+ ASSERT_EQ(fake_parent_->descendant_count(), 2);
device_->parent()->GetLatestChild()->InitOp();
// Add 2nd interface
@@ -142,7 +142,7 @@
ASSERT_EQ(iface_id, 1);
ASSERT_NE(mvm->mvmvif[iface_id], nullptr);
ASSERT_EQ(mvm->mvmvif[iface_id]->mac_role, WLAN_MAC_ROLE_CLIENT);
- //ASSERT_EQ(fake_parent_->descendant_count(), 3);
+ ASSERT_EQ(fake_parent_->descendant_count(), 3);
device_->parent()->GetLatestChild()->InitOp();
// Add 3rd interface
@@ -150,21 +150,21 @@
ASSERT_EQ(iface_id, 2);
ASSERT_NE(mvm->mvmvif[iface_id], nullptr);
ASSERT_EQ(mvm->mvmvif[iface_id]->mac_role, WLAN_MAC_ROLE_CLIENT);
- //ASSERT_EQ(fake_parent_->descendant_count(), 4);
+ ASSERT_EQ(fake_parent_->descendant_count(), 4);
device_->parent()->GetLatestChild()->InitOp();
// Remove the 2nd interface
ASSERT_EQ(device_->WlanphyImplDestroyIface(1), ZX_OK);
- //mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
+ mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
ASSERT_EQ(mvm->mvmvif[1], nullptr);
- //ASSERT_EQ(fake_parent_->descendant_count(), 3);
+ ASSERT_EQ(fake_parent_->descendant_count(), 3);
// Add a new interface and it should be the 2nd one.
ASSERT_EQ(device_->WlanphyImplCreateIface(&req, &iface_id), ZX_OK);
ASSERT_EQ(iface_id, 1);
ASSERT_NE(mvm->mvmvif[iface_id], nullptr);
ASSERT_EQ(mvm->mvmvif[iface_id]->mac_role, WLAN_MAC_ROLE_CLIENT);
- //ASSERT_EQ(fake_parent_->descendant_count(), 4);
+ ASSERT_EQ(fake_parent_->descendant_count(), 4);
device_->parent()->GetLatestChild()->InitOp();
// Add 4th interface
@@ -172,40 +172,40 @@
ASSERT_EQ(iface_id, 3);
ASSERT_NE(mvm->mvmvif[iface_id], nullptr);
ASSERT_EQ(mvm->mvmvif[iface_id]->mac_role, WLAN_MAC_ROLE_CLIENT);
- //ASSERT_EQ(fake_parent_->descendant_count(), 5);
+ ASSERT_EQ(fake_parent_->descendant_count(), 5);
device_->parent()->GetLatestChild()->InitOp();
// Add 5th interface and it should fail
ASSERT_EQ(device_->WlanphyImplCreateIface(&req, &iface_id), ZX_ERR_NO_RESOURCES);
- //ASSERT_EQ(fake_parent_->descendant_count(), 5);
+ ASSERT_EQ(fake_parent_->descendant_count(), 5);
// Remove the 2nd interface
ASSERT_EQ(device_->WlanphyImplDestroyIface(1), ZX_OK);
- //mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
+ mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
ASSERT_EQ(mvm->mvmvif[1], nullptr);
- //ASSERT_EQ(fake_parent_->descendant_count(), 4);
+ ASSERT_EQ(fake_parent_->descendant_count(), 4);
// Remove the 3rd interface
ASSERT_EQ(device_->WlanphyImplDestroyIface(2), ZX_OK);
- //mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
+ mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
ASSERT_EQ(mvm->mvmvif[2], nullptr);
- //ASSERT_EQ(fake_parent_->descendant_count(), 3);
+ ASSERT_EQ(fake_parent_->descendant_count(), 3);
// Remove the 4th interface
ASSERT_EQ(device_->WlanphyImplDestroyIface(3), ZX_OK);
- //mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
+ mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
ASSERT_EQ(mvm->mvmvif[3], nullptr);
- //ASSERT_EQ(fake_parent_->descendant_count(), 2);
+ ASSERT_EQ(fake_parent_->descendant_count(), 2);
// Remove the 1st interface
ASSERT_EQ(device_->WlanphyImplDestroyIface(0), ZX_OK);
- //mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
+ mock_ddk::ReleaseFlaggedDevices(fake_parent_.get());
ASSERT_EQ(mvm->mvmvif[0], nullptr);
- //ASSERT_EQ(fake_parent_->descendant_count(), 1);
+ ASSERT_EQ(fake_parent_->descendant_count(), 1);
// Remove the 1st interface again and it should fail.
ASSERT_EQ(device_->WlanphyImplDestroyIface(0), ZX_ERR_NOT_FOUND);
- //ASSERT_EQ(fake_parent_->descendant_count(), 1);
+ ASSERT_EQ(fake_parent_->descendant_count(), 1);
}
} // namespace