ltp icon indicating copy to clipboard operation
ltp copied to clipboard

Write an kernel automounter testcase

Open metan-ucw opened this issue 6 years ago • 2 comments

Here is an basic example code to get you started:

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <linux/auto_fs4.h>
#include "tst_test.h"

#define MNTPOINT "mntpoint"
static int mounted;

{
        int p[2], r;
        char buf[1024];

        SAFE_PIPE(p);
        snprintf(buf, sizeof(buf), "fd=%i,minproto=5,maxproto=5,direct", p[1]);
        SAFE_MOUNT("ltp-test", MNTPOINT, "autofs", 0, buf);
        mounted = 1;
        SAFE_CLOSE(p[1]);

        pid_t pid = SAFE_FORK();
        if (!pid) {
                /* our process group has to be different from the automounter */
                setpgrp();

                /* the open call will block until we got reply from the autofs
                 * daemon, which is our parent process, which will never happen
                 * and parent will just kill us, poor process we are.
                 */
                int fd = open(MNTPOINT "/file", O_RDWR | O_CREAT, 0666);
                tst_res(TINFO | TERRNO, "fd=%i", fd);
                exit(0);        
        }

        r = read(p[0], buf, sizeof(buf));

        if (r > 0)
                tst_res(TPASS, "Got autofs request");

        struct autofs_v5_packet *packet = (void*)buf;

        if (packet->hdr.type == autofs_ptype_missing_direct)
                tst_res(TPASS, "Got missing direct request");
        
        /*  we get our packet, let's kill the child process */
        SAFE_KILL(pid, SIGKILL);
        SAFE_WAITPID(pid, NULL, 0);
}

static void setup(void)
{
        SAFE_MKDIR(MNTPOINT, 0666);
}

static void cleanup(void)
{
        if (mounted)
                SAFE_UMOUNT(MNTPOINT);
}

static struct tst_test test = {
        .setup = setup,
        .cleanup = cleanup,
        .test_all = automount,
        .needs_tmpdir = 1,
        .forks_child = 1,
};

metan-ucw avatar Aug 03 '18 12:08 metan-ucw

Hi, I have the similar testcase written in shell script, also I have few more tescases for autofs - direct mapping which can be written in shell script and can be consumed as part of LTP. Can I go ahead and submit here?

Mona-Bagare avatar Apr 27 '23 08:04 Mona-Bagare

We do have a shell test API in LTP as well, although it's not as advanced as the C API.

And the preferred way how to send patches is the LTP mailing list.

metan-ucw avatar Apr 27 '23 08:04 metan-ucw