1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2004-2020. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%%---------------------------------------------------------------------- 22%% Purpose: Various (snmp manager) user related tests 23%%---------------------------------------------------------------------- 24-module(snmp_manager_user_SUITE). 25 26 27%%---------------------------------------------------------------------- 28%% Include files 29%%---------------------------------------------------------------------- 30-include_lib("common_test/include/ct.hrl"). 31-include("snmp_test_lib.hrl"). 32 33 34%%---------------------------------------------------------------------- 35%% External exports 36%%---------------------------------------------------------------------- 37 38-export([ 39 suite/0, all/0, groups/0, 40 init_per_suite/1, end_per_suite/1, 41 init_per_group/2, end_per_group/2, 42 init_per_testcase/2, end_per_testcase/2, 43 44 45 simple_register_and_unregister1/1, 46 simple_register_and_unregister2/1, 47 simple_register_and_unregister3/1, 48 register_and_crash1/1, 49 register_and_crash2/1, 50 register_and_crash3/1, 51 register_request_and_crash1/1, 52 register_request_and_crash2/1, 53 register_request_and_crash3/1, 54 simple_register_monitor_and_unregister1/1, 55 simple_register_monitor_and_unregister2/1, 56 simple_register_monitor_and_unregister3/1, 57 register_monitor_and_crash1/1, 58 register_monitor_and_crash2/1, 59 register_monitor_and_crash3/1, 60 register_monitor_and_crash4/1, 61 register_monitor_and_crash5/1, 62 register_monitor_request_and_crash1/1, 63 register_monitor_request_and_crash2/1, 64 register_monitor_request_and_crash3/1, 65 register_monitor_request_and_crash4/1, 66 67 68 otp7902/1 69 70 ]). 71 72 73%%---------------------------------------------------------------------- 74%% Internal exports 75%%---------------------------------------------------------------------- 76-export([ 77 ]). 78 79 80%%---------------------------------------------------------------------- 81%% Macros 82%%---------------------------------------------------------------------- 83 84 85%%---------------------------------------------------------------------- 86%% Records 87%%---------------------------------------------------------------------- 88 89 90%%====================================================================== 91%% Common Test interface functions 92%%====================================================================== 93 94suite() -> 95 [{ct_hooks, [ts_install_cth]}]. 96 97 98all() -> 99 [ 100 {group, register_user}, 101 {group, tickets} 102 ]. 103 104groups() -> 105 [ 106 {register_user, [], register_user_cases()}, 107 {tickets, [], tickets_cases()} 108 ]. 109 110register_user_cases() -> 111 [ 112 simple_register_and_unregister1, 113 simple_register_and_unregister2, 114 simple_register_and_unregister3, register_and_crash1, 115 register_and_crash2, register_and_crash3, 116 register_request_and_crash1, 117 register_request_and_crash2, 118 register_request_and_crash3, 119 simple_register_monitor_and_unregister1, 120 simple_register_monitor_and_unregister2, 121 simple_register_monitor_and_unregister3, 122 register_monitor_and_crash1, 123 register_monitor_and_crash2, 124 register_monitor_and_crash3, 125 register_monitor_and_crash4, 126 register_monitor_and_crash5, 127 register_monitor_request_and_crash1, 128 register_monitor_request_and_crash2, 129 register_monitor_request_and_crash3, 130 register_monitor_request_and_crash4 131 ]. 132 133tickets_cases() -> 134 [ 135 otp7902 136 ]. 137 138 139 140%% 141%% ----- 142%% 143 144init_per_suite(Config0) when is_list(Config0) -> 145 146 ?IPRINT("init_per_suite -> entry with" 147 "~n Config0: ~p", [Config0]), 148 149 case ?LIB:init_per_suite(Config0) of 150 {skip, _} = SKIP -> 151 SKIP; 152 Config1 when is_list(Config1) -> 153 snmp_test_sys_monitor:start(), 154 Config2 = snmp_test_lib:init_suite_top_dir(?MODULE, Config1), 155 156 ?IPRINT("init_per_suite -> done when" 157 "~n Config: ~p", [Config2]), 158 159 Config2 160 end. 161 162end_per_suite(Config) when is_list(Config) -> 163 164 ?IPRINT("end_per_suite -> entry with" 165 "~n Config: ~p", [Config]), 166 167 snmp_test_sys_monitor:stop(), 168 Config1 = ?LIB:end_per_suite(Config), 169 170 ?IPRINT("end_per_suite -> end"), 171 172 Config1. 173 174 175 176%% 177%% ----- 178%% 179 180init_per_group(_GroupName, Config) -> 181 Config. 182 183end_per_group(_GroupName, Config) -> 184 Config. 185 186 187 188%% 189%% ----- 190%% 191 192init_per_testcase(Case, Config) when is_list(Config) -> 193 ?IPRINT("init_per_testcase -> entry with" 194 "~n Config: ~p", [Config]), 195 196 snmp_test_global_sys_monitor:reset_events(), 197 198 SuiteTopDir = ?config(snmp_suite_top_dir, Config), 199 CaseTopDir = filename:join(SuiteTopDir, atom_to_list(Case)), 200 ?line ok = file:make_dir(CaseTopDir), 201 ?IPRINT("init_per_testcase -> CaseTopDir: ~p", [CaseTopDir]), 202 MgrTopDir = filename:join(CaseTopDir, "manager/"), 203 ?line ok = file:make_dir(MgrTopDir), 204 MgrConfDir = filename:join(MgrTopDir, "conf/"), 205 ?line ok = file:make_dir(MgrConfDir), 206 MgrDbDir = filename:join(MgrTopDir, "db/"), 207 ?line ok = file:make_dir(MgrDbDir), 208 MgrLogDir = filename:join(MgrTopDir, "log/"), 209 ?line ok = file:make_dir(MgrLogDir), 210 211 Config1 = [{case_top_dir, CaseTopDir}, 212 {manager_dir, MgrTopDir}, 213 {manager_conf_dir, MgrConfDir}, 214 {manager_db_dir, MgrDbDir}, 215 {manager_log_dir, MgrLogDir} | Config], 216 217 ?IPRINT("init_per_testcase -> done when" 218 "~n Config: ~p", [Config1]), 219 220 Config1. 221 222 223end_per_testcase(_Case, Config) when is_list(Config) -> 224 225 ?IPRINT("end_per_testcase -> entry with" 226 "~n Config: ~p", 227 [Config]), 228 229 ?IPRINT("system events during test: ~p", 230 [snmp_test_global_sys_monitor:events()]), 231 232 Config. 233 234 235 236%%====================================================================== 237%% Test functions 238%%====================================================================== 239 240simple_register_and_unregister1(suite) -> []; 241simple_register_and_unregister1(doc) -> 242 "Start a user, register and unregister the user."; 243simple_register_and_unregister1(Conf) when is_list(Conf) -> 244 put(tname,srar1), 245 ?IPRINT("start"), 246 process_flag(trap_exit, true), 247 248 ConfDir = ?config(manager_conf_dir, Conf), 249 DbDir = ?config(manager_db_dir, Conf), 250 251 write_manager_conf(ConfDir), 252 253 Opts = [{server, [{verbosity, trace}]}, 254 {net_if, [{verbosity, trace}]}, 255 {note_store, [{verbosity, trace}]}, 256 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 257 258 ?IPRINT("try starting manager"), 259 ok = snmpm:start_link(Opts), 260 261 ?SLEEP(1000), 262 263 Id = make_ref(), 264 265 ?line Pid = start_user(), 266 267 ?line [] = Users1 = which_users(), 268 ?IPRINT("Users1: ~p", [Users1]), 269 270 ?line ok = register_user(Pid, Id), 271 272 ?line [Id] = Users2 = which_users(), 273 ?IPRINT("Users2: ~p", [Users2]), 274 275 ?line ok = unregister_user(Pid), 276 277 ?line [] = Users3 = which_users(), 278 ?IPRINT("Users3: ~p", [Users3]), 279 280 ?line stop_user(Pid), 281 282 ?line ok = snmpm:stop(), 283 284 ?IPRINT("end"), 285 ok. 286 287 288%% ------------------------------------------------------------------ 289 290simple_register_and_unregister2(suite) -> []; 291simple_register_and_unregister2(doc) -> 292 "Start a single user process, " 293 "register 2 users (per that process) and unregister the 2 users."; 294simple_register_and_unregister2(Conf) when is_list(Conf) -> 295 put(tname,srar2), 296 ?IPRINT("start"), 297 process_flag(trap_exit, true), 298 299 ConfDir = ?config(manager_conf_dir, Conf), 300 DbDir = ?config(manager_db_dir, Conf), 301 302 write_manager_conf(ConfDir), 303 304 Opts = [{server, [{verbosity, trace}]}, 305 {net_if, [{verbosity, trace}]}, 306 {note_store, [{verbosity, trace}]}, 307 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 308 309 ?IPRINT("try starting manager"), 310 ok = snmpm:start_link(Opts), 311 312 ?SLEEP(1000), 313 314 Id1 = make_ref(), 315 Id2 = make_ref(), 316 317 ?line Pid = start_user(), 318 319 ?line [] = Users1 = which_users(), 320 ?IPRINT("Users1: ~p", [Users1]), 321 322 ?line ok = register_user(Pid, Id1), 323 ?line ok = register_user(Pid, Id2), 324 325 ?line Users2 = case which_users() of 326 [Id1, Id2] = U1 -> 327 U1; 328 [Id2, Id1] = U2 -> 329 U2; 330 Else -> 331 ?FAIL({invalid_users, Else}) 332 end, 333 ?IPRINT("Users2: ~p", [Users2]), 334 335 336 ?line ok = unregister_user(Pid, Id1), 337 ?line ok = unregister_user(Pid, Id2), 338 339 ?line [] = Users3 = which_users(), 340 ?IPRINT("Users3: ~p", [Users3]), 341 342 ?line stop_user(Pid), 343 344 ?line ok = snmpm:stop(), 345 346 ?IPRINT("end"), 347 ok. 348 349 350%% ------------------------------------------------------------------ 351 352simple_register_and_unregister3(suite) -> []; 353simple_register_and_unregister3(doc) -> 354 "Start 2 user processes, " 355 "register one users per process and unregister the 2 users."; 356simple_register_and_unregister3(Conf) when is_list(Conf) -> 357 put(tname,srar2), 358 ?IPRINT("start"), 359 process_flag(trap_exit, true), 360 361 ConfDir = ?config(manager_conf_dir, Conf), 362 DbDir = ?config(manager_db_dir, Conf), 363 364 write_manager_conf(ConfDir), 365 366 Opts = [{server, [{verbosity, trace}]}, 367 {net_if, [{verbosity, trace}]}, 368 {note_store, [{verbosity, trace}]}, 369 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 370 371 ?IPRINT("try starting manager"), 372 ok = snmpm:start_link(Opts), 373 374 ?SLEEP(1000), 375 376 Id1 = make_ref(), 377 Id2 = make_ref(), 378 379 ?line Pid1 = start_user(), 380 ?line Pid2 = start_user(), 381 382 ?line [] = Users1 = which_users(), 383 ?IPRINT("Users1: ~p", [Users1]), 384 385 ?line ok = register_user(Pid1, Id1), 386 ?line ok = register_user(Pid2, Id2), 387 388 ?line Users2 = case which_users() of 389 [Id1, Id2] = U1 -> 390 U1; 391 [Id2, Id1] = U2 -> 392 U2; 393 Else -> 394 ?FAIL({invalid_users, Else}) 395 end, 396 ?IPRINT("Users2: ~p", [Users2]), 397 398 399 ?line ok = unregister_user(Pid1, Id1), 400 ?line ok = unregister_user(Pid2, Id2), 401 402 ?line [] = Users3 = which_users(), 403 ?IPRINT("Users3: ~p", [Users3]), 404 405 ?line stop_user(Pid1), 406 ?line stop_user(Pid2), 407 408 ?line ok = snmpm:stop(), 409 410 ?IPRINT("end"), 411 ok. 412 413 414%% ------------------------------------------------------------------ 415 416register_and_crash1(suite) -> []; 417register_and_crash1(doc) -> 418 "Start a user, register and crash user."; 419register_and_crash1(Conf) when is_list(Conf) -> 420 put(tname,racau1), 421 ?IPRINT("start"), 422 process_flag(trap_exit, true), 423 424 ConfDir = ?config(manager_conf_dir, Conf), 425 DbDir = ?config(manager_db_dir, Conf), 426 427 write_manager_conf(ConfDir), 428 429 Opts = [{server, [{verbosity, trace}]}, 430 {net_if, [{verbosity, trace}]}, 431 {note_store, [{verbosity, trace}]}, 432 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 433 434 ?IPRINT("try starting manager"), 435 ?line ok = snmpm:start_link(Opts), 436 437 ?SLEEP(1000), 438 439 Id = make_ref(), 440 441 ?line Pid = start_user(), 442 443 ?line [] = Users1 = which_users(), 444 ?IPRINT("Users1: ~p", [Users1]), 445 446 ?line ok = register_user(Pid, Id), 447 448 ?line [Id] = Users2 = which_users(), 449 ?IPRINT("Users2: ~p", [Users2]), 450 451 ?line ok = simulate_crash(Pid), 452 453 ?line [Id] = Users3 = which_users(), 454 ?IPRINT("Users3: ~p", [Users3]), 455 456 ?IPRINT("stop manager"), 457 ?line ok = snmpm:stop(), 458 459 ?IPRINT("end"), 460 ok. 461 462 463%% ------------------------------------------------------------------ 464 465register_and_crash2(suite) -> []; 466register_and_crash2(doc) -> 467 "Start a single user process, " 468 "register 2 users (per that process) and crash the process."; 469register_and_crash2(Conf) when is_list(Conf) -> 470 put(tname,racau2), 471 ?IPRINT("start"), 472 process_flag(trap_exit, true), 473 474 ConfDir = ?config(manager_conf_dir, Conf), 475 DbDir = ?config(manager_db_dir, Conf), 476 477 write_manager_conf(ConfDir), 478 479 Opts = [{server, [{verbosity, trace}]}, 480 {net_if, [{verbosity, trace}]}, 481 {note_store, [{verbosity, trace}]}, 482 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 483 484 ?IPRINT("try starting manager"), 485 ?line ok = snmpm:start_link(Opts), 486 487 ?SLEEP(1000), 488 489 Id1 = make_ref(), 490 Id2 = make_ref(), 491 492 ?line Pid = start_user(), 493 494 ?line [] = Users1 = which_users(), 495 ?IPRINT("Users1: ~p", [Users1]), 496 497 ?line ok = register_user(Pid, Id1), 498 ?line ok = register_user(Pid, Id2), 499 500 ?line Users2 = case which_users() of 501 [Id1, Id2] = U1 -> 502 U1; 503 [Id2, Id1] = U2 -> 504 U2; 505 Else1 -> 506 ?FAIL({invalid_users, Else1}) 507 end, 508 ?IPRINT("Users2: ~p", [Users2]), 509 510 ?line ok = simulate_crash(Pid), 511 512 ?line Users3 = case which_users() of 513 [Id1, Id2] = U3 -> 514 U3; 515 [Id2, Id1] = U4 -> 516 U4; 517 Else2 -> 518 ?FAIL({invalid_users, Else2}) 519 end, 520 ?IPRINT("Users3: ~p", [Users3]), 521 522 ?IPRINT("stop manager"), 523 ?line ok = snmpm:stop(), 524 525 ?IPRINT("end"), 526 ok. 527 528 529%% ------------------------------------------------------------------ 530 531register_and_crash3(suite) -> []; 532register_and_crash3(doc) -> 533 "Start 2 user processes, " 534 "register one user per process and " 535 "crash the first user process."; 536register_and_crash3(Conf) when is_list(Conf) -> 537 %% put(tname,rac3), 538 %% ?IPRINT("start"), 539 %% process_flag(trap_exit, true), 540 ?SKIP(not_yet_implemented). 541 542 543%% ------------------------------------------------------------------ 544 545register_request_and_crash1(suite) -> []; 546register_request_and_crash1(doc) -> 547 "Start a single user process, " 548 "register user, send request and crash user."; 549register_request_and_crash1(Conf) when is_list(Conf) -> 550 %% put(tname,rrac1), 551 %% ?IPRINT("start"), 552 %% process_flag(trap_exit, true), 553 ?SKIP(not_yet_implemented). 554 555 556%% ------------------------------------------------------------------ 557 558register_request_and_crash2(suite) -> []; 559register_request_and_crash2(doc) -> 560 "Start a single user process, " 561 "register 2 users (per that single user process), " 562 "send a request for each user and crash the single user process."; 563register_request_and_crash2(Conf) when is_list(Conf) -> 564 %% put(tname,rrac2), 565 %% ?IPRINT("start"), 566 %% process_flag(trap_exit, true), 567 ?SKIP(not_yet_implemented). 568 569 570%% ------------------------------------------------------------------ 571 572register_request_and_crash3(suite) -> []; 573register_request_and_crash3(doc) -> 574 "Start 2 user processes, " 575 "register one user per process, " 576 "send a request for each user and crash the first user process."; 577register_request_and_crash3(Conf) when is_list(Conf) -> 578 %% put(tname,rrac3), 579 %% ?IPRINT("start"), 580 %% process_flag(trap_exit, true), 581 ?SKIP(not_yet_implemented). 582 583 584%% ------------------------------------------------------------------ 585 586simple_register_monitor_and_unregister1(suite) -> []; 587simple_register_monitor_and_unregister1(doc) -> 588 "Start a user, register-link and unregister the user."; 589simple_register_monitor_and_unregister1(Conf) when is_list(Conf) -> 590 put(tname,srlau1), 591 ?IPRINT("start"), 592 process_flag(trap_exit, true), 593 594 ConfDir = ?config(manager_conf_dir, Conf), 595 DbDir = ?config(manager_db_dir, Conf), 596 597 write_manager_conf(ConfDir), 598 599 Opts = [{server, [{verbosity, trace}]}, 600 {net_if, [{verbosity, trace}]}, 601 {note_store, [{verbosity, trace}]}, 602 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 603 604 ?IPRINT("try starting manager"), 605 ok = snmpm:start_link(Opts), 606 607 ?SLEEP(1000), 608 609 Id = make_ref(), 610 611 ?IPRINT("start user"), 612 ?line Pid = start_user(), 613 614 ?IPRINT("get users (=0)"), 615 ?line [] = Users1 = which_users(), 616 ?IPRINT("Users1: ~p", [Users1]), 617 618 ?IPRINT("register monitored user"), 619 ?line ok = register_user_monitor(Pid, Id), 620 621 ?IPRINT("get users (=1)"), 622 ?line [Id] = Users2 = which_users(), 623 ?IPRINT("Users2: ~p", [Users2]), 624 625 ?IPRINT("unregister monitored user"), 626 ?line unregister_user(Pid), 627 628 ?IPRINT("get users (=0)"), 629 ?line [] = Users3 = which_users(), 630 ?IPRINT("Users3: ~p", [Users3]), 631 632 ?IPRINT("start user"), 633 ?line stop_user(Pid), 634 635 ?IPRINT("stop manager"), 636 ?line ok = snmpm:stop(), 637 638 ?IPRINT("end"), 639 ok. 640 641 642%% ------------------------------------------------------------------ 643 644simple_register_monitor_and_unregister2(suite) -> []; 645simple_register_monitor_and_unregister2(doc) -> 646 "Start a single user process, " 647 "register-link 2 users (per that process) and " 648 "unregister the 2 users."; 649simple_register_monitor_and_unregister2(Conf) when is_list(Conf) -> 650 put(tname,srlau2), 651 ?IPRINT("start"), 652 process_flag(trap_exit, true), 653 654 ConfDir = ?config(manager_conf_dir, Conf), 655 DbDir = ?config(manager_db_dir, Conf), 656 657 write_manager_conf(ConfDir), 658 659 Opts = [{server, [{verbosity, trace}]}, 660 {net_if, [{verbosity, trace}]}, 661 {note_store, [{verbosity, trace}]}, 662 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 663 664 ?IPRINT("try starting manager"), 665 ok = snmpm:start_link(Opts), 666 667 ?SLEEP(1000), 668 669 Id1 = make_ref(), 670 Id2 = make_ref(), 671 672 ?line Pid = start_user(), 673 674 ?line [] = Users1 = which_users(), 675 ?IPRINT("Users1: ~p", [Users1]), 676 677 ?line ok = register_user_monitor(Pid, Id1), 678 ?line ok = register_user_monitor(Pid, Id2), 679 680 ?line Users2 = case which_users() of 681 [Id1, Id2] = U1 -> 682 U1; 683 [Id2, Id1] = U2 -> 684 U2; 685 Else -> 686 ?FAIL({invalid_users, Else}) 687 end, 688 ?IPRINT("Users2: ~p", [Users2]), 689 690 ?line ok = unregister_user(Pid, Id1), 691 ?line ok = unregister_user(Pid, Id2), 692 693 ?line [] = Users3 = which_users(), 694 ?IPRINT("Users3: ~p", [Users3]), 695 696 ?line stop_user(Pid), 697 698 ?line ok = snmpm:stop(), 699 700 ?IPRINT("end"), 701 ok. 702 703 704%% ------------------------------------------------------------------ 705 706simple_register_monitor_and_unregister3(suite) -> []; 707simple_register_monitor_and_unregister3(doc) -> 708 "Start a single user process, " 709 "register one user and register-monitor one user " 710 "(per that process) and " 711 "unregister the 2 users."; 712simple_register_monitor_and_unregister3(Conf) when is_list(Conf) -> 713 put(tname,srlau3), 714 ?IPRINT("start"), 715 process_flag(trap_exit, true), 716 717 ConfDir = ?config(manager_conf_dir, Conf), 718 DbDir = ?config(manager_db_dir, Conf), 719 720 write_manager_conf(ConfDir), 721 722 Opts = [{server, [{verbosity, trace}]}, 723 {net_if, [{verbosity, trace}]}, 724 {note_store, [{verbosity, trace}]}, 725 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 726 727 ?IPRINT("try starting manager"), 728 ok = snmpm:start_link(Opts), 729 730 ?SLEEP(1000), 731 732 Id1 = make_ref(), 733 Id2 = make_ref(), 734 735 ?line Pid = start_user(), 736 737 ?line [] = Users1 = which_users(), 738 ?IPRINT("Users1: ~p", [Users1]), 739 740 ?line ok = register_user(Pid, Id1), 741 ?line ok = register_user_monitor(Pid, Id2), 742 743 ?line Users2 = case which_users() of 744 [Id1, Id2] = U1 -> 745 U1; 746 [Id2, Id1] = U2 -> 747 U2; 748 Else -> 749 ?FAIL({invalid_users, Else}) 750 end, 751 ?IPRINT("Users2: ~p", [Users2]), 752 753 ?line unregister_user(Pid), 754 755 ?line [] = Users3 = which_users(), 756 ?IPRINT("Users3: ~p", [Users3]), 757 758 ?line stop_user(Pid), 759 760 ?line ok = snmpm:stop(), 761 762 ?IPRINT("end"), 763 ok. 764 765 766%% ------------------------------------------------------------------ 767 768register_monitor_and_crash1(suite) -> []; 769register_monitor_and_crash1(doc) -> 770 "Start a user, register-monitor and crash the user."; 771register_monitor_and_crash1(Conf) when is_list(Conf) -> 772 put(tname,rlac1), 773 ?IPRINT("start"), 774 process_flag(trap_exit, true), 775 776 ConfDir = ?config(manager_conf_dir, Conf), 777 DbDir = ?config(manager_db_dir, Conf), 778 779 write_manager_conf(ConfDir), 780 781 Opts = [{server, [{verbosity, trace}]}, 782 {net_if, [{verbosity, trace}]}, 783 {note_store, [{verbosity, trace}]}, 784 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 785 786 ?IPRINT("try starting manager"), 787 ?line ok = snmpm:start_link(Opts), 788 789 ?SLEEP(1000), 790 791 Id = make_ref(), 792 793 ?line Pid = start_user(), 794 795 ?line [] = Users1 = which_users(), 796 ?IPRINT("Users1: ~p", [Users1]), 797 798 ?line ok = register_user_monitor(Pid, Id), 799 800 ?line [Id] = Users2 = which_users(), 801 ?IPRINT("Users2: ~p", [Users2]), 802 803 ?line ok = simulate_crash(Pid), 804 805 ?SLEEP(1000), 806 807 ?line [] = Users3 = which_users(), 808 ?IPRINT("Users3: ~p", [Users3]), 809 810 ?IPRINT("stop manager"), 811 ?line ok = snmpm:stop(), 812 813 ?IPRINT("end"), 814 ok. 815 816 817%% ------------------------------------------------------------------ 818 819register_monitor_and_crash2(suite) -> []; 820register_monitor_and_crash2(doc) -> 821 "Start a single user process, " 822 "register-monitor 2 users (per that process) " 823 "and crash the single user process."; 824register_monitor_and_crash2(Conf) when is_list(Conf) -> 825 put(tname,rlac2), 826 ?IPRINT("start"), 827 process_flag(trap_exit, true), 828 829 ConfDir = ?config(manager_conf_dir, Conf), 830 DbDir = ?config(manager_db_dir, Conf), 831 832 write_manager_conf(ConfDir), 833 834 Opts = [{server, [{verbosity, trace}]}, 835 {net_if, [{verbosity, trace}]}, 836 {note_store, [{verbosity, trace}]}, 837 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 838 839 ?IPRINT("try starting manager"), 840 ?line ok = snmpm:start_link(Opts), 841 842 ?SLEEP(1000), 843 844 Id1 = make_ref(), 845 Id2 = make_ref(), 846 847 ?line Pid = start_user(), 848 849 ?line [] = Users1 = which_users(), 850 ?IPRINT("Users1: ~p", [Users1]), 851 852 ?line ok = register_user_monitor(Pid, Id1), 853 ?line ok = register_user_monitor(Pid, Id2), 854 855 ?line Users2 = case which_users() of 856 [Id1, Id2] = U1 -> 857 U1; 858 [Id2, Id1] = U2 -> 859 U2; 860 Else -> 861 ?FAIL({invalid_users, Else}) 862 end, 863 ?IPRINT("Users2: ~p", [Users2]), 864 865 ?line ok = simulate_crash(Pid), 866 867 ?SLEEP(1000), 868 869 ?line [] = Users3 = which_users(), 870 ?IPRINT("Users3: ~p", [Users3]), 871 872 ?IPRINT("stop manager"), 873 ?line ok = snmpm:stop(), 874 875 ?IPRINT("end"), 876 ok. 877 878 879%% ------------------------------------------------------------------ 880 881register_monitor_and_crash3(suite) -> []; 882register_monitor_and_crash3(doc) -> 883 "Start a single user process, " 884 "register-monitor one user and register one user, " 885 "crash the single user process."; 886register_monitor_and_crash3(Conf) when is_list(Conf) -> 887 process_flag(trap_exit, true), 888 put(tname,rlac3), 889 890 %% <CONDITIONAL-SKIP> 891 %% The point of this is to catch machines running 892 %% SLES9 (2.6.5) 893 LinuxVersionVerify = 894 fun() -> 895 case os:cmd("uname -m") of 896 "i686" ++ _ -> 897%% io:format("found an i686 machine, " 898%% "now check version~n", []), 899 case os:version() of 900 {2, 6, Rev} when Rev >= 16 -> 901 true; 902 {2, Min, _} when Min > 6 -> 903 true; 904 {Maj, _, _} when Maj > 2 -> 905 true; 906 _ -> 907 false 908 end; 909 _ -> 910 true 911 end 912 end, 913 Skippable = [{unix, [{linux, LinuxVersionVerify}]}], 914 Condition = fun() -> ?OS_BASED_SKIP(Skippable) end, 915 ?NON_PC_TC_MAYBE_SKIP(Conf, Condition), 916 %% </CONDITIONAL-SKIP> 917 918 ?IPRINT("start"), 919 920 ConfDir = ?config(manager_conf_dir, Conf), 921 DbDir = ?config(manager_db_dir, Conf), 922 923 write_manager_conf(ConfDir), 924 925 Opts = [{server, [{verbosity, trace}]}, 926 {net_if, [{verbosity, trace}]}, 927 {note_store, [{verbosity, trace}]}, 928 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 929 930 ?IPRINT("try starting manager"), 931 ?line ok = snmpm:start_link(Opts), 932 933 ?SLEEP(1000), 934 935 Id1 = make_ref(), 936 Id2 = make_ref(), 937 938 ?line Pid = start_user(), 939 940 ?line [] = Users1 = which_users(), 941 ?IPRINT("Users1: ~p", [Users1]), 942 943 ?line ok = register_user(Pid, Id1), 944 ?line ok = register_user_monitor(Pid, Id2), 945 946 ?line Users2 = case which_users() of 947 [Id1, Id2] = U1 -> 948 U1; 949 [Id2, Id1] = U2 -> 950 U2; 951 Else -> 952 ?FAIL({invalid_users, Else}) 953 end, 954 ?IPRINT("Users2: ~p", [Users2]), 955 956 ?line ok = simulate_crash(Pid), 957 958 ?SLEEP(1000), 959 960 ?line [Id1] = Users3 = which_users(), 961 ?IPRINT("Users3: ~p", [Users3]), 962 963 ?IPRINT("stop manager"), 964 ?line ok = snmpm:stop(), 965 966 ?IPRINT("end"), 967 ok. 968 969 970%% ------------------------------------------------------------------ 971 972register_monitor_and_crash4(suite) -> []; 973register_monitor_and_crash4(doc) -> 974 "Start 2 user processes, " 975 "register-monitor one user per process " 976 "and crash the first user process."; 977register_monitor_and_crash4(Conf) when is_list(Conf) -> 978 put(tname,rlac4), 979 ?IPRINT("start"), 980 process_flag(trap_exit, true), 981 982 ConfDir = ?config(manager_conf_dir, Conf), 983 DbDir = ?config(manager_db_dir, Conf), 984 985 write_manager_conf(ConfDir), 986 987 Opts = [{server, [{verbosity, trace}]}, 988 {net_if, [{verbosity, trace}]}, 989 {note_store, [{verbosity, trace}]}, 990 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 991 992 ?IPRINT("start manager"), 993 ?line ok = snmpm:start_link(Opts), 994 995 ?SLEEP(1000), 996 997 Id1 = make_ref(), 998 Id2 = make_ref(), 999 1000 ?IPRINT("start user processes"), 1001 ?line Pid1 = start_user(), 1002 ?line Pid2 = start_user(), 1003 1004 ?line [] = Users1 = which_users(), 1005 ?IPRINT("Users1: ~p", [Users1]), 1006 1007 ?line ok = register_user_monitor(Pid1, Id1), 1008 ?line ok = register_user_monitor(Pid2, Id2), 1009 1010 ?line Users2 = case which_users() of 1011 [Id1, Id2] = U1 -> 1012 U1; 1013 [Id2, Id1] = U2 -> 1014 U2; 1015 Else -> 1016 ?FAIL({invalid_users, Else}) 1017 end, 1018 ?IPRINT("Users2: ~p", [Users2]), 1019 1020 ?line ok = simulate_crash(Pid1), 1021 1022 ?SLEEP(1000), 1023 1024 ?line [Id2] = Users3 = which_users(), 1025 ?IPRINT("Users3: ~p", [Users3]), 1026 1027 ?line stop_user(Pid2), 1028 1029 ?IPRINT("stop manager"), 1030 ?line ok = snmpm:stop(), 1031 1032 ?IPRINT("end"), 1033 ok. 1034 1035 1036%% ------------------------------------------------------------------ 1037 1038register_monitor_and_crash5(suite) -> []; 1039register_monitor_and_crash5(doc) -> 1040 "OTP-7961: " 1041 "Start 2 user processes, " 1042 "register-monitor a user for per process, " 1043 "let each user register an agent " 1044 "and crash the first user process."; 1045register_monitor_and_crash5(Conf) when is_list(Conf) -> 1046 put(tname,rlac4), 1047 ?IPRINT("start"), 1048 process_flag(trap_exit, true), 1049 1050 ConfDir = ?config(manager_conf_dir, Conf), 1051 DbDir = ?config(manager_db_dir, Conf), 1052 1053 write_manager_conf(ConfDir), 1054 1055 Opts = [{server, [{verbosity, trace}]}, 1056 {net_if, [{verbosity, trace}]}, 1057 {note_store, [{verbosity, trace}]}, 1058 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 1059 1060 ?IPRINT("start manager"), 1061 ?line ok = snmpm:start_link(Opts), 1062 1063 ?SLEEP(1000), 1064 1065 Id1 = gurka, %% make_ref(), 1066 Id2 = tomat, %% make_ref(), 1067 1068 ?IPRINT("start user processes"), 1069 ?line Pid1 = start_user(), 1070 ?line Pid2 = start_user(), 1071 1072 ?line [] = Users1 = which_users(), 1073 ?IPRINT("Users1: ~p", [Users1]), 1074 1075 ?line ok = register_user_monitor(Pid1, Id1), 1076 ?line ok = register_user_monitor(Pid2, Id2), 1077 1078 LocalHost = snmp_test_lib:localhost(), 1079 1080 TargetName1 = "kalle1", 1081 Address1 = LocalHost, 1082 Port1 = 5001, 1083 EngineId1 = "agentEngineId-1", 1084 1085 TargetName2 = "kalle2", 1086 Address2 = LocalHost, 1087 Port2 = 5002, 1088 EngineId2 = "agentEngineId-2", 1089 1090 ?line ok = register_agent(Pid1, 1091 Id1, TargetName1, [{address, Address1}, 1092 {port, Port1}, 1093 {engine_id, EngineId1}]), 1094 ?line ok = register_agent(Pid2, 1095 Id2, TargetName2, [{address, Address2}, 1096 {port, Port2}, 1097 {engine_id, EngineId2}]), 1098 1099 ?line Users2 = case which_users() of 1100 [Id1, Id2] = U1 -> 1101 U1; 1102 [Id2, Id1] = U2 -> 1103 U2; 1104 U3 -> 1105 ?FAIL({invalid_users, U3}) 1106 end, 1107 ?IPRINT("Users2: ~p", [Users2]), 1108 1109 ?IPRINT("verify all agent(s): expect 2"), 1110 ?line Agents1 = case which_agents() of 1111 [TargetName1, TargetName2] = A1 -> 1112 A1; 1113 [TargetName2, TargetName1] = A2 -> 1114 A2; 1115 A3 -> 1116 ?FAIL({invalid_agents, A3}) 1117 end, 1118 ?IPRINT("Agents1: ~p", [Agents1]), 1119 1120 ?line ok = simulate_crash(Pid1), 1121 1122 ?IPRINT("wait some time"), 1123 ?SLEEP(1000), 1124 1125 ?line [Id2] = Users3 = which_users(), 1126 ?IPRINT("Users3: ~p", [Users3]), 1127 1128 ?line [TargetName2] = Agents2 = which_agents(), 1129 ?IPRINT("Agents2: ~p", [Agents2]), 1130 1131 ?line stop_user(Pid2), 1132 1133 ?IPRINT("stop manager"), 1134 ?line ok = snmpm:stop(), 1135 1136 ?IPRINT("end"), 1137 ok. 1138 1139 1140%% ------------------------------------------------------------------ 1141 1142register_monitor_request_and_crash1(suite) -> []; 1143register_monitor_request_and_crash1(doc) -> 1144 "Start a single user process, " 1145 "register-monitor one user, " 1146 "send request and crash the user."; 1147register_monitor_request_and_crash1(Conf) when is_list(Conf) -> 1148 %% put(tname,rlrac1), 1149 %% ?IPRINT("start"), 1150 %% process_flag(trap_exit, true), 1151 ?SKIP(not_yet_implemented). 1152 1153 1154%% ------------------------------------------------------------------ 1155 1156register_monitor_request_and_crash2(suite) -> []; 1157register_monitor_request_and_crash2(doc) -> 1158 "Start a single user process, " 1159 "register-monitor 2 user (per that one process), " 1160 "send a request for each user and crash the single user process."; 1161register_monitor_request_and_crash2(Conf) when is_list(Conf) -> 1162 %% put(tname,rlrac2), 1163 %% ?IPRINT("start"), 1164 %% process_flag(trap_exit, true), 1165 ?SKIP(not_yet_implemented). 1166 1167 1168%% ------------------------------------------------------------------ 1169 1170register_monitor_request_and_crash3(suite) -> []; 1171register_monitor_request_and_crash3(doc) -> 1172 "Start a single user process, " 1173 "register-monitor one user and register one user, " 1174 "send a request for each user and crash the single user process."; 1175register_monitor_request_and_crash3(Conf) when is_list(Conf) -> 1176 %% put(tname,rlrac3), 1177 %% ?IPRINT("start"), 1178 %% process_flag(trap_exit, true), 1179 ?SKIP(not_yet_implemented). 1180 1181 1182%% ------------------------------------------------------------------ 1183 1184register_monitor_request_and_crash4(suite) -> []; 1185register_monitor_request_and_crash4(doc) -> 1186 "Start 2 user processes, " 1187 "register-monitor one user and register one user on the " 1188 "first user process and do the same for the other user process, " 1189 "then for each user, send a request and " 1190 "crash the first user process."; 1191register_monitor_request_and_crash4(Conf) when is_list(Conf) -> 1192 %% put(tname,rlrac4), 1193 %% ?IPRINT("start"), 1194 %% process_flag(trap_exit, true), 1195 ?SKIP(not_yet_implemented). 1196 1197 1198 1199%% ------------------------------------------------------------------ 1200 1201otp7902(suite) -> []; 1202otp7902(doc) -> 1203 "OTP-7902 - Start old user and make sure it wors."; 1204otp7902(Conf) when is_list(Conf) -> 1205 put(tname, otp7902), 1206 ?IPRINT("start"), 1207 process_flag(trap_exit, true), 1208 1209 ConfDir = ?config(manager_conf_dir, Conf), 1210 DbDir = ?config(manager_db_dir, Conf), 1211 1212 write_manager_conf(ConfDir), 1213 1214 Opts = [{server, [{verbosity, trace}]}, 1215 {net_if, [{verbosity, trace}]}, 1216 {note_store, [{verbosity, trace}]}, 1217 {config, [{verbosity, trace}, {dir, ConfDir}, {db_dir, DbDir}]}], 1218 1219 ?IPRINT("try starting manager"), 1220 ok = snmpm:start_link(Opts), 1221 1222 ?SLEEP(1000), 1223 1224 ?line [] = Users1 = which_users(), 1225 ?IPRINT("Users1: ~p", [Users1]), 1226 1227 ?line ok = snmp_manager_user_old:start(), 1228 1229 ?line [_] = Users2 = which_users(), 1230 ?IPRINT("Users2: ~p", [Users2]), 1231 1232 ?line ok = snmp_manager_user_old:stop(), 1233 1234 ?line [] = Users3 = which_users(), 1235 ?IPRINT("Users3: ~p", [Users3]), 1236 1237 ?line ok = snmpm:stop(), 1238 1239 ?IPRINT("end"), 1240 ok. 1241 1242 1243%% ------------------------------------------------------------------ 1244 1245start_user() -> 1246 {ok, Pid} = snmp_manager_user_test_lib:start_link(), 1247 Pid. 1248 1249stop_user(Pid) -> 1250 snmp_manager_user_test_lib:stop(Pid). 1251 1252simulate_crash(Pid) -> 1253 snmp_manager_user_test_lib:simulate_crash(Pid, simulate_crash), 1254 receive 1255 {'EXIT', Pid, simulate_crash} -> 1256 ok; 1257 {'EXIT', Pid, Whatever} -> 1258 {ok, Whatever} 1259 after 5000 -> 1260 {error, timeout} 1261 end. 1262 1263register_user(Pid, Id) -> 1264 snmp_manager_user_test_lib:register(Pid, Id). 1265 1266register_user_monitor(Pid, Id) -> 1267 snmp_manager_user_test_lib:register_monitor(Pid, Id). 1268 1269unregister_user(Pid) -> 1270 case snmp_manager_user_test_lib:unregister(Pid) of 1271 {ok, Res} -> 1272 case [R || R <- Res, R =/= ok] of 1273 [] -> 1274 ok; 1275 Errs -> 1276 {error, Errs} 1277 end; 1278 Error -> 1279 Error 1280 end. 1281 1282unregister_user(Pid, Id) -> 1283 snmp_manager_user_test_lib:unregister(Pid, Id). 1284 1285 1286register_agent(Pid, Id, TargetName, Config) -> 1287 snmp_manager_user_test_lib:register_agent(Pid, Id, TargetName, Config). 1288 1289 1290%% ------ 1291 1292which_users() -> 1293 snmpm:which_users(). 1294 1295which_agents() -> 1296 snmpm:which_agents(). 1297 1298 1299%% ------ 1300 1301 1302write_manager_conf(Dir) -> 1303 Port = "5000", 1304 MMS = "484", 1305 EngineID = "\"mgrEngine\"", 1306 Str = lists:flatten( 1307 io_lib:format("%% Minimum manager config file\n" 1308 "{port, ~s}.\n" 1309 "{max_message_size, ~s}.\n" 1310 "{engine_id, ~s}.\n", 1311 [Port, MMS, EngineID])), 1312 write_manager_conf(Dir, Str). 1313 1314write_manager_conf(Dir, Str) -> 1315 write_conf_file(Dir, "manager.conf", Str). 1316 1317 1318write_conf_file(Dir, File, Str) -> 1319 ?line {ok, Fd} = file:open(filename:join(Dir, File), write), 1320 ?line ok = io:format(Fd, "~s", [Str]), 1321 file:close(Fd). 1322 1323