-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add GL smoke tests with CI headless fixes #8557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../gl/glRenderSmokeTest/src/GLSmokeTestCore.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../gl/glRenderSmokeTest/src/main.cpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../gl/glRenderSmokeTest/src/ofApp.cpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../../../gl/glRenderSmokeTest/src/ofApp.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # GL render smoke test | ||
|
|
||
| Exercises the code paths touched by the OpenGL ES 3.0/3.1 support work: | ||
| an indexed `ofVboMesh` drawn both directly (`drawElements`) and instanced | ||
| (`drawElementsInstanced`), a tessellated `ofPath` (tess2 / `ofIndexType`), | ||
| and an `ofFbo` round trip with a pixel readback to catch garbage/blank | ||
| triangles caused by an index-type/size mismatch. | ||
|
|
||
| The actual test logic lives in `src/GLSmokeTestCore.h` and is shared, | ||
| unmodified, by every platform target (desktop here, `tests/emscripten/glRenderSmokeTest`, | ||
| `tests/ios/glRenderSmokeTest`) — only the platform bridge (`ofApp`/`main`) | ||
| differs. | ||
|
|
||
| On desktop this is a normal windowed openFrameworks app picked up | ||
| automatically by the existing `tests/` CI harness (`scripts/ci/*/run_tests.sh`): | ||
| it runs a fixed number of frames, logs `GL_SMOKE_TEST RESULT=PASS` or | ||
| `RESULT=FAIL reason=...`, and exits with a matching process exit code. | ||
|
|
||
| To run manually: | ||
|
|
||
| ```sh | ||
| cd tests/gl/glRenderSmokeTest | ||
| cp ../../../scripts/templates/osx/Makefile . # or linux/linux64 template | ||
| cp ../../../scripts/templates/osx/config.make . | ||
| make Debug | ||
| make RunDebug | ||
| ``` |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| #pragma once | ||
|
|
||
| #include "ofMain.h" | ||
|
|
||
| // Shared by every platform target of glRenderSmokeTest (desktop, Emscripten, | ||
| // iOS, Android). Exercises the code paths touched by the OpenGL ES 3.0/3.1 | ||
| // support work: indexed ofVboMesh draw + drawInstanced (drawElements / | ||
| // drawElementsInstanced), a tessellated ofPath (tess2 / ofIndexType), and an | ||
| // ofFbo round trip, on whatever GL/GLES context the host window created. | ||
| // | ||
| // No custom shader is used deliberately: the GLSL version/#define story | ||
| // differs per platform (desktop core profile vs GLES2 vs GLES3 "300 es" vs | ||
| // Emscripten) and isn't what this PR touches. Using the renderer's own | ||
| // default shader keeps the test focused on the index-type and tess2 paths | ||
| // while still exercising the ES-version #ifdef branches in | ||
| // ofGLProgrammableRenderer indirectly (every draw call goes through them). | ||
| class GLSmokeTestCore { | ||
| public: | ||
| static constexpr int framesToRun = 12; | ||
|
|
||
| void allocate() { | ||
| release(); | ||
|
|
||
| indexedMesh.setMode(OF_PRIMITIVE_TRIANGLES); | ||
| indexedMesh.addVertices({ | ||
| {-60.f, -60.f, 0.f}, {60.f, -60.f, 0.f}, | ||
| {60.f, 60.f, 0.f}, {-60.f, 60.f, 0.f} | ||
| }); | ||
| indexedMesh.addColors({ofColor::red, ofColor::green, ofColor::blue, ofColor::yellow}); | ||
| indexedMesh.addIndices({0, 1, 2, 0, 2, 3}); | ||
|
|
||
| tessellatedPath.clear(); | ||
| tessellatedPath.setFilled(true); | ||
| tessellatedPath.setFillColor(ofColor(255, 140, 20)); | ||
| tessellatedPath.setPolyWindingMode(OF_POLY_WINDING_ODD); | ||
| for (int i = 0; i < 12; ++i) { | ||
| const float radius = (i % 2 == 0) ? 55.f : 22.f; | ||
| const float angle = ofDegToRad(i * 30.f - 90.f); | ||
| const glm::vec2 point(std::cos(angle) * radius, std::sin(angle) * radius); | ||
| if (i == 0) { | ||
| tessellatedPath.moveTo(point); | ||
| } else { | ||
| tessellatedPath.lineTo(point); | ||
| } | ||
| } | ||
| tessellatedPath.close(); | ||
|
|
||
| ofFbo::Settings settings; | ||
| settings.width = 128; | ||
| settings.height = 128; | ||
| settings.internalformat = GL_RGBA; | ||
| settings.useDepth = false; | ||
| settings.numSamples = 0; | ||
| fbo.allocate(settings); | ||
|
|
||
| allocated = fbo.isAllocated(); | ||
| if (!allocated) { | ||
| fail("ofFbo failed to allocate"); | ||
| } | ||
| } | ||
|
|
||
| void release() { | ||
| fbo.clear(); | ||
| allocated = false; | ||
| } | ||
|
|
||
| void drawFrame() { | ||
| if (!allocated) { | ||
| fail("resources not allocated"); | ||
| return; | ||
| } | ||
|
|
||
| clearGLErrors(); | ||
|
|
||
| fbo.begin(); | ||
| ofClear(0, 0, 0, 255); | ||
| ofSetColor(255); | ||
| ofPushMatrix(); | ||
| ofTranslate(fbo.getWidth() * 0.5f, fbo.getHeight() * 0.5f); | ||
| indexedMesh.draw(); // ofGLProgrammableRenderer::draw(ofVboMesh) -> drawElements | ||
| indexedMesh.drawInstanced(OF_MESH_FILL, 2); // forces the drawElementsInstanced path (primCount > 1) | ||
| ofPopMatrix(); | ||
| fbo.end(); | ||
| checkGLErrors("after mesh draw"); | ||
|
|
||
| ofSetColor(255); | ||
| fbo.draw(0.f, 0.f, static_cast<float>(fbo.getWidth()), static_cast<float>(fbo.getHeight())); | ||
|
|
||
| ofPushMatrix(); | ||
| ofTranslate(180.f, 160.f); | ||
| tessellatedPath.draw(); // tess2 triangulation -> ofIndexType-sized indices | ||
| ofPopMatrix(); | ||
| checkGLErrors("after path draw"); | ||
|
|
||
| if (frame == framesToRun - 1) { | ||
| verifyPixels(); | ||
| } | ||
| ++frame; | ||
| } | ||
|
|
||
| bool finished() const { | ||
| return frame >= framesToRun; | ||
| } | ||
|
|
||
| bool passed() const { | ||
| return allocated && glErrorCount == 0 && pixelCheckPassed && failureReason.empty(); | ||
| } | ||
|
|
||
| std::string resultLine() const { | ||
| if (passed()) { | ||
| return "GL_SMOKE_TEST RESULT=PASS frames=" + ofToString(frame); | ||
| } | ||
| std::string reason = failureReason; | ||
| if (reason.empty() && glErrorCount > 0) { | ||
| reason = "glGetError seen " + ofToString(glErrorCount) + " time(s), last=" + ofToHex(lastGLError); | ||
| } | ||
| if (reason.empty() && !pixelCheckPassed) { | ||
| reason = "FBO readback did not contain the expected non-background color"; | ||
| } | ||
| return "GL_SMOKE_TEST RESULT=FAIL reason=" + reason; | ||
| } | ||
|
|
||
| private: | ||
| void fail(const std::string & reason) { | ||
| if (failureReason.empty()) { | ||
| failureReason = reason; | ||
| } | ||
| ofLogError("glRenderSmokeTest") << reason; | ||
| } | ||
|
|
||
| void clearGLErrors() { | ||
| while (glGetError() != GL_NO_ERROR) { | ||
| } | ||
| } | ||
|
|
||
| void checkGLErrors(const std::string & where) { | ||
| GLenum error = glGetError(); | ||
| while (error != GL_NO_ERROR) { | ||
| ++glErrorCount; | ||
| lastGLError = error; | ||
| ofLogError("glRenderSmokeTest") << "glGetError=" << ofToHex(error) << " " << where; | ||
| error = glGetError(); | ||
| } | ||
| } | ||
|
|
||
| void verifyPixels() { | ||
| ofPixels pixels; | ||
| fbo.readToPixels(pixels); | ||
| if (!pixels.isAllocated()) { | ||
| fail("FBO readToPixels produced no pixels"); | ||
| return; | ||
| } | ||
| const ofColor center = pixels.getColor(pixels.getWidth() / 2, pixels.getHeight() / 2); | ||
| // Background is cleared to black; any of the mesh's red/green/blue/yellow | ||
| // vertex colors interpolating in means the indexed draw actually reached | ||
| // the GPU with correctly-sized indices instead of reading garbage/nothing. | ||
| pixelCheckPassed = (center.r > 10 || center.g > 10 || center.b > 10); | ||
| if (!pixelCheckPassed) { | ||
| ofLogError("glRenderSmokeTest") << "center pixel=" << center << " (expected non-background)"; | ||
| } | ||
| } | ||
|
|
||
| ofVboMesh indexedMesh; | ||
| ofPath tessellatedPath; | ||
| ofFbo fbo; | ||
|
|
||
| bool allocated = false; | ||
| bool pixelCheckPassed = false; | ||
| int frame = 0; | ||
| int glErrorCount = 0; | ||
| GLenum lastGLError = GL_NO_ERROR; | ||
| std::string failureReason; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include "ofMain.h" | ||
| #include "ofApp.h" | ||
| #if defined(TARGET_GLFW_WINDOW) | ||
| #include "ofAppGLFWWindow.h" | ||
| #endif | ||
|
|
||
| int main() { | ||
| ofGLWindowSettings settings; | ||
| settings.setSize(320, 240); | ||
| settings.windowMode = OF_WINDOW; | ||
|
|
||
| auto window = ofCreateWindow(settings); | ||
| #if defined(TARGET_GLFW_WINDOW) | ||
| auto glfw = dynamic_cast<ofAppGLFWWindow *>(window.get()); | ||
| if (!glfw || !glfw->getGLFWWindow()) { | ||
| ofLogWarning("glRenderSmokeTest") << "no GL window (headless / GLFW init failed) — skip"; | ||
| return 0; | ||
| } | ||
| #endif | ||
|
|
||
| ofRunApp(window, std::make_shared<ofApp>()); | ||
| return ofRunMainLoop(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #include "ofApp.h" | ||
|
|
||
| #include <cstdlib> | ||
| #ifdef __EMSCRIPTEN__ | ||
| #include <emscripten.h> | ||
| #endif | ||
|
|
||
| namespace { | ||
| // std::exit() alone doesn't stop Emscripten's requestAnimationFrame loop | ||
| // (the runtime stays alive for pending async work), so draw() keeps getting | ||
| // called forever after "finishing" unless we guard against it below, and the | ||
| // process itself needs emscripten_force_exit() to actually stop. | ||
| void terminateProcess(int code) { | ||
| #ifdef __EMSCRIPTEN__ | ||
| emscripten_force_exit(code); | ||
| #else | ||
| std::exit(code); | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| void ofApp::setup() { | ||
| ofSetLogLevel(OF_LOG_NOTICE); | ||
| ofSetFrameRate(60); | ||
| ofBackground(0); | ||
| ofLogNotice("glRenderSmokeTest") << "renderer=" << glGetString(GL_RENDERER) | ||
| << " version=" << glGetString(GL_VERSION); | ||
| core.allocate(); | ||
| } | ||
|
|
||
| void ofApp::draw() { | ||
| if (core.finished()) { | ||
| return; | ||
| } | ||
|
|
||
| core.drawFrame(); | ||
|
|
||
| if (core.finished()) { | ||
| ofLogNotice("glRenderSmokeTest") << core.resultLine(); | ||
| terminateProcess(core.passed() ? 0 : 1); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
|
|
||
| #include "ofMain.h" | ||
| #include "GLSmokeTestCore.h" | ||
|
|
||
| class ofApp : public ofBaseApp { | ||
| public: | ||
| void setup() override; | ||
| void draw() override; | ||
|
|
||
| private: | ||
| GLSmokeTestCore core; | ||
| }; |
Empty file.
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Virtual Frame buffer - allows for headless linux to run GPU tests