Gets OpenGL output working with testing VM and display

* Refactors test routine to its own thread to not interfere with OpenGL on main thread
    * Misc TESTING/HEADLESS switch tweaks
This commit is contained in:
Aaron Culliney 2014-11-22 14:08:53 -08:00
parent 8416dd4d49
commit c075460b76
7 changed files with 77 additions and 56 deletions

View File

@ -246,7 +246,7 @@ void c_calibrate_joystick()
extern void gldriver_joystick_reset(void);
void c_joystick_reset()
{
#if !HEADLESS
#if !defined(TESTING)
if (!is_headless) {
gldriver_joystick_reset();
}

View File

@ -1160,6 +1160,7 @@ static int begin_cpu_stepping() {
}
#ifdef TESTING
#warning FIXME TODO : this is mis-named now ... GLVideo pushes sync state so we don't need to force poll ... but we need this to type the testing strings ... should refactor to leverage a common codepath, preferablly using the 'typing' mechanism here...
extern void testing_video_sync();
testing_video_sync();
#else

View File

@ -60,20 +60,8 @@ void test_common_setup() {
// ----------------------------------------------------------------------------
// test video functions and stubs
extern void video_driver_sync(void);
void testing_video_sync() {
#if !HEADLESS
if (!is_headless) {
clock_gettime(CLOCK_MONOTONIC, &ti);
struct timespec deltat = timespec_diff(t0, ti, NULL);
if (deltat.tv_sec || (deltat.tv_nsec >= NANOSECONDS/15) ) {
video_driver_sync();
ti = t0;
}
}
#endif
if (!input_length) {
input_length = strlen(input_str);
}
@ -108,7 +96,12 @@ void test_breakpoint(void *arg) {
fprintf(GREATEST_STDOUT, "set breakpoint on test_breakpoint to check for problems...\n");
#if !HEADLESS
if (!is_headless) {
video_driver_sync();
fprintf(GREATEST_STDOUT, "DISPLAY NOTE: busy-spinning, needs gdb/lldb intervention to continue...\n");
static volatile bool debug_continue = false;
while (!debug_continue) {
struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL);
}
}
#endif
}
@ -136,7 +129,7 @@ void test_common_init(bool do_cputhread) {
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
c_debugger_set_watchpoint(WATCHPOINT_ADDR);
if (is_headless) {
c_debugger_set_timeout(5);
c_debugger_set_timeout(10);
} else {
fprintf(stderr, "NOTE : RUNNING WITH DISPLAY ... pass HEADLESS=1 to environment to run test in faster headless mode\n");
c_debugger_set_timeout(0);

View File

@ -339,18 +339,12 @@ TEST test_80col_hires() {
// ----------------------------------------------------------------------------
// Test Suite
GREATEST_SUITE(test_suite_display) {
static int begin_video = -1;
GREATEST_SET_SETUP_CB(testdisplay_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testdisplay_teardown, NULL);
srandom(time(NULL));
test_common_init(/*cputhread*/true);
pthread_mutex_lock(&interface_mutex);
static void *test_thread(void *dummyptr) {
// TESTS --------------------------
begin_video=!is_headless;
RUN_TESTp(test_boot_disk);
@ -454,6 +448,32 @@ GREATEST_SUITE(test_suite_display) {
// ...
c_eject_6(0);
pthread_mutex_unlock(&interface_mutex);
GREATEST_MAIN_END();
}
GREATEST_SUITE(test_suite_display) {
GREATEST_SET_SETUP_CB(testdisplay_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testdisplay_teardown, NULL);
srandom(time(NULL));
pthread_mutex_lock(&interface_mutex);
test_common_init(/*cputhread*/true);
pthread_t p;
pthread_create(&p, NULL, (void *)&test_thread, (void *)NULL);
while (begin_video < 0) {
struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL);
}
if (begin_video) {
video_main_loop();
}
pthread_join(p, NULL);
}
SUITE(test_suite_display);
@ -462,7 +482,6 @@ GREATEST_MAIN_DEFS();
int test_display(int argc, char **argv) {
GREATEST_MAIN_BEGIN();
RUN_SUITE(test_suite_display);
GREATEST_MAIN_END();
}
#if !defined(__APPLE__)

View File

@ -3409,19 +3409,12 @@ TEST test_check_cxrom(bool flag_cxrom) {
// ----------------------------------------------------------------------------
// Test Suite
GREATEST_SUITE(test_suite_vm) {
static int begin_video = -1;
GREATEST_SET_SETUP_CB(testvm_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testvm_teardown, NULL);
c_read_random(0x0);
srandom(0); // force a known sequence
test_common_init(/*cputhread*/true);
pthread_mutex_lock(&interface_mutex);
static void *test_thread(void *dummyptr) {
// TESTS --------------------------
begin_video=!is_headless;
RUN_TESTp(test_boot_disk_bytes);
RUN_TESTp(test_boot_disk_cputrace);
@ -3603,6 +3596,33 @@ GREATEST_SUITE(test_suite_vm) {
// ...
c_eject_6(0);
pthread_mutex_unlock(&interface_mutex);
GREATEST_MAIN_END();
}
GREATEST_SUITE(test_suite_vm) {
GREATEST_SET_SETUP_CB(testvm_setup, NULL);
GREATEST_SET_TEARDOWN_CB(testvm_teardown, NULL);
c_read_random(0x0);
srandom(0); // force a known sequence
pthread_mutex_lock(&interface_mutex);
test_common_init(/*cputhread*/true);
pthread_t p;
pthread_create(&p, NULL, (void *)&test_thread, (void *)NULL);
while (begin_video < 0) {
struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL);
}
if (begin_video) {
video_main_loop();
}
pthread_join(p, NULL);
}
SUITE(test_suite_vm);
@ -3611,7 +3631,6 @@ GREATEST_MAIN_DEFS();
int test_vm(int argc, char **argv) {
GREATEST_MAIN_BEGIN();
RUN_SUITE(test_suite_vm);
GREATEST_MAIN_END();
}
#if !defined(__APPLE__)

View File

@ -15,6 +15,8 @@
#include "video/glinput.h"
#include <math.h>
#if !defined(TESTING)
//----------------------------------------------------------------------------
//
// keyboard
@ -142,7 +144,6 @@ static int _glutkey_to_scancode(int key) {
return key;
}
#if !defined(TESTING)
void gldriver_on_key_down(unsigned char key, int x, int y) {
_capslock_hackaround();
//LOG("onKeyDown %02x(%d)'%c'", key, key, key);
@ -202,7 +203,6 @@ static void gldriver_joystick_callback(unsigned int buttonMask, int x, int y, in
joy_y = 0xFF;
}
}
#endif
//----------------------------------------------------------------------------
//
@ -235,3 +235,5 @@ void gldriver_joystick_reset(void) {
glutJoystickFunc(gldriver_joystick_callback, (int)JOYSTICK_POLL_INTERVAL_MILLIS);
}
#endif // TESTING

View File

@ -526,9 +526,8 @@ static void gldriver_init_common(void) {
demoSource *vtxSource = _create_shader_source("Basic.vsh");
demoSource *frgSource = _create_shader_source("Basic.fsh");
// Build Program
// Build/use Program
program = _build_program(vtxSource, frgSource, /*withNormal:*/false, /*withTexcoord:*/true);
glUseProgram(program);
srcDestroySource(vtxSource);
srcDestroySource(frgSource);
@ -560,7 +559,7 @@ static void gldriver_init_common(void) {
GL_ERRLOG("finished initialization");
#if !defined(__APPLE__)
glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
//glBindFramebuffer(GL_FRAMEBUFFER, defaultFBO);
#endif
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
@ -587,10 +586,6 @@ static void gldriver_update(void) {
#endif
static void gldriver_render(void) {
if (is_headless) {
return;
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#if PERSPECTIVE
@ -706,14 +701,14 @@ static void gldriver_init_glut(GLuint fbo) {
glutIdleFunc(gldriver_update);
glutDisplayFunc(gldriver_render);
glutReshapeFunc(gldriver_reshape);
//glutMouseFunc(gldriver_mouse);
//glutMotionFunc(gldriver_mouse_drag);
#if !defined(TESTING)
glutKeyboardFunc(gldriver_on_key_down);
glutKeyboardUpFunc(gldriver_on_key_up);
glutSpecialFunc(gldriver_on_key_special_down);
glutSpecialUpFunc(gldriver_on_key_special_up);
//glutMouseFunc(gldriver_mouse);
//glutMotionFunc(gldriver_mouse_drag);
#endif
}
#endif
@ -749,15 +744,7 @@ void video_driver_reshape(int w, int h) {
gldriver_reshape(w, h);
}
void video_driver_sync(void) {
if (is_headless) {
return;
}
#if USE_GLUT
glutPostRedisplay();
#endif
}
void video_driver_shutdown(void) {
gldriver_shutdown();
}