Module rsyscall.tests.test_chroot

Expand source code Browse git
from rsyscall.tests.trio_test_case import TrioTestCase
from rsyscall import local_thread

from rsyscall.stdlib import mkdtemp
from rsyscall.sys.mount import MS
from rsyscall.sched import CLONE
from rsyscall.unistd import O
import unittest

class TestChroot(TrioTestCase):
    async def asyncSetUp(self) -> None:
        self.tmpdir = await mkdtemp(local_thread)
        self.path = self.tmpdir.path
        self.thr = await local_thread.clone(CLONE.NEWUSER|CLONE.NEWNS)

    async def asyncTearDown(self) -> None:
        await self.tmpdir.cleanup()

    async def test_basic(self) -> None:
        await self.thr.mkdir(self.path/"proc")
        await self.thr.mount("/proc", self.path/"proc", "", MS.BIND, "")
        await self.thr.task.chroot(await self.thr.ptr(self.path))
        await self.thr.task.open(await self.thr.ptr("/proc/self"), O.RDONLY)

Classes

class TestChroot (methodName='runTest')

A trio-enabled variant of unittest.TestCase

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Expand source code Browse git
class TestChroot(TrioTestCase):
    async def asyncSetUp(self) -> None:
        self.tmpdir = await mkdtemp(local_thread)
        self.path = self.tmpdir.path
        self.thr = await local_thread.clone(CLONE.NEWUSER|CLONE.NEWNS)

    async def asyncTearDown(self) -> None:
        await self.tmpdir.cleanup()

    async def test_basic(self) -> None:
        await self.thr.mkdir(self.path/"proc")
        await self.thr.mount("/proc", self.path/"proc", "", MS.BIND, "")
        await self.thr.task.chroot(await self.thr.ptr(self.path))
        await self.thr.task.open(await self.thr.ptr("/proc/self"), O.RDONLY)

Ancestors

Class variables

var nursery : trio.Nursery

Methods

async def test_basic(self) ‑> NoneType
Expand source code Browse git
async def test_basic(self) -> None:
    await self.thr.mkdir(self.path/"proc")
    await self.thr.mount("/proc", self.path/"proc", "", MS.BIND, "")
    await self.thr.task.chroot(await self.thr.ptr(self.path))
    await self.thr.task.open(await self.thr.ptr("/proc/self"), O.RDONLY)

Inherited members