98
108
%% Test case definitions
99
109
%%======================================================================
100
110
%% ?SKIP(not_yet_implemented).
104
open_write_and_close,
112
[open_and_close, {group, open_write_and_close},
113
{group, log_to_io}, {group, log_to_txt}].
116
[{open_write_and_close, [],
117
[open_write_and_close1, open_write_and_close2,
118
open_write_and_close3, open_write_and_close4]},
119
{log_to_io, [], [log_to_io1, log_to_io2]},
121
[log_to_txt1, log_to_txt2, log_to_txt3]}].
123
init_per_group(_GroupName, Config) ->
126
end_per_group(_GroupName, Config) ->
112
137
%%======================================================================
133
158
%%======================================================================
135
open_write_and_close(suite) -> [];
136
open_write_and_close(Config) when is_list(Config) ->
137
p(open_write_and_close),
138
put(sname,open_write_and_close),
139
put(verbosity,trace),
140
?DBG("open_write_and_close -> start", []),
160
open_write_and_close1(suite) ->
162
open_write_and_close1(doc) ->
163
"Open a plain (no sequence-numbering) log file";
164
open_write_and_close1(Config) when is_list(Config) ->
165
p(open_write_and_close1),
166
put(sname,open_write_and_close1),
167
put(verbosity,trace),
168
?DBG("open_write_and_close1 -> start", []),
171
?line ok = open_write_and_close(SeqNoGen, Config),
173
?DBG("open_write_and_close1 -> done", []),
177
%%======================================================================
179
open_write_and_close2(suite) ->
181
open_write_and_close2(doc) ->
182
"Open a log file with sequence-numbering explicitly disabled";
183
open_write_and_close2(Config) when is_list(Config) ->
184
p(open_write_and_close2),
185
put(sname,open_write_and_close2),
186
put(verbosity,trace),
187
?DBG("open_write_and_close2 -> start", []),
190
?line ok = open_write_and_close(SeqNoGen, Config),
192
?DBG("open_write_and_close2 -> done", []),
196
%%======================================================================
198
open_write_and_close3(suite) ->
200
open_write_and_close3(doc) ->
201
"Open a log file with sequence-numbering using MFA";
202
open_write_and_close3(Config) when is_list(Config) ->
203
p(open_write_and_close3),
204
put(sname,open_write_and_close3),
205
put(verbosity,trace),
206
?DBG("open_write_and_close2 -> start", []),
209
SeqNoGen = {?MODULE, next_seqno, [10, 100]},
210
?line ok = open_write_and_close(SeqNoGen, Config),
213
?DBG("open_write_and_close2 -> done", []),
217
%%======================================================================
219
open_write_and_close4(suite) ->
221
open_write_and_close4(doc) ->
222
"Open a log file with sequence-numbering using fun";
223
open_write_and_close4(Config) when is_list(Config) ->
224
p(open_write_and_close4),
225
put(sname,open_write_and_close4),
226
put(verbosity,trace),
227
?DBG("open_write_and_close2 -> start", []),
230
SeqNoGen = fun() -> next_seqno(10, 100) end,
231
?line ok = open_write_and_close(SeqNoGen, Config),
234
?DBG("open_write_and_close2 -> done", []),
238
%%======================================================================
241
ets:new(snmp_log_test_seqno_tab, [named_table, set, protected]).
244
ets:delete(snmp_log_test_seqno_tab).
246
next_seqno(Initial, Max) ->
252
UpdateOp = {Position, Increment, Threshold, SetValue},
253
Tab = snmp_log_test_seqno_tab,
254
case (catch ets:update_counter(Tab, Key, UpdateOp)) of
255
{'EXIT', {badarg, _}} ->
256
ets:insert(Tab, {seqno, Initial}),
258
Next when is_integer(Next) ->
262
open_write_and_close(SeqNoGen, Config) ->
263
?DBG("open_write_and_close1 -> start", []),
141
264
Dir = ?config(log_dir, Config),
142
265
Name = "snmp_test",
143
266
File = join(Dir, "snmp_test.log"),
144
267
Size = {1024, 10},
146
269
?DBG("open_write_and_close -> create log", []),
147
?line {ok, Log} = snmp_log:create(Name, File, Size, Repair),
274
snmp_log:create(Name, File, Size, Repair);
276
snmp_log:create(Name, File, SeqNoGen, Size, Repair)
149
279
Vsn = 'version-2',
150
280
Community = "all-rights",
152
?DBG("open_write_and_close -> create messages to log", []),
282
?DBG("open_write_and_close1 -> create messages to log", []),
154
284
?line Req = get_next_request(Vsn, Community, [1,1], 1, 235779012),
309
439
put(verbosity,trace),
310
440
?DBG("log_to_txt1 -> start", []),
442
Name = "snmp_test_l2t1",
444
?line ok = log_to_txt(Name, SeqNoGen, Config),
446
?DBG("log_to_txt1 -> done", []),
451
%%======================================================================
453
log_to_txt2(suite) -> [];
454
log_to_txt2(Config) when is_list(Config) ->
457
put(verbosity,trace),
458
?DBG("log_to_txt2 -> start", []),
460
Name = "snmp_test_l2t2",
462
SeqNoGen = {?MODULE, next_seqno, [1, 100]},
463
?line ok = log_to_txt(Name, SeqNoGen, Config),
466
?DBG("log_to_txt2 -> done", []),
471
%%======================================================================
473
log_to_txt(Name, SeqNoGen, Config) when is_list(Config) ->
474
?DBG("log_to_txt -> entry", []),
311
475
Dir = ?config(log_dir, Config),
312
Name = "snmp_test_l2t1",
313
File = join(Dir, "snmp_test_l2t1.log"),
476
File = join(Dir, Name ++ ".log"),
314
477
Size = {10240, 10},
316
?DBG("log_to_txt1 -> create log", []),
317
?line {ok, Log} = snmp_log:create(Name, File, Size, Repair),
319
?DBG("log_to_txt1 -> create messages to log", []),
480
?DBG("log_to_txt -> create log", []),
484
snmp_log:create(Name, File, Size, Repair);
486
snmp_log:create(Name, File, SeqNoGen, Size, Repair)
489
?DBG("log_to_txt -> create messages to log", []),
320
490
Msgs = messages(),
322
?DBG("log_to_txt1 -> create logger funs", []),
492
?DBG("log_to_txt -> create logger funs", []),
323
493
Addr = ?LOCALHOST(),
325
495
Logger = fun(Packet) ->
333
503
To = lists:duplicate(20, 5000),
335
?DBG("log_to_txt1 -> log the messages", []),
505
?DBG("log_to_txt -> log the messages", []),
336
506
Start = calendar:local_time(),
337
507
lists:foreach(BatchLogger, To),
338
508
Stop = calendar:local_time(),
340
?DBG("log_to_txt1 -> display info", []),
510
?DBG("log_to_txt -> display info", []),
341
511
?line {ok, Info} = snmp_log:info(Log),
342
512
display_info(Info),
344
514
Out1 = join(Dir, "snmp_text-1.txt"),
345
?DBG("log_to_txt1 -> do the convert to a text file when"
515
?DBG("log_to_txt -> do the convert to a text file when"
346
516
"~n Out1: ~p", [Out1]),
347
517
?line ok = snmp:log_to_txt(Dir, [], Out1, Log, File),
349
519
?line {ok, #file_info{size = Size1}} = file:read_file_info(Out1),
350
?DBG("log_to_txt1 -> text file size: ~p", [Size1]),
520
?DBG("log_to_txt -> text file size: ~p", [Size1]),
351
521
validate_size(Size1),
353
523
Out2 = join(Dir, "snmp_text-2.txt"),
354
?DBG("log_to_txt1 -> do the convert to a text file when"
524
?DBG("log_to_txt -> do the convert to a text file when"
357
527
"~n Out2: ~p", [Start, Stop, Out2]),
358
528
?line ok = snmp:log_to_txt(Dir, [], Out2, Log, File, Start, Stop),
360
530
?line {ok, #file_info{size = Size2}} = file:read_file_info(Out2),
361
?DBG("log_to_txt1 -> text file size: ~p", [Size2]),
531
?DBG("log_to_txt -> text file size: ~p", [Size2]),
362
532
validate_size(Size2, {le, Size1}),
364
534
%% Calculate new start / stop times...
365
535
GStart = calendar:datetime_to_gregorian_seconds(Start),
366
?DBG("log_to_txt1 -> GStart: ~p", [GStart]),
536
?DBG("log_to_txt -> GStart: ~p", [GStart]),
367
537
GStop = calendar:datetime_to_gregorian_seconds(Stop),
368
?DBG("log_to_txt1 -> GStop: ~p", [GStop]),
538
?DBG("log_to_txt -> GStop: ~p", [GStop]),
369
539
Diff4 = (GStop - GStart) div 4,
370
?DBG("log_to_txt1 -> Diff4: ~p", [Diff4]),
540
?DBG("log_to_txt -> Diff4: ~p", [Diff4]),
371
541
GStart2 = GStart + Diff4,
372
542
GStop2 = GStop - Diff4,
381
551
Stop2 = calendar:gregorian_seconds_to_datetime(GStop2),
383
553
Out3 = join(Dir, "snmp_text-3.txt"),
384
?DBG("log_to_txt1 -> do the convert to a text file when"
554
?DBG("log_to_txt -> do the convert to a text file when"
387
557
"~n Out3: ~p", [Start2, Stop2, Out3]),
388
558
?line ok = snmp:log_to_txt(Dir, [], Out3, Log, File, Start2, Stop2),
390
560
?line {ok, #file_info{size = Size3}} = file:read_file_info(Out3),
391
?DBG("log_to_txt1 -> text file size: ~p", [Size3]),
561
?DBG("log_to_txt -> text file size: ~p", [Size3]),
392
562
validate_size(Size3, {l, Size1}),
394
?DBG("log_to_txt1 -> close log", []),
564
?DBG("log_to_txt -> close log", []),
395
565
?line ok = snmp_log:close(Log),
397
?DBG("log_to_txt1 -> done", []),
567
?DBG("log_to_txt -> done", []),
406
576
%% Test: ts:run(snmp, snmp_log_test, log_to_txt2, [batch]).
408
log_to_txt2(suite) -> [];
409
log_to_txt2(doc) -> "Log to txt file from a different process than which "
410
"opened and wrote the log";
411
log_to_txt2(Config) when is_list(Config) ->
578
log_to_txt3(suite) ->
581
"Log to txt file from a different process than which "
582
"opened and wrote the log";
583
log_to_txt3(Config) when is_list(Config) ->
412
584
process_flag(trap_exit, true),
415
587
put(verbosity,trace),
416
?DBG("log_to_txt2 -> start", []),
588
?DBG("log_to_txt3 -> start", []),
417
589
Dir = ?config(log_dir, Config),
418
Name = "snmp_test_l2t2",
419
LogFile = join(Dir, "snmp_test_l2t2.log"),
420
TxtFile = join(Dir, "snmp_test_l2t2.txt"),
590
Name = "snmp_test_l2t3",
591
LogFile = join(Dir, "snmp_test_l2t3.log"),
592
TxtFile = join(Dir, "snmp_test_l2t3.txt"),
422
594
Size = {10*Meg, 10},
425
597
StdMibDir = filename:join(code:priv_dir(snmp), "mibs") ++ "/",
426
598
Mibs = [join(StdMibDir, "SNMPv2-MIB")],
428
?DBG("log_to_txt2 -> create log writer process", []),
600
?DBG("log_to_txt3 -> create log writer process", []),
429
601
?line {ok, Log, Logger} = log_writer_start(Name, LogFile, Size, Repair),
431
?DBG("log_to_txt2 -> create log reader process", []),
603
?DBG("log_to_txt3 -> create log reader process", []),
432
604
?line {ok, Reader} = log_reader_start(),
434
?DBG("log_to_txt2 -> wait some time", []),
606
?DBG("log_to_txt3 -> wait some time", []),
437
?DBG("log_to_txt2 -> display log info", []),
609
?DBG("log_to_txt3 -> display log info", []),
438
610
?line log_writer_info(Logger),
440
?DBG("log_to_txt2 -> instruct the log writer to sleep some", []),
612
?DBG("log_to_txt3 -> instruct the log writer to sleep some", []),
441
613
?line ok = log_writer_sleep(Logger, 5000),
443
?DBG("log_to_txt2 -> instruct the log reader to log to txt", []),
615
?DBG("log_to_txt3 -> instruct the log reader to log to txt", []),
445
617
log_reader_log_to(Reader,
460
?DBG("log_to_txt2 -> ~n Info: ~p", [Info]),
632
?DBG("log_to_txt3 -> ~n Info: ~p", [Info]),
461
633
?line {ok, #file_info{size = FileSize}} =
462
634
file:read_file_info(TxtFile),
463
?DBG("log_to_txt2 -> text file size: ~p", [FileSize]),
635
?DBG("log_to_txt3 -> text file size: ~p", [FileSize]),
464
636
validate_size(FileSize);
466
?DBG("log_to_txt2 -> log to txt failed: "
638
?DBG("log_to_txt3 -> log to txt failed: "
468
640
"~n Info: ~p", [Error, Info]),
469
641
?line ?FAIL({log_lo_txt_failed, Error, Info})
472
?DBG("log_to_txt2 -> instruct the log writer to stop", []),
644
?DBG("log_to_txt3 -> instruct the log writer to stop", []),
473
645
?line log_writer_stop(Logger),
475
?DBG("log_to_txt2 -> instruct the log reader to stop", []),
647
?DBG("log_to_txt3 -> instruct the log reader to stop", []),
476
648
?line log_reader_stop(Reader),
478
?DBG("log_to_txt2 -> done", []),
650
?DBG("log_to_txt3 -> done", []),