etnaviv_cmd_stream_test.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (C) 2015 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 <string.h>
  29. #include <stdio.h>
  30. #include "etnaviv_drmif.h"
  31. static void test_avail()
  32. {
  33. struct etna_cmd_stream *stream;
  34. printf("testing etna_cmd_stream_avail ... ");
  35. /* invalid size */
  36. stream = etna_cmd_stream_new(NULL, 0, NULL, NULL);
  37. assert(stream == NULL);
  38. stream = etna_cmd_stream_new(NULL, 4, NULL, NULL);
  39. assert(stream);
  40. assert(etna_cmd_stream_avail(stream) == 2);
  41. etna_cmd_stream_del(stream);
  42. stream = etna_cmd_stream_new(NULL, 20, NULL, NULL);
  43. assert(stream);
  44. assert(etna_cmd_stream_avail(stream) == 18);
  45. etna_cmd_stream_del(stream);
  46. /* odd number of 32 bit words */
  47. stream = etna_cmd_stream_new(NULL, 1, NULL, NULL);
  48. assert(stream);
  49. assert(etna_cmd_stream_avail(stream) == 0);
  50. etna_cmd_stream_del(stream);
  51. stream = etna_cmd_stream_new(NULL, 23, NULL, NULL);
  52. assert(stream);
  53. assert(etna_cmd_stream_avail(stream) == 22);
  54. etna_cmd_stream_del(stream);
  55. printf("ok\n");
  56. }
  57. static void test_emit()
  58. {
  59. struct etna_cmd_stream *stream;
  60. printf("testing etna_cmd_stream_emit ... ");
  61. stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
  62. assert(stream);
  63. assert(etna_cmd_stream_avail(stream) == 4);
  64. etna_cmd_stream_emit(stream, 0x1);
  65. assert(etna_cmd_stream_avail(stream) == 3);
  66. etna_cmd_stream_emit(stream, 0x2);
  67. assert(etna_cmd_stream_avail(stream) == 2);
  68. etna_cmd_stream_emit(stream, 0x3);
  69. assert(etna_cmd_stream_avail(stream) == 1);
  70. etna_cmd_stream_del(stream);
  71. printf("ok\n");
  72. }
  73. static void test_offset()
  74. {
  75. struct etna_cmd_stream *stream;
  76. printf("testing etna_cmd_stream_offset ... ");
  77. stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
  78. assert(etna_cmd_stream_offset(stream) == 0);
  79. etna_cmd_stream_emit(stream, 0x1);
  80. assert(etna_cmd_stream_offset(stream) == 1);
  81. etna_cmd_stream_emit(stream, 0x2);
  82. assert(etna_cmd_stream_offset(stream) == 2);
  83. etna_cmd_stream_emit(stream, 0x3);
  84. etna_cmd_stream_emit(stream, 0x4);
  85. assert(etna_cmd_stream_offset(stream) == 4);
  86. etna_cmd_stream_del(stream);
  87. printf("ok\n");
  88. }
  89. int main(int argc, char *argv[])
  90. {
  91. test_avail();
  92. test_emit();
  93. test_offset();
  94. return 0;
  95. }