added files
[bcm963xx.git] / userapps / opensource / net-snmp / perl / agent / test.pl
1 # Before `make install' is performed this script should be runnable with
2 # `make test'. After `make install' it should work as `perl test.pl'
3
4 ######################### We start with some black magic to print on failure.
5
6 # Change 1..1 below to 1..last_test_to_print .
7 # (It may become useful if the test is moved to ./t subdirectory.)
8
9 BEGIN { $| = 1; print "1..5\n"; }
10 END {print "not ok 1\n" unless $loaded;}
11 use NetSNMP::agent (':all');
12 use NetSNMP::default_store (':all');
13 use NetSNMP::agent::default_store (':all');
14 use NetSNMP::ASN (':all');
15 use NetSNMP::OID;
16 #use NetSNMP::agent (':all');
17 use SNMP;
18 $loaded = 1;
19 print "ok 1\n";
20
21 ######################### End of black magic.
22
23 sub it {
24     if ($_[0]) {
25         return "ok " . $_[1] . "\n";
26     } else {
27         return "not ok ". $_[1] ."\n";
28     }
29 }
30
31 # Insert your test code below (better if it prints "ok 13"
32 # (correspondingly "not ok 13") depending on the success of chunk 13
33 # of the test code):
34
35 print it((MODE_GET == 0xa0 &&
36           MODE_GETNEXT == 0xa1 &&
37           MODE_GETBULK == 0xa5 &&
38           MODE_SET_BEGIN == -1 &&
39           MODE_SET_RESERVE1 == 0 &&
40           MODE_SET_RESERVE2 == 1 &&
41           MODE_SET_ACTION == 2 &&
42           MODE_SET_COMMIT == 3 &&
43           MODE_SET_FREE == 4 &&
44           MODE_SET_UNDO == 5), 2);
45
46 my $agent = new NetSNMP::agent('Name' => 'test',
47                                'Ports' => '9161');
48 print it($agent, 3);
49
50 $regitem = $agent->register("test_reg", ".1.3.6.1.8888", \&testsub);
51 print it($regitem, 4);
52 #print STDERR $regitem,":",ref($regitem),"\n";
53 print it(ref($regitem) eq "netsnmp_handler_registrationPtr", 5);
54 exit;
55
56 while(1) {
57     print netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, 
58                                 NETSNMP_DS_AGENT_PORTS), "\n";
59     $agent->agent_check_and_process(1);
60     print netsnmp_ds_get_string(NETSNMP_DS_APPLICATION_ID, 
61                                 NETSNMP_DS_AGENT_PORTS), "\n";
62     print "got something\n";
63 }
64 exit;
65
66 $x = NetSNMP::agent::handler_registration::new("hi",\&testsub,".1.3.6.1.999");
67 print ((ref($x) eq "handler_registrationPtr") ? "ok 2\n" : "not ok 2\n");
68
69 print (($x->register() == 0) ? "ok 3\n" : "not ok 3\n");
70
71 my $y = NetSNMP::agent::register_mib("me",\&testsub,".1.3.6.1.8888");
72 while(1) {
73   NetSNMP::agent::agent_check_and_process();
74   print "got something\n";
75 }
76
77 use Data::Dumper;
78 sub testsub {
79     print STDERR "in perl handler sub\n";
80     print STDERR "  args: ", join(", ", @_), "\n";
81     print STDERR "  dumped args: ", Dumper(@_);
82     $oid= $_[3]->getOID();
83     print STDERR "  request oid: ", ref($oid), " -> ", $oid, "\n";
84     print STDERR "  mode: ", $_[2]->getMode(),"\n";
85     $_[3]->setOID(".1.3.6.1.8888.1");
86     $_[3]->setValue(2, 42);
87     $_[3]->setValue(ASN_INTEGER, 42);
88     print STDERR "  oid: ", $_[3]->getOID(),"\n";
89     print STDERR "  ref: ", ref($_[3]),"\n";
90     print STDERR "  val: ", $_[3]->getValue(),"\n";
91 }