zircon/system/ulib/async-loop/test/loop_tests.cc
// The goal here is to schedule a lot of work and see whether it runs
// on as many threads as we expected it to.
The goal here is to schedule a lot of work and see whether it runs
on as many threads as we expected it to.
The goal here is to schedule a lot of work and see whether it runs on as many threads as we expected it to .
TEST(Loop, ThreadsTasksRunSequentially) {
  for (int i = 0; i < 3; i++) {
    const size_t num_threads = 4;
    const size_t num_items = 100;
    async::Loop loop(&kAsyncLoopConfigNoAttachToCurrentThread);
    for (size_t i = 0; i < num_threads; i++) {
      EXPECT_EQ(ZX_OK, loop.StartThread(), "start thread");
    }
    ConcurrencyMeasure measure(num_items);
    ThreadAssertTask* items[num_items];
    zx::time start_time = async::Now(loop.dispatcher());
    for (size_t i = 0; i < num_items; i++) {
      items[i] = new ThreadAssertTask(&measure);
      EXPECT_EQ(ZX_OK, items[i]->PostForTime(loop.dispatcher(), start_time + zx::msec(i)),
                "post task");
    }
    loop.JoinThreads();
    EXPECT_EQ(num_items, measure.count(), "item count");
    for (size_t i = 0; i < num_items; i++) {
      EXPECT_EQ(1u, items[i]->run_count, "run count");
      EXPECT_EQ(ZX_OK, items[i]->last_status, "status");
      delete items[i];
    }
    EXPECT_EQ(1u, measure.max_threads(), "tasks handled sequentially");
  }
}
TEST ( Loop , ThreadsTasksRunSequentially ) { for ( int i = 0 ; i < 3 ; i ++ ) { const size_t num_threads = 4 ; const size_t num_items = 100 ; async :: Loop loop ( & kAsyncLoopConfigNoAttachToCurrentThread ) ; for ( size_t i = 0 ; i < num_threads ; i ++ ) { EXPECT_EQ ( ZX_OK , loop . StartThread ( ) , " " ) ; } ConcurrencyMeasure measure ( num_items ) ; ThreadAssertTask * items [ num_items ] ; zx :: time start_time = async :: Now ( loop . dispatcher ( ) ) ; for ( size_t i = 0 ; i < num_items ; i ++ ) { items [ i ] = new ThreadAssertTask ( & measure ) ; EXPECT_EQ ( ZX_OK , items [ i ] -> PostForTime ( loop . dispatcher ( ) , start_time + zx :: msec ( i ) ) , " " ) ; } loop . JoinThreads ( ) ; EXPECT_EQ ( num_items , measure . count ( ) , " " ) ; for ( size_t i = 0 ; i < num_items ; i ++ ) { EXPECT_EQ ( 1u , items [ i ] -> run_count , " " ) ; EXPECT_EQ ( ZX_OK , items [ i ] -> last_status , " " ) ; delete items [ i ] ; } EXPECT_EQ ( 1u , measure . max_threads ( ) , " " ) ; } }
The goal here is to schedule a lot of work and see whether it runs
on as many threads as we expected it to.
The goal here is to schedule a lot of work and see whether it runs on as many threads as we expected it to .
// Post a number of work items to run all at once. // Wait until quitted. // Ensure all work items completed. // Ensure that we actually ran tasks sequentially despite having many // threads available.