Skip to content

Commit

Permalink
net: sandbox: Add a priv ptr for tests to use
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Bin Meng <[email protected]>
  • Loading branch information
jhershbe committed Oct 10, 2018
1 parent 3f02c98 commit 9cbe597
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions arch/sandbox/include/asm/eth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
};

/*
Expand All @@ -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 */
20 changes: 20 additions & 0 deletions drivers/net/sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9cbe597

Please sign in to comment.