etnaviv_bo_cache_test.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2016 Etnaviv Project
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Christian Gmeiner <christian.gmeiner@gmail.com>
  25. */
  26. #undef NDEBUG
  27. #include <assert.h>
  28. #include <fcntl.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <unistd.h>
  32. #include "xf86drm.h"
  33. #include "etnaviv_drmif.h"
  34. #include "etnaviv_drm.h"
  35. static void test_cache(struct etna_device *dev)
  36. {
  37. struct etna_bo *bo, *tmp;
  38. /* allocate and free some bo's with same size - we must
  39. * get the same bo over and over. */
  40. printf("testing bo cache ... ");
  41. bo = tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);
  42. assert(bo);
  43. etna_bo_del(bo);
  44. for (unsigned i = 0; i < 100; i++) {
  45. tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);
  46. etna_bo_del(tmp);
  47. assert(tmp == bo);
  48. }
  49. printf("ok\n");
  50. }
  51. static void test_size_rounding(struct etna_device *dev)
  52. {
  53. struct etna_bo *bo;
  54. printf("testing size rounding ... ");
  55. bo = etna_bo_new(dev, 15, ETNA_BO_UNCACHED);
  56. assert(etna_bo_size(bo) == 4096);
  57. etna_bo_del(bo);
  58. bo = etna_bo_new(dev, 4096, ETNA_BO_UNCACHED);
  59. assert(etna_bo_size(bo) == 4096);
  60. etna_bo_del(bo);
  61. bo = etna_bo_new(dev, 4100, ETNA_BO_UNCACHED);
  62. assert(etna_bo_size(bo) == 8192);
  63. etna_bo_del(bo);
  64. printf("ok\n");
  65. }
  66. int main(int argc, char *argv[])
  67. {
  68. struct etna_device *dev;
  69. drmVersionPtr version;
  70. int fd, ret = 0;
  71. fd = open(argv[1], O_RDWR);
  72. if (fd < 0)
  73. return 1;
  74. version = drmGetVersion(fd);
  75. if (version) {
  76. printf("Version: %d.%d.%d\n", version->version_major,
  77. version->version_minor, version->version_patchlevel);
  78. printf(" Name: %s\n", version->name);
  79. printf(" Date: %s\n", version->date);
  80. printf(" Description: %s\n", version->desc);
  81. drmFreeVersion(version);
  82. }
  83. dev = etna_device_new(fd);
  84. if (!dev) {
  85. ret = 2;
  86. goto out;
  87. }
  88. test_cache(dev);
  89. test_size_rounding(dev);
  90. etna_device_del(dev);
  91. out:
  92. close(fd);
  93. return ret;
  94. }