util.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * KUnit fixture to have a (configurable) wiphy
  4. *
  5. * Copyright (C) 2023 Intel Corporation
  6. */
  7. #include <linux/ieee80211.h>
  8. #include <net/cfg80211.h>
  9. #include <kunit/test.h>
  10. #include <kunit/test-bug.h>
  11. #include "util.h"
  12. int t_wiphy_init(struct kunit_resource *resource, void *ctx)
  13. {
  14. struct kunit *test = kunit_get_current_test();
  15. struct cfg80211_ops *ops;
  16. struct wiphy *wiphy;
  17. struct t_wiphy_priv *priv;
  18. ops = kzalloc_obj(*ops);
  19. KUNIT_ASSERT_NOT_NULL(test, ops);
  20. wiphy = wiphy_new_nm(ops, sizeof(*priv), "kunit");
  21. KUNIT_ASSERT_NOT_NULL(test, wiphy);
  22. priv = wiphy_priv(wiphy);
  23. priv->ctx = ctx;
  24. priv->ops = ops;
  25. /* Initialize channels, feel free to add more here channels/bands */
  26. memcpy(priv->channels_2ghz, channels_2ghz, sizeof(channels_2ghz));
  27. wiphy->bands[NL80211_BAND_2GHZ] = &priv->band_2ghz;
  28. priv->band_2ghz.channels = priv->channels_2ghz;
  29. priv->band_2ghz.n_channels = ARRAY_SIZE(channels_2ghz);
  30. resource->data = wiphy;
  31. resource->name = "wiphy";
  32. return 0;
  33. }
  34. void t_wiphy_exit(struct kunit_resource *resource)
  35. {
  36. struct t_wiphy_priv *priv;
  37. struct cfg80211_ops *ops;
  38. priv = wiphy_priv(resource->data);
  39. ops = priv->ops;
  40. /* Should we ensure anything about the state here?
  41. * e.g. full destruction or no calls to any ops on destruction?
  42. */
  43. wiphy_free(resource->data);
  44. kfree(ops);
  45. }