Framework::ReturnCode Framework::run() { Ensures(m_program_options.parse_options()); if (m_program_options.asked_for_help()) { return help(); } if (m_program_options.asked_for_list()) { return list(); } CPPUNIT_NS::TextUi::TestRunner runner; if (m_program_options.asked_to_run_only_some_tests()) { Ensures(combine_tests_subset(runner)); } else if (m_program_options.asked_for_regtest()) { Ensures(combine_regtest_subset(runner)); } else { runner.addTest(get_registry()->makeTest()); } CPPUNIT_NS::TestResult controller; CPPUNIT_NS::TestResultCollector result; controller.addListener(&result); CPPUNIT_NS::BriefTestProgressListener progress; controller.addListener(&progress); runner.run(controller); CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr); outputter.write(); return result.wasSuccessful() ? SUCCESS : FAILURE; }
/****************** * unit test of QSS2 on lotka_volterra model, * based on powerdevs results * * note: results have to be the same as test_QSS2_LotkaVolterra ******************/ void test_QSS2_LotkaVolterraXY() { auto ctx = vu::make_context(); std::cout << " test_QSS2_LotkaVolterraXY " << std::endl; vle::utils::Package pack(ctx, "vle.ode_test"); std::unique_ptr<vz::Vpz> vpz(new vz::Vpz(pack.getExpFile("LotkaVolterraXY.vpz", vle::utils::PKG_BINARY))); ttconfOutputPlugins(*vpz); { std::vector<std::string> conds; conds.push_back("condLV"); conds.push_back("condQSS2"); conds.push_back("condQSS2_X"); ttattachConditions(*vpz,conds,"LotkaVolterraX"); } { std::vector<std::string> conds; conds.push_back("condLV"); conds.push_back("condQSS2"); conds.push_back("condQSS2_Y"); ttattachConditions(*vpz,conds,"LotkaVolterraY"); } //simulation vm::Error error; vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE, std::chrono::milliseconds(0), &std::cout); std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error); //checks that simulation has succeeded EnsuresEqual(error.code, 0); //checks the number of views EnsuresEqual(out->size(),1); //checks the selected view const va::Matrix& view = out->getMatrix("view"); EnsuresEqual(view.columns(),3); //note: the number of rows depend on the averaging of sum of 0.01 Ensures(view.rows() <= 15003); Ensures(view.rows() >= 15002); //gets X,Y int colX = ttgetColumnFromView(view, "Top model:LotkaVolterraX", "X"); int colY = ttgetColumnFromView(view, "Top model:LotkaVolterraY", "Y"); //check X,Y line 15000 EnsuresApproximatelyEqual(view.getDouble(colX,15001), 0.69363324986147468, 10e-5); //previous 0.696088281553273 EnsuresApproximatelyEqual(view.getDouble(colY,15001), 0.07761934820509947, 10e-5); //previous 0.0774536442779648 }
/****************** * Unit test based on powerdevs ******************/ void test_QSS2_Seir() { auto ctx = vu::make_context(); std::cout << " test_QSS2_Seir " << std::endl; vle::utils::Package pack(ctx, "vle.ode_test"); std::unique_ptr<vz::Vpz> vpz(new vz::Vpz(pack.getExpFile("Seir.vpz", vle::utils::PKG_BINARY))); ttconfOutputPlugins(*vpz); std::vector<std::string> conds; conds.push_back("condQSS2"); conds.push_back("condSeir"); ttattachConditions(*vpz,conds,"Seir"); //simulation vm::Error error; vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE, std::chrono::milliseconds(0), &std::cout); std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error); //checks that simulation has succeeded EnsuresEqual(error.code, 0); //checks the number of views EnsuresEqual(out->size(),1); //checks the selected view const va::Matrix& view = out->getMatrix("view"); EnsuresEqual(view.columns(),5); //note: the number of rows depend on the averaging of sum of 0.01 Ensures(view.rows() <= 1503); Ensures(view.rows() >= 1502); //gets S,E,I,R int colS = ttgetColumnFromView(view, "Top model:Seir", "S"); int colE = ttgetColumnFromView(view, "Top model:Seir", "E"); int colI = ttgetColumnFromView(view, "Top model:Seir", "I"); int colR = ttgetColumnFromView(view, "Top model:Seir", "R"); //check S,E,I,R line 1500 EnsuresApproximatelyEqual(view.getDouble(colS,1501), 0.636836529382071, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colE,1501), 0.636051925651117, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colI,1501), 2.95405622447345, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colR,1501), 6.77305532047774, 10e-5); }
HistoryGroupedMedia::HistoryGroupedMedia( not_null<Element*> parent, const std::vector<not_null<HistoryItem*>> &items) : HistoryMedia(parent) , _caption(st::minPhotoSize - st::msgPadding.left() - st::msgPadding.right()) { const auto result = (items.size() <= kMaxDisplayedGroupSize) ? applyGroup(items) : applyGroup(std::vector<not_null<HistoryItem*>>( begin(items), begin(items) + kMaxDisplayedGroupSize)); Ensures(result); }
void Pmr_resource::do_deallocate(void* ptr, std::size_t s, std::size_t a) { Expects(s != 0); // POSIX malloc will allow size 0, but return nullptr. bool trigger_non_full = UNLIKELY(full() and non_full != nullptr); bool trigger_avail_thresh = UNLIKELY(allocatable() < avail_thresh and allocatable() + s >= avail_thresh and avail != nullptr); pool_->deallocate(ptr,s,a); deallocs++; used -= s; if (UNLIKELY(trigger_avail_thresh)) { Ensures(allocatable() >= avail_thresh); Ensures(avail != nullptr); avail(*this); } if (UNLIKELY(trigger_non_full)) { Ensures(!full()); Ensures(non_full != nullptr); non_full(*this); } }
/** Ported more or less directly from SanOS. */ int Virtio::Queue::enqueue(gsl::span<Token> buffers){ debug ("Enqueuing %i tokens \n", buffers.size()); uint16_t last = _free_head; uint16_t first = _free_head; // Place each buffer in a token for( auto buf : buffers ) { debug (" buf @ %p \n", buffers.data()); // Set read / write flags _queue.desc[_free_head].flags = buf.direction() ? VIRTQ_DESC_F_NEXT : VIRTQ_DESC_F_NEXT | VIRTQ_DESC_F_WRITE; // Assign raw buffer _queue.desc[_free_head].addr = (uint64_t) buf.data(); _queue.desc[_free_head].len = buf.size(); last = _free_head; _free_head = _queue.desc[_free_head].next; } _desc_in_flight += buffers.size(); Ensures(_desc_in_flight <= size()); // No continue on last buffer _queue.desc[last].flags &= ~VIRTQ_DESC_F_NEXT; // Place the head of this current chain in the avail ring uint16_t avail_index = (_queue.avail->idx + _num_added) % _size; // we added a token _num_added++; _queue.avail->ring[avail_index] = first; debug("<Q %i> avail_index: %i size: %i, _free_head %i \n", _pci_index, avail_index, size(), _free_head ); debug ("Free tokens: %i \n", num_free()); return buffers.size(); }
/****************** * Unit test based on deSolve R package * see R/check.R function test_Euler_Seir * * Note: we test that the version of Seir based on four * differential_equation (SeirXY.vpz) gets the same results * in the case of Euler integration ******************/ void test_Euler_SeirXY() { auto ctx = vu::make_context(); std::cout << " test_Euler_SeirXY " << std::endl; vle::utils::Package pack(ctx, "vle.ode_test"); std::unique_ptr<vz::Vpz> vpz(new vz::Vpz(pack.getExpFile("SeirXY.vpz", vle::utils::PKG_BINARY))); //set all output plugin to storage vz::Outputs::iterator itb = vpz->project().experiment().views().outputs().begin(); vz::Outputs::iterator ite = vpz->project().experiment().views().outputs().end(); for(;itb!=ite;itb++) { std::unique_ptr<va::Map> configOutput(new va::Map()); configOutput->addInt("rows",10000); configOutput->addInt("inc_rows",10000); configOutput->addString("header","top"); vz::Output& output = itb->second; output.setStream("", "storage", "vle.output"); output.setData(std::move(configOutput)); } //attach condition condEuler and condLV to atomics models std::vector<std::string> conds; { conds.clear(); conds.push_back("condEuler"); conds.push_back("condSeir"); vz::Model& vpz_mod = vpz->project().model(); vz::BaseModel* mdl = vpz_mod.node()->findModelFromPath("Sm"); Ensures(mdl != 0); vz::AtomicModel* atomg = mdl->toAtomic(); atomg->setConditions(conds); } { conds.clear(); conds.push_back("condEuler"); conds.push_back("condSeir"); vz::Model& vpz_mod = vpz->project().model(); vz::BaseModel* mdl = vpz_mod.node()->findModelFromPath("Em"); Ensures(mdl != 0); vz::AtomicModel* atomg = mdl->toAtomic(); atomg->setConditions(conds); } { conds.clear(); conds.push_back("condEuler"); conds.push_back("condSeir"); vz::Model& vpz_mod = vpz->project().model(); vz::BaseModel* mdl = vpz_mod.node()->findModelFromPath("Im"); Ensures(mdl != 0); vz::AtomicModel* atomg = mdl->toAtomic(); atomg->setConditions(conds); } { conds.clear(); conds.push_back("condEuler"); conds.push_back("condSeir"); vz::Model& vpz_mod = vpz->project().model(); vz::BaseModel* mdl = vpz_mod.node()->findModelFromPath("Rm"); Ensures(mdl != 0); vz::AtomicModel* atomg = mdl->toAtomic(); atomg->setConditions(conds); } //simulation vm::Error error; vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE, std::chrono::milliseconds(0), &std::cout); std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error); //checks that simulation has succeeded EnsuresEqual(error.code, 0); //checks the number of views EnsuresEqual(out->size(),1); //checks the selected view const va::Matrix& view = out->getMatrix("view"); //note: the number of rows depend on the averaging of sum of 0.01 Ensures(view.rows() <= 1503); Ensures(view.rows() >= 1502); //gets S,E,I,R int colS = ttgetColumnFromView(view, "Top model:Sm", "S"); int colE = ttgetColumnFromView(view, "Top model:Em", "E"); int colI = ttgetColumnFromView(view, "Top model:Im", "I"); int colR = ttgetColumnFromView(view, "Top model:Rm", "R"); //check S,E,I,R line 1501 EnsuresApproximatelyEqual(view.getDouble(colS,1501), 0.634334231496758, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colE,1501), 0.65430775343564, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colI,1501), 2.97798653683738, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colR,1501), 6.73337147823022, 10e-5); }
/****************** * Unit test based on deSolve R package * see R/check.R function test_Euler_LotkaVolterra ******************/ void test_Euler_LotkaVolterra() { auto ctx = vu::make_context(); std::cout << " test_Euler_LotkaVolterra " << std::endl; vle::utils::Package pack(ctx, "vle.ode_test"); std::unique_ptr<vz::Vpz> vpz(new vz::Vpz( pack.getExpFile("LotkaVolterra.vpz", vle::utils::PKG_BINARY))); //set all output plugin to storage vz::Outputs::iterator itb = vpz->project().experiment().views().outputs().begin(); vz::Outputs::iterator ite = vpz->project().experiment().views().outputs().end(); for(;itb!=ite;itb++) { std::unique_ptr<va::Map> configOutput(new va::Map()); configOutput->addInt("rows",10000); configOutput->addInt("inc_rows",10000); configOutput->addString("header","top"); vz::Output& output = itb->second; output.setStream("", "storage", "vle.output"); output.setData(std::move(configOutput)); } //attach condition condEuler and condLV std::vector<std::string> conds; conds.push_back("condEuler"); conds.push_back("condLV"); vz::Model& vpz_mod = vpz->project().model(); vz::BaseModel* mdl = vpz_mod.node()->findModelFromPath("LotkaVolterra"); Ensures(mdl != 0); vz::AtomicModel* atomg = mdl->toAtomic(); atomg->setConditions(conds); //simulation vm::Error error; vm::Simulation sim(ctx, vm::LOG_NONE, vm::SIMULATION_NONE, std::chrono::milliseconds(0), &std::cout); std::unique_ptr<va::Map> out = sim.run(std::move(vpz), &error); //checks that simulation has succeeded EnsuresEqual(error.code, 0); //checks the number of views EnsuresEqual(out->size(),1); //checks the selected view const va::Matrix& view = out->getMatrix("view"); EnsuresEqual(view.columns(),3); //note: the number of rows depend on the averaging of sum of 0.01 Ensures(view.rows() <= 15003); Ensures(view.rows() >= 15002); //gets X,Y int colX = ttgetColumnFromView(view, "Top model:LotkaVolterra", "X"); int colY = ttgetColumnFromView(view, "Top model:LotkaVolterra", "Y"); //check X,Y line 10 EnsuresApproximatelyEqual(view.getDouble(colX,10), 9.677077, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colY,10), 5.317209, 10e-5); //check X,Y line 30 EnsuresApproximatelyEqual(view.getDouble(colX,30), 8.903716, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colY,30), 6.030680, 10e-5); //check X,Y line 15000 EnsuresApproximatelyEqual(view.getDouble(colX,15000), 0.5528446, 10e-5); EnsuresApproximatelyEqual(view.getDouble(colY,15000), 0.09330513, 10e-5); }