// This test checks the behavior of passed invalid limits. TEST_F(PosixRLimitsIsolatorTest, InvalidLimits) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); flags.isolation = "posix/rlimits"; Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_NE(0u, offers->size()); TaskInfo task = createTask( offers.get()[0].slave_id(), offers.get()[0].resources(), "true"); ContainerInfo* container = task.mutable_container(); container->set_type(ContainerInfo::MESOS); // Set impossible limit soft > hard. RLimitInfo rlimitInfo; RLimitInfo::RLimit* rlimit = rlimitInfo.add_rlimits(); rlimit->set_type(RLimitInfo::RLimit::RLMT_CPU); rlimit->set_soft(100); rlimit->set_hard(1); container->mutable_rlimit_info()->CopyFrom(rlimitInfo); Future<TaskStatus> taskStatus; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&taskStatus)); driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(taskStatus); EXPECT_EQ(task.task_id(), taskStatus->task_id()); EXPECT_EQ(TASK_FAILED, taskStatus->state()); EXPECT_EQ(TaskStatus::REASON_EXECUTOR_TERMINATED, taskStatus->reason()); driver.stop(); driver.join(); }
// Test that memory pressure listening is restarted after recovery. TEST_F(MemoryPressureMesosTest, CGROUPS_ROOT_SlaveRecovery) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); // We only care about memory cgroup for this test. flags.isolation = "cgroups/mem"; flags.agent_subsystems = None(); Fetcher fetcher; Try<MesosContainerizer*> _containerizer = MesosContainerizer::create(flags, true, &fetcher); ASSERT_SOME(_containerizer); Owned<MesosContainerizer> containerizer(_containerizer.get()); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), containerizer.get(), flags); ASSERT_SOME(slave); MockScheduler sched; // Enable checkpointing for the framework. FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO; frameworkInfo.set_checkpoint(true); MesosSchedulerDriver driver( &sched, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); Offer offer = offers.get()[0]; // Run a task that triggers memory pressure event. We request 1G // disk because we are going to write a 512 MB file repeatedly. TaskInfo task = createTask( offer.slave_id(), Resources::parse("cpus:1;mem:256;disk:1024").get(), "while true; do dd count=512 bs=1M if=/dev/zero of=./temp; done"); Future<TaskStatus> running; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&running)); Future<Nothing> _statusUpdateAcknowledgement = FUTURE_DISPATCH(_, &Slave::_statusUpdateAcknowledgement); driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(running); EXPECT_EQ(task.task_id(), running.get().task_id()); EXPECT_EQ(TASK_RUNNING, running.get().state()); // Wait for the ACK to be checkpointed. AWAIT_READY(_statusUpdateAcknowledgement); // We restart the slave to let it recover. slave.get()->terminate(); // Set up so we can wait until the new slave updates the container's // resources (this occurs after the executor has re-registered). Future<Nothing> update = FUTURE_DISPATCH(_, &MesosContainerizerProcess::update); // Use the same flags. _containerizer = MesosContainerizer::create(flags, true, &fetcher); ASSERT_SOME(_containerizer); containerizer.reset(_containerizer.get()); Future<SlaveReregisteredMessage> reregistered = FUTURE_PROTOBUF(SlaveReregisteredMessage(), master.get()->pid, _); slave = StartSlave(detector.get(), containerizer.get(), flags); ASSERT_SOME(slave); AWAIT_READY(reregistered); // Wait until the containerizer is updated. AWAIT_READY(update); Future<hashset<ContainerID>> containers = containerizer->containers(); AWAIT_READY(containers); ASSERT_EQ(1u, containers.get().size()); ContainerID containerId = *(containers.get().begin()); // Wait a while for some memory pressure events to occur. Duration waited = Duration::zero(); do { Future<ResourceStatistics> usage = containerizer->usage(containerId); AWAIT_READY(usage); if (usage.get().mem_low_pressure_counter() > 0) { // We will check the correctness of the memory pressure counters // later, because the memory-hammering task is still active // and potentially incrementing these counters. break; } os::sleep(Milliseconds(100)); waited += Milliseconds(100); } while (waited < Seconds(5)); EXPECT_LE(waited, Seconds(5)); // Pause the clock to ensure that the reaper doesn't reap the exited // command executor and inform the containerizer/slave. Clock::pause(); Clock::settle(); Future<TaskStatus> killed; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&killed)); // Stop the memory-hammering task. driver.killTask(task.task_id()); AWAIT_READY(killed); EXPECT_EQ(task.task_id(), killed->task_id()); EXPECT_EQ(TASK_KILLED, killed->state()); // Now check the correctness of the memory pressure counters. Future<ResourceStatistics> usage = containerizer->usage(containerId); AWAIT_READY(usage); EXPECT_GE(usage.get().mem_low_pressure_counter(), usage.get().mem_medium_pressure_counter()); EXPECT_GE(usage.get().mem_medium_pressure_counter(), usage.get().mem_critical_pressure_counter()); Clock::resume(); driver.stop(); driver.join(); }
// This test confirms that setting no values for the soft and hard // limits implies an unlimited resource. TEST_F(PosixRLimitsIsolatorTest, UnsetLimits) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); flags.isolation = "posix/rlimits"; Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_NE(0u, offers->size()); TaskInfo task = createTask( offers.get()[0].slave_id(), offers.get()[0].resources(), "exit `ulimit -c | grep -q unlimited`"); // Force usage of C locale as we interpret a potentially translated // string in the task's command. mesos::Environment::Variable* locale = task.mutable_command()->mutable_environment()->add_variables(); locale->set_name("LC_ALL"); locale->set_value("C"); ContainerInfo* container = task.mutable_container(); container->set_type(ContainerInfo::MESOS); // Setting rlimit for core without soft or hard limit signifies // unlimited range. RLimitInfo rlimitInfo; RLimitInfo::RLimit* rlimit = rlimitInfo.add_rlimits(); rlimit->set_type(RLimitInfo::RLimit::RLMT_CORE); container->mutable_rlimit_info()->CopyFrom(rlimitInfo); Future<TaskStatus> statusRunning; Future<TaskStatus> statusFinal; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&statusRunning)) .WillOnce(FutureArg<1>(&statusFinal)); driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(statusRunning); EXPECT_EQ(task.task_id(), statusRunning->task_id()); EXPECT_EQ(TASK_RUNNING, statusRunning->state()); AWAIT_READY(statusFinal); EXPECT_EQ(task.task_id(), statusFinal->task_id()); EXPECT_EQ(TASK_FINISHED, statusFinal->state()); driver.stop(); driver.join(); }
// This test confirms that if a task exceeds configured resource // limits it is forcibly terminated. TEST_F(PosixRLimitsIsolatorTest, TaskExceedingLimit) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); flags.isolation = "posix/rlimits"; Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_NE(0u, offers->size()); // The task attempts to use an infinite amount of CPU time. TaskInfo task = createTask( offers.get()[0].slave_id(), offers.get()[0].resources(), "while true; do true; done"); ContainerInfo* container = task.mutable_container(); container->set_type(ContainerInfo::MESOS); // Limit the process to use maximally 1 second of CPU time. RLimitInfo rlimitInfo; RLimitInfo::RLimit* cpuLimit = rlimitInfo.add_rlimits(); cpuLimit->set_type(RLimitInfo::RLimit::RLMT_CPU); cpuLimit->set_soft(1); cpuLimit->set_hard(1); container->mutable_rlimit_info()->CopyFrom(rlimitInfo); Future<TaskStatus> statusRunning; Future<TaskStatus> statusFailed; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&statusRunning)) .WillOnce(FutureArg<1>(&statusFailed)); driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(statusRunning); EXPECT_EQ(task.task_id(), statusRunning->task_id()); EXPECT_EQ(TASK_RUNNING, statusRunning->state()); AWAIT_READY(statusFailed); EXPECT_EQ(task.task_id(), statusFailed->task_id()); EXPECT_EQ(TASK_FAILED, statusFailed->state()); driver.stop(); driver.join(); }
MRESULT EXPENTRY LOGNOTEDlgProc(HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2) { PLOGNOTEFORMINFO pLOGNOTEFormInfo=(PLOGNOTEFORMINFO) WinQueryWindowULong(hwndDlg, QWL_USER); HWND hwndFrame = WinQueryWindow(hwndDlg, QW_PARENT); /* ##START Form.37 Top of window procedure */ /* Code sections - Top of window procedure */ /* ##END Top of window procedure */ switch (msg) { /* Form event Opened WM_INITDLG */ case WM_INITDLG : if (mp2==0) mp2 = (MPARAM) malloc(sizeof(LOGNOTEFORMINFO)); HandleMessage(hwndFrame, hwndDlg, msg, mp1, mp2); pLOGNOTEFormInfo=(PLOGNOTEFORMINFO) WinQueryWindowULong(hwndDlg, QWL_USER); { /* ##START Form.1 */ /* Form events - Opened */ // CHAR ipaddr[260]; CHAR comboaddr[260]; INT vh; ULONG fgndcolor; CHAR bstatus[20]; WinQueryDlgItemText(hwndMainDlg, 1002, sizeof(bstatus), bstatus); if( strcmp(bstatus, "Listen OFF") == 0 ) { LISTENWASOFF = TRUE; } else LISTENWASOFF = FALSE; if( pgmData[33] == 1 ) WinCheckButton(hwndDlg, 1007, 1); fgndcolor = CLR_DARKBLUE; WinSetPresParam(WinWindowFromID(hwndDlg, 1003), PP_FOREGROUNDCOLORINDEX, sizeof(ULONG), &fgndcolor); WinSetPresParam(WinWindowFromID(hwndDlg, 1004), PP_FOREGROUNDCOLORINDEX, sizeof(ULONG), &fgndcolor); if( loadLogList(hwndDlg) == -1 ) { msgBox(hwndDlg, "Attention!", "No log file found."); WinSendMsg(hwndDlg, WM_CLOSE, 0, 0); } else { INT slen, j; j = 0; do { slen = strlen(logdat[j].INDATE); if( slen > 0 ) j++; } while( slen > 0 ); // debugMsgInt(j, "j"); for( vh=0;vh<j;vh++ ) { WinSendDlgItemMsg(hwndDlg, 1000, LM_INSERTITEM, MPFROMSHORT(LIT_END), MPFROMP(logdat[vh].INFROM)); } WinSendDlgItemMsg(hwndDlg, 1000, LM_SELECTITEM, MPFROMLONG(0), MPFROMLONG(TRUE)); strcpy(logpaddr, logdat[0].INSUBJECT+strlen(cphrase)); strcpy(comboaddr, "IP : "); strcat(comboaddr, logpaddr); strcat(comboaddr, " Ports : "); strcat(comboaddr, logdat[0].INPORTS); WinSetDlgItemText(hwndDlg, 1003, comboaddr); // WinSetDlgItemText(hwndDlg, 1003, ipaddr); WinSetDlgItemText(hwndDlg, 1004, logdat[0].INDATE); // WinSetDlgItemText(hwndDlg, 1008, logdat[0].INNOTE); /* if( LISTENWASOFF ) { WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); } */ } /* ##END */ } break; /* Form event Closed WM_CLOSE */ case WM_CLOSE : /* ##START Form.2 */ /* ##END */ HandleMessage(hwndFrame, hwndDlg, msg, mp1, mp2); break; case WM_COMMAND : switch (SHORT1FROMMP(mp1)) { /* Button 1001 Clicked/Selected */ case 1001: { /* ##START 1001.0 */ /* Event Clicked/selected - ~Connect 1001 */ CHAR bstatus[20]; CHAR gp[40]; INT sel, k, h; INT ret; BOOL TOBU; if( !registered(ncpw) ) { USHORT usReturn; HWND hNewFrame; hNewFrame = OpenABOUT(hwndDlg, 0); usReturn = (USHORT) WinProcessDlg(hNewFrame); } WinQueryDlgItemText(hwndMainDlg, 1002, sizeof(bstatus), bstatus); if( WinQueryButtonCheckstate(hwndDlg,1007) == 1 ) { ret = 1; } else { ret = 0; } strcpy(guestIP, logpaddr); sel = (LONG)WinSendDlgItemMsg(hwndDlg, 1000, LM_QUERYSELECTION, MPFROMLONG(LIT_FIRST), MPFROMLONG(0)); if( strcmp(logdat[sel].INPORTS, "Unknown") != 0 && ret == 1 ) { strcpy(gp, logdat[sel].INPORTS); k = 2; h = 0; do { grport[h] = gp[k]; h++; } while( gp[k++] != ' ' && h < 5 ); grport[h-1] = '\0'; k += 2; h = 0; do { gsport[h] = gp[k]; h++; } while( gp[k++] != ' ' && h < 5 ); gsport[h-1] = '\0'; k += 2; h = 0; do { gfport[h] = gp[k]; h++; } while( gp[k++] != ' ' && h < 5 ); gfport[h-1] = '\0'; if( atoi(grport) != atoi(gsport) ) { if( pgmData[4] != atoi(gsport) || pgmData[5] != atoi(grport) || pgmData[8] != atoi(gfport) ) TOBU = TRUE; else TOBU = FALSE; } else { if( pgmData[4] != atoi(grport) || pgmData[5] != atoi(gsport) || pgmData[8] != atoi(gfport) ) TOBU = TRUE; else TOBU = FALSE; } // if( pgmData[4] != atoi(grport) || // pgmData[5] != atoi(gsport) || // pgmData[8] != atoi(gfport) ) if( TOBU ) { if( strcmp(bstatus, "Listen ON") == 0 ) { WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); if( atoi(grport) == atoi(gsport) ) { pgmData[4] = atoi(grport); pgmData[5] = atoi(gsport); pgmData[8] = atoi(gfport); } else { pgmData[5] = atoi(grport); pgmData[4] = atoi(gsport); pgmData[8] = atoi(gfport); } saveNCSet(); makeTBar(); WinSetWindowText(WinWindowFromID(hwndMainF, FID_TITLEBAR), tbarmsg); WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); } else { if( atoi(grport) == atoi(gsport) ) { pgmData[4] = atoi(grport); pgmData[5] = atoi(gsport); pgmData[8] = atoi(gfport); } else { pgmData[5] = atoi(grport); pgmData[4] = atoi(gsport); pgmData[8] = atoi(gfport); } saveNCSet(); makeTBar(); WinSetWindowText(WinWindowFromID(hwndMainF, FID_TITLEBAR), tbarmsg); WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); } } else { if( strcmp(bstatus, "Listen OFF") == 0 ) { WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); } } } else { if( strcmp(bstatus, "Listen OFF") == 0 ) { WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); } } _beginthread(attemptConnect, NULL, BSTACK, (PVOID)&hwndMainDlg); WinPostMsg(hwndDlg, WM_CLOSE, 0, 0); /* ##END */ } break; /* Button 1002 Clicked/Selected */ case 1002: { /* ##START 1002.0 */ /* Event Clicked/selected - ~Don't connect 1002 */ CHAR bstatus[20]; WinQueryDlgItemText(hwndMainDlg, 1002, sizeof(bstatus), bstatus); if( strcmp(bstatus, "Listen ON") == 0 ) { if( LISTENWASOFF ) WinSendMsg(hwndMainF, WM_COMMAND, MPFROM2SHORT(1002,2345), 0); } WinPostMsg(hwndDlg, WM_CLOSE, 0, 0); /* ##END */ } break; } /* end switch */ break; case WM_CONTROL : switch (SHORT1FROMMP(mp1)) { /* List Box 1000 Event Handlers */ case 1000: switch (SHORT2FROMMP(mp1)) { /* Click/Selected */ case LN_SELECT: { /* ##START 1000.0 */ /* Event Click/Selected - List Box 1000 */ INT sel; // CHAR ipaddr[260]; CHAR comboaddr[260]; sel = (LONG)WinSendDlgItemMsg(hwndDlg, 1000, LM_QUERYSELECTION, MPFROMLONG(LIT_FIRST), MPFROMLONG(0)); strcpy(logpaddr, logdat[sel].INSUBJECT+strlen(cphrase)); strcpy(comboaddr, "IP : "); strcat(comboaddr, logpaddr); strcat(comboaddr, " Ports : "); strcat(comboaddr, logdat[sel].INPORTS); WinSetDlgItemText(hwndDlg, 1003, comboaddr); // WinSetDlgItemText(hwndDlg, 1003, logpaddr); WinSetDlgItemText(hwndDlg, 1004, logdat[sel].INDATE); WinSetDlgItemText(hwndDlg, 1005, logdat[sel].REPTO); WinSetDlgItemText(hwndDlg, 1008, logdat[sel].INNOTE); /* ##END */ } break; /* Enter */ case LN_SETFOCUS: { /* ##START 1000.1 */ /* Event Enter - List Box 1000 */ /* ##END */ } break; /* Mouse button 1 double click */ case LN_ENTER: { /* ##START 1000.3 */ /* Event Mouse button 1 double click - List Box 1000 */ WinSendMsg(hwndDlg, WM_COMMAND, MPFROM2SHORT(1001, 0), 0); /* ##END */ } break; } /* end switch */ break; } /* end switch */ break; /* Allow frame window to handle accelerators */ case WM_TRANSLATEACCEL: if (WinSendMsg(hwndFrame, msg, mp1, mp2 )) return (MRESULT) TRUE; return WinDefDlgProc( hwndDlg, msg, mp1, mp2 ); break; /* ##START Form.38 User defined messages */ /* ##END User defined messages */ default : HandleMessage(hwndFrame, hwndDlg, msg, mp1, mp2); return WinDefDlgProc(hwndDlg,msg,mp1,mp2); } /* end switch for main msg dispatch */ return (MRESULT)FALSE; } /* end dialog procedure */
/** * Main application entry point. * * Accepted argumemnts: * - cpu Perform depth processing with the CPU. * - gl Perform depth processing with OpenGL. * - cl Perform depth processing with OpenCL. * - <number> Serial number of the device to open. * - -noviewer Disable viewer window. */ int main(int argc, char *argv[]) /// [main] { std::string program_path(argv[0]); std::cerr << "Environment variables: LOGFILE=<protonect.log>" << std::endl; std::cerr << "Usage: " << program_path << " [gl | cl | cpu] [<device serial>] [-noviewer]" << std::endl; size_t executable_name_idx = program_path.rfind("Protonect"); std::string binpath = "/"; if(executable_name_idx != std::string::npos) { binpath = program_path.substr(0, executable_name_idx); } #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) // avoid flooing the very slow Windows console with debug messages libfreenect2::setGlobalLogger(libfreenect2::createConsoleLogger(libfreenect2::Logger::Info)); #else // create a console logger with debug level (default is console logger with info level) /// [logging] libfreenect2::setGlobalLogger(libfreenect2::createConsoleLogger(libfreenect2::Logger::Debug)); /// [logging] #endif /// [file logging] MyFileLogger *filelogger = new MyFileLogger(getenv("LOGFILE")); if (filelogger->good()) libfreenect2::setGlobalLogger(filelogger); /// [file logging] /// [context] libfreenect2::Freenect2 freenect2; libfreenect2::Freenect2Device *dev = 0; libfreenect2::PacketPipeline *pipeline = 0; /// [context] /// [discovery] if(freenect2.enumerateDevices() == 0) { std::cout << "no device connected!" << std::endl; return -1; } std::string serial = freenect2.getDefaultDeviceSerialNumber(); /// [discovery] bool viewer_enabled = true; for(int argI = 1; argI < argc; ++argI) { const std::string arg(argv[argI]); if(arg == "cpu") { if(!pipeline) /// [pipeline] pipeline = new libfreenect2::CpuPacketPipeline(); /// [pipeline] } else if(arg == "gl") { #ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT if(!pipeline) pipeline = new libfreenect2::OpenGLPacketPipeline(); #else std::cout << "OpenGL pipeline is not supported!" << std::endl; #endif } else if(arg == "cl") { #ifdef LIBFREENECT2_WITH_OPENCL_SUPPORT if(!pipeline) pipeline = new libfreenect2::OpenCLPacketPipeline(); #else std::cout << "OpenCL pipeline is not supported!" << std::endl; #endif } else if(arg.find_first_not_of("0123456789") == std::string::npos) //check if parameter could be a serial number { serial = arg; } else if(arg == "-noviewer") { viewer_enabled = false; } else { std::cout << "Unknown argument: " << arg << std::endl; } } if(pipeline) { /// [open] dev = freenect2.openDevice(serial, pipeline); /// [open] } else { dev = freenect2.openDevice(serial); } if(dev == 0) { std::cout << "failure opening device!" << std::endl; return -1; } signal(SIGINT,sigint_handler); protonect_shutdown = false; /// [listeners] libfreenect2::SyncMultiFrameListener listener(libfreenect2::Frame::Color | libfreenect2::Frame::Ir | libfreenect2::Frame::Depth); libfreenect2::FrameMap frames; dev->setColorFrameListener(&listener); dev->setIrAndDepthFrameListener(&listener); /// [listeners] /// [start] dev->start(); std::cout << "device serial: " << dev->getSerialNumber() << std::endl; std::cout << "device firmware: " << dev->getFirmwareVersion() << std::endl; /// [start] /// [registration setup] libfreenect2::Registration* registration = new libfreenect2::Registration(dev->getIrCameraParams(), dev->getColorCameraParams()); libfreenect2::Frame undistorted(512, 424, 4), registered(512, 424, 4); /// [registration setup] size_t framecount = 0; #ifdef EXAMPLES_WITH_OPENGL_SUPPORT Viewer viewer; if (viewer_enabled) viewer.initialize(); #else viewer_enabled = false; #endif /// [loop start] while(!protonect_shutdown) { listener.waitForNewFrame(frames); libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color]; libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir]; libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth]; /// [loop start] /// [registration] registration->apply(rgb, depth, &undistorted, ®istered); /// [registration] framecount++; if (!viewer_enabled) { if (framecount % 100 == 0) std::cout << "The viewer is turned off. Received " << framecount << " frames. Ctrl-C to stop." << std::endl; listener.release(frames); continue; } #ifdef EXAMPLES_WITH_OPENGL_SUPPORT viewer.addFrame("RGB", rgb); viewer.addFrame("ir", ir); viewer.addFrame("depth", depth); viewer.addFrame("registered", ®istered); protonect_shutdown = protonect_shutdown || viewer.render(); #endif /// [loop end] listener.release(frames); /** libfreenect2::this_thread::sleep_for(libfreenect2::chrono::milliseconds(100)); */ } /// [loop end] // TODO: restarting ir stream doesn't work! // TODO: bad things will happen, if frame listeners are freed before dev->stop() :( /// [stop] dev->stop(); dev->close(); /// [stop] delete registration; return 0; }
//update the kinect void Device::updateKinect() { libfreenect2::FrameMap frames; //Temporary arrays float * newDepth = new float[FRAME_SIZE_DEPTH]; float * newIr = new float[FRAME_SIZE_DEPTH]; float * newUndisorted = new float[FRAME_SIZE_DEPTH]; libfreenect2::Frame undistorted(512, 424, 4), registered(512, 424, 4); //MAIN THREAD while(initialized_device){ listener->waitForNewFrame(frames); if(enableRegistered){ libfreenect2::Frame * rgb = frames[libfreenect2::Frame::Color]; memcpy(colorData, reinterpret_cast<const uint32_t *>(rgb->data), 1920 * 1080 * 4); libfreenect2::Frame * depth = frames[libfreenect2::Frame::Depth]; memcpy(newDepth, reinterpret_cast<const float * >(depth->data), FRAME_BYTE_SIZE_DEPTH); //Mappers RGB + Depth registration->apply(rgb, depth, &undistorted, ®istered); memcpy(newUndisorted, reinterpret_cast<const float * >(undistorted.data), FRAME_BYTE_SIZE_DEPTH); memcpy(registeredData, reinterpret_cast<const uint32_t * >(registered.data), FRAME_BYTE_SIZE_DEPTH); }else if(enableVideo && !enableDepth){ libfreenect2::Frame * rgb = frames[libfreenect2::Frame::Color]; memcpy(colorData, reinterpret_cast<const uint32_t *>(rgb->data), 1920 * 1080 * 4); }else if( !enableVideo && enableDepth ){ libfreenect2::Frame * depth = frames[libfreenect2::Frame::Depth]; memcpy(newDepth, reinterpret_cast<const float * >(depth->data), FRAME_BYTE_SIZE_DEPTH); }else if(enableVideo && enableDepth && !enableRegistered){ libfreenect2::Frame * rgb = frames[libfreenect2::Frame::Color]; memcpy(colorData, reinterpret_cast<const uint32_t *>(rgb->data), 1920 * 1080 * 4); libfreenect2::Frame * depth = frames[libfreenect2::Frame::Depth]; memcpy(newDepth, reinterpret_cast<const float * >(depth->data), FRAME_BYTE_SIZE_DEPTH); } if(enableIR){ libfreenect2::Frame * ir = frames[libfreenect2::Frame::Ir]; memcpy(newIr, reinterpret_cast<const float * >(ir->data), FRAME_BYTE_SIZE_DEPTH); } int indexFD = 0; int pIndexEnd = (FRAME_SIZE_DEPTH); int indexX = 0; int indexY = 0; int cameraXYZ = 0; while(indexFD < pIndexEnd){ float depth = newDepth[indexFD]; //Depth //0.0566666f -> (value/45000)* 255 rawDepthData[indexFD] = uint32_t(depth); //IR irData[indexFD] = colorByte2Int((uint32_t(newIr[indexFD]*0.0566666f)>>2)); //undisorted undisortedData[indexFD] = colorByte2Int(uint32_t(newUndisorted[indexFD]*0.0566666f)); depthData[indexFD] = colorByte2Int(uint32_t(depth*0.0566666f)); //evaluates the depth XYZ position; depthCameraData[cameraXYZ++] = (indexX - dev->getIrCameraParams().cx) * depth / dev->getIrCameraParams().fx;//x depthCameraData[cameraXYZ++] = (indexY - dev->getIrCameraParams().cy) * depth / dev->getIrCameraParams().fy; //y depthCameraData[cameraXYZ++] = depth; //z indexX++; if(indexX >= 512){ indexX=0; indexY++;} indexFD++; // } } //framw listener listener->release(frames); } //clean up if(newDepth != NULL) delete newDepth; if(newIr != NULL) delete newIr; if(newUndisorted != NULL) delete newUndisorted; }
TEST_F(MemoryPressureMesosTest, ROOT_CGROUPS_Statistics) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); // We only care about memory cgroup for this test. flags.isolation = "cgroups/mem"; Fetcher fetcher(flags); Try<MesosContainerizer*> _containerizer = MesosContainerizer::create(flags, true, &fetcher); ASSERT_SOME(_containerizer); Owned<MesosContainerizer> containerizer(_containerizer.get()); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), containerizer.get(), flags); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_FALSE(offers->empty()); Offer offer = offers.get()[0]; // Run a task that triggers memory pressure event. We request 1G // disk because we are going to write a 512 MB file repeatedly. TaskInfo task = createTask( offer.slave_id(), Resources::parse("cpus:1;mem:256;disk:1024").get(), "while true; do dd count=512 bs=1M if=/dev/zero of=./temp; done"); Future<TaskStatus> starting; Future<TaskStatus> running; Future<TaskStatus> killed; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&starting)) .WillOnce(FutureArg<1>(&running)) .WillOnce(FutureArg<1>(&killed)) .WillRepeatedly(Return()); // Ignore subsequent updates. driver.launchTasks(offer.id(), {task}); AWAIT_READY(starting); EXPECT_EQ(task.task_id(), starting->task_id()); EXPECT_EQ(TASK_STARTING, starting->state()); AWAIT_READY(running); EXPECT_EQ(task.task_id(), running->task_id()); EXPECT_EQ(TASK_RUNNING, running->state()); Future<hashset<ContainerID>> containers = containerizer->containers(); AWAIT_READY(containers); ASSERT_EQ(1u, containers->size()); ContainerID containerId = *(containers->begin()); // Wait a while for some memory pressure events to occur. Duration waited = Duration::zero(); do { Future<ResourceStatistics> usage = containerizer->usage(containerId); AWAIT_READY(usage); if (usage->mem_low_pressure_counter() > 0) { // We will check the correctness of the memory pressure counters // later, because the memory-hammering task is still active // and potentially incrementing these counters. break; } os::sleep(Milliseconds(100)); waited += Milliseconds(100); } while (waited < Seconds(5)); EXPECT_LE(waited, Seconds(5)); // Pause the clock to ensure that the reaper doesn't reap the exited // command executor and inform the containerizer/slave. Clock::pause(); Clock::settle(); // Stop the memory-hammering task. driver.killTask(task.task_id()); AWAIT_READY_FOR(killed, Seconds(120)); EXPECT_EQ(task.task_id(), killed->task_id()); EXPECT_EQ(TASK_KILLED, killed->state()); // Now check the correctness of the memory pressure counters. Future<ResourceStatistics> usage = containerizer->usage(containerId); AWAIT_READY(usage); EXPECT_GE(usage->mem_low_pressure_counter(), usage->mem_medium_pressure_counter()); EXPECT_GE(usage->mem_medium_pressure_counter(), usage->mem_critical_pressure_counter()); Clock::resume(); driver.stop(); driver.join(); }
//-------------------------------------------------------------------------------- void ofxKinectV2::threadedFunction() { libfreenect2::Frame undistorted(DEPTH_WIDTH, DEPTH_HEIGHT, 4), registered(DEPTH_WIDTH, DEPTH_HEIGHT, 4); while (isThreadRunning()) { if (!bOpened) continue; listener->waitForNewFrame(frames); libfreenect2::Frame *rgb = frames[libfreenect2::Frame::Color]; libfreenect2::Frame *ir = frames[libfreenect2::Frame::Ir]; libfreenect2::Frame *depth = frames[libfreenect2::Frame::Depth]; registration->apply(rgb, depth, &undistorted, ®istered); frameColor[indexBack].setFromPixels(rgb->data, rgb->width, rgb->height, 4); frameIr[indexBack].setFromPixels((float *)ir->data, ir->width, ir->height, 1); frameRawDepth[indexBack].setFromPixels((float *)depth->data, depth->width, depth->height, 1); frameAligned[indexBack].setFromPixels(registered.data, registered.width, registered.height, 4); listener->release(frames); for (auto pixel : frameColor[indexBack].getPixelsIter()) // swap rgb std::swap(pixel[0], pixel[2]); for (auto pixel : frameIr[indexBack].getPixelsIter()) // downscale to 0-1 pixel[0] /= 65535.0f; for (auto pixel : frameAligned[indexBack].getPixelsIter()) // swap rgb std::swap(pixel[0], pixel[2]); if(!bUseRawDepth) { auto& depth = frameDepth[indexBack]; auto& raw_depth = frameRawDepth[indexBack]; if ((depth.getWidth() != raw_depth.getWidth()) || (depth.getHeight() != raw_depth.getHeight())) { depth.allocate(raw_depth.getWidth(), raw_depth.getHeight(), 3); } std::pair<float, float> minmax(0.0, 0.8); for (int i = 0; i < raw_depth.size(); i++) { float hue = ofMap(raw_depth[i], minDistance, maxDistance, minmax.first, minmax.second, true); if (hue == minmax.first || hue == minmax.second) depth.setColor(i * 3, ofColor(0)); else depth.setColor(i * 3, ofFloatColor::fromHsb(hue, 0.9, 0.9)); } } // get point cloud { float rgbPix = 0; size_t i = 0; for (int y = 0; y < DEPTH_HEIGHT; y++) { for (int x = 0; x < DEPTH_WIDTH; x++) { auto& pt = pcVertices[indexBack][i]; registration->getPointXYZRGB(&undistorted, ®istered, y, x, pt.x, pt.y, pt.z, rgbPix); pt.z *= -1.0f; pt.w = 1.0f; const uint8_t *p = reinterpret_cast<uint8_t*>(&rgbPix); pcColors[indexBack][i] = ofColor(p[2], p[1], p[0]); i++; } } } //while (bNewFrame) { // wait for main thread } std::lock_guard<std::mutex> guard(mutex); std::swap(indexFront, indexBack); bNewFrame = true; } }
// Tests that the default container logger writes files into the sandbox. TEST_F(ContainerLoggerTest, DefaultToSandbox) { // Create a master, agent, and framework. Try<PID<Master>> master = StartMaster(); ASSERT_SOME(master); Future<SlaveRegisteredMessage> slaveRegisteredMessage = FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _); // We'll need access to these flags later. slave::Flags flags = CreateSlaveFlags(); Fetcher fetcher; // We use an actual containerizer + executor since we want something to run. Try<MesosContainerizer*> containerizer = MesosContainerizer::create(flags, false, &fetcher); CHECK_SOME(containerizer); Try<PID<Slave>> slave = StartSlave(containerizer.get(), flags); ASSERT_SOME(slave); AWAIT_READY(slaveRegisteredMessage); SlaveID slaveId = slaveRegisteredMessage.get().slave_id(); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); Future<FrameworkID> frameworkId; EXPECT_CALL(sched, registered(&driver, _, _)) .WillOnce(FutureArg<1>(&frameworkId)); // Wait for an offer, and start a task. Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(frameworkId); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); // We'll start a task that outputs to stdout. TaskInfo task = createTask(offers.get()[0], "echo 'Hello World!'"); Future<TaskStatus> status; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&status)) .WillRepeatedly(Return()); // Ignore subsequent updates. driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(status); EXPECT_EQ(TASK_RUNNING, status.get().state()); // Check that the sandbox was written to. string sandboxDirectory = path::join( slave::paths::getExecutorPath( flags.work_dir, slaveId, frameworkId.get(), status->executor_id()), "runs", "latest"); ASSERT_TRUE(os::exists(sandboxDirectory)); string stdoutPath = path::join(sandboxDirectory, "stdout"); ASSERT_TRUE(os::exists(stdoutPath)); Result<string> stdout = os::read(stdoutPath); ASSERT_SOME(stdout); EXPECT_TRUE(strings::contains(stdout.get(), "Hello World!")); driver.stop(); driver.join(); Shutdown(); }
// This test verifies that the slave run task label decorator can add // and remove labels from a task during the launch sequence. A task // with two labels ("foo":"bar" and "bar":"baz") is launched and will // get modified by the slave hook to strip the "foo":"bar" pair and // add a new "baz":"qux" pair. TEST_F(HookTest, VerifySlaveRunTaskHook) { Try<PID<Master>> master = StartMaster(); ASSERT_SOME(master); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); Try<PID<Slave>> slave = StartSlave(&containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_EQ(1u, offers.get().size()); TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); // Add two labels: (1) will be removed by the hook to ensure that // runTaskHook can remove labels (2) will be preserved to ensure // that the framework can add labels to the task and have those be // available by the end of the launch task sequence when hooks are // used (to protect against hooks removing labels completely). Labels* labels = task.mutable_labels(); Label* label1 = labels->add_labels(); label1->set_key("foo"); label1->set_value("bar"); Label* label2 = labels->add_labels(); label2->set_key("bar"); label2->set_value("baz"); vector<TaskInfo> tasks; tasks.push_back(task); EXPECT_CALL(exec, registered(_, _, _, _)); Future<TaskInfo> taskInfo; EXPECT_CALL(exec, launchTask(_, _)) .WillOnce(DoAll( FutureArg<1>(&taskInfo), SendStatusUpdateFromTask(TASK_RUNNING))); driver.launchTasks(offers.get()[0].id(), tasks); AWAIT_READY(taskInfo); // The master hook will hang an extra label off. const Labels& labels_ = taskInfo.get().labels(); ASSERT_EQ(3, labels_.labels_size()); // The slave run task hook will prepend a new "baz":"qux" label. EXPECT_EQ(labels_.labels(0).key(), "baz"); EXPECT_EQ(labels_.labels(0).value(), "qux"); // Master launch task hook will still hang off test label. EXPECT_EQ(labels_.labels(1).key(), testLabelKey); EXPECT_EQ(labels_.labels(1).value(), testLabelValue); // And lastly, we only expect the "foo":"bar" pair to be stripped by // the module. The last pair should be the original "bar":"baz" // pair set by the test. EXPECT_EQ(labels_.labels(2).key(), "bar"); EXPECT_EQ(labels_.labels(2).value(), "baz"); driver.stop(); driver.join(); Shutdown(); // Must shutdown before 'containerizer' gets deallocated. }
// Test executor environment decorator hook and remove executor hook // for slave. We expect the environment-decorator hook to create a // temporary file and the remove-executor hook to delete that file. TEST_F(HookTest, DISABLED_VerifySlaveLaunchExecutorHook) { master::Flags masterFlags = CreateMasterFlags(); Try<PID<Master>> master = StartMaster(masterFlags); ASSERT_SOME(master); slave::Flags slaveFlags = CreateSlaveFlags(); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); Try<PID<Slave>> slave = StartSlave(&containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); // Launch a task with the command executor. TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); vector<TaskInfo> tasks; tasks.push_back(task); EXPECT_CALL(exec, launchTask(_, _)); Future<ExecutorInfo> executorInfo; EXPECT_CALL(exec, registered(_, _, _, _)) .WillOnce(FutureArg<1>(&executorInfo)); // On successful completion of the "slaveLaunchExecutorHook", the // test hook will send a HookExecuted message to itself. We wait // until that message is intercepted by the testing infrastructure. Future<HookExecuted> hookFuture = FUTURE_PROTOBUF(HookExecuted(), _, _); driver.launchTasks(offers.get()[0].id(), tasks); AWAIT_READY(executorInfo); driver.stop(); driver.join(); Shutdown(); // Must shutdown before 'containerizer' gets deallocated. // Now wait for the hook to finish execution. AWAIT_READY(hookFuture); }
// Test that the label decorator hook hangs a new label off the // taskinfo message during master launch task. TEST_F(HookTest, VerifyMasterLaunchTaskHook) { Try<PID<Master>> master = StartMaster(CreateMasterFlags()); ASSERT_SOME(master); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); // Start a mock slave since we aren't testing the slave hooks yet. Try<PID<Slave>> slave = StartSlave(&containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get(), DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); TaskInfo task; task.set_name(""); task.mutable_task_id()->set_value("1"); task.mutable_slave_id()->CopyFrom(offers.get()[0].slave_id()); task.mutable_resources()->CopyFrom(offers.get()[0].resources()); task.mutable_executor()->CopyFrom(DEFAULT_EXECUTOR_INFO); // Add label which will be removed by the hook. Labels* labels = task.mutable_labels(); Label* label = labels->add_labels(); label->set_key(testRemoveLabelKey); label->set_value(testRemoveLabelValue); vector<TaskInfo> tasks; tasks.push_back(task); Future<RunTaskMessage> runTaskMessage = FUTURE_PROTOBUF(RunTaskMessage(), _, _); EXPECT_CALL(exec, registered(_, _, _, _)); EXPECT_CALL(exec, launchTask(_, _)) .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING)); Future<TaskStatus> status; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&status)) .WillRepeatedly(Return()); driver.launchTasks(offers.get()[0].id(), tasks); AWAIT_READY(runTaskMessage); AWAIT_READY(status); // At launchTasks, the label decorator hook inside should have been // executed and we should see the labels now. Also, verify that the // hook module has stripped the first 'testRemoveLabelKey' label. // We do this by ensuring that only one label is present and that it // is the new 'testLabelKey' label. const Labels &labels_ = runTaskMessage.get().task().labels(); ASSERT_EQ(1, labels_.labels_size()); EXPECT_EQ(labels_.labels().Get(0).key(), testLabelKey); EXPECT_EQ(labels_.labels().Get(0).value(), testLabelValue); driver.stop(); driver.join(); Shutdown(); // Must shutdown before 'containerizer' gets deallocated. }