lichao
2021-06-03 69f60d8bcc5121eb952b57277c94ad5cecb8d44a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "center.h"
#include "defs.h"
#include "log.h"
#include "util.h"
#include <atomic>
#include <condition_variable>
#include <stdio.h>
#include <string>
#include <thread>
#include <vector>
 
namespace
{
bool InitLog()
{
    ns_log::AddLog("/tmp/bhshmq_test.log", true, true);
    ns_log::ResetLogLevel(ns_log::LogLevel::debug);
    return true;
}
static bool g_test_init_log = InitLog();
} // namespace
 
using namespace bhome_shm;
using namespace bhome_msg;
 
SharedMemory &TestShm()
{
    static SharedMemory shm("utest_0", 1024 * 1024 * 512);
    return shm;
}
 
template <class A, class B>
struct IsSameType {
    static const bool value = false;
};
template <class A>
struct IsSameType<A, A> {
    static const bool value = true;
};
 
BOOST_AUTO_TEST_CASE(Temp)
{
    const std::string shm_name("ShmTemp");
    ShmRemover auto_remove(shm_name); //remove twice? in case of killed?
    SharedMemory shm(shm_name, 1024 * 1024 * 10);
 
    typedef std::chrono::steady_clock clock;
    int n = 1000 * 1000;
    std::vector<clock::time_point> tps(n);
    {
        printf("thread switch %d times, ", n);
        boost::timer::auto_cpu_timer timer;
        for (auto &tp : tps) {
            tp = clock::now();
            std::this_thread::yield();
        }
    }
    printf("time: %ld ns\n", (tps.back() - tps.front()).count());
}
 
int test_main(int argc, char *argv[])
{
    printf("test main\n");
    int a = 0;
    int b = 0;
    BOOST_CHECK_EQUAL(a, b);
 
    return 0;
}