diff mbox series

[U-Boot,v2,07/10] net: sandbox: Add a priv ptr for tests to use

Message ID 20180926214902.38803-8-joe.hershberger@ni.com
State Accepted
Commit 9cbe5972c3c00e974482181cd4062d9229a9b7d5
Delegated to: Joe Hershberger
Headers show
Series net: Fix packet corruption issue when handling asynch replies | expand

Commit Message

Joe Hershberger Sept. 26, 2018, 9:48 p.m. UTC
Tests need to be able to pass their "unit test state" to the handlers
where asserts are evaluated. Add a function that allows the tests to set
this private data on the sandbox eth device.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

---

Changes in v2:
- add missing commit message
- rename local "uc_priv" variable to "dev_priv" to not be misleading.

 arch/sandbox/include/asm/eth.h |  9 +++++++++
 drivers/net/sandbox.c          | 20 ++++++++++++++++++++
 2 files changed, 29 insertions(+)

Comments

Bin Meng Sept. 27, 2018, 6:52 a.m. UTC | #1
On Thu, Sep 27, 2018 at 5:49 AM Joe Hershberger <joe.hershberger@ni.com> wrote:
>
> Tests need to be able to pass their "unit test state" to the handlers
> where asserts are evaluated. Add a function that allows the tests to set
> this private data on the sandbox eth device.
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>
> ---
>
> Changes in v2:
> - add missing commit message
> - rename local "uc_priv" variable to "dev_priv" to not be misleading.
>
>  arch/sandbox/include/asm/eth.h |  9 +++++++++
>  drivers/net/sandbox.c          | 20 ++++++++++++++++++++
>  2 files changed, 29 insertions(+)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Joe Hershberger Oct. 11, 2018, 7:25 p.m. UTC | #2
Hi Joe,

https://patchwork.ozlabs.org/patch/975419/ was applied to http://git.denx.de/?p=u-boot/u-boot-net.git

Thanks!
-Joe
diff mbox series

Patch

diff --git a/arch/sandbox/include/asm/eth.h b/arch/sandbox/include/asm/eth.h
index 7a49e98fa8..a6adec4e83 100644
--- a/arch/sandbox/include/asm/eth.h
+++ b/arch/sandbox/include/asm/eth.h
@@ -59,6 +59,7 @@  typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt,
  * recv_packet_length - lengths of the packet returned as received
  * recv_packets - number of packets returned
  * tx_handler - function to generate responses to sent packets
+ * priv - a pointer to some structure a test may want to keep track of
  */
 struct eth_sandbox_priv {
 	uchar fake_host_hwaddr[ARP_HLEN];
@@ -68,6 +69,7 @@  struct eth_sandbox_priv {
 	int recv_packet_length[PKTBUFSRX];
 	int recv_packets;
 	sandbox_eth_tx_hand_f *tx_handler;
+	void *priv;
 };
 
 /*
@@ -77,4 +79,11 @@  struct eth_sandbox_priv {
  */
 void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler);
 
+/*
+ * Set priv ptr
+ *
+ * priv - priv void ptr to store in the device
+ */
+void sandbox_eth_set_priv(int index, void *priv);
+
 #endif /* __ETH_H */
diff --git a/drivers/net/sandbox.c b/drivers/net/sandbox.c
index 9c0e0d009e..e26e72ecc1 100644
--- a/drivers/net/sandbox.c
+++ b/drivers/net/sandbox.c
@@ -206,6 +206,26 @@  void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler)
 		priv->tx_handler = sb_default_handler;
 }
 
+/*
+ * Set priv ptr
+ *
+ * priv - priv void ptr to store in the device
+ */
+void sandbox_eth_set_priv(int index, void *priv)
+{
+	struct udevice *dev;
+	struct eth_sandbox_priv *dev_priv;
+	int ret;
+
+	ret = uclass_get_device(UCLASS_ETH, index, &dev);
+	if (ret)
+		return;
+
+	dev_priv = dev_get_priv(dev);
+
+	dev_priv->priv = priv;
+}
+
 static int sb_eth_start(struct udevice *dev)
 {
 	struct eth_sandbox_priv *priv = dev_get_priv(dev);