summaryrefslogtreecommitdiffstats
path: root/fnet/src/tests/info/info.cpp
blob: f15c8f83d8009db920c05547448b434c8d203592 (plain) (blame)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/fnet/frt/frt.h>
#include <mutex>
#include <condition_variable>
 
struct RPC : public FRT_Invokable
{
  void GetInfo(FRT_RPCRequest *req)
  {
    req->GetReturn()->AddString("fastos X current");
    req->GetReturn()->AddString(FNET_Info::GetFNETVersion());
    const char *endian_str = "UNKNOWN";
    if (FNET_Info::GetEndian() == FNET_Info::ENDIAN_LITTLE)
      endian_str = "LITTLE";
    if (FNET_Info::GetEndian() == FNET_Info::ENDIAN_BIG)
      endian_str = "BIG";
    req->GetReturn()->AddString(endian_str);
    req->GetReturn()->AddInt32(FD_SETSIZE);
    req->GetReturn()->AddInt32(sizeof(FRT_RPCRequest));
  }

  void Init(FRT_Supervisor *s)
  {
    FRT_ReflectionBuilder rb(s);
    //-------------------------------------------------------------------
    rb.DefineMethod("getInfo", "", "sssii", true,
                    FRT_METHOD(RPC::GetInfo), this);
    // FastOS version
    // FNET version
    // endian
    // FD_SETSIZE
    // req object size
    //-------------------------------------------------------------------
  }
};

TEST("info") {
    RPC rpc;
    FRT_Supervisor orb;
    char spec[64];
    rpc.Init(&orb);
    ASSERT_TRUE(orb.Listen("tcp/0"));
    sprintf(spec, "tcp/localhost:%d", orb.GetListenPort());
    ASSERT_TRUE(orb.Start());

    FRT_Target     *target      = orb.GetTarget(spec);
    FRT_RPCRequest *local_info  = orb.AllocRPCRequest();
    FRT_RPCRequest *remote_info = orb.AllocRPCRequest();

    rpc.GetInfo(local_info);
    remote_info->SetMethodName("getInfo");
    target->InvokeSync(remote_info, 10.0);
    EXPECT_FALSE(remote_info->IsError());

    FRT_Values &l = *local_info->GetReturn();
 // FRT_Values &r = *remote_info->GetReturn();

    fprintf(stderr, "FastOS Version: %s\n", l[0]._string._str);
    fprintf(stderr, "FNET Version: %s\n", l[1]._string._str);
    fprintf(stderr, "Endian: %s\n", l[2]._string._str);
    fprintf(stderr, "FD_SETSIZE: %d\n", l[3]._intval32);
    fprintf(stderr, "sizeof(FRT_RPCRequest): %d\n", l[4]._intval32);

    target->SubRef();
    local_info->SubRef();
    remote_info->SubRef();
    orb.ShutDown(true);
};

TEST("size of important objects")
{
    EXPECT_EQUAL(184u, sizeof(FNET_IOComponent));
    EXPECT_EQUAL(32u, sizeof(FNET_Channel));
    EXPECT_EQUAL(40u, sizeof(FNET_PacketQueue_NoLock));
    EXPECT_EQUAL(488u, sizeof(FNET_Connection));
    EXPECT_EQUAL(96u, sizeof(FastOS_Cond));
    EXPECT_EQUAL(56u, sizeof(FNET_DataBuffer));
    EXPECT_EQUAL(24u, sizeof(FastOS_Time));
    EXPECT_EQUAL(8u, sizeof(FNET_Context));
    EXPECT_EQUAL(8u, sizeof(fastos::TimeStamp));
    EXPECT_EQUAL(48u, sizeof(FastOS_Mutex));
    EXPECT_EQUAL(40u, sizeof(pthread_mutex_t));
    EXPECT_EQUAL(48u, sizeof(pthread_cond_t));
    EXPECT_EQUAL(40u, sizeof(std::mutex));
    EXPECT_EQUAL(48u, sizeof(std::condition_variable));
}

TEST_MAIN() { TEST_RUN_ALL(); }