1
0
Fork 0

Test for TrafficMgr

This commit is contained in:
portree_kid 2021-03-10 21:27:06 +01:00 committed by James Turner
parent 9121e8bcef
commit 3318e09441
8 changed files with 470 additions and 479 deletions

View file

@ -444,7 +444,7 @@ void shutdownTestGlobals()
delete globals;
globals = nullptr;
if (global_loggingToKML) {
if (global_kmlStream) {
if (global_lineStringOpen) {
endCurrentLineString();
}

View file

@ -0,0 +1,62 @@
<?xml version="1.0"?>
<!-- Updated 29NOV20 to remove EGEL flights as no runway defined in FG -->
<trafficlist>
<aircraft>
<model>Aircraft/BN-2/BN-2-Hebridean.xml</model>
<livery>TST</livery>
<airline>TST</airline>
<home-port>YSSY</home-port>
<required-aircraft>TST_BN_2</required-aircraft>
<actype>BN2</actype>
<offset>0</offset>
<radius>8</radius>
<flighttype>gate</flighttype>
<performance-class>turboprop_transport</performance-class>
<registration>G-HEBO</registration>
<heavy>false</heavy>
</aircraft>
<aircraft>
<model>Aircraft/BN-2/BN-2-Hebridean.xml</model>
<livery>TST</livery>
<airline>TST</airline>
<home-port>YBBN</home-port>
<required-aircraft>TST_BN_2</required-aircraft>
<actype>BN2</actype>
<offset>0</offset>
<radius>8</radius>
<flighttype>gate</flighttype>
<performance-class>turboprop_transport</performance-class>
<registration>G-HEBS</registration>
<heavy>false</heavy>
</aircraft>
<flight>
<callsign>Hebridean_1000</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YBBN</port>
<time>00:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YSSY</port>
<time>01:00:00</time>
</arrival>
<repeat>Hr</repeat>
</flight>
<flight>
<callsign>Hebridean_1000</callsign>
<required-aircraft>TST_BN_2</required-aircraft>
<fltrules>VFR</fltrules>
<departure>
<port>YSSY</port>
<time>00:00:00</time>
</departure>
<cruise-alt>50</cruise-alt>
<arrival>
<port>YBBN</port>
<time>01:00:00</time>
</arrival>
<repeat>Hr</repeat>
</flight>
</trafficlist>

View file

@ -5,6 +5,7 @@ set(TESTSUITE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/test_AIFlightPlan.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_TrafficMgr.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.cxx
${CMAKE_CURRENT_SOURCE_DIR}/test_submodels.cxx
PARENT_SCOPE
@ -15,6 +16,7 @@ set(TESTSUITE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/test_AIFlightPlan.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_AIManager.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_traffic.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_TrafficMgr.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_groundnet.hxx
${CMAKE_CURRENT_SOURCE_DIR}/test_submodels.hxx
PARENT_SCOPE

View file

@ -21,6 +21,7 @@
#include "test_AIManager.hxx"
#include "test_groundnet.hxx"
#include "test_traffic.hxx"
#include "test_TrafficMgr.hxx"
#include "test_submodels.hxx"
#include "test_AIFlightPlan.hxx"
@ -28,4 +29,5 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIFlightPlanTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIManagerTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GroundnetTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficMgrTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SubmodelsTests, "Unit tests");

View file

@ -0,0 +1,153 @@
/*
* Copyright (C) 2021 Keith Paterson
*
* This file is part of the program FlightGear.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "test_TrafficMgr.hxx"
#include <cstring>
#include <memory>
#include <unistd.h>
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include <Airports/airport.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
// Set up function for each test.
void TrafficMgrTests::setUp()
{
FGTestApi::setUp::initTestGlobals("TrafficMgr");
FGTestApi::setUp::initNavDataCache();
fgSetBool("sim/ai/enabled", true);
fgSetBool("sim/traffic-manager/enabled", true);
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
//Otherwise TrafficMgr won't load
fgSetBool("sim/signals/fdm-initialized", true);
globals->set_fg_root(SGPath::fromUtf8(FG_TEST_SUITE_DATA));
}
// Clean up after each test.
void TrafficMgrTests::tearDown()
{
FGTestApi::tearDown::shutdownTestGlobals();
}
void TrafficMgrTests::testParse() {
globals->add_new_subsystem<FGTrafficManager>();
globals->get_subsystem_mgr()->bind();
globals->get_subsystem_mgr()->init();
globals->get_subsystem_mgr()->postinit();
FGTrafficManager *tmgr = (FGTrafficManager *) globals->get_subsystem("traffic-manager");
FGScheduledFlightVecIterator fltBegin, fltEnd;
for (size_t i = 0; i < 1000000; i++)
{
FGTestApi::runForTime(10.0);
// We have to wait for async parser
fltBegin = tmgr->getFirstFlight("TST_BN_2");
fltEnd = tmgr->getLastFlight("TST_BN_2");
if (fltBegin != fltEnd) {
break;
}
}
int counter = 0;
for (FGScheduledFlightVecIterator i = fltBegin; i != fltEnd; i++) {
cout << (*i)->getCallSign() << counter++ << endl;
}
CPPUNIT_ASSERT_EQUAL(2, counter);
}
void TrafficMgrTests::testTrafficManager()
{
FGAirportRef egeo = FGAirport::getByIdent("EGEO");
fgSetString("/sim/presets/airport-id", "EGEO");
std::cout << globals->get_fg_root() << "\r\n";
globals->set_fg_root(SGPath::fromUtf8(FG_TEST_SUITE_DATA));
std::cout << globals->get_fg_root() << "\r\n";
fgSetBool("/sim/traffic-manager/enabled", true);
fgSetBool("/sim/traffic-manager/active", false);
fgSetBool("/sim/ai/enabled", true);
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
fgSetBool("/sim/terrasync/ai-data-update-now", false);
fgSetBool("/sim/traffic-manager/instantaneous-action", true);
fgSetBool("/sim/traffic-manager/heuristics", true);
fgSetBool("/sim/traffic-manager/dumpdata", false);
fgSetBool("/sim/signals/fdm-initialized", true);
FGTestApi::setPositionAndStabilise(egeo->geod());
auto tmgr = globals->add_new_subsystem<FGTrafficManager>();
tmgr->bind();
tmgr->init();
for( int i = 0; i < 30; i++) {
bool active = fgGetBool("/sim/traffic-manager/inited");
// std::cout << "Inited " << "\t" << i << "\t" << active << "\r\n";
FGTestApi::runForTime(5.0);
if(active) {
break;
}
}
const SGPropertyNode *tm = fgGetNode("/sim/traffic-manager", true);
for (int i = 0; i < tm->nChildren(); i++) {
const SGPropertyNode *model = tm->getChild(i);
std::cout << "TM : " << model->getDisplayName() << "\t" << model->nChildren() << "\n";
for (int g = 0; g < model->nChildren(); g++) {
const SGPropertyNode *v;
v = model->getChild(g);
std::cout << "Node " << g << "\t" << v->getDisplayName() << "\n";
}
}
FGTestApi::runForTime(360.0);
FGScheduledFlightVecIterator fltBegin, fltEnd;
fltBegin = tmgr->getFirstFlight("HBR_BN_2");
fltEnd = tmgr->getLastFlight("HBR_BN_2");
if (fltBegin == fltEnd) {
CPPUNIT_FAIL("No Traffic found");
}
int counter = 0;
for (FGScheduledFlightVecIterator i = fltBegin; i != fltEnd; i++) {
cout << (*i)->getDepartureAirport()->getId() << "\t" << (*i)->getArrivalAirport()->getId() << "\t" << (*i)->getDepartureTime() << "\n";
counter++;
}
CPPUNIT_ASSERT_EQUAL(25, counter);
}

View file

@ -0,0 +1,53 @@
/*
* Copyright (C) 2021 Keith Paterson
*
* This file is part of the program FlightGear.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include <simgear/props/props.hxx>
class SGGeod;
class FGAIAircraft;
// The flight plan unit tests.
class TrafficMgrTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(TrafficMgrTests);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testTrafficManager);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
// Clean up after each test.
void tearDown();
// The tests.
void testTrafficManager();
void testParse();
};

View file

@ -28,9 +28,7 @@
#include "test_suite/FGTestApi/NavDataCache.hxx"
#include "test_suite/FGTestApi/TestDataLogger.hxx"
#include "test_suite/FGTestApi/testGlobals.hxx"
#include "test_suite/FGTestApi/mock_scenery.hxx"
#include <simgear/math/sg_geodesy.hxx>
#include <AIModel/AIAircraft.hxx>
#include <AIModel/AIFlightPlan.hxx>
#include <AIModel/AIManager.hxx>
@ -39,8 +37,9 @@
#include <Airports/airportdynamicsmanager.hxx>
#include <Airports/groundnetwork.hxx>
#include <Scenery/scenery.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <Time/TimeManager.hxx>
#include <Traffic/TrafficMgr.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <ATC/atc_mgr.hxx>
@ -52,21 +51,16 @@
// Set up function for each test.
void TrafficTests::setUp()
{
FGTestApi::setUp::initTestGlobals("Traffic");
FGTestApi::setUp::initNavDataCache();
/*
globals->add_new_subsystem<FGMockScenery>(SGSubsystemMgr::DISPLAY);
globals->get_scenery()->init();
globals->get_scenery()->bind();
*/
auto props = globals->get_props();
props->setBoolValue("sim/ai/enabled", true);
props->setBoolValue("sim/traffic-manager/enabled", true);
props->setBoolValue("sim/signals/fdm-initialized", false);
props->setDoubleValue("/environment/visibility-m", 10000000.0);
fgSetBool("sim/ai/enabled", true);
fgSetBool("sim/traffic-manager/enabled", true);
fgSetBool("sim/signals/fdm-initialized", false);
fgSetInt("/environment/visibility-m", 1000);
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
fgSetBool("/sim/terrasync/ai-data-update-now", false);
// ensure EDDF has a valid ground net for parking testing
@ -75,7 +69,6 @@ void TrafficTests::setUp()
egph->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "EGPH.groundnet.xml");
FGAirportRef yssy = FGAirport::getByIdent("YSSY");
yssy->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "YSSY.groundnet.xml");
FGAirportRef ybbn = FGAirport::getByIdent("YBBN");
ybbn->testSuiteInjectGroundnetXML(SGPath::fromUtf8(FG_TEST_SUITE_DATA) / "YBBN.groundnet.xml");
@ -98,37 +91,33 @@ void TrafficTests::tearDown()
void TrafficTests::testPushback()
{
FGAirportRef egph = FGAirport::getByIdent("EGPH");
FGAirportRef departureAirport = FGAirport::getByIdent("EGPH");
FGAirportRef egpf = FGAirport::getByIdent("EGPF");
fgSetString("/sim/presets/airport-id", "EGPH");
fgSetInt("/environment/visibility-m", 1000);
FGAirportRef arrivalAirport = FGAirport::getByIdent("EGPF");
fgSetString("/sim/presets/airport-id", departureAirport->getId());
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 50;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 320;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(30);
// Time to arrive
std::string arr = getTimeString(320);
const int radius = 18.0;
const int cruiseAltFt = 32000;
const int cruiseSpeedKnots = 80;
const char* flighttype = "gate";
FGAISchedule* schedule = new FGAISchedule(
"B737", "KLM", "EGPH", "G-BLA", "ID", false, "B737", "KLM", "N", "gate", 24, 8);
FGScheduledFlight* flight = new FGScheduledFlight("", "", "EGPH", "EGPF", 24, dep, arr, "WEEK", "HBR_BN_2");
"B737", "KLM", departureAirport->getId(), "G-BLA", "ID", false, "B737", "KLM", "N", flighttype, radius, 8);
FGScheduledFlight* flight = new FGScheduledFlight("", "", departureAirport->getId(), arrivalAirport->getId(), 24, dep, arr, "WEEK", "HBR_BN_2");
schedule->assign(flight);
FGAIAircraft* aiAircraft = new FGAIAircraft{schedule};
const SGGeod position = egph->geod();
ParkingAssignment parking = egph->getDynamics()->getParkingByName("north-cargo208");
FGTestApi::setPositionAndStabilise(egph->getDynamics()->getParkingByName("ga206").parking()->geod());
const SGGeod position = departureAirport->geod();
ParkingAssignment parking = departureAirport->getDynamics()->getParkingByName("north-cargo208");
FGTestApi::setPositionAndStabilise(departureAirport->getDynamics()->getParkingByName("ga206").parking()->geod());
aiAircraft->setPerformance("jet_transport", "");
aiAircraft->setCompany("KLM");
@ -136,20 +125,16 @@ void TrafficTests::testPushback()
aiAircraft->setSpeed(0);
aiAircraft->setBank(0);
const string flightPlanName = egph->getId() + "-" + egpf->getId() + ".xml";
const string flightPlanName = departureAirport->getId() + "-" + arrivalAirport->getId() + ".xml";
const int radius = 18.0;
const int cruiseAltFt = 32000;
const int cruiseSpeedKnots = 80;
const double crs = SGGeodesy::courseDeg(egph->geod(), egpf->geod()); // direct course
const double crs = SGGeodesy::courseDeg(departureAirport->geod(), arrivalAirport->geod()); // direct course
time_t departureTime;
time(&departureTime); // now
departureTime = departureTime - 50;
std::unique_ptr<FGAIFlightPlan> fp(new FGAIFlightPlan(aiAircraft,
flightPlanName, crs, departureTime,
egph, egpf, true, radius,
departureAirport, arrivalAirport, true, radius,
cruiseAltFt, // cruise alt
position.getLatitudeDeg(),
position.getLongitudeDeg(),
@ -157,47 +142,25 @@ void TrafficTests::testPushback()
aiAircraft->getAcType(),
aiAircraft->getCompany()));
if (fp->isValidPlan()) {
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
}
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
for (size_t i = 0; i < 6000 && aiAircraft->GetFlightPlan()->getLeg() < 8; i++)
{
//this->dump(aiAircraft);
if(geods.empty()||SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
}
FGTestApi::runForTime(3.0);
}
FGTestApi::setUp::logPositionToKML("flight_EDPH_" + std::to_string(departureTime));
FGTestApi::writeGeodsToKML("Aircraft", geods);
CPPUNIT_ASSERT_EQUAL( 5, aiAircraft->GetFlightPlan()->getLeg());
aiAircraft = flyAI(aiAircraft, "flight_EGPH_EGPF_" + std::to_string(departureTime));
CPPUNIT_ASSERT_EQUAL(5, aiAircraft->GetFlightPlan()->getLeg());
}
void TrafficTests::testPushback2()
void TrafficTests::testPushbackCargo()
{
FGAirportRef egph = FGAirport::getByIdent("EGPH");
FGAirportRef egpf = FGAirport::getByIdent("EGPF");
fgSetString("/sim/presets/airport-id", "EGPH");
fgSetInt("/environment/visibility-m", 1000);
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 50;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 320;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(30);
// Time to arrive
std::string arr = getTimeString(320);
FGAISchedule* schedule = new FGAISchedule(
@ -238,118 +201,13 @@ void TrafficTests::testPushback2()
aiAircraft->getAcType(),
aiAircraft->getCompany()));
if (fp->isValidPlan()) {
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
}
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
for (size_t i = 0; i < 6000 && aiAircraft->GetFlightPlan()->getLeg() < 10; i++)
{
// this->dump(aiAircraft);
if(geods.empty()||SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
}
aiAircraft = flyAI(aiAircraft, "flight_cargo_EDPH_" + std::to_string(departureTime));
FGTestApi::runForTime(3.0);
}
FGTestApi::setUp::logPositionToKML("flight_cargo_EDPH_" + std::to_string(departureTime));
FGTestApi::writeGeodsToKML("Aircraft", geods);
CPPUNIT_ASSERT_EQUAL( 5, aiAircraft->GetFlightPlan()->getLeg());
}
void TrafficTests::testTrafficManager()
{
FGAirportRef egeo = FGAirport::getByIdent("EGEO");
fgSetString("/sim/presets/airport-id", "EGEO");
std::cout << globals->get_fg_root() << "\r\n";
globals->set_fg_root(SGPath::fromUtf8(FG_TEST_SUITE_DATA));
std::cout << globals->get_fg_root() << "\r\n";
fgSetBool("/sim/traffic-manager/enabled", true);
fgSetBool("/sim/traffic-manager/active", false);
fgSetBool("/sim/ai/enabled", true);
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
fgSetBool("/sim/terrasync/ai-data-update-now", false);
fgSetBool("/sim/traffic-manager/instantaneous-action", true);
fgSetBool("/sim/traffic-manager/heuristics", true);
fgSetBool("/sim/traffic-manager/dumpdata", false);
fgSetBool("/sim/signals/fdm-initialized", true);
FGTestApi::setPositionAndStabilise(egeo->geod());
auto tmgr = globals->add_new_subsystem<FGTrafficManager>();
tmgr->bind();
tmgr->init();
for( int i = 0; i < 30; i++) {
bool active = fgGetBool("/sim/traffic-manager/inited");
// std::cout << "Inited " << "\t" << i << "\t" << active << "\r\n";
FGTestApi::runForTime(5.0);
if(active) {
break;
}
// SGTimeStamp::sleepForMSec(300);
}
const SGPropertyNode *tm = fgGetNode("/sim/traffic-manager", true);
for (int i = 0; i < tm->nChildren(); i++) {
const SGPropertyNode *model = tm->getChild(i);
std::cout << "TM : " << model->getDisplayName() << "\t" << model->nChildren() << "\n";
for (int g = 0; g < model->nChildren(); g++) {
const SGPropertyNode *v;
v = model->getChild(g);
std::cout << "Node " << g << "\t" << v->getDisplayName() << "\n";
}
}
FGTestApi::runForTime(240.0);
FGScheduledFlightVecIterator fltBegin, fltEnd;
fltBegin = tmgr->getFirstFlight("HBR_BN_2");
fltEnd = tmgr->getLastFlight("HBR_BN_2");
if (fltBegin == fltEnd) {
CPPUNIT_FAIL("No Traffic found");
}
int counter = 0;
for (FGScheduledFlightVecIterator i = fltBegin; i != fltEnd; i++) {
cout << (*i)->getDepartureAirport()->getId() << "\t" << (*i)->getArrivalAirport()->getId() << "\t" << (*i)->getDepartureTime() << "\n";
counter++;
//sort(fltBegin, fltEnd, compareScheduledFlights);
//cerr << counter++ << endl;
}
const SGPropertyNode *ai = fgGetNode("/ai/models", false);
std::cout << "Num Children " << ai->nChildren() << "\n";
for (int i = 0; i < ai->nChildren(); i++) {
const SGPropertyNode *model;
model = ai->getChild(i);
std::cout << "Model : " << model->getDisplayName() << "\t" << model->nChildren() << "\n";
for (int g = 0; g < model->nChildren(); g++) {
const SGPropertyNode *v;
v = model->getChild(g);
std::cout << "Node " << g << "\t" << v->getDisplayName() << "\n";
}
}
const SGPropertyNode *modelCount = fgGetNode("/ai/models/count", false);
for (size_t i = 0; i < 20; i++)
{
FGTestApi::runForTime(1000.0);
// std::cout << "AI Count " << modelCount->getIntValue() << "\r\n";
if(modelCount->getIntValue()>0)
break;
}
CPPUNIT_ASSERT_EQUAL(25, counter);
CPPUNIT_ASSERT_EQUAL(5, aiAircraft->GetFlightPlan()->getLeg());
}
void TrafficTests::testChangeRunway()
@ -362,20 +220,10 @@ void TrafficTests::testChangeRunway()
fgSetInt("/environment/metar/base-wind-speed-kt", 10);
fgSetInt("/environment/metar/base-wind-dir-deg", 160);
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 50;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 320;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(60);
// Time to arrive
std::string arr = getTimeString(320);
const int radius = 24.0;
const int cruiseAltFt = 32000;
@ -415,24 +263,13 @@ void TrafficTests::testChangeRunway()
aiAircraft->getAcType(),
aiAircraft->getCompany()));
CPPUNIT_ASSERT_EQUAL( fp->isValidPlan(), true);
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
auto prefs = departureAirport->getDynamics();
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
for (size_t i = 0; i < 6000; i++)
{
if(geods.empty()||SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
}
aiAircraft = flyAI(aiAircraft, "flight_runway_EGPH_" + std::to_string(departureTime));
FGTestApi::runForTime(3.0);
}
FGTestApi::setUp::logPositionToKML("flight_runway_EGPH_" + std::to_string(departureTime));
FGTestApi::writeGeodsToKML("Aircraft", geods);
CPPUNIT_ASSERT_EQUAL( 5, aiAircraft->GetFlightPlan()->getLeg());
CPPUNIT_ASSERT_EQUAL(5, aiAircraft->GetFlightPlan()->getLeg());
}
@ -442,21 +279,11 @@ void TrafficTests::testPushforward()
FGAirportRef arrivalAirport = FGAirport::getByIdent("YBBN");
fgSetString("/sim/presets/airport-id", departureAirport->getId());
fgSetInt("/environment/visibility-m", 1000);
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 50;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 320;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(60);
// Time to arrive
std::string arr = getTimeString(320);
const int radius = 8.0;
const int cruiseAltFt = 32000;
@ -496,24 +323,13 @@ void TrafficTests::testPushforward()
aiAircraft->getAcType(),
aiAircraft->getCompany()));
CPPUNIT_ASSERT_EQUAL( fp->isValidPlan(), true);
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
for (size_t i = 0; i < 6000 && aiAircraft->GetFlightPlan()->getLeg() < 3; i++)
{
//this->dump(aiAircraft);
aiAircraft = flyAI(aiAircraft, "flight_ga_YSSY_depart_" + std::to_string(departureTime));
if(geods.empty()||SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
}
FGTestApi::runForTime(3.0);
}
FGTestApi::setUp::logPositionToKML("flight_ga_YSSY_depart_" + std::to_string(departureTime));
FGTestApi::writeGeodsToKML("Aircraft", geods);
CPPUNIT_ASSERT_EQUAL( 5, aiAircraft->GetFlightPlan()->getLeg());
CPPUNIT_ASSERT_EQUAL(5, aiAircraft->GetFlightPlan()->getLeg());
}
void TrafficTests::testPushforwardSpeedy()
@ -522,21 +338,11 @@ void TrafficTests::testPushforwardSpeedy()
FGAirportRef arrivalAirport = FGAirport::getByIdent("YBBN");
fgSetString("/sim/presets/airport-id", departureAirport->getId());
fgSetInt("/environment/visibility-m", 1000);
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 50;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 320;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(60);
// Time to arrive
std::string arr = getTimeString(320);
const int radius = 8.0;
const int cruiseAltFt = 32000;
@ -576,24 +382,13 @@ void TrafficTests::testPushforwardSpeedy()
aiAircraft->getAcType(),
aiAircraft->getCompany()));
CPPUNIT_ASSERT_EQUAL( fp->isValidPlan(), true);
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
for (size_t i = 0; i < 6000 && aiAircraft->GetFlightPlan()->getLeg() < 3; i++)
{
//this->dump(aiAircraft);
aiAircraft = flyAI(aiAircraft, "flight_ga_YSSY_fast_depart_" + std::to_string(departureTime));
if(geods.empty()||SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
}
FGTestApi::runForTime(3.0);
}
FGTestApi::setUp::logPositionToKML("flight_ga_YSSY_fast_depart_" + std::to_string(departureTime));
FGTestApi::writeGeodsToKML("Aircraft", geods);
CPPUNIT_ASSERT_EQUAL( 5, aiAircraft->GetFlightPlan()->getLeg());
CPPUNIT_ASSERT_EQUAL(5, aiAircraft->GetFlightPlan()->getLeg());
}
void TrafficTests::testPushforwardParkYBBN()
@ -603,25 +398,11 @@ void TrafficTests::testPushforwardParkYBBN()
FGAirportRef arrivalAirport = FGAirport::getByIdent("YSSY");
fgSetString("/sim/presets/airport-id", arrivalAirport->getId());
fgSetInt("/environment/visibility-m", 1000);
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
fgSetBool("/sim/terrasync/ai-data-update-now", false);
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 60;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 3200;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(60);
// Time to arrive
std::string arr = getTimeString(3260);
const int radius = 8.0;
const int cruiseAltFt = 32000;
@ -661,72 +442,19 @@ void TrafficTests::testPushforwardParkYBBN()
aiAircraft->getAcType(),
aiAircraft->getCompany()));
CPPUNIT_ASSERT_EQUAL( fp->isValidPlan(), true);
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
FGTestApi::setUp::logLinestringsToKML("flight_ga_YSSY_park_" + std::to_string(departureTime));
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
char buffer [50];
int lastLeg = -1;
double lastHeading = 0;
int lastDistanceToAirport = 100000000;
for (size_t i = 0; i < 12000000
&& !aiAircraft->getDie()
&& aiAircraft->GetFlightPlan()->getLeg() < 10; i++)
{
if(!aiAircraft->getDie()) {
// collect position
if(geods.empty() ||
SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 0.1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
lastHeading = aiAircraft->_getHeading();
}
if(geods.empty()||
(aiAircraft->getSpeed() > 0 &&
SGGeodesy::distanceM(aiAircraft->getGeodPos(), FGTestApi::getPosition()) > 50) &&
// stop following to the end
aiAircraft->GetFlightPlan()->getLeg() < 8
) {
// std::cout << "Reposition to " << aiAircraft->getGeodPos() << "\t" << aiAircraft->isValid() << "\t" << aiAircraft->getDie() << "\n";
FGTestApi::setPositionAndStabilise(aiAircraft->getGeodPos());
}
}
// in cruise
if(aiAircraft->GetFlightPlan()->getLeg() == 9) {
int currentDistance =
SGGeodesy::distanceM(aiAircraft->getGeodPos(), arrivalAirport->getTowerLocation());
if( currentDistance < lastDistanceToAirport ) {
this->dump(aiAircraft);
}
if( currentDistance >= lastDistanceToAirport ) {
this->dump(aiAircraft);
}
// CPPUNIT_ASSERT_LESS(lastDistanceToAirport, currentDistance);
lastDistanceToAirport = currentDistance;
}
if (aiAircraft->GetFlightPlan()->getLeg() > lastLeg)
{
sprintf(buffer, "AI Leg %d", lastLeg);
FGTestApi::writeGeodsToKML(buffer, geods);
lastLeg = aiAircraft->GetFlightPlan()->getLeg();
SGGeod last = geods.back();
geods.clear();
geods.insert(geods.end(), last);
}
CPPUNIT_ASSERT_LESSEQUAL(10, aiAircraft->GetFlightPlan()->getLeg());
FGTestApi::runForTime(0.5);
}
lastLeg = aiAircraft->GetFlightPlan()->getLeg();
sprintf(buffer, "AI Leg %d", lastLeg);
aiAircraft = flyAI(aiAircraft, "flight_ga_YSSY_YBBN_park_" + std::to_string(departureTime));
int shortestDistance = 10000;
const FGParkingList& parkings(arrivalAirport->groundNetwork()->allParkings());
FGParkingList::const_iterator it;
FGParking* nearestParking = 0;
for (it = parkings.begin(); it != parkings.end(); ++it) {
int currentDistance = !nearestParking?9999:
SGGeodesy::distanceM(nearestParking->geod(), (*it)->geod());
if(currentDistance < shortestDistance) {
int currentDistance = !nearestParking ? 9999 : SGGeodesy::distanceM(nearestParking->geod(), (*it)->geod());
if (currentDistance < shortestDistance) {
nearestParking = (*it);
shortestDistance = currentDistance;
std::cout << (*it)->name() << "\t" << (*it)->getHeading()
@ -734,11 +462,9 @@ void TrafficTests::testPushforwardParkYBBN()
}
}
FGTestApi::writeGeodsToKML(buffer, geods);
CPPUNIT_ASSERT_EQUAL( true, aiAircraft->getDie());
CPPUNIT_ASSERT_EQUAL( 0, shortestDistance);
CPPUNIT_ASSERT_EQUAL( nearestParking->getHeading(), lastHeading);
geods.clear();
CPPUNIT_ASSERT_EQUAL(true, aiAircraft->getDie());
CPPUNIT_ASSERT_EQUAL(0, shortestDistance);
// CPPUNIT_ASSERT_EQUAL(nearestParking->getHeading(), lastHeading);
}
void TrafficTests::testPushforwardParkYBBNRepeat()
@ -748,25 +474,13 @@ void TrafficTests::testPushforwardParkYBBNRepeat()
FGAirportRef arrivalAirport = FGAirport::getByIdent("YSSY");
fgSetString("/sim/presets/airport-id", arrivalAirport->getId());
fgSetInt("/environment/visibility-m", 1000);
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
fgSetBool("/sim/terrasync/ai-data-update-now", false);
time_t rawtime;
struct tm * timeinfo;
char dep [11];
char arr [11];
time (&rawtime);
rawtime = rawtime + 60;
timeinfo = gmtime (&rawtime);
strftime (dep,11,"%w/%H:%M:%S",timeinfo);
rawtime = rawtime + 3200;
timeinfo = gmtime (&rawtime);
strftime (arr,11,"%w/%H:%M:%S",timeinfo);
// Time to depart
std::string dep = getTimeString(60);
// Time to arrive
std::string arr = getTimeString(3260);
// Time to arrive back
std::string ret = getTimeString(6460);
const int radius = 8.0;
const int cruiseAltFt = 32000;
@ -778,6 +492,9 @@ void TrafficTests::testPushforwardParkYBBNRepeat()
FGScheduledFlight* flight = new FGScheduledFlight("gaParkYSSY", "", departureAirport->getId(), arrivalAirport->getId(), 24, dep, arr, "WEEK", "HBR_BN_2");
schedule->assign(flight);
FGScheduledFlight* returnFlight = new FGScheduledFlight("gaParkYSSY", "", arrivalAirport->getId(), departureAirport->getId(), 24, arr, ret, "WEEK", "HBR_BN_2");
schedule->assign(returnFlight);
FGAIAircraft* aiAircraft = new FGAIAircraft{schedule};
const SGGeod position = departureAirport->geod();
@ -805,53 +522,59 @@ void TrafficTests::testPushforwardParkYBBNRepeat()
cruiseSpeedKnots, flighttype,
aiAircraft->getAcType(),
aiAircraft->getCompany()));
CPPUNIT_ASSERT_EQUAL( fp->isValidPlan(), true);
CPPUNIT_ASSERT_EQUAL(fp->isValidPlan(), true);
aiAircraft->FGAIBase::setFlightPlan(std::move(fp));
globals->get_subsystem<FGAIManager>()->attach(aiAircraft);
FGTestApi::setUp::logLinestringsToKML("flight_ga_YSSY_park_" + std::to_string(departureTime));
aiAircraft = flyAI(aiAircraft, "flight_ga_YSSY_YBBN_park_repeat" + std::to_string(departureTime));
int shortestDistance = 10000;
const FGParkingList& parkings(arrivalAirport->groundNetwork()->allParkings());
FGParkingList::const_iterator it;
FGParking* nearestParking = 0;
for (it = parkings.begin(); it != parkings.end(); ++it) {
int currentDistance = !nearestParking ? 9999 : SGGeodesy::distanceM(nearestParking->geod(), (*it)->geod());
if (currentDistance < shortestDistance) {
nearestParking = (*it);
shortestDistance = currentDistance;
std::cout << (*it)->name() << "\t" << (*it)->getHeading()
<< "\t" << shortestDistance << "\t" << (*it)->geod() << "\n";
}
}
CPPUNIT_ASSERT_EQUAL(true, aiAircraft->getDie());
CPPUNIT_ASSERT_EQUAL(0, shortestDistance);
// CPPUNIT_ASSERT_EQUAL(nearestParking->getHeading(), lastHeading);
}
FGAIAircraft * TrafficTests::flyAI(FGAIAircraft * aiAircraft, std::string fName) {
FGTestApi::setUp::logLinestringsToKML(fName);
flightgear::SGGeodVec geods = flightgear::SGGeodVec();
char buffer [50];
char buffer[50];
int lastLeg = -1;
double lastHeading = 0;
int lastDistanceToAirport = 100000000;
for (size_t i = 0; i < 12000000
&& !aiAircraft->getDie()
&& aiAircraft->GetFlightPlan()->getLeg() < 10; i++)
{
if(!aiAircraft->getDie()) {
for (size_t i = 0; i < 12000000 && !(aiAircraft->getDie()) && aiAircraft->GetFlightPlan()->getLeg() < 10; i++) {
if (!aiAircraft->getDie()) {
// collect position
if(geods.empty() ||
if (geods.empty() ||
SGGeodesy::distanceM(aiAircraft->getGeodPos(), geods.back()) > 0.1) {
geods.insert(geods.end(), aiAircraft->getGeodPos());
lastHeading = aiAircraft->_getHeading();
}
if(geods.empty()||
if (geods.empty() ||
(aiAircraft->getSpeed() > 0 &&
SGGeodesy::distanceM(aiAircraft->getGeodPos(), FGTestApi::getPosition()) > 50) &&
// stop following to the end
aiAircraft->GetFlightPlan()->getLeg() < 8
) {
SGGeodesy::distanceM(aiAircraft->getGeodPos(), FGTestApi::getPosition()) > 50 &&
/* stop following towards the end*/
aiAircraft->GetFlightPlan()->getLeg() < 8)) {
// std::cout << "Reposition to " << aiAircraft->getGeodPos() << "\t" << aiAircraft->isValid() << "\t" << aiAircraft->getDie() << "\n";
FGTestApi::setPositionAndStabilise(aiAircraft->getGeodPos());
}
}
// in cruise
if(aiAircraft->GetFlightPlan()->getLeg() == 9) {
int currentDistance =
SGGeodesy::distanceM(aiAircraft->getGeodPos(), arrivalAirport->getTowerLocation());
if( currentDistance < lastDistanceToAirport ) {
if (aiAircraft->GetFlightPlan()->getLeg() == 9) {
this->dump(aiAircraft);
}
if( currentDistance >= lastDistanceToAirport ) {
this->dump(aiAircraft);
}
// CPPUNIT_ASSERT_LESS(lastDistanceToAirport, currentDistance);
lastDistanceToAirport = currentDistance;
}
if (aiAircraft->GetFlightPlan()->getLeg() > lastLeg)
{
if (aiAircraft->GetFlightPlan()->getLeg() > lastLeg) {
sprintf(buffer, "AI Leg %d", lastLeg);
FGTestApi::writeGeodsToKML(buffer, geods);
lastLeg = aiAircraft->GetFlightPlan()->getLeg();
@ -860,46 +583,43 @@ void TrafficTests::testPushforwardParkYBBNRepeat()
geods.insert(geods.end(), last);
}
CPPUNIT_ASSERT_LESSEQUAL(10, aiAircraft->GetFlightPlan()->getLeg());
FGTestApi::runForTime(0.5);
FGTestApi::runForTime(3);
}
lastLeg = aiAircraft->GetFlightPlan()->getLeg();
sprintf(buffer, "AI Leg %d", lastLeg);
int shortestDistance = 10000;
const FGParkingList& parkings(arrivalAirport->groundNetwork()->allParkings());
FGParkingList::const_iterator it;
FGParking* nearestParking = 0;
for (it = parkings.begin(); it != parkings.end(); ++it) {
int currentDistance = !nearestParking?9999:
SGGeodesy::distanceM(nearestParking->geod(), (*it)->geod());
if(currentDistance < shortestDistance) {
nearestParking = (*it);
shortestDistance = currentDistance;
std::cout << (*it)->name() << "\t" << (*it)->getHeading()
<< "\t" << shortestDistance << "\t" << (*it)->geod() << "\n";
}
}
FGTestApi::writeGeodsToKML(buffer, geods);
CPPUNIT_ASSERT_EQUAL( true, aiAircraft->getDie());
CPPUNIT_ASSERT_EQUAL( 0, shortestDistance);
CPPUNIT_ASSERT_EQUAL( nearestParking->getHeading(), lastHeading);
geods.clear();
return aiAircraft;
}
void TrafficTests::dump(FGAIAircraft* aiAircraft) {
void TrafficTests::dump(FGAIAircraft* aiAircraft)
{
std::cout << "********************\n";
std::cout << "Geod " << aiAircraft->getGeodPos() << "\t Speed : " << aiAircraft->getSpeed() << "\n";
std::cout << "Heading " << aiAircraft->getTrueHeadingDeg() << "\t VSpeed : " << aiAircraft->getVerticalSpeedFPM() << "\n";
FGAIWaypoint* currentWP = aiAircraft->GetFlightPlan()->getCurrentWaypoint();
if(currentWP) {
if (currentWP) {
std::cout << "WP " << currentWP->getName() << "\t" << aiAircraft->GetFlightPlan()->getCurrentWaypoint()->getPos() << "\r\n";
std::cout << "Distance " << SGGeodesy::distanceM(aiAircraft->getGeodPos(), currentWP->getPos()) << "\n";
} else {
std::cout << "No Current WP\n";
}
std::cout << "Flightplan " << "\n";
std::cout << "Flightplan "
<< "\n";
FGAIFlightPlan* fp = aiAircraft->GetFlightPlan();
if(fp->isValidPlan()) {
std::cout << fp->getNrOfWayPoints() << "\n";
if (fp->isValidPlan()) {
std::cout << "Leg : " << fp->getLeg() << "\n";
std::cout << "Length : " << fp->getNrOfWayPoints() << "\n";
}
}
std::string TrafficTests::getTimeString(int timeOffset)
{
char ret[11];
time_t rawtime;
time (&rawtime);
rawtime = rawtime + timeOffset;
tm* timeinfo = gmtime(&rawtime);
strftime(ret, 11, "%w/%H:%M:%S", timeinfo);
return ret;
}

View file

@ -35,17 +35,14 @@ class TrafficTests : public CppUnit::TestFixture
{
// Set up the test suite.
CPPUNIT_TEST_SUITE(TrafficTests);
CPPUNIT_TEST(testTrafficManager);
CPPUNIT_TEST(testPushback);
CPPUNIT_TEST(testPushback2);
CPPUNIT_TEST(testPushbackCargo);
CPPUNIT_TEST(testChangeRunway);
CPPUNIT_TEST(testPushforward);
CPPUNIT_TEST(testPushforwardSpeedy);
CPPUNIT_TEST(testPushforwardParkYBBN);
CPPUNIT_TEST(testPushforwardParkYBBNRepeat);
CPPUNIT_TEST_SUITE_END();
public:
// Set up function for each test.
void setUp();
@ -53,15 +50,17 @@ public:
// Clean up after each test.
void tearDown();
// The tests.
void testTrafficManager();
// Pushback Tests
void testPushback();
void testPushback2();
void testPushbackCargo();
void testChangeRunway();
//GA Tests with forward push
void testPushforward();
void testPushforwardSpeedy();
void testPushforwardParkYBBN();
void testPushforwardParkYBBNRepeat();
private:
void dump(FGAIAircraft* aiAircraft);
std::string getTimeString(int timeOffset);
FGAIAircraft * flyAI(FGAIAircraft * aiAircraft, std::string fName);
};