Fixed issue with c tests running too fast (overwhelming plugin)

This commit is contained in:
Chris Teubert
2017-05-02 16:51:58 -07:00
parent 10f3ce2854
commit db92652bc2
4 changed files with 90 additions and 35 deletions

View File

@@ -6,7 +6,7 @@
#include "Test.h" #include "Test.h"
#include "xplaneConnect.h" #include "xplaneConnect.h"
int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[7]) int doCTRLTest(XPCSocket *sock, char* drefs[7], float values[], int size, int ac, float expected[7])
{ {
float* data[7]; float* data[7];
int sizes[7]; int sizes[7];
@@ -17,13 +17,13 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[
} }
// Execute command // Execute command
XPCSocket sock = openUDP(IP); int result = sendCTRL(*sock, values, size, ac);
int result = sendCTRL(sock, values, size, ac); int d = 0.0f;
if (result >= 0) if (result >= 0)
{ {
result = getDREFs(sock, drefs, data, 7, sizes); result = getDREFs(*sock, drefs, data, 7, sizes);
} }
closeUDP(sock);
if (result < 0) if (result < 0)
{ {
return -1; return -1;
@@ -35,6 +35,7 @@ int doCTRLTest(char* drefs[7], float values[], int size, int ac, float expected[
{ {
actual[i] = data[i][0]; actual[i] = data[i][0];
} }
return compareArray(expected, actual, 7); return compareArray(expected, actual, 7);
} }
@@ -70,11 +71,14 @@ int basicCTRLTest(char** drefs, int ac)
// Set control surfaces to known state. // Set control surfaces to known state.
float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F }; float CTRL[6] = { 0.0F, 0.0F, 0.0F, 0.8F, 1.0F, 0.5F };
float expected[7] = { 0.0F, 0.0F, 0.0F, NAN, NAN, NAN, NAN }; float expected[7] = { 0.0F, 0.0F, 0.0F, NAN, NAN, NAN, NAN };
int result = doCTRLTest(drefs, CTRL, 3, ac, expected); XPCSocket sock = openUDP(IP);
pauseSim(sock, 1); // Pause so the controls wont change between 2 and 3
int result = doCTRLTest(&sock, drefs, CTRL, 3, ac, expected);
if (result < 0) if (result < 0)
{ {
return -10000 + result; return -10000 + result;
} }
crossPlatformUSleep(SLEEP_AMOUNT);
// Test control surfaces and set other values to known state. // Test control surfaces and set other values to known state.
expected[0] = CTRL[0] = 0.2F; expected[0] = CTRL[0] = 0.2F;
@@ -83,22 +87,29 @@ int basicCTRLTest(char** drefs, int ac)
expected[3] = 0.8F; expected[3] = 0.8F;
expected[4] = 1.0F; expected[4] = 1.0F;
expected[5] = 0.5F; expected[5] = 0.5F;
result = doCTRLTest(drefs, CTRL, 6, ac, expected); result = doCTRLTest(&sock, drefs, CTRL, 6, ac, expected);
if (result < 0) if (result < 0)
{ {
return -20000 + result; return -20000 + result;
} }
crossPlatformUSleep(SLEEP_AMOUNT);
// Test other values and verify control surfaces unchanged. // Test other values and verify control surfaces unchanged.
CTRL[0] = -998; expected[0] = CTRL[0] = 0.15F;
CTRL[1] = -998; expected[1] = CTRL[1] = 0.15F;
CTRL[2] = -998; expected[2] = CTRL[2] = 0.15F;
expected[3] = CTRL[3] = 0.9F; expected[3] = CTRL[3] = 0.9F;
expected[4] = CTRL[4] = 0.0F; CTRL[4] = -998;
expected[5] = CTRL[5] = 0.75F; CTRL[5] = -998;
result = doCTRLTest(drefs, CTRL, 6, ac, expected); result = doCTRLTest(&sock, drefs, CTRL, 6, ac, expected);
pauseSim(sock, 0);
closeUDP(sock);
if (result < 0) if (result < 0)
{ {
if (result == -1004) {
printf("GEAR FAILURE... ARE YOU USING AN AIRCRAFT WITH FIXED GEARS? ");
}
return -30000 + result; return -30000 + result;
} }
return 0; return 0;
@@ -129,7 +140,7 @@ int testCTRL_NonPlayer()
"sim/multiplayer/position/plane1_throttle", "sim/multiplayer/position/plane1_throttle",
"sim/multiplayer/position/plane1_gear_deploy", "sim/multiplayer/position/plane1_gear_deploy",
"sim/multiplayer/position/plane1_flap_ratio", "sim/multiplayer/position/plane1_flap_ratio",
"sim/multiplayer/position/plane1_sbrkrqst" "sim/multiplayer/position/plane1_speedbrake_ratio"
}; };
return basicCTRLTest(drefs, 1); return basicCTRLTest(drefs, 1);
} }
@@ -150,7 +161,9 @@ int testCTRL_Speedbrakes()
// Arm // Arm
float CTRL[7] = { -998, -998, -998, -998, -998, -998, -0.5F }; float CTRL[7] = { -998, -998, -998, -998, -998, -998, -0.5F };
float expected[7] = { NAN, NAN, NAN, NAN, NAN, NAN, -0.5F }; float expected[7] = { NAN, NAN, NAN, NAN, NAN, NAN, -0.5F };
int result = doCTRLTest(drefs, CTRL, 7, 0, expected); XPCSocket sock = openUDP(IP);
pauseSim(sock, 1); // Pause so the controls wont change between 2 and 3
int result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected);
if (result < 0) if (result < 0)
{ {
return -10000 + result; return -10000 + result;
@@ -158,7 +171,7 @@ int testCTRL_Speedbrakes()
// Set to full // Set to full
expected[6] = CTRL[6] = 1.5F; expected[6] = CTRL[6] = 1.5F;
result = doCTRLTest(drefs, CTRL, 7, 0, expected); result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected);
if (result < 0) if (result < 0)
{ {
return -20000 + result; return -20000 + result;
@@ -166,7 +179,9 @@ int testCTRL_Speedbrakes()
// Retract // Retract
expected[6] = CTRL[6] = 0.0F; expected[6] = CTRL[6] = 0.0F;
result = doCTRLTest(drefs, CTRL, 7, 0, expected); result = doCTRLTest(&sock, drefs, CTRL, 7, 0, expected);
pauseSim(sock, 0);
closeUDP(sock);
if (result < 0) if (result < 0)
{ {
return -30000 + result; return -30000 + result;

View File

@@ -21,6 +21,14 @@ void runTest(int(*test)(), char* name)
} }
} }
void crossPlatformUSleep(int uSleep) {
#ifdef _WIN32
Sleep(uSleep/1000);
#else
usleep(uSleep);
#endif
}
int compareFloat(float expected, float actual) int compareFloat(float expected, float actual)
{ {
return feq(expected, actual) || isnan(expected) ? 0 : -1; return feq(expected, actual) || isnan(expected) ? 0 : -1;

View File

@@ -9,10 +9,21 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#ifdef LINUX
#include <unistd.h>
#endif
#ifdef WINDOWS
#include <windows.h>
#endif
#define SLEEP_AMOUNT 100000
#define feq(x, y) (fabs(x - y) < 1e-4) #define feq(x, y) (fabs(x - y) < 1e-4)
#define IP "127.0.0.1" #define IP "127.0.0.1"
void crossPlatformUSleep(int uSleep);
extern int testFailed; extern int testFailed;
extern int testPassed; extern int testPassed;

View File

@@ -11,8 +11,7 @@
#include "ViewTests.h" #include "ViewTests.h"
#include "WyptTests.h" #include "WyptTests.h"
int main(int argc, const char * argv[]) int main(int argc, const char * argv[]) {
{
printf("XPC Tests-c "); printf("XPC Tests-c ");
#ifdef _WIN32 #ifdef _WIN32
@@ -27,36 +26,58 @@ int main(int argc, const char * argv[])
// Basic Networking // Basic Networking
runTest(testOpen, "open"); runTest(testOpen, "open");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testClose, "close"); runTest(testClose, "close");
crossPlatformUSleep(SLEEP_AMOUNT);
// Datarefs // Datarefs
runTest(testGETD_Basic, "GETD"); runTest(testGETD_Basic, "GETD");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETD_Types, "GETD (types)"); runTest(testGETD_Types, "GETD (types)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETD_TestFloat, "GETD (test float)"); runTest(testGETD_TestFloat, "GETD (test float)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testDREF, "DREF"); runTest(testDREF, "DREF");
// Pause // Pause
runTest(testSIMU_Basic, "SIMU"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testSIMU_Toggle, "SIMU (toggle)"); runTest(testSIMU_Basic, "SIMU");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testSIMU_Toggle, "SIMU (toggle)");
// CTRL // CTRL
runTest(testCTRL_Player, "CTRL (player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testCTRL_NonPlayer, "CTRL (non-player)"); runTest(testCTRL_Player, "CTRL (player)");
runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETC, "GETC (player)"); runTest(testCTRL_NonPlayer, "CTRL (non-player)");
runTest(testGETC_NonPlayer, "GETC (Non-player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testCTRL_Speedbrakes, "CTRL (speedbrakes)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETC, "GETC (player)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGETC_NonPlayer, "GETC (Non-player)");
// POSI // POSI
runTest(testPOSI_Player, "POSI (player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testPOSI_NonPlayer, "POSI (non-player)"); runTest(testPOSI_Player, "POSI (player)");
runTest(testGetPOSI_Player, "GETP (player)"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGetPOSI_NonPlayer, "GETP (non-player)"); runTest(testPOSI_NonPlayer, "POSI (non-player)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGetPOSI_Player, "GETP (player)");
crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testGetPOSI_NonPlayer, "GETP (non-player)");
// Data // Data
runTest(testDATA, "DATA"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testDATA, "DATA");
// Text // Text
runTest(testTEXT, "TEXT"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testTEXT, "TEXT");
// Waypoints // Waypoints
runTest(testWYPT, "WYPT"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testWYPT, "WYPT");
// View // View
runTest(testView, "VIEW"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testView, "VIEW");
// setConn // setConn
runTest(testCONN, "CONN"); crossPlatformUSleep(SLEEP_AMOUNT);
runTest(testCONN, "CONN");
printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed ); printf( "----------------\nTest Summary\n\tFailed: %i\n\tPassed: %i\n", testFailed, testPassed );
printf("Press any key to exit."); printf("Press any key to exit.");