xref: /OK3568_Linux_fs/buildroot/support/testing/tests/package/test_opkg.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyunimport os
2*4882a593Smuzhiyun
3*4882a593Smuzhiyunimport infra.basetest
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun
6*4882a593Smuzhiyunclass TestOpkg(infra.basetest.BRTest):
7*4882a593Smuzhiyun    # The snmpd service is used as an example for this test of a set of files
8*4882a593Smuzhiyun    # that can be archived up and deployed/removed to test opkg
9*4882a593Smuzhiyun    #
10*4882a593Smuzhiyun    # The post build script uses an ipk-build template and assembles the test
11*4882a593Smuzhiyun    # package.
12*4882a593Smuzhiyun    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
13*4882a593Smuzhiyun        """
14*4882a593Smuzhiyun        BR2_PACKAGE_NETSNMP=y
15*4882a593Smuzhiyun        # BR2_PACKAGE_NETSNMP_CLIENTS is not set
16*4882a593Smuzhiyun        # BR2_PACKAGE_NETSNMP_ENABLE_MIBS is not set
17*4882a593Smuzhiyun        BR2_PACKAGE_OPKG=y
18*4882a593Smuzhiyun        BR2_TARGET_ROOTFS_CPIO=y
19*4882a593Smuzhiyun        # BR2_TARGET_ROOTFS_TAR is not set
20*4882a593Smuzhiyun        BR2_PACKAGE_HOST_OPKG_UTILS=y
21*4882a593Smuzhiyun        BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
22*4882a593Smuzhiyun        """.format(infra.filepath("tests/package/test_opkg/post-build.sh"))
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun    def test_run(self):
25*4882a593Smuzhiyun        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
26*4882a593Smuzhiyun        self.emulator.boot(arch="armv5",
27*4882a593Smuzhiyun                           kernel="builtin",
28*4882a593Smuzhiyun                           options=["-initrd", cpio_file])
29*4882a593Smuzhiyun        self.emulator.login()
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun        # This test sequence tests the install and removal of a running
32*4882a593Smuzhiyun        # service and configuration files.  It also exercises the postinst
33*4882a593Smuzhiyun        # and prerm scripting provided in the package archive.
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun        cmd = "opkg install example-snmpd-package_1.0_arm.ipk"
36*4882a593Smuzhiyun        self.assertRunOk(cmd)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun        cmd = "opkg list-installed | grep example-snmpd-package"
39*4882a593Smuzhiyun        self.assertRunOk(cmd)
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun        # Check that postinst script ran to start the services
42*4882a593Smuzhiyun        cmd = "ps aux | grep [s]nmpd"
43*4882a593Smuzhiyun        self.assertRunOk(cmd)
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun        # If successful, the prerm script ran to stop the service prior to
46*4882a593Smuzhiyun        # the removal of the service scripting and files
47*4882a593Smuzhiyun        cmd = "opkg remove example-snmpd-package"
48*4882a593Smuzhiyun        self.assertRunOk(cmd)
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun        # Verify after package removal that the services is not
51*4882a593Smuzhiyun        # running, but let's give it some time to really stop
52*4882a593Smuzhiyun        # (otherwise a [snmpd] process might show up in the ps output)
53*4882a593Smuzhiyun        cmd = "sleep 1 && ps aux | grep [s]nmpd"
54*4882a593Smuzhiyun        _, exit_code = self.emulator.run(cmd)
55*4882a593Smuzhiyun        self.assertEqual(exit_code, 1)
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun        # This folder for configs is provided by the package install and
58*4882a593Smuzhiyun        # should no longer be present after package removal
59*4882a593Smuzhiyun        cmd = "ls /etc/snmp"
60*4882a593Smuzhiyun        _, exit_code = self.emulator.run(cmd)
61*4882a593Smuzhiyun        self.assertEqual(exit_code, 1)
62