1
%% ``The contents of this file are subject to the Erlang Public License,
2
%% Version 1.1, (the "License"); you may not use this file except in
3
%% compliance with the License. You should have received a copy of the
4
%% Erlang Public License along with this software. If not, it can be
5
%% retrieved via the world wide web at http://www.erlang.org/.
7
%% Software distributed under the License is distributed on an "AS IS"
8
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
9
%% the License for the specific language governing rights and limitations
12
%% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
13
%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
14
%% AB. All Rights Reserved.''
18
%%----------------------------------------------------------------------
19
%% Purpose: Test the snmp mib compiler
21
%% Run test: ts:run(snmp, snmp_compiler_test, [batch]).
23
%%----------------------------------------------------------------------
24
-module(snmp_compiler_test).
26
%%----------------------------------------------------------------------
28
%%----------------------------------------------------------------------
29
-include("test_server.hrl").
30
-include("snmp_test_lib.hrl").
31
-include_lib("snmp/include/snmp_types.hrl").
34
%%----------------------------------------------------------------------
36
%%----------------------------------------------------------------------
39
init_per_testcase/2, fin_per_testcase/2,
51
%%----------------------------------------------------------------------
53
%%----------------------------------------------------------------------
57
%%----------------------------------------------------------------------
59
%%----------------------------------------------------------------------
61
%%----------------------------------------------------------------------
63
%%----------------------------------------------------------------------
65
%%======================================================================
67
%%======================================================================
69
init_per_testcase(_Case, Config) when list(Config) ->
70
Dir = ?config(priv_dir, Config),
71
DataDir = ?config(data_dir, Config),
72
[_|RL] = lists:reverse(filename:split(DataDir)),
73
MibDir = join(lists:reverse(["snmp_test_data"|RL])),
74
CompDir = join(Dir, "comp_dir/"),
75
?line ok = file:make_dir(CompDir),
76
[{comp_dir, CompDir},{mib_dir, MibDir}|Config].
78
fin_per_testcase(_Case, Config) when list(Config) ->
79
CompDir = ?config(comp_dir, Config),
80
?line ok = ?DEL_DIR(CompDir),
81
lists:keydelete(comp_dir, 1, Config).
84
%%======================================================================
85
%% Test case definitions
86
%%======================================================================
103
%%======================================================================
105
%%======================================================================
107
description(suite) -> [];
108
description(Config) when list(Config) ->
110
p("starting with Config: ~p~n", [Config]),
112
Dir = ?config(comp_dir, Config),
113
Filename = join(Dir,"test"),
114
MibSrcName = Filename ++ ".mib",
115
MibBinName = Filename ++ ".bin",
116
Desctext = "This is a test description",
117
Oid = [1,3,6,1,2,1,15,1],
118
write_mib(MibSrcName,Desctext),
119
?line {ok,_} = snmpc:compile(MibSrcName, [{outdir, Dir},
120
{group_check, false},
122
{description, false}]),
123
MIB1 = read_mib(MibBinName),
124
%% io:format("description -> MIB1: ~n~p~n", [MIB1]),
125
check_mib(MIB1#mib.mes, Oid, undefined),
126
?line {ok,_} = snmpc:compile(MibSrcName, [{outdir, Dir},
127
{group_check, false},
129
{description, true}]),
130
MIB2 = read_mib(MibBinName),
131
%% io:format("description -> MIB2: ~n~p~n", [MIB2]),
132
check_mib(MIB2#mib.mes, Oid, Desctext),
135
file:delete(MibSrcName),
136
file:delete(MibBinName),
140
oid_conflicts(suite) -> [];
141
oid_conflicts(Config) when list(Config) ->
142
put(tname,oid_conflicts),
143
p("starting with Config: ~p~n", [Config]),
145
Dir = ?config(comp_dir, Config),
146
Mib = join(Dir,"TESTv2.mib"),
147
?line ok = write_oid_conflict_mib(Mib),
148
?line {error,compilation_failed} =
149
snmpc:compile(Mib,[{outdir, Dir},{verbosity,trace}]),
155
imports(Config) when list(Config) ->
156
?SKIP(not_yet_implemented).
159
module_identity(suite) ->
161
module_identity(Config) when list(Config) ->
162
?SKIP(not_yet_implemented).
167
otp_6150(Config) when is_list(Config) ->
169
p("starting with Config: ~p~n", [Config]),
171
Dir = ?config(comp_dir, Config),
172
MibDir = ?config(mib_dir, Config),
173
MibFile = join(MibDir, "ERICSSON-TOP-MIB.mib"),
174
?line {ok, Mib} = snmpc:compile(MibFile, [{outdir, Dir}, {verbosity, trace}]),
175
io:format("otp_6150 -> Mib: ~n~p~n", [Mib]),
179
%%======================================================================
180
%% Internal functions
181
%%======================================================================
183
write_oid_conflict_mib(Filename) ->
184
MibText = "TESTv2 DEFINITIONS ::= BEGIN
187
MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE,
188
Integer32, snmpModules ,experimental
190
MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP
198
exampleModule MODULE-IDENTITY
199
LAST-UPDATED \"0005290000Z\"
200
ORGANIZATION \"Erlang\"
201
CONTACT-INFO \" test mib
202
Ericsson Utvecklings AB
208
\" Objects for management \"
209
REVISION \"0005290000Z\"
211
\"The initial version\"
212
::= { snmpModules 1 }
214
example1 OBJECT IDENTIFIER ::= { experimental 7}
215
-- example2 OBJECT IDENTIFIER ::= { experimental 7}
220
MAX-ACCESS read-write
226
myNotification NOTIFICATION-TYPE
232
friendsTable OBJECT-TYPE
233
SYNTAX SEQUENCE OF FriendsEntry
234
MAX-ACCESS not-accessible
237
\"A list of friends.\"
240
friendsEntry OBJECT-TYPE
242
MAX-ACCESS not-accessible
247
::= { friendsTable 1 }
249
FriendsEntry ::= SEQUENCE {
252
fAddress DisplayString,
262
::= { friendsEntry 1 }
265
SYNTAX DisplayString (SIZE (0..255))
266
MAX-ACCESS read-write
270
::= { friendsEntry 2 }
273
SYNTAX DisplayString (SIZE (0..255))
274
MAX-ACCESS read-write
277
\"Address of a friend\"
278
::= { friendsEntry 3 }
282
MAX-ACCESS read-write
285
\"The status of this conceptual row.\"
286
::= { friendsEntry 4 }
288
-- myName2 OBJECT IDENTIFIER ::= { example1 1 }
290
friendGroup OBJECT-GROUP
291
OBJECTS { myName, fIndex, fName,fAddress, fStatus }
293
DESCRIPTION \" A object group\"
296
myNotificationGroup NOTIFICATION-GROUP
297
NOTIFICATIONS { myNotification }
300
\"Test notification group\"
304
file:write_file(Filename, MibText).
307
write_mib(Filename,Desc) ->
308
Binary = "Test DEFINITIONS ::= BEGIN
311
MODULE-IDENTITY, OBJECT-TYPE,
315
snmpMIB MODULE-IDENTITY
316
LAST-UPDATED \"9511090000Z\"
320
::= { snmpModules 1 }
323
test OBJECT IDENTIFIER ::= { mib-2 15 }
326
SYNTAX BITS { b0(0), b1(1), b2(2) }
327
MAX-ACCESS read-write
329
DESCRIPTION \"" ++ Desc ++ "\"
333
Message = file:write_file(Filename ,Binary),
337
exit({failed_writing_mib,Reason})
341
read_mib(Filename) ->
342
case file:read_file(Filename) of
346
exit({failed_reading_mib,Filename,Reason})
351
check_mib([#me{oid = Oid, description = Description}| _T], Oid, Testdata) ->
352
check_desc(Description, Testdata);
353
check_mib([_H|T], Oid, Testdata ) ->
354
check_mib(T, Oid, Testdata ).
356
check_desc(Desc, Desc) ->
358
check_desc(Desc1, Desc2) ->
359
exit({'description not equal', Desc1, Desc2}).
378
io:format("*** [~w][~s] ***"
379
"~n" ++ F ++ "~n", [TName,format_timestamp(now())|A]).
381
format_timestamp({_N1, _N2, N3} = Now) ->
382
{Date, Time} = calendar:now_to_datetime(Now),
384
{Hour,Min,Sec} = Time,
386
io_lib:format("~.4w:~.2.0w:~.2.0w ~.2.0w:~.2.0w:~.2.0w 4~w",
387
[YYYY,MM,DD,Hour,Min,Sec,round(N3/1000)]),
388
lists:flatten(FormatDate).