Skip to content
Snippets Groups Projects
Commit e0e21b87 authored by Jeremy Whiting's avatar Jeremy Whiting
Browse files

Add test for SrtGraphics object.

Added missing _get_multiarch_tuple and _get_issues helpers.
Added test for object, good, bad and software rendering.
parent eef37c44
No related branches found
No related tags found
1 merge request!24Add SrtGraphics wrapper to wrap graphics checker.
......@@ -26,7 +26,7 @@
#pragma once
#include "steam-runtime-tools/graphics.h"
#include "steam-runtime-tools/steam-runtime-tools.h"
/*
* _srt_graphics_new:
......@@ -68,5 +68,13 @@ _srt_graphics_new (const char *multiarch_tuple,
"version-string", version_string,
NULL);
}
static inline int _srt_graphics_hash_key(SrtWindowSystem window_system, SrtRenderingInterface rendering_interface)
{
/* This allows us to have up to 100 unique renderers, we won't need nearly that
many, but setting to 100 just to allow room to grow */
return (int)window_system * 100 + (int)rendering_interface;
}
#endif
/*< internal_header >*/
/*
* Copyright © 2019 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* 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, sublicense, 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 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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.
*/
#pragma once
// Test strings for use in mock and graphics test
#define SRT_TEST_GOOD_GRAPHICS_RENDERER "Mesa DRI Intel(R) Haswell Desktop "
#define SRT_TEST_SOFTWARE_GRAPHICS_RENDERER "llvmpipe (LLVM 8.0, 256 bits)"
#define SRT_TEST_GOOD_GRAPHICS_VERSION "3.0 Mesa 19.1.3"
#define SRT_TEST_SOFTWARE_GRAPHICS_VERSION "3.1 Mesa 19.1.3"
......@@ -235,7 +235,19 @@ srt_graphics_class_init (SrtGraphicsClass *cls)
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
}
G_GNUC_INTERNAL SrtGraphicsIssues
/**
* srt_check_graphics:
* @multiarch_tuple: A multiarch tuple to check e.g. i386-linux-gnu
* @winsys: The window system to check.
* @renderer: The graphics renderer to check.
* @details_out: The SrtGraphics object containing the details of the check.
*
* Return the problems found when checking the graphics stack given.
*
* Returns: A bitfield containing problems, or %SRT_GRAPHICS_ISSUES_NONE
* if no problems were found
*/
SrtGraphicsIssues
srt_check_graphics (const char *multiarch_tuple,
SrtWindowSystem window_system,
SrtRenderingInterface rendering_interface,
......
/*
* Copyright © 2019 Collabora Ltd.
*
* SPDX-License-Identifier: MIT
*
* 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, sublicense, 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 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 NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 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 <steam-runtime-tools/steam-runtime-tools.h>
#include <string.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gstdio.h>
#include "steam-runtime-tools/graphics-internal.h"
#include "steam-runtime-tools/graphics-test-defines.h"
#include "test-utils.h"
typedef struct
{
int unused;
} Fixture;
typedef struct
{
int unused;
} Config;
static void
setup (Fixture *f,
gconstpointer context)
{
G_GNUC_UNUSED const Config *config = context;
}
static void
teardown (Fixture *f,
gconstpointer context)
{
G_GNUC_UNUSED const Config *config = context;
}
/*
* Test basic functionality of the SrtGraphics object.
*/
static void
test_object (Fixture *f,
gconstpointer context)
{
SrtGraphics *graphics;
SrtGraphicsIssues issues;
gchar *tuple;
gchar *renderer;
gchar *version;
graphics = _srt_graphics_new("mock-good",
SRT_WINDOW_SYSTEM_GLX,
SRT_RENDERING_INTERFACE_GL,
SRT_TEST_GOOD_GRAPHICS_RENDERER,
SRT_TEST_GOOD_GRAPHICS_VERSION,
SRT_LIBRARY_ISSUES_NONE);
g_assert_cmpint (srt_graphics_get_issues (graphics), ==,
SRT_GRAPHICS_ISSUES_NONE);
g_assert_cmpstr (srt_graphics_get_multiarch_tuple (graphics), ==,
"mock-good");
g_assert_cmpstr (srt_graphics_get_renderer_string (graphics), ==,
SRT_TEST_GOOD_GRAPHICS_RENDERER);
g_assert_cmpstr (srt_graphics_get_version_string (graphics), ==,
SRT_TEST_GOOD_GRAPHICS_VERSION);
g_object_get (graphics,
"multiarch-tuple", &tuple,
"issues", &issues,
"renderer-string", &renderer,
"version-string", &version,
NULL);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_NONE);
g_assert_cmpstr (tuple, ==, "mock-good");
g_assert_cmpstr (renderer, ==, SRT_TEST_GOOD_GRAPHICS_RENDERER);
g_assert_cmpstr (version, ==, SRT_TEST_GOOD_GRAPHICS_VERSION);
g_free (tuple);
g_object_unref (graphics);
}
/*
* Test a mock system with hardware graphics stack
*/
static void
test_good_graphics (Fixture *f,
gconstpointer context)
{
SrtGraphics *graphics = NULL;
SrtGraphicsIssues issues;
gchar *tuple;
gchar *renderer;
gchar *version;
issues = srt_check_graphics ("mock-good",
SRT_WINDOW_SYSTEM_GLX,
SRT_RENDERING_INTERFACE_GL,
&graphics);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_NONE);
g_assert_cmpstr (srt_graphics_get_renderer_string (graphics), ==,
SRT_TEST_GOOD_GRAPHICS_RENDERER);
g_assert_cmpstr (srt_graphics_get_version_string (graphics), ==,
SRT_TEST_GOOD_GRAPHICS_VERSION);
g_object_get (graphics,
"multiarch-tuple", &tuple,
"issues", &issues,
"renderer-string", &renderer,
"version-string", &version,
NULL);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_NONE);
g_assert_cmpstr (tuple, ==, "mock-good");
g_assert_cmpstr (renderer, ==, SRT_TEST_GOOD_GRAPHICS_RENDERER);
g_assert_cmpstr (version, ==, SRT_TEST_GOOD_GRAPHICS_VERSION);
g_free (tuple);
g_free (renderer);
g_free (version);
g_object_unref (graphics);
}
/*
* Test a mock system with no graphics stack
*/
static void
test_bad_graphics (Fixture *f,
gconstpointer context)
{
SrtGraphics *graphics = NULL;
SrtGraphicsIssues issues;
gchar *tuple;
gchar *renderer;
gchar *version;
issues = srt_check_graphics ("mock-bad",
SRT_WINDOW_SYSTEM_GLX,
SRT_RENDERING_INTERFACE_GL,
&graphics);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_CANNOT_LOAD);
g_assert_cmpstr (srt_graphics_get_renderer_string (graphics), ==,
NULL);
g_assert_cmpstr (srt_graphics_get_version_string (graphics), ==,
NULL);
g_object_get (graphics,
"multiarch-tuple", &tuple,
"issues", &issues,
"renderer-string", &renderer,
"version-string", &version,
NULL);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_CANNOT_LOAD);
g_assert_cmpstr (tuple, ==, "mock-bad");
g_assert_cmpstr (renderer, ==, NULL);
g_assert_cmpstr (version, ==, NULL);
g_free (tuple);
g_free (renderer);
g_free (version);
g_object_unref (graphics);
}
/*
* Test a mock system with software rendering
*/
static void
test_software_rendering (Fixture *f,
gconstpointer context)
{
SrtGraphics *graphics = NULL;
SrtGraphicsIssues issues;
gchar *tuple;
gchar *renderer;
gchar *version;
issues = srt_check_graphics ("mock-software",
SRT_WINDOW_SYSTEM_GLX,
SRT_RENDERING_INTERFACE_GL,
&graphics);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_SOFTWARE_RENDERING);
g_assert_cmpstr (srt_graphics_get_renderer_string (graphics), ==,
SRT_TEST_SOFTWARE_GRAPHICS_RENDERER);
g_assert_cmpstr (srt_graphics_get_version_string (graphics), ==,
SRT_TEST_SOFTWARE_GRAPHICS_VERSION);
g_object_get (graphics,
"multiarch-tuple", &tuple,
"issues", &issues,
"renderer-string", &renderer,
"version-string", &version,
NULL);
g_assert_cmpint (issues, ==, SRT_GRAPHICS_ISSUES_SOFTWARE_RENDERING);
g_assert_cmpstr (tuple, ==, "mock-software");
g_assert_cmpstr (renderer, ==, SRT_TEST_SOFTWARE_GRAPHICS_RENDERER);
g_assert_cmpstr (version, ==, SRT_TEST_SOFTWARE_GRAPHICS_VERSION);
g_free (tuple);
g_free (renderer);
g_free (version);
g_object_unref (graphics);
}
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add ("/object", Fixture, NULL,
setup, test_object, teardown);
g_test_add ("/good", Fixture, NULL,
setup, test_good_graphics, teardown);
g_test_add ("/bad", Fixture, NULL,
setup, test_bad_graphics, teardown);
g_test_add ("/software", Fixture, NULL,
setup, test_software_rendering, teardown);
return g_test_run ();
}
......@@ -29,6 +29,7 @@ test_env.prepend('PATH', join_paths(meson.current_build_dir(), '..', 'bin'))
tests = [
'architecture',
'graphics',
'library',
'system-info',
'system-info-cli',
......
......@@ -25,7 +25,7 @@
#include <stdio.h>
void usage(void);
#include "../steam-runtime-tools/graphics-test-defines.h"
int
main (int argc,
......@@ -33,7 +33,11 @@ main (int argc,
{
// Give good output
printf ("{\n\t\"waffle\": {\n\t\t\"platform\": \"glx\",\n\t\t\"api\": \"gl\"\n\t},\n\t\"OpenGL\": {\n\t\t\"vendor string\": \"Intel Open Source Technology Center\",\n"
"\t\t\"renderer string\": \"Mesa DRI Intel(R) Haswell Desktop \",\n\t\t\"version string\": \"3.0 Mesa 19.1.3\",\n\t\t\"shading language version string\": \"1.30\",\n"
"\t\t\"renderer string\": \""
SRT_TEST_GOOD_GRAPHICS_RENDERER
"\",\n\t\t\"version string\": \""
SRT_TEST_GOOD_GRAPHICS_VERSION
"\",\n\t\t\"shading language version string\": \"1.30\",\n"
"\t\t\"extensions\": [\n"
"\t\t]\n\t}\n}\n");
return 0;
......
......@@ -25,13 +25,19 @@
#include <stdio.h>
#include "../steam-runtime-tools/graphics-test-defines.h"
int
main (int argc,
char **argv)
{
// Give software renderer output
printf ("{\n\t\"waffle\": {\n\t\t\"platform\": \"glx\",\n\t\t\"api\": \"gl\"\n\t\t},\n\t\"OpenGL\": {\n\t\t\"vendor string\": \"VMware, Inc.\",\n"
"\t\t\"renderer string\": \"llvmpipe (LLVM 8.0, 256 bits)\",\n\t\t\"version string\": \"3.1 Mesa 19.1.3\",\n\t\t\"shading language version string\": \"1.40\",\n"
"\t\t\"renderer string\": \""
SRT_TEST_SOFTWARE_GRAPHICS_RENDERER
"\",\n\t\t\"version string\": \""
SRT_TEST_SOFTWARE_GRAPHICS_VERSION
"\",\n\t\t\"shading language version string\": \"1.40\",\n"
"\t\t\"extensions\": [\n"
"\t\t]\n\t}\n}\n");
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment