forked from dgiot/dgiot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emqx_vm_SUITE.erl
99 lines (79 loc) · 3.07 KB
/
emqx_vm_SUITE.erl
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
90
91
92
93
94
95
96
97
98
%%--------------------------------------------------------------------
%% Copyright (c) 2017-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%--------------------------------------------------------------------
-module(emqx_vm_SUITE).
-compile(export_all).
-compile(nowarn_export_all).
-include_lib("eunit/include/eunit.hrl").
all() -> emqx_ct:all(?MODULE).
t_load(_Config) ->
?assertMatch([{load1, _}, {load5, _}, {load15, _}], emqx_vm:loads()).
t_systeminfo(_Config) ->
?assertEqual(emqx_vm:system_info_keys(),
[Key || {Key, _} <- emqx_vm:get_system_info()]),
?assertEqual(undefined, emqx_vm:get_system_info(undefined)).
t_mem_info(_Config) ->
application:ensure_all_started(os_mon),
MemInfo = emqx_vm:mem_info(),
[{total_memory, _}, {used_memory, _}]= MemInfo,
application:stop(os_mon).
t_process_info(_Config) ->
ProcessInfo = emqx_vm:get_process_info(),
?assertEqual(emqx_vm:process_info_keys(), [K || {K, _V}<- ProcessInfo]).
t_process_gc(_Config) ->
GcInfo = emqx_vm:get_process_gc_info(),
?assertEqual(emqx_vm:process_gc_info_keys(), [K || {K, _V}<- GcInfo]).
t_get_ets_list(_Config) ->
ets:new(test, [named_table]),
Ets = emqx_vm:get_ets_list(),
true = lists:member(test, Ets).
t_get_ets_info(_Config) ->
ets:new(test, [named_table]),
[] = emqx_vm:get_ets_info(test1),
EtsInfo = emqx_vm:get_ets_info(test),
test = proplists:get_value(name, EtsInfo),
Tid = proplists:get_value(id, EtsInfo),
EtsInfos = emqx_vm:get_ets_info(),
?assertEqual(true, lists:foldl(fun(Info, Acc) ->
case proplists:get_value(id, Info) of
Tid -> true;
_ -> Acc
end
end, false, EtsInfos)).
t_scheduler_usage(_Config) ->
emqx_vm:scheduler_usage(5000).
t_get_memory(_Config) ->
emqx_vm:get_memory().
t_schedulers(_Config) ->
emqx_vm:schedulers().
t_get_process_group_leader_info(_Config) ->
emqx_vm:get_process_group_leader_info(self()).
t_get_process_limit(_Config) ->
emqx_vm:get_process_limit().
t_cpu_util(_Config) ->
_Cpu = emqx_vm:cpu_util().
easy_server() ->
{ok, LSock} = gen_tcp:listen(5678, [binary, {packet, 0}, {active, false}]),
{ok, Sock} = gen_tcp:accept(LSock),
ok = do_recv(Sock),
ok = gen_tcp:close(Sock),
ok = gen_tcp:close(LSock).
do_recv(Sock) ->
case gen_tcp:recv(Sock, 0) of
{ok, _} ->
do_recv(Sock);
{error, closed} ->
ok
end.