Commit a7aa5efd authored by Kenneth Moreland's avatar Kenneth Moreland

Separate out OpenGL and non-OpenGL tests

Previously, if OpenGL was enabled all tests would create a render window
even if it was never used because they were all crammed into the same
executable that initalized with the OpenGL context. This is an artifact
from early versions of IceT that always required OpenGL.

Creating an OpenGL context shouldn't change the results of the test, but
it was annoying to have a bunch of windows created for every test. This
change separates out the OpenGl tests from those that don't use it so
that most of the tests now just run in the background.
parent a9baf8fa
......@@ -42,7 +42,7 @@ IF (NOT ICET_TESTS_USE_OPENGL)
MESSAGE(STATUS "Most tests require ICET_USE_OPENGL and GLUT or GLFW. Those tests are disabled.")
ENDIF (NOT ICET_TESTS_USE_OPENGL)
SET(MyTests
SET(IceTTestSrcs
BackgroundCorrect.c
CompressionSize.c
FloatingViewport.c
......@@ -57,22 +57,24 @@ SET(MyTests
SparseImageCopy.c
)
IF (ICET_TESTS_USE_OPENGL)
SET(MyTests ${MyTests}
BlankTiles.c
BoundsBehindViewer.c
DisplayNoDraw.c
RandomTransform.c
SimpleExample.c
)
ENDIF (ICET_TESTS_USE_OPENGL)
SET(IceTOpenGLTestSrcs
BlankTiles.c
BoundsBehindViewer.c
DisplayNoDraw.c
RandomTransform.c
SimpleExample.c
)
SET(UTIL_SRCS init.c ppm.c)
SET(UTIL_SRCS
test_common.c
ppm.c
)
SET(TEST_HEADERS
test_codes.h
test_util.h
mpi_comm.h
test_mpi.h
test_mpi_opengl.h
)
SET_SOURCE_FILES_PROPERTIES(${TEST_HEADERS}
PROPERTIES HEADER_ONLY TRUE
......@@ -88,25 +90,6 @@ INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
)
CREATE_TEST_SOURCELIST(Tests icetTests_mpi.c ${MyTests}
EXTRA_INCLUDE mpi_comm.h
FUNCTION init_mpi_comm)
ADD_EXECUTABLE(icetTests_mpi ${Tests} ${UTIL_SRCS} ${TEST_HEADERS})
TARGET_LINK_LIBRARIES(icetTests_mpi
IceTCore
IceTMPI
)
IF (ICET_TESTS_USE_OPENGL)
TARGET_LINK_LIBRARIES(icetTests_mpi IceTGL)
IF (ICET_TESTS_USE_GLUT)
TARGET_LINK_LIBRARIES(icetTests_mpi ${GLUT_LIBRARIES})
ENDIF (ICET_TESTS_USE_GLUT)
IF (ICET_TESTS_USE_GLFW)
TARGET_LINK_LIBRARIES(icetTests_mpi ${GLFW_LIBRARY})
ENDIF (ICET_TESTS_USE_GLFW)
ENDIF (ICET_TESTS_USE_OPENGL)
IF (ICET_MPIRUN_EXE)
SET(PRE_TEST_FLAGS ${ICET_MPIRUN_EXE} ${ICET_MPI_NUMPROC_FLAG} ${ICET_MPI_MAX_NUMPROCS} ${ICET_MPI_PREFLAGS})
SET(POST_TEST_FLAGS ${ICET_MPI_POSTFLAGS})
......@@ -116,7 +99,17 @@ SET(ICET_TEST_FLAGS "" CACHE STRING "Arguments given to the test program. These
MARK_AS_ADVANCED(ICET_TEST_FLAGS)
SEPARATE_ARGUMENTS(ICET_TEST_FLAGS)
FOREACH (test ${MyTests})
CREATE_TEST_SOURCELIST(Tests icetTests_mpi.c ${IceTTestSrcs}
EXTRA_INCLUDE test_mpi.h
FUNCTION init_mpi)
ADD_EXECUTABLE(icetTests_mpi ${Tests} ${UTIL_SRCS} ${TEST_HEADERS})
TARGET_LINK_LIBRARIES(icetTests_mpi
IceTCore
IceTMPI
)
FOREACH (test ${IceTTestSrcs})
GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
ADD_TEST(NAME IceT${TName}
COMMAND
......@@ -134,6 +127,43 @@ FOREACH (test ${MyTests})
ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.1)
ENDFOREACH(test)
IF (ICET_TESTS_USE_OPENGL)
CREATE_TEST_SOURCELIST(OpenGLTests icetTests_mpi_opengl.c ${IceTOpenGLTestSrcs}
EXTRA_INCLUDE test_mpi_opengl.h
FUNCTION init_mpi_opengl)
ADD_EXECUTABLE(icetTests_mpi_opengl ${OpenGLTests} ${UTIL_SRCS} ${TEST_HEADERS})
TARGET_LINK_LIBRARIES(icetTests_mpi_opengl
IceTCore
IceTMPI
IceTGL
)
IF (ICET_TESTS_USE_GLUT)
TARGET_LINK_LIBRARIES(icetTests_mpi_opengl ${GLUT_LIBRARIES})
ENDIF (ICET_TESTS_USE_GLUT)
IF (ICET_TESTS_USE_GLFW)
TARGET_LINK_LIBRARIES(icetTests_mpi_opengl ${GLFW_LIBRARY})
ENDIF (ICET_TESTS_USE_GLFW)
FOREACH (test ${IceTOpenGLTestSrcs})
GET_FILENAME_COMPONENT(TName ${test} NAME_WE)
ADD_TEST(NAME IceT${TName}
COMMAND
${PRE_TEST_FLAGS}
$<TARGET_FILE:icetTests_mpi_opengl> ${ICET_TEST_FLAGS} ${TName}
${POST_TEST_FLAGS})
IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.1)
SET_TESTS_PROPERTIES(IceT${TName}
PROPERTIES FAIL_REGULAR_EXPRESSION
":ERROR:;TEST NOT RUN;TEST NOT PASSED;TEST FAILED"
)
SET_TESTS_PROPERTIES(IceT${TName}
PROPERTIES PASS_REGULAR_EXPRESSION "Test Passed"
)
ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.1)
ENDFOREACH(test)
ENDIF (ICET_TESTS_USE_OPENGL)
IF (WIN32)
ADD_CUSTOM_TARGET(logclean erase log.???? *.ppm)
ELSE (WIN32)
......
......@@ -111,8 +111,8 @@ static int SimpleExampleRun()
/* Normally, the first thing that you do is set up your communication and
* then create at least one IceT context. This has already been done in
* the calling function (i.e. icetTests_mpi.c). See the init_mpi_comm in
* mpi_comm.h for an example.
* the calling function (i.e. icetTests_mpi.c). See the init_mpi in
* test_mpi.h for an example.
*/
/* If we had set up the communication layer ourselves, we could have
......
......@@ -902,8 +902,8 @@ static int SimpleTimingDoRender()
/* Normally, the first thing that you do is set up your communication and
* then create at least one IceT context. This has already been done in the
* calling function (i.e. icetTests_mpi.c). See the init_mpi_comm in
* mpi_comm.h for an example.
* calling function (i.e. icetTests_mpi.c). See the init_mpi in
* test_mpi.h for an example.
*/
init_opacity_lookup();
......
/* -*- c -*- *******************************************************/
/*
* Copyright (C) 2003 Sandia Corporation
* Copyright (C) 2015 Sandia Corporation
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
......@@ -10,10 +10,6 @@
#include "test_util.h"
#include "test_codes.h"
#ifdef ICET_TESTS_USE_OPENGL
#include <IceTGL.h>
#endif
#include <IceTDevCommunication.h>
#ifndef __USE_POSIX
......@@ -29,18 +25,6 @@
#include <sys/stat.h>
#include <fcntl.h>
#ifdef ICET_TESTS_USE_GLUT
#ifndef __APPLE__
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#endif
#endif
#ifdef ICET_TESTS_USE_GLFW
#include <GLFW/glfw3.h>
#endif
#ifndef WIN32
#include <unistd.h>
#else
......@@ -60,42 +44,6 @@ int SINGLE_IMAGE_STRATEGY_LIST_SIZE = 4;
IceTSizeType SCREEN_WIDTH;
IceTSizeType SCREEN_HEIGHT;
#ifdef ICET_TESTS_USE_GLUT
static int windowId;
#endif
#ifdef ICET_TESTS_USE_GLFW
static GLFWwindow *window;
#endif
#ifdef ICET_TESTS_USE_OPENGL
static void checkOglError(void)
{
GLenum error = glGetError();
#define CASE_ERROR(ename) \
case ename: printrank("## Current IceT error = " #ename "\n"); break;
switch (error) {
case GL_NO_ERROR: break;
CASE_ERROR(GL_INVALID_ENUM);
CASE_ERROR(GL_INVALID_VALUE);
CASE_ERROR(GL_INVALID_OPERATION);
CASE_ERROR(GL_STACK_OVERFLOW);
CASE_ERROR(GL_STACK_UNDERFLOW);
CASE_ERROR(GL_OUT_OF_MEMORY);
#ifdef GL_TABLE_TOO_LARGE
CASE_ERROR(GL_TABLE_TOO_LARGE);
#endif
default:
printrank("## UNKNOWN OPENGL ERROR CODE!!!!!!\n");
break;
}
#undef CASE_ERROR
}
#endif /* ICET_TESTS_USE_OPENGL */
static void checkIceTError(void)
{
IceTEnum error = icetGetError();
......@@ -182,6 +130,7 @@ static void usage(char **argv)
printf(" -h, -help This help message.\n");
}
extern void initialize_render_window(int width, int height);
void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
{
int arg;
......@@ -196,8 +145,8 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
rank = (*comm->Comm_rank)(comm);
num_proc = (*comm->Comm_size)(comm);
/* This is convenient code to attach a debugger to a particular process at the
start of a test. */
/* This is convenience code to attach a debugger to a particular process at
the start of a test. */
#if 0
if (rank == 0) {
int i = 0;
......@@ -206,15 +155,6 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
}
#endif
#ifdef ICET_TESTS_USE_GLUT
/* Let Glut have first pass at the arguments to grab any that it can use. */
glutInit(argcp, *argvp);
#endif
#ifdef ICET_TESTS_USE_GLFW
if (!glfwInit()) { exit(1); }
#endif
/* Parse my arguments. */
for (arg = 1; arg < argc; arg++) {
if (strcmp(argv[arg], "-width") == 0) {
......@@ -260,46 +200,14 @@ void initialize_test(int *argcp, char ***argvp, IceTCommunicator comm)
exit(1);
}
#ifdef ICET_TESTS_USE_GLUT
/* Create a renderable window. */
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
glutInitWindowPosition(0, 0);
glutInitWindowSize(width, height);
{
char title[256];
sprintf(title, "IceT Test %d of %d", rank, num_proc);
windowId = glutCreateWindow(title);
}
#endif /* ICET_TESTS_USE_GLUT */
#ifdef ICET_TESTS_USE_GLFW
/* Create a renderable window. */
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_DEPTH_BITS, 24);
glfwWindowHint(GLFW_SAMPLES, 0);
{
char title[256];
sprintf(title, "IceT Test %d of %d", rank, num_proc);
window = glfwCreateWindow(width, height, title, NULL, NULL);
}
glfwMakeContextCurrent(window);
#endif /* ICET_TESTS_USE_GLFW */
SCREEN_WIDTH = width;
SCREEN_HEIGHT = height;
/* Create an IceT context. */
context = icetCreateContext(comm);
icetDiagnostics(diag_level);
#ifdef ICET_TESTS_USE_OPENGL
icetGLInitialize();
#endif
initialize_render_window(width, height);
/* Redirect standard output on demand. */
if (redirect) {
......@@ -347,115 +255,27 @@ IceTBoolean strategy_uses_single_image_strategy(IceTEnum strategy)
}
}
#if defined(ICET_TESTS_USE_GLUT)
static int (*test_function)(void);
static void no_op()
{
}
static void glut_draw()
int run_test_base(int (*test_function)(void))
{
int result;
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
swap_buffers();
result = test_function();
finalize_test(result);
glutDestroyWindow(windowId);
exit(result);
}
int run_test(int (*tf)(void))
{
/* Record the test function so we can run it in the Glut draw callback. */
test_function = tf;
glutDisplayFunc(no_op);
glutIdleFunc(glut_draw);
/* Glut will reliably create the OpenGL context only after the main loop is
* started. This will create the window and then call our glut_draw function
* to populate it. It will never return, which is why we call exit in
* glut_draw. */
glutMainLoop();
/* We do not expect to be here. Raise an alert to signal that the tests are
* not running as expected. */
return TEST_NOT_PASSED;
}
#elif defined(ICET_TESTS_USE_GLFW)
int run_test(int (*tf)(void))
{
int result;
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
swap_buffers();
result = tf();
finalize_test(result);
glfwDestroyWindow(window);
glfwTerminate();
return result;
}
#elif defined(ICET_TESTS_USE_OPENGL)
#error "ICET_TESTS_USE_OPENGL defined but no window library is defined."
#else /* ICET_TESTS_USE_OPENGL */
int run_test(int (*tf)(void))
{
int result;
result = tf();
finalize_test(result);
return result;
}
#endif /* !ICET_TESTS_USE_OPENGL */
#ifdef ICET_TESTS_USE_GLUT
void swap_buffers(void)
{
glutSwapBuffers();
}
#endif
#ifdef ICET_TESTS_USE_GLFW
void swap_buffers(void)
{
glfwSwapBuffers(window);
glfwPollEvents();
}
#endif
#define TEST_RESULT_TAG 3492
extern void finalize_rendering(void);
extern void finalize_communication(void);
void finalize_test(IceTInt result)
{
IceTInt rank;
IceTInt num_proc;
#ifdef ICET_TESTS_USE_OPENGL
checkOglError();
#endif
finalize_rendering();
checkIceTError();
icetGetIntegerv(ICET_RANK, &rank);
......
......@@ -7,13 +7,15 @@
* This source code is released under the New BSD License.
*/
#ifndef _MPI_COMM_H_
#define _MPI_COMM_H_
#ifndef _TEST_MPI_H_
#define _TEST_MPI_H_
#include "test_util.h"
#include <IceTMPI.h>
void init_mpi_comm(int *argcp, char ***argvp)
extern int run_test_base(int (*test_function)(void));
void init_mpi(int *argcp, char ***argvp)
{
IceTCommunicator comm;
......@@ -22,7 +24,7 @@ void init_mpi_comm(int *argcp, char ***argvp)
initialize_test(argcp, argvp, comm);
icetDestroyMPICommunicator(comm);
icetDestroyMPICommunicator(comm);
}
void finalize_communication(void)
......@@ -30,4 +32,18 @@ void finalize_communication(void)
MPI_Finalize();
}
#endif /*_MPI_COMM_H_*/
#ifndef ICET_NO_MPI_RENDERING_FUNCTIONS
int run_test(int (*test_function)())
{
return run_test_base(test_function);
}
void initialize_render_window(int width, int height)
{
(void)width;
(void)height;
}
void swap_buffers() { }
void finalize_rendering() { }
#endif /* !ICET_NO_MPI_RENDERING_FUNCTIONS */
#endif /*_TEST_MPI_H_*/
/* -*- c -*- *******************************************************/
/*
* Copyright (C) 2015 Sandia Corporation
* Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
* the U.S. Government retains certain rights in this software.
*
* This source code is released under the New BSD License.
*/
#ifndef _TEST_MPI_OPENGL_H
#define _TEST_MPI_OPENGL_H
#define ICET_NO_MPI_RENDERING_FUNCTIONS
#include "test_mpi.h"
#include "test_config.h"
#include <IceTGL.h>
#ifdef ICET_TESTS_USE_GLUT
#ifndef __APPLE__
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#endif
#endif
#ifdef ICET_TESTS_USE_GLFW
#include <GLFW/glfw3.h>
#endif
#ifdef ICET_TESTS_USE_GLUT
static int windowId;
#endif
#ifdef ICET_TESTS_USE_GLFW
static GLFWwindow *window;
#endif
static void checkOglError(void)
{
GLenum error = glGetError();
#define CASE_ERROR(ename) \
case ename: printrank("## Current IceT error = " #ename "\n"); break;
switch (error) {
case GL_NO_ERROR: break;
CASE_ERROR(GL_INVALID_ENUM);
CASE_ERROR(GL_INVALID_VALUE);
CASE_ERROR(GL_INVALID_OPERATION);
CASE_ERROR(GL_STACK_OVERFLOW);
CASE_ERROR(GL_STACK_UNDERFLOW);
CASE_ERROR(GL_OUT_OF_MEMORY);
#ifdef GL_TABLE_TOO_LARGE
CASE_ERROR(GL_TABLE_TOO_LARGE);
#endif
default:
printrank("## UNKNOWN OPENGL ERROR CODE!!!!!!\n");
break;
}
#undef CASE_ERROR
}
void init_mpi_opengl(int *argcp, char ***argvp)
{
#ifdef ICET_TESTS_USE_GLUT
/* Let Glut have first pass at the arguments to grab any that it can use. */
glutInit(argcp, *argvp);
#endif
#ifdef ICET_TESTS_USE_GLFW
if (!glfwInit()) { exit(1); }
#endif
init_mpi(argcp, argvp);
}
#if defined(ICET_TESTS_USE_GLUT)
static int (*g_test_function)(void);
static void no_op()
{
}
static void glut_draw()
{
int result;
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
swap_buffers();
result = run_test_base(g_test_function);
glutDestroyWindow(windowId);
exit(result);
}
int run_test(int (*test_function)(void))
{
/* Record the test function so we can run it in the Glut draw callback. */
g_test_function = test_function;
glutDisplayFunc(no_op);
glutIdleFunc(glut_draw);
/* Glut will reliably create the OpenGL context only after the main loop is
* started. This will create the window and then call our glut_draw function
* to populate it. It will never return, which is why we call exit in
* glut_draw. */
glutMainLoop();
/* We do not expect to be here. Raise an alert to signal that the tests are
* not running as expected. */
return TEST_NOT_PASSED;
}
void initialize_render_window(int width, int height)
{
IceTInt rank, num_proc;
icetGetIntegerv(ICET_RANK, &rank);
icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc);
/* Create a renderable window. */
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA);
glutInitWindowPosition(0, 0);
glutInitWindowSize(width, height);
{
char title[256];
sprintf(title, "IceT Test %d of %d", rank, num_proc);
windowId = glutCreateWindow(title);
}
icetGLInitialize();
}
void swap_buffers(void)
{
glutSwapBuffers();
}
#elif defined(ICET_TESTS_USE_GLFW)
int run_test(int (*test_function)())
{
int result;
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, (GLsizei)SCREEN_WIDTH, (GLsizei)SCREEN_HEIGHT);
glClear(GL_COLOR_BUFFER_BIT);
swap_buffers();
result = run_test_base(test_function);
glfwDestroyWindow(window);
glfwTerminate();
return result;
}
void initialize_render_window(int width, int height)
{
IceTInt rank, num_proc;
icetGetIntegerv(ICET_RANK, &rank);
icetGetIntegerv(ICET_NUM_PROCESSES, &num_proc);
/* Create a renderable window. */
glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_DEPTH_BITS, 24);
glfwWindowHint(GLFW_SAMPLES, 0);
{
char title[256];
sprintf(title, "IceT Test %d of %d", rank, num_proc);
window = glfwCreateWindow(width, height, title, NULL, NULL);
}
glfwMakeContextCurrent(window);
icetGLInitialize();
}
void swap_buffers(void)
{
glfwSwapBuffers(window);
glfwPollEvents();
}
#else
#error "ICET_TESTS_USE_OPENGL defined but no window library is defined."
#endif
void finalize_rendering()
{
checkOglError();
}
#endif /* _TEST_MPI_OPENGL_H */
......@@ -41,9 +41,7 @@ void printstat(const char *fmt, ...);
/* Like printf but adds the rank of the local process. */
void printrank(const char *fmt, ...);
#ifdef ICET_TESTS_USE_OPENGL
void swap_buffers(void);
#endif
void finalize_test(IceTInt result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment