qdf_hashtable_test.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #include "qdf_hashtable.h"
  19. #include "qdf_hashtable_test.h"
  20. #include "qdf_trace.h"
  21. /* 16 buckets */
  22. #define QDF_HT_HASH_BITS 4
  23. struct qdf_ht_test_item {
  24. struct qdf_ht_entry entry;
  25. uintptr_t key;
  26. };
  27. static uint32_t qdf_ht_test_single(void)
  28. {
  29. const int bits = QDF_HT_HASH_BITS;
  30. struct qdf_ht_test_item item = { .key = (uintptr_t)&bits };
  31. struct qdf_ht_test_item *cursor;
  32. int i, count;
  33. qdf_ht_declare(ht, QDF_HT_HASH_BITS);
  34. qdf_ht_init(ht);
  35. qdf_ht_add(ht, &item.entry, item.key);
  36. qdf_ht_get(ht, cursor, entry, item.key, key);
  37. QDF_BUG(cursor);
  38. QDF_BUG(cursor->key == item.key);
  39. count = 0;
  40. qdf_ht_for_each(ht, i, cursor, entry) {
  41. QDF_BUG(cursor->key == item.key);
  42. count++;
  43. }
  44. QDF_BUG(count == 1);
  45. count = 0;
  46. qdf_ht_for_each_in_bucket(ht, cursor, entry, item.key) {
  47. QDF_BUG(cursor->key == item.key);
  48. count++;
  49. }
  50. QDF_BUG(count == 1);
  51. count = 0;
  52. qdf_ht_for_each_match(ht, cursor, entry, item.key, key) {
  53. QDF_BUG(cursor->key == item.key);
  54. count++;
  55. }
  56. QDF_BUG(count == 1);
  57. qdf_ht_remove(&item.entry);
  58. QDF_BUG(qdf_ht_empty(ht));
  59. qdf_ht_deinit(ht);
  60. return 0;
  61. }
  62. uint32_t qdf_ht_unit_test(void)
  63. {
  64. uint32_t errors = 0;
  65. errors += qdf_ht_test_single();
  66. return errors;
  67. }