state_tracker: Move the format test out to be an actual unit test.

We want errors in the table to show up as unit test failures in MRs.
Also keeps unit test code out of the built drivers.

Reviewed-by: Thomas Helland <thomashelland90@gmail.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com>
This commit is contained in:
Eric Anholt 2019-07-01 13:06:09 -07:00
parent 9eccae671e
commit f8c27c2775
3 changed files with 117 additions and 51 deletions

View File

@ -1107,45 +1107,6 @@ st_pipe_format_to_mesa_format(enum pipe_format format)
}
}
/**
* Debug only: check that the two functions above correctly map
* Mesa formats to Gallium formats and back again.
*/
static void
test_format_conversion(struct st_context *st)
{
GLuint i;
/* test all Mesa formats */
for (i = 1; i < MESA_FORMAT_COUNT; i++) {
enum pipe_format pf;
if (st_compressed_format_fallback(st, i))
continue;
pf = st_mesa_format_to_pipe_format(st, i);
if (pf != PIPE_FORMAT_NONE) {
mesa_format MAYBE_UNUSED mf = st_pipe_format_to_mesa_format(pf);
assert(mf == i);
}
}
/* Test all Gallium formats */
for (i = 1; i < PIPE_FORMAT_COUNT; i++) {
mesa_format mf = st_pipe_format_to_mesa_format(i);
if (st_compressed_format_fallback(st, mf))
continue;
if (mf != MESA_FORMAT_NONE) {
enum pipe_format MAYBE_UNUSED pf =
st_mesa_format_to_pipe_format(st, mf);
assert(pf == i);
}
}
}
/**
* Map GL texture formats to Gallium pipe formats.
*/
@ -2196,18 +2157,6 @@ st_choose_format(struct st_context *st, GLenum internalFormat,
int j;
enum pipe_format pf;
#ifndef NDEBUG
{
static boolean firstCall = TRUE;
if (firstCall) {
test_format_conversion(st);
firstCall = FALSE;
}
}
#else
(void) test_format_conversion;
#endif
/* can't render to compressed formats at this time */
if (_mesa_is_compressed_format(st->ctx, internalFormat)
&& (bindings & ~PIPE_BIND_SAMPLER_VIEW)) {

View File

@ -25,6 +25,20 @@ libmesa_st_test_common = static_library(
dependencies : [dep_thread, idep_gtest],
)
test(
'st_format_test',
executable(
'st_format_test',
['st_format.c'],
include_directories : inc_common,
link_with : [
libmesa_st_test_common, libmesa_gallium, libglapi, libgallium,
libmesa_util,
],
),
suite : ['st_mesa'],
)
test(
'st_renumerate_test',
executable(

View File

@ -0,0 +1,103 @@
/**************************************************************************
*
* Copyright 2007 VMware, Inc.
* Copyright (c) 2008-2010 VMware, Inc.
* Copyright (c) 2019 Google, LLC
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#include "pipe/p_context.h"
#include "pipe/p_screen.h"
#include "state_tracker/st_context.h"
#include "state_tracker/st_format.h"
#include "state_tracker/st_texture.h"
#include "util/u_format.h"
#include <stdbool.h>
static boolean
is_format_supported(struct pipe_screen *pscreen,
enum pipe_format format,
enum pipe_texture_target target,
unsigned sample_count,
unsigned storage_sample_count,
unsigned usage)
{
return true;
}
int main(int argc, char **argv)
{
struct pipe_screen screen = {
.is_format_supported = is_format_supported,
};
struct pipe_context pctx = {
.screen = &screen,
};
struct st_context local_st = {
.pipe = &pctx,
};
struct st_context *st = &local_st;
GLuint i;
/* test all Mesa formats */
for (i = 1; i < MESA_FORMAT_COUNT; i++) {
enum pipe_format pf;
if (st_compressed_format_fallback(st, i))
continue;
pf = st_mesa_format_to_pipe_format(st, i);
if (pf != PIPE_FORMAT_NONE) {
mesa_format MAYBE_UNUSED mf = st_pipe_format_to_mesa_format(pf);
if (mf != i) {
fprintf(stderr, "Round-tripping %s -> %s -> %s failed\n",
_mesa_get_format_name(i), util_format_short_name(pf),
_mesa_get_format_name(mf));
return 1;
}
}
}
/* Test all Gallium formats */
for (i = 1; i < PIPE_FORMAT_COUNT; i++) {
mesa_format mf = st_pipe_format_to_mesa_format(i);
if (st_compressed_format_fallback(st, mf))
continue;
if (mf != MESA_FORMAT_NONE) {
enum pipe_format MAYBE_UNUSED pf =
st_mesa_format_to_pipe_format(st, mf);
if (pf != i) {
fprintf(stderr, "Round-tripping %s -> %s -> %s failed\n",
util_format_short_name(i),
_mesa_get_format_name(pf),
util_format_short_name(pf));
return 1;
}
}
}
return 0;
}