Home | History | Annotate | Download | only in etnaviv
      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 (at) gmail.com>
     25  */
     26 
     27 #undef NDEBUG
     28 #include <assert.h>
     29 #include <string.h>
     30 #include <stdio.h>
     31 
     32 #include "etnaviv_drmif.h"
     33 
     34 static void test_avail()
     35 {
     36 	struct etna_cmd_stream *stream;
     37 
     38 	printf("testing etna_cmd_stream_avail ... ");
     39 
     40 	/* invalid size */
     41 	stream = etna_cmd_stream_new(NULL, 0, NULL, NULL);
     42 	assert(stream == NULL);
     43 
     44 	stream = etna_cmd_stream_new(NULL, 4, NULL, NULL);
     45 	assert(stream);
     46 	assert(etna_cmd_stream_avail(stream) == 2);
     47 	etna_cmd_stream_del(stream);
     48 
     49 	stream = etna_cmd_stream_new(NULL, 20, NULL, NULL);
     50 	assert(stream);
     51 	assert(etna_cmd_stream_avail(stream) == 18);
     52 	etna_cmd_stream_del(stream);
     53 
     54 	/* odd number of 32 bit words */
     55 	stream = etna_cmd_stream_new(NULL, 1, NULL, NULL);
     56 	assert(stream);
     57 	assert(etna_cmd_stream_avail(stream) == 0);
     58 	etna_cmd_stream_del(stream);
     59 
     60 	stream = etna_cmd_stream_new(NULL, 23, NULL, NULL);
     61 	assert(stream);
     62 	assert(etna_cmd_stream_avail(stream) == 22);
     63 	etna_cmd_stream_del(stream);
     64 
     65 	printf("ok\n");
     66 }
     67 
     68 static void test_emit()
     69 {
     70 	struct etna_cmd_stream *stream;
     71 
     72 	printf("testing etna_cmd_stream_emit ... ");
     73 
     74 	stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
     75 	assert(stream);
     76 	assert(etna_cmd_stream_avail(stream) == 4);
     77 
     78 	etna_cmd_stream_emit(stream, 0x1);
     79 	assert(etna_cmd_stream_avail(stream) == 3);
     80 
     81 	etna_cmd_stream_emit(stream, 0x2);
     82 	assert(etna_cmd_stream_avail(stream) == 2);
     83 
     84 	etna_cmd_stream_emit(stream, 0x3);
     85 	assert(etna_cmd_stream_avail(stream) == 1);
     86 
     87 	etna_cmd_stream_del(stream);
     88 
     89 	printf("ok\n");
     90 }
     91 
     92 static void test_offset()
     93 {
     94 	struct etna_cmd_stream *stream;
     95 
     96 	printf("testing etna_cmd_stream_offset ... ");
     97 
     98 	stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
     99 	assert(etna_cmd_stream_offset(stream) == 0);
    100 
    101 	etna_cmd_stream_emit(stream, 0x1);
    102 	assert(etna_cmd_stream_offset(stream) == 1);
    103 
    104 	etna_cmd_stream_emit(stream, 0x2);
    105 	assert(etna_cmd_stream_offset(stream) == 2);
    106 
    107 	etna_cmd_stream_emit(stream, 0x3);
    108 	etna_cmd_stream_emit(stream, 0x4);
    109 	assert(etna_cmd_stream_offset(stream) == 4);
    110 
    111 	etna_cmd_stream_del(stream);
    112 
    113 	printf("ok\n");
    114 }
    115 
    116 int main(int argc, char *argv[])
    117 {
    118 	test_avail();
    119 	test_emit();
    120 	test_offset();
    121 
    122 	return 0;
    123 }
    124