From 34cd75f77d0ca94dbdba4e6cc9451fe4d33e78b3 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 19 五月 2021 19:14:13 +0800 Subject: [PATCH] add api BHQueryProcs. --- utest/robust_test.cpp | 68 ++++++++++++++++++++++++++++++---- 1 files changed, 60 insertions(+), 8 deletions(-) diff --git a/utest/robust_test.cpp b/utest/robust_test.cpp index 68c0e72..ea6144c 100644 --- a/utest/robust_test.cpp +++ b/utest/robust_test.cpp @@ -16,6 +16,35 @@ ///////////////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE(InitTest) +{ + AtomicReqRep rr; + auto client = [&]() { + for (int i = 0; i < 20; ++i) { + int64_t reply = 0; + bool r = rr.ClientRequest(i, reply); + printf("init request %d, %s, reply %d\n", i, (r ? "ok" : "failed"), reply); + } + }; + + bool run = true; + auto server = [&]() { + auto onReq = [](int64_t req) { return req + 100; }; + while (run) { + rr.ServerProcess(onReq); + } + }; + + ThreadManager clients, servers; + servers.Launch(server); + for (int i = 0; i < 2; ++i) { + clients.Launch(client); + } + clients.WaitAll(); + run = false; + servers.WaitAll(); +} + BOOST_AUTO_TEST_CASE(QueueTest) { const int nthread = 100; @@ -39,19 +68,24 @@ std::atomic<uint64_t> nwrite(0); std::atomic<uint64_t> writedone(0); -#if 0 - typedef AtomicQueue<4> Rcb; +#if 1 + const int kPower = 0; + typedef AtomicQueue<kPower> Rcb; Rcb tmp; - BOOST_CHECK(tmp.like_empty()); + // BOOST_CHECK(tmp.like_empty()); BOOST_CHECK(tmp.push(1)); - BOOST_CHECK(tmp.tail() == 1); + if (kPower != 0) { + BOOST_CHECK(tmp.tail() == 1); + } BOOST_CHECK(tmp.head() == 0); int64_t d; BOOST_CHECK(tmp.pop(d)); - BOOST_CHECK(tmp.like_empty()); - BOOST_CHECK(tmp.head() == 1); - BOOST_CHECK(tmp.tail() == 1); + if (kPower != 0) { + // BOOST_CHECK(tmp.like_empty()); + BOOST_CHECK(tmp.head() == 1); + BOOST_CHECK(tmp.tail() == 1); + } ShmObject<Rcb> rcb(shm, "test_rcb"); bool try_more = true; @@ -165,6 +199,24 @@ BOOST_AUTO_TEST_CASE(MutexTest) { + { + int sem_id = semget(100, 1, 0666 | IPC_CREAT); + auto P = [&]() { + sembuf op = {0, -1, SEM_UNDO}; + semop(sem_id, &op, 1); + }; + auto V = [&]() { + sembuf op = {0, 1, SEM_UNDO}; + semop(sem_id, &op, 1); + }; + for (int i = 0; i < 10; ++i) { + V(); + } + Sleep(10s); + + return; + } + // typedef robust::MFMutex RobustMutex; typedef robust::SemMutex RobustMutex; @@ -188,7 +240,7 @@ std::mutex m; typedef std::chrono::steady_clock Clock; - auto Now = []() { return Clock::now().time_since_epoch(); }; + if (pi) { auto old = *pi; printf("int : %d, add1: %d\n", old, ++*pi); -- Gitblit v1.8.0