1import os 2 3import infra.basetest 4 5 6class TestNetSNMP(infra.basetest.BRTest): 7 rootfs_overlay = \ 8 infra.filepath("tests/package/test_netsnmp/rootfs-overlay") 9 config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ 10 f""" 11 BR2_PACKAGE_NETSNMP=y 12 BR2_ROOTFS_OVERLAY="{rootfs_overlay}" 13 BR2_TARGET_ROOTFS_CPIO=y 14 # BR2_TARGET_ROOTFS_TAR is not set 15 """ 16 17 def test_run(self): 18 cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio") 19 self.emulator.boot(arch="armv5", 20 kernel="builtin", 21 options=["-initrd", cpio_file]) 22 self.emulator.login() 23 24 # We check the daemon and a client program can execute. 25 self.assertRunOk("snmpd --version") 26 self.assertRunOk("snmpget --version") 27 28 # The daemon is supposed to be started by the initscript, 29 # since we included a /etc/snmp/snmpd.conf file. We should be 30 # able to walk through the SNMPv2 system MIB. 31 self.assertRunOk("snmpwalk -v 2c -c public 127.0.0.1 system") 32 33 # We check few OIDs has the expected values. sysContact and 34 # sysLocation are set in the snmpd.conf file. 35 tests = [ 36 ("system.sysName.0", "STRING: buildroot"), 37 ("system.sysContact.0", "STRING: Buildroot Test User"), 38 ("system.sysLocation.0", "STRING: Buildroot Test Infra") 39 ] 40 for oid, expected_out in tests: 41 cmd = f"snmpget -v 2c -c public -Ov 127.0.0.1 {oid}" 42 out, ret = self.emulator.run(cmd) 43 self.assertEqual(ret, 0) 44 self.assertEqual(out[0], expected_out) 45