visualtest/src/variator_exhaustive.c
author Sam Lantinga
Tue, 10 Jan 2017 08:54:33 -0800
changeset 10806 36f40b8cc979
parent 7924 fcb86d323770
permissions -rw-r--r--
Fixed bugs 2570, 3145, improved OpenGL ES context support on Windows and X11

Mark Callow

The attached patch does the following for the X11 and Windows platforms, the only ones where SDL attempts to use context_create_es_profile:

- Adds SDL_HINT_OPENGL_ES_DRIVER by which the application can
say to use the OpenGL ES driver & EGL rather than the Open GL
driver. (For bug #2570)
- Adds code to {WIN,X11}_GL_InitExtensions to determine the maximum
OpenGL ES version supported by the OpenGL driver (for bug #3145)
- Modifies the test that determines whether to use the OpenGL
driver or the real OpenGL ES driver to take into account the
hint, the requested and supported ES version and whether ES 1.X
is being requested. (For bug #2570 & bug #3145)
- Enables the testgles2 test for __WINDOWS__ and __LINUX__ and adds
the test to the VisualC projects.

With the fix in place I have run testdraw2, testgl and testgles2 without any issues and have run my own apps that use OpenGL, OpenGL ES 3 and OpenGL ES 1.1.
     1 /* See COPYING.txt for the full license governing this code. */
     2 /**
     3  * \file variator_exhaustive.c
     4  *
     5  * Source file for the variator that tests the SUT with all the different
     6  * variations of input parameters that are valid.
     7  */
     8 
     9 #include <time.h>
    10 #include <SDL_test.h>
    11 #include "SDL_visualtest_sut_configparser.h"
    12 #include "SDL_visualtest_exhaustive_variator.h"
    13 
    14 static int
    15 NextVariation(SDLVisualTest_Variation* variation,
    16               SDLVisualTest_SUTConfig* config)
    17 {
    18     int i, carry;
    19     if(!variation)
    20     {
    21         SDLTest_LogError("variation argument cannot be NULL");
    22         return -1;
    23     }
    24     if(!config)
    25     {
    26         SDLTest_LogError("config argument cannot be NULL");
    27         return -1;
    28     }
    29 
    30     carry = 1;
    31     for(i = 0; i < variation->num_vars; i++)
    32     {
    33         carry = SDLVisualTest_NextValue(&variation->vars[i], &config->options[i]);
    34         if(carry != 1)
    35             break;
    36     }
    37 
    38     if(carry == 1) /* we're done, we've tried all possible variations */
    39         return 0;
    40     if(carry == 0)
    41         return 1;
    42     SDLTest_LogError("NextVariation() failed");
    43     return -1;
    44 }
    45 
    46 int
    47 SDLVisualTest_InitExhaustiveVariator(SDLVisualTest_ExhaustiveVariator* variator,
    48                                      SDLVisualTest_SUTConfig* config)
    49 {
    50     if(!variator)
    51     {
    52         SDLTest_LogError("variator argument cannot be NULL");
    53         return 0;
    54     }
    55     if(!config)
    56     {
    57         SDLTest_LogError("config argument cannot be NULL");
    58         return 0;
    59     }
    60 
    61     SDLTest_FuzzerInit(time(NULL));
    62 
    63     variator->config = *config;
    64     variator->variation.num_vars = 0;
    65     variator->variation.vars = NULL;
    66 
    67     return 1;
    68 }
    69 
    70 /* TODO: Right now variations where an option is not specified at all are not
    71    tested for. This can be implemented by switching the on attribute for integer,
    72    enum and string options to true and false. */
    73 char*
    74 SDLVisualTest_GetNextExhaustiveVariation(SDLVisualTest_ExhaustiveVariator* variator)
    75 {
    76     int success;
    77     if(!variator)
    78     {
    79         SDLTest_LogError("variator argument cannot be NULL");
    80         return NULL;
    81     }
    82 
    83     if(!variator->variation.vars) /* the first time this function is called */
    84     {
    85         success = SDLVisualTest_InitVariation(&variator->variation,
    86                                               &variator->config);
    87         if(!success)
    88         {
    89             SDLTest_LogError("SDLVisualTest_InitVariation() failed");
    90             return NULL;
    91         }
    92         success = SDLVisualTest_MakeStrFromVariation(&variator->variation,
    93                   &variator->config, variator->buffer, MAX_SUT_ARGS_LEN);
    94         if(!success)
    95         {
    96             SDLTest_LogError("SDLVisualTest_MakeStrFromVariation() failed");
    97             return NULL;
    98         }
    99         return variator->buffer;
   100     }
   101     else
   102     {
   103         success = NextVariation(&variator->variation, &variator->config);
   104         if(success == 1)
   105         {
   106             success = SDLVisualTest_MakeStrFromVariation(&variator->variation,
   107                       &variator->config, variator->buffer, MAX_SUT_ARGS_LEN);
   108             if(!success)
   109             {
   110                 SDLTest_LogError("SDLVisualTest_MakeStrFromVariation() failed");
   111                 return NULL;
   112             }
   113             return variator->buffer;
   114         }
   115         else if(success == -1)
   116             SDLTest_LogError("NextVariation() failed.");
   117         return NULL;
   118     }
   119     return NULL;
   120 }
   121 
   122 void
   123 SDLVisualTest_FreeExhaustiveVariator(SDLVisualTest_ExhaustiveVariator* variator)
   124 {
   125     if(!variator)
   126     {
   127         SDLTest_LogError("variator argument cannot be NULL");
   128         return;
   129     }
   130     SDL_free(variator->variation.vars);
   131     variator->variation.vars = NULL;
   132 }