int main(int argc, char** argv) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " path/to/lena" << std::endl; exit(1); } cv::Mat image, orig, lena, noize, diag, tool; image = cv::imread(argv[1], 1); diag = cv::imread(DIAG, CV_LOAD_IMAGE_GRAYSCALE); orig = cv::imread(ORIG, CV_LOAD_IMAGE_GRAYSCALE); lena = cv::imread(LENA, 1); noize = cv::imread(NOIZE, 1); tool = cv::imread(TOOL, CV_LOAD_IMAGE_GRAYSCALE); std::cout << "Task 1 Status: " << (task1(image) ? "OK" : "Error") << std::endl; std::cout << "Task 2 Status: " << (task2(image) ? "OK" : "Error") << std::endl; std::cout << "Task 3 Status: " << (task3(image) ? "OK" : "Error") << std::endl; std::cout << "Task 4 Status: " << (task4(image) ? "OK" : "Error") << std::endl; std::cout << "Task 5 Status: " << (task5((PATH + "noize/").c_str()) ? "OK" : "Error") << std::endl; std::cout << "Task 6 Status: " << (task6(image) ? "OK" : "Error") << std::endl; std::cout << "Task 3.1 Status: " << (task3_1(orig) ? "OK" : "Error") << std::endl; std::cout << "Task 3.2 Status: " << (task3_2(orig) ? "OK" : "Error") << std::endl; std::cout << "Task 3.3 Status: " << (task3_3(tool) ? "OK" : "Error") << std::endl; std::cout << "Task 3.5 Status: " << (task3_5(diag, orig) ? "OK" : "Error") << std::endl; std::cout << "Task 3.6 Status: " << (task3_6(lena, noize) ? "OK" : "Error") << std::endl; // cv::namedWindow("Lesson 2", CV_WINDOW_NORMAL); // cv::imshow("Lesson 2", image); // cv::waitKey(0); return 0; }
void PriorityTapeTest::testPriority() { boost::posix_time::ptime begin; boost::posix_time::ptime current; int duration; CPPUNIT_ASSERT( true == priority_->Enable(true) ); PriorityTapeTask task0(priority_.get(),100,0,10); PriorityTapeTask task1(priority_.get(),100,1,10); PriorityTapeTask task2(priority_.get(),100,2,10); PriorityTapeTask task3(priority_.get(),100,3,10); PriorityTapeTask task4(priority_.get(),100,4,10); PriorityTapeTask task5(priority_.get(),100,5,10); task0.Start(); boost::this_thread::sleep( boost::posix_time::milliseconds(5) ); task1.Start(); task2.Start(); task3.Start(); task4.Start(); task5.Start(); CPPUNIT_ASSERT( false == task0.Finished() ); CPPUNIT_ASSERT( false == task1.Finished() ); CPPUNIT_ASSERT( false == task2.Finished() ); CPPUNIT_ASSERT( false == task3.Finished() ); CPPUNIT_ASSERT( false == task4.Finished() ); CPPUNIT_ASSERT( false == task5.Finished() ); boost::this_thread::sleep( boost::posix_time::milliseconds(100) ); CPPUNIT_ASSERT( true == task0.Finished() ); CPPUNIT_ASSERT( true == task5.Finished() ); CPPUNIT_ASSERT( true == task4.Finished() ); CPPUNIT_ASSERT( true == task3.Finished() ); CPPUNIT_ASSERT( true == task2.Finished() ); CPPUNIT_ASSERT( true == task1.Finished() ); duration = (task0.End() - task0.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task1.End() - task1.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task2.End() - task2.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task3.End() - task3.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task4.End() - task4.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); duration = (task5.End() - task5.Begin()).total_milliseconds(); CPPUNIT_ASSERT( duration >= 10 ); CPPUNIT_ASSERT( task0.End() <= task5.Begin() ); CPPUNIT_ASSERT( task5.End() <= task4.Begin() ); CPPUNIT_ASSERT( task4.End() <= task3.Begin() ); CPPUNIT_ASSERT( task3.End() <= task2.Begin() ); CPPUNIT_ASSERT( task2.End() <= task1.Begin() ); }
int main(unsigned long long speid, unsigned long long argp, unsigned long long envp) { printf("Hello World! from Cell no %lld, id (0x%llx)\n", argp, speid); // TODO Task 4 - print the spe index received as argument task5(); return 0; }
int main(int argc, const char * argv[]) { // insert code here... int t; printf("Меню:\n1)Все числа от 1 до n\n2)Все числа от А до В\n3)Функция Аккермана\n4)Точная степень двойки\n5)Сумма цифр числа\n"); printf("Выберите номер задания\n"); scanf("%d",&t); while(t!=6) { switch(t) { case 1: { printf("Все числа от 1 до n\n"); task1(); break; } case 2: { printf("Все числа от А до В\n"); task2(); break; } case 3: { printf("Функция Аккермана\n"); task3(); break; } case 4: { printf("Точная степень двойки\n"); task4(); break; } case 5: { printf("Сумма цифр числа\n"); task5(); break; } } printf("\nМеню:\n1)Все числа от 1 до n\n2)Все числа от А до В\n3)Функция Аккермана\n4)Точная степень двойки\n5)Сумма цифр числа\n"); printf("Выберите номер задания\n"); scanf("%d",&t); } return 0; }
void runTestMulti() { #if defined(DEBUG) os::diag::trace.putString(__PRETTY_FUNCTION__); os::diag::trace.putNewLine(); #endif ts.setClassName("os::core::Thread"); ts.setFunctionNameOrPrefix("sleep()"); Task task1("T1", hal::arch::MIN_STACK_SIZE); Task task2("T2", hal::arch::MIN_STACK_SIZE); Task task3("T3", hal::arch::MIN_STACK_SIZE); Task task4("T4", hal::arch::MIN_STACK_SIZE); Task task5("T5", hal::arch::MIN_STACK_SIZE); Task* taskArray[5] = { &task1, &task2, &task3, &task4, &task5 }; for (auto pTask : taskArray) { ts.setPreconditions(pTask->getName()); ts.assertCondition(pTask->getCount() == 0); } for (auto pTask : taskArray) { ts.assertCondition(pTask->getThread().start()); } for (auto pTask : taskArray) { pTask->getThread().join(); } for (auto pTask : taskArray) { ts.setPreconditions(pTask->getName()); ts.assertCondition( ((pTask->getDeltaTicks() - pTask->getCount()) <= pTask->getSleepCalls())); } }
void Scheduler_ut::test_tasks() { IPRINTF("\nExecuting %s\n", __func__); /* Create the tasks. */ Task_properties tprops; tprops.period = units::Nanoseconds(20 * units::MSEC); tprops.prio = higher_priority; Test_task task1("task_2_1", 1); CPPUNIT_ASSERT_EQUAL(true, task1.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task1.is_valid()); tprops.prio = lower_priority; Test_task task2("task_2_2", 2); CPPUNIT_ASSERT_EQUAL(true, task2.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task2.is_valid()); tprops.period = units::Nanoseconds(10 * units::MSEC); tprops.prio = highest_priority; Test_task task3("task_1_3", 3); CPPUNIT_ASSERT_EQUAL(true, task3.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task3.is_valid()); tprops.period = units::Nanoseconds(40 * units::MSEC); tprops.prio = lowest_priority; Test_task task4("task_4_4", 4); CPPUNIT_ASSERT_EQUAL(true, task4.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task4.is_valid()); /* Set up this task with invalid period (faster than the scheduler). */ tprops.period = units::Nanoseconds(sched_period / 2); tprops.prio = lowest_priority; Test_task task5("task_invalid_period", 5); CPPUNIT_ASSERT_EQUAL(true, task5.set_properties(tprops)); CPPUNIT_ASSERT_EQUAL(true, task5.is_valid()); /* Runtimes should be zero before the task starts. */ units::Nanoseconds last_runtime = task1.get_last_runtime(); CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), last_runtime); CPPUNIT_ASSERT_EQUAL(units::Nanoseconds(0), task1.get_max_runtime()); /* Off to the races. */ task_terminated = false; CPPUNIT_ASSERT_EQUAL(true, task1.start()); CPPUNIT_ASSERT_EQUAL(true, task2.start()); CPPUNIT_ASSERT_EQUAL(true, task3.start()); CPPUNIT_ASSERT_EQUAL(true, task4.start()); IPRINTF("\nTesting invalid period, an error is expected\n"); CPPUNIT_ASSERT_EQUAL(false, task5.start()); /* Not the most reliable timing method. */ sleep(units::Nanoseconds(1 * units::SEC)); /* Stop the tasks so the counters stop incrementing. This makes * cleanup faster too. */ DPRINTF("Halting all test tasks\n"); DPRINTF("Stopping task 1\n"); task1.stop(); DPRINTF("Stopping task 2\n"); task2.stop(); DPRINTF("Stopping task 3\n"); task3.stop(); DPRINTF("Stopping task 4\n"); task4.stop(); CPPUNIT_ASSERT_EQUAL(true, task_terminated); /* Check the counters to see if the counts match. Allow some variance * to account for the imprecision of halting the task based on a * timer. */ CPPUNIT_ASSERT((counter[1] >= 48) && (counter[1] <= 60)); CPPUNIT_ASSERT((counter[2] >= 48) && (counter[2] <= 60)); CPPUNIT_ASSERT((counter[3] >= 98) && (counter[3] <= 110)); CPPUNIT_ASSERT((counter[4] >= 23) && (counter[4] <= 35)); /* Check that the runtimes are reasonable. */ last_runtime = task1.get_last_runtime(); IPRINTF("last_runtime = %" PRId64 "\n", int64_t(last_runtime)); CPPUNIT_ASSERT(last_runtime > units::Nanoseconds(0)); CPPUNIT_ASSERT(task1.get_max_runtime() >= last_runtime); }
// // a task gets dispatched on every tick_flag tick (10ms) // void task_dispatch(void) { /* scan the task bits for an active task and execute it */ char task; /* take care of the task timers. if the value ==0 skip it else decrement it. If it decrements to zero, activate the task associated with it */ task=0; while (task < NUM_TASKS ) { if (task_timers[task]) { task_timers[task]--; /* dec the timer */ if (task_timers[task] == 0 ) { set_task(task); /* if ==0 activate the task bit */ } } task++; } task = 0; /* start at the most significant task */ while (task <= NUM_TASKS ) { if ((task_bits & pgm_read_byte(&bit_mask[task]))) { break; /* if activate task found..*/ } task++; /* else try the next one */ } switch(task) /* if task bit is active..execute the task */ { case 0: task0(); break; case 1: task1(); break; case 2: task2(); break; case 3: task3(); break; case 4: task4(); break; case 5: task5(); break; case 6: task6(); break; case 7: task7(); break; default: break; /* no task was active!! */ } }