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, ThreadsReceiversRunConcurrently) {
  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);
    ThreadAssertReceiver receiver(&measure);
    for (size_t i = 0; i < num_items; i++) {
      EXPECT_EQ(ZX_OK, receiver.QueuePacket(loop.dispatcher(), nullptr), "queue packet");
    }
    loop.JoinThreads();
    EXPECT_EQ(num_items, measure.count(), "item count");
    EXPECT_EQ(num_items, receiver.run_count, "run count");
    EXPECT_EQ(ZX_OK, receiver.last_status, "status");
    EXPECT_NE(1u, measure.max_threads(), "packets handled concurrently");
  }
}
TEST ( Loop , ThreadsReceiversRunConcurrently ) { 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 ) ; ThreadAssertReceiver receiver ( & measure ) ; for ( size_t i = 0 ; i < num_items ; i ++ ) { EXPECT_EQ ( ZX_OK , receiver . QueuePacket ( loop . dispatcher ( ) , nullptr ) , " " ) ; } loop . JoinThreads ( ) ; EXPECT_EQ ( num_items , measure . count ( ) , " " ) ; EXPECT_EQ ( num_items , receiver . run_count , " " ) ; EXPECT_EQ ( ZX_OK , receiver . last_status , " " ) ; 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 packets all at once. // Wait until quitted. // Ensure all work items completed. // Ensure that we actually processed many packets concurrently on different threads.