testing rearchitecting
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-08-19 12:41:53 -04:00
parent 25346978e6
commit 415e20d02d
21 changed files with 280 additions and 97 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Mon Aug 19 09:32:22 EDT 2024
buildNumber=260
#Mon Aug 19 12:41:14 EDT 2024
buildNumber=276

View File

@ -612,6 +612,8 @@ Small oit shader work
(08/19/2024)
Disable cloud ring
Undo oit shader work to fix build pipeline
Testing rearchitecting
# TODO

29
pom.xml
View File

@ -290,6 +290,9 @@
</activation>
<properties>
<lwjgl.natives>natives-linux</lwjgl.natives>
<!--The tests to run-->
<groups>fast</groups>
</properties>
<build>
<plugins>
@ -377,6 +380,9 @@
</activation>
<properties>
<lwjgl.natives>natives-windows</lwjgl.natives>
<!--The tests to run-->
<groups>fast</groups>
</properties>
<build>
<plugins>
@ -406,6 +412,21 @@
</plugins>
</build>
</profile>
<!-- INTEGRATION TESTING -->
<!-- To execute this profile, run a command like "mvn test -P lwjgl-natives-windows,integration" -->
<profile>
<id>integration</id>
<properties>
<!--The tests to run-->
<groups>fast,integration</groups>
</properties>
</profile>
</profiles>
@ -417,6 +438,8 @@
<!-- MAIN BUILD -->
<build>
<plugins>
<!--Shade the jar (pack all dependencies)-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
@ -439,6 +462,9 @@
</execution>
</executions>
</plugin>
<!--Exec build tools-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@ -488,6 +514,9 @@
</execution> -->
</executions>
</plugin>
<!--Incrementing (local) build numbers-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>

View File

@ -0,0 +1,26 @@
package annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Timeout.ThreadMode;
/**
* A fast test that does not depend on setup/shutdown -- A unit test
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Tag("fast")
@Test
@Timeout( value = 20, unit = TimeUnit.MILLISECONDS, threadMode = ThreadMode.SAME_THREAD )
public @interface FastTest {
}

View File

@ -0,0 +1,21 @@
package annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
/**
* Used to flag work that should be done before each integration test
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@BeforeEach
@Tag("integration")
public @interface IntegrationSetup {
}

View File

@ -0,0 +1,20 @@
package annotations;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Tag;
/**
* Flags for work to be done tearing down after running an integration test
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@AfterEach
@Tag("integration")
public @interface IntegrationTeardown {
}

View File

@ -0,0 +1,26 @@
package annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.Timeout.ThreadMode;
/**
* An integration test. Has defaults for timeout on the test
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Tag("integration")
@Test
@Timeout( value = 2, unit = TimeUnit.MINUTES, threadMode = ThreadMode.SAME_THREAD )
public @interface IntegrationTest {
}

View File

@ -1,5 +0,0 @@
package db;
public class DBTest {
}

View File

@ -1,4 +1,4 @@
package entity;
package electrosphere.entity;
public class InventoryStateTest {

View File

@ -1,4 +1,4 @@
package entity;
package electrosphere.entity;
public class LifeStateTest {

View File

@ -1,4 +1,4 @@
package entity;
package electrosphere.entity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -13,6 +13,7 @@ public class SpawningCreaturesTest {
@BeforeEach
public void initEngine(){
LoggerInterface.initLoggers();
LoggerInterface.loggerEngine.INFO("[Test] Spawn many creatures");
Globals.RUN_CLIENT = true;
Globals.RUN_SERVER = true;

View File

@ -1,56 +0,0 @@
package electrosphere.renderer.ui.elements;
import java.awt.image.BufferedImage;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.menu.WindowUtils;
import electrosphere.menu.mainmenu.MenuGeneratorsUITesting;
import electrosphere.renderer.RenderingEngine;
import testutils.TestEngineUtils;
/**
* Integration tests for the window class
*/
public class WindowIntegrationTest {
@BeforeEach
@Tag("integration")
/**
* Initializes the engine
*/
public void initEngine(){
TestEngineUtils.initGraphicalEngine();
}
@Test
@Tag("integration")
/**
* Tests creating a window
*/
public void testCreateWindow(){
//create ui testing window
TestEngineUtils.simulateFrames(1);
WindowUtils.replaceMainMenuContents(MenuGeneratorsUITesting.createUITestMenu());
TestEngineUtils.simulateFrames(1);
BufferedImage screenshot = RenderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState());
}
@AfterEach
@Tag("integration")
/**
* Shuts down the engine
*/
public void closeEngine(){
Main.shutdown();
}
}

View File

@ -0,0 +1,27 @@
package electrosphere.renderer.ui.elements;
import annotations.IntegrationTest;
import electrosphere.menu.WindowUtils;
import electrosphere.menu.mainmenu.MenuGeneratorsUITesting;
import template.RenderingTestTemplate;
import testutils.TestEngineUtils;
/**
* Tests for the window class
*/
public class WindowTest extends RenderingTestTemplate {
/**
* Tests creating a window
*/
@IntegrationTest
public void testCreateWindow(){
//create ui testing window
TestEngineUtils.simulateFrames(1);
WindowUtils.replaceMainMenuContents(MenuGeneratorsUITesting.createUITestMenu());
TestEngineUtils.simulateFrames(1);
// TestRenderingUtils.saveTestRender("./test/java/electrosphere/renderer/ui/elements/window.png");
this.checkRender("Basic", "./test/java/electrosphere/renderer/ui/elements/window.png");
}
}

View File

@ -1,10 +0,0 @@
package electrosphere.renderer.ui.elements;
/**
* Unit testing the window class
*/
public class WindowUnitTest {
}

View File

@ -1,16 +1,15 @@
package startup;
import org.junit.jupiter.api.Test;
package integration;
import annotations.IntegrationSetup;
import annotations.IntegrationTest;
import electrosphere.engine.Globals;
import electrosphere.engine.Main;
import electrosphere.engine.profiler.Profiler;
import electrosphere.logger.LoggerInterface;
import electrosphere.net.NetUtils;
public class StartupTest {
@Test
@IntegrationSetup
public void testStartupHeadless(){
LoggerInterface.loggerEngine.INFO("[Test] Startup Headless");
Globals.RUN_CLIENT = false;
@ -22,7 +21,7 @@ public class StartupTest {
// Main.mainLoop(1);
}
@Test
@IntegrationTest
public void testEmpty() {
LoggerInterface.loggerEngine.INFO("[Test] Empty test");
}

View File

@ -1,5 +0,0 @@
package networking;
public class NetworkingTest {
}

View File

@ -1,5 +0,0 @@
package physics;
public class PhysicsTest {
}

View File

@ -1,5 +0,0 @@
package script;
public class ScriptTest {
}

View File

@ -0,0 +1,52 @@
package template;
import java.io.File;
import annotations.IntegrationSetup;
import annotations.IntegrationTeardown;
import electrosphere.engine.Main;
import testutils.TestEngineUtils;
import testutils.TestRenderingUtils;
/**
* A test class that involves testing renders
*/
public abstract class RenderingTestTemplate {
/**
* Initializes the engine
*/
@IntegrationSetup
public void initEngine(){
TestEngineUtils.initGraphicalEngine();
}
/**
* Shuts down the engine
*/
@IntegrationTeardown
public void closeEngine(){
Main.shutdown();
}
/**
* Checks the most recent render versus an existing image
* @param renderName The name associated with the render
* @param existingRenderPath The path to the existing image
*/
public void checkRender(String renderName, String existingRenderPath){
//of the format "electrosphere.renderer.ui.elements.WindowTest"
String canonicalName = this.getClass().getCanonicalName();
//check the render
TestRenderingUtils.assertEqualsRender(existingRenderPath, () -> {
//on failure, save the failed render
String failureSavePath = "./.testcache/" + canonicalName + "-" + renderName + ".png";
File saveFile = new File(failureSavePath);
System.err.println("[[ATTACHMENT|" + saveFile.getAbsolutePath() + "]]");
TestRenderingUtils.saveTestRender(failureSavePath);
});
}
}

View File

@ -0,0 +1,66 @@
package testutils;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import static org.junit.jupiter.api.Assertions.*;
import electrosphere.engine.Globals;
import electrosphere.renderer.RenderingEngine;
/**
* Utilities for comparing renders
*/
public class TestRenderingUtils {
/**
* Asserts that the most recent render matches the image stored at the provided filepath
* @param existingRenderPath The filepath of the existing render
*/
public static void assertEqualsRender(String existingRenderPath, Runnable onFailure){
BufferedImage testData = null;
try {
testData = ImageIO.read(new File(existingRenderPath));
} catch (IOException e){
fail("Failed to read existing image path " + existingRenderPath);
}
BufferedImage screenshot = RenderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState());
//check basic data
if(testData.getWidth() != screenshot.getWidth()){
onFailure.run();
}
assertEquals(testData.getHeight(), screenshot.getHeight());
if(testData.getWidth() != screenshot.getWidth()){
onFailure.run();
}
assertEquals(testData.getHeight(), screenshot.getHeight());
//pixel-by-pixel check
for(int x = 0; x < testData.getWidth(); x++){
for(int y = 0; y < testData.getHeight(); y++){
if(testData.getRGB(x, y) != screenshot.getRGB(x, y)){
onFailure.run();
}
assertEquals(testData.getRGB(x, y),screenshot.getRGB(x, y));
}
}
}
/**
* Used for saving a copy of the current render (ie for generating test data)
* @param existingRenderPath The filepath of the existing render
*/
public static void saveTestRender(String existingRenderPath){
BufferedImage screenshot = RenderingEngine.defaultFramebuffer.getPixels(Globals.renderingEngine.getOpenGLState());
try {
ImageIO.write(screenshot, "png", new File(existingRenderPath));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB