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, ThroadsWitsRunConcurrently) {
  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);
    zx::event event;
    EXPECT_EQ(ZX_OK, zx::event::create(0u, &event), "create event");
    EXPECT_EQ(ZX_OK, event.signal(0u, ZX_USER_SIGNAL_0), "signal");
    ThreadAssertWait* items[num_items];
    for (size_t i = 0; i < num_items; i++) {
      items[i] = new ThreadAssertWait(event.get(), ZX_USER_SIGNAL_0, &measure);
      EXPECT_EQ(ZX_OK, items[i]->Begin(loop.dispatcher()), "begin wait");
    }
    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");
      EXPECT_NE(items[i]->last_signal, nullptr, "signal");
      EXPECT_EQ(ZX_USER_SIGNAL_0, items[i]->last_signal->observed & ZX_USER_SIGNAL_ALL, "observed");
      delete items[i];
    }
    EXPECT_NE(1u, measure.max_threads(), "waits handled concurrently");
  }
}
TEST ( Loop , ThroadsWitsRunConcurrently ) { 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 ) ; zx :: event event ; EXPECT_EQ ( ZX_OK , zx :: event :: create ( 0u , & event ) , " " ) ; EXPECT_EQ ( ZX_OK , event . signal ( 0u , ZX_USER_SIGNAL_0 ) , " " ) ; ThreadAssertWait * items [ num_items ] ; for ( size_t i = 0 ; i < num_items ; i ++ ) { items [ i ] = new ThreadAssertWait ( event . get ( ) , ZX_USER_SIGNAL_0 , & measure ) ; EXPECT_EQ ( ZX_OK , items [ i ] -> Begin ( loop . dispatcher ( ) ) , " " ) ; } 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 , " " ) ; EXPECT_NE ( items [ i ] -> last_signal , nullptr , " " ) ; EXPECT_EQ ( ZX_USER_SIGNAL_0 , items [ i ] -> last_signal -> observed & ZX_USER_SIGNAL_ALL , " " ) ; delete items [ i ] ; } EXPECT_NE ( 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 many waits concurrently on different threads.