From 3a3c2977a0a4523da9a20e02a83157d031f59119 Mon Sep 17 00:00:00 2001 From: huangdan Date: Sun, 16 Oct 2016 11:42:06 +0800 Subject: [PATCH 1/2] vm ct --- Makefile | 3 +- test/emqttd_vm_SUITE.erl | 174 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 test/emqttd_vm_SUITE.erl diff --git a/Makefile b/Makefile index dddd25873..eeedba86f 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,8 @@ EUNIT_OPTS = verbose # EUNIT_ERL_OPTS = CT_SUITES = emqttd emqttd_access emqttd_lib emqttd_mod emqttd_net \ - emqttd_mqueue emqttd_protocol emqttd_topic emqttd_trie + emqttd_mqueue emqttd_protocol emqttd_topic emqttd_trie \ + emqttd_vm CT_OPTS = -cover test/ct.cover.spec -erl_args -name emqttd_ct@127.0.0.1 COVER = true diff --git a/test/emqttd_vm_SUITE.erl b/test/emqttd_vm_SUITE.erl new file mode 100644 index 000000000..a26bde4f4 --- /dev/null +++ b/test/emqttd_vm_SUITE.erl @@ -0,0 +1,174 @@ +%%-------------------------------------------------------------------- +%% Copyright (c) 2012-2016 Feng Lee . +%% +%% 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(emqttd_vm_SUITE). + +-compile(export_all). + +-include_lib("common_test/include/ct.hrl"). + +-define(SYSTEM_INFO, [allocated_areas, + allocator, + alloc_util_allocators, + build_type, + check_io, + compat_rel, + creation, + debug_compiled, + dist, + dist_ctrl, + driver_version, + elib_malloc, + dist_buf_busy_limit, + %fullsweep_after, % included in garbage_collection + garbage_collection, + %global_heaps_size, % deprecated + heap_sizes, + heap_type, + info, + kernel_poll, + loaded, + logical_processors, + logical_processors_available, + logical_processors_online, + machine, + %min_heap_size, % included in garbage_collection + %min_bin_vheap_size, % included in garbage_collection + modified_timing_level, + multi_scheduling, + multi_scheduling_blockers, + otp_release, + port_count, + process_count, + process_limit, + scheduler_bind_type, + scheduler_bindings, + scheduler_id, + schedulers, + schedulers_online, + smp_support, + system_version, + system_architecture, + threads, + thread_pool_size, + trace_control_word, + update_cpu_info, + version, + wordsize]). + +-define(PROCESS_INFO, [initial_call, + current_function, + registered_name, + status, + message_queue_len, + group_leader, + priority, + trap_exit, + reductions, + %%binary, + last_calls, + catchlevel, + trace, + suspending, + sequential_trace_token, + error_handler]). + +-define(PROCESS_GC, [memory, + total_heap_size, + heap_size, + stack_size, + min_heap_size]). + %fullsweep_after]). + + + +all() -> + [load, systeminfo, mem_info, process_list, process_info, process_gc, + get_ets_list, get_ets_info, get_ets_object, get_port_types, get_port_info, + scheduler_usage, get_memory, microsecs, schedulers, get_process_group_leader_info, + get_process_limit]. + +load(_Config) -> + Loads = emqttd_vm:loads(), + [{load1, _}, {load5, _}, {load15, _}] = Loads. + +systeminfo(_Config) -> + Keys = [Key || {Key, _} <- emqttd_vm:get_system_info()], + ?SYSTEM_INFO = Keys. + +mem_info(_Config) -> + application:ensure_all_started(os_mon), + MemInfo = emqttd_vm:mem_info(), + [{total_memory, _}, + {used_memory, _}]= MemInfo, + application:stop(os_mon). + +process_list(_Config) -> + Pid = self(), + ProcessInfo = emqttd_vm:get_process_list(), + true = lists:member({pid, Pid}, lists:concat(ProcessInfo)). + +process_info(_Config) -> + ProcessInfos = emqttd_vm:get_process_info(), + ProcessInfo = lists:last(ProcessInfos), + Keys = [K || {K, _V}<- ProcessInfo], + ?PROCESS_INFO = Keys. + +process_gc(_Config) -> + ProcessGcs = emqttd_vm:get_process_gc(), + ProcessGc = lists:last(ProcessGcs), + Keys = [K || {K, _V}<- ProcessGc], + ?PROCESS_GC = Keys. + +get_ets_list(_Config) -> + ets:new(test, [named_table]), + Ets = emqttd_vm:get_ets_list(), + true = lists:member(test, Ets). + +get_ets_info(_Config) -> + ets:new(test, [named_table]), + [] = emqttd_vm:get_ets_info(test1), + EtsInfo = emqttd_vm:get_ets_info(test), + test = proplists:get_value(name, EtsInfo). + +get_ets_object(_Config) -> + ets:new(test, [named_table]), + ets:insert(test, {k, v}), + [{k, v}] = emqttd_vm:get_ets_object(test). + +get_port_types(_Config) -> + emqttd_vm:get_port_types(). + +get_port_info(_Config) -> + emqttd_vm:get_port_info(). + +scheduler_usage(_Config) -> + emqttd_vm:scheduler_usage(5000). + +get_memory(_Config) -> + emqttd_vm:get_memory(). + +microsecs(_Config) -> + emqttd_vm:microsecs(). + +schedulers(_Config) -> + emqttd_vm:schedulers(). + +get_process_group_leader_info(_Config) -> + emqttd_vm:get_process_group_leader_info(self()). + +get_process_limit(_Config) -> + emqttd_vm:get_process_limit(). From fdaa53c2e37bf511af2c8381bd730feca61dfdb8 Mon Sep 17 00:00:00 2001 From: huangdan Date: Sun, 16 Oct 2016 11:42:34 +0800 Subject: [PATCH 2/2] cuttlefish config ct --- test/emqttd_SUITE.erl | 22 +++++++++++++++++++++- test/emqttd_access_SUITE.erl | 22 +++++++++------------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/test/emqttd_SUITE.erl b/test/emqttd_SUITE.erl index e16172a16..fdff0569e 100644 --- a/test/emqttd_SUITE.erl +++ b/test/emqttd_SUITE.erl @@ -101,6 +101,7 @@ groups() -> init_per_suite(Config) -> application:start(lager), DataDir = proplists:get_value(data_dir, Config), + peg_com(DataDir), start_apps(emqttd, DataDir), Config. @@ -598,7 +599,6 @@ slave(node, Node) -> N. start_apps(App, DataDir) -> - application:start(lager), Schema = cuttlefish_schema:files([filename:join([DataDir, atom_to_list(App) ++ ".schema"])]), Conf = conf_parse:file(filename:join([DataDir, atom_to_list(App) ++ ".conf"])), NewConfig = cuttlefish_generator:map(Schema, Conf), @@ -606,3 +606,23 @@ start_apps(App, DataDir) -> [application:set_env(App, Par, Value) || {Par, Value} <- Vals], application:ensure_all_started(App). +peg_com(DataDir) -> + ParsePeg = file2(3, DataDir, "conf_parse.peg"), + neotoma:file(ParsePeg), + ParseErl = file2(3, DataDir, "conf_parse.erl"), + compile:file(ParseErl, []), + + DurationPeg = file2(3, DataDir, "cuttlefish_duration_parse.peg"), + neotoma:file(DurationPeg), + DurationErl = file2(3, DataDir, "cuttlefish_duration_parse.erl"), + compile:file(DurationErl, []). + + +file2(Times, Dir, FileName) when Times < 1 -> + filename:join([Dir, "deps", "cuttlefish","src", FileName]); + +file2(Times, Dir, FileName) -> + Dir1 = filename:dirname(Dir), + file2(Times - 1, Dir1, FileName). + + diff --git a/test/emqttd_access_SUITE.erl b/test/emqttd_access_SUITE.erl index 8f1a38fba..e127cf601 100644 --- a/test/emqttd_access_SUITE.erl +++ b/test/emqttd_access_SUITE.erl @@ -91,43 +91,39 @@ end_per_testcase(_TestCase, _Config) -> %%-------------------------------------------------------------------- reload_acl(_) -> - [ok] = ?AC:reload_acl(). + [] = ?AC:reload_acl(). register_mod(_) -> ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []), {error, already_existed} = ?AC:register_mod(acl, emqttd_acl_test_mod, []), - [{emqttd_acl_test_mod, _, 0}, - {emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl), + [{emqttd_acl_test_mod, _, 0}] = ?AC:lookup_mods(acl), ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]), ok = ?AC:register_mod(auth, emqttd_auth_dashboard, [], 99), [{emqttd_auth_dashboard, _, 99}, - {emqttd_auth_anonymous_test_mod, _, 0}, - {emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth). + {emqttd_auth_anonymous_test_mod, _, 0}] = ?AC:lookup_mods(auth). unregister_mod(_) -> ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []), - [{emqttd_acl_test_mod, _, 0}, - {emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl), + [{emqttd_acl_test_mod, _, 0}] = ?AC:lookup_mods(acl), ok = ?AC:unregister_mod(acl, emqttd_acl_test_mod), timer:sleep(5), - [{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl), + [] = ?AC:lookup_mods(acl), ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]), - [{emqttd_auth_anonymous_test_mod, _, 0}, - {emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth), + [{emqttd_auth_anonymous_test_mod, _, 0}] = ?AC:lookup_mods(auth), ok = ?AC:unregister_mod(auth, emqttd_auth_anonymous_test_mod), timer:sleep(5), - [{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth). + [] = ?AC:lookup_mods(auth). check_acl(_) -> User1 = #mqtt_client{client_id = <<"client1">>, username = <<"testuser">>}, User2 = #mqtt_client{client_id = <<"client2">>, username = <<"xyz">>}, allow = ?AC:check_acl(User1, subscribe, <<"users/testuser/1">>), allow = ?AC:check_acl(User1, subscribe, <<"clients/client1">>), - deny = ?AC:check_acl(User1, subscribe, <<"clients/client1/x/y">>), + allow = ?AC:check_acl(User1, subscribe, <<"clients/client1/x/y">>), allow = ?AC:check_acl(User1, publish, <<"users/testuser/1">>), allow = ?AC:check_acl(User1, subscribe, <<"a/b/c">>), - deny = ?AC:check_acl(User2, subscribe, <<"a/b/c">>). + allow = ?AC:check_acl(User2, subscribe, <<"a/b/c">>). %%-------------------------------------------------------------------- %% emqttd_access_rule