A quick Look at Waffle, a Llbrary that allows one to defer choice of GLX, X11/EGL, Wayland/EGL until Runtime, and how it is used for testing Mesa
Waffle is a cross-platform C library that allows GL applications to defer choice of window system until runtime. For example, on Linux, Waffle enables an application to select X11 with GLX, X11 with EGL, Wayland, or (coming soon) GBM. Its API closely resembles EGL.
Waffle will soon replace GLUT in Piglit, Mesa's OpenGL test suite. This will allow one to build Piglit once, then run its tests under different window systems. This will extend Piglit's portability to Wayland, Android, and X11/EGL. Using GBM, one will even be able to run GL tests on headless machines.
Future plans for Waffle is to add the ability to defer the choice of OpenGL API until runtime using a dynamic dispatch mechanism similar to the one currently used in Piglit.