Path: blob/21.2-virgl/src/etnaviv/drm/tests/etnaviv_bo_cache_test.c
4570 views
/*1* Copyright (C) 2016 Etnaviv Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*22* Authors:23* Christian Gmeiner <[email protected]>24*/2526#undef NDEBUG27#include <assert.h>2829#include <fcntl.h>30#include <stdio.h>31#include <string.h>32#include <unistd.h>3334#include "drm/etnaviv_drmif.h"35#include "drm-uapi/etnaviv_drm.h"3637static void test_cache(struct etna_device *dev)38{39struct etna_bo *bo, *tmp;4041/* allocate and free some bo's with same size - we must42* get the same bo over and over. */43printf("testing bo cache ... ");4445bo = tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);46assert(bo);47etna_bo_del(bo);4849for (unsigned i = 0; i < 100; i++) {50tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);51etna_bo_del(tmp);52assert(tmp == bo);53}5455printf("ok\n");56}5758static void test_size_rounding(struct etna_device *dev)59{60struct etna_bo *bo;6162printf("testing size rounding ... ");6364bo = etna_bo_new(dev, 15, ETNA_BO_UNCACHED);65assert(etna_bo_size(bo) == 4096);66etna_bo_del(bo);6768bo = etna_bo_new(dev, 4096, ETNA_BO_UNCACHED);69assert(etna_bo_size(bo) == 4096);70etna_bo_del(bo);7172bo = etna_bo_new(dev, 4100, ETNA_BO_UNCACHED);73assert(etna_bo_size(bo) == 8192);74etna_bo_del(bo);7576printf("ok\n");77}7879int main(int argc, char *argv[])80{81struct etna_device *dev;8283drmVersionPtr version;84int fd, ret = 0;85const char *node = "/dev/dri/renderD128";8687if (argc > 1)88node = argv[1];8990fd = open(node, O_RDWR);91if (fd < 0) {92fprintf(stderr, "Failed to open render node %s.\n", node);93return 1;94}9596version = drmGetVersion(fd);97if (version) {98printf("Version: %d.%d.%d\n", version->version_major,99version->version_minor, version->version_patchlevel);100printf(" Name: %s\n", version->name);101printf(" Date: %s\n", version->date);102printf(" Description: %s\n", version->desc);103drmFreeVersion(version);104}105106dev = etna_device_new(fd);107if (!dev) {108ret = 2;109goto out;110}111112test_cache(dev);113test_size_rounding(dev);114115etna_device_del(dev);116117out:118close(fd);119120return ret;121}122123124