2 * Copyright (C) 2012-2013 ProFUSION embedded systems
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
27 #include <sys/utsname.h>
29 #include <shared/util.h>
31 #include <libkmod/libkmod.h>
33 #include "testsuite.h"
36 #define TEST_UNAME "4.0.20-kmod"
37 static noreturn int testsuite_uname(const struct test *t)
45 if (!streq(u.release, TEST_UNAME)) {
46 char *ldpreload = getenv("LD_PRELOAD");
47 ERR("u.release=%s should be %s\n", u.release, TEST_UNAME);
48 ERR("LD_PRELOAD=%s\n", ldpreload);
54 DEFINE_TEST(testsuite_uname,
55 .description = "test if trap to uname() works",
57 [TC_UNAME_R] = TEST_UNAME,
61 static int testsuite_rootfs_fopen(const struct test *t)
67 fp = fopen("/lib/modules/a", "r");
71 n = fscanf(fp, "%s", s);
75 if (!streq(s, "kmod-test-chroot-works"))
80 DEFINE_TEST(testsuite_rootfs_fopen,
81 .description = "test if rootfs works - fopen()",
83 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/",
87 static int testsuite_rootfs_open(const struct test *t)
92 fd = open("/lib/modules/a", O_RDONLY);
97 int r = read(fd, buf + done, sizeof(buf) - 1 - done);
108 if (!streq(buf, "kmod-test-chroot-works\n"))
113 DEFINE_TEST(testsuite_rootfs_open,
114 .description = "test if rootfs works - open()",
116 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/",
120 static int testsuite_rootfs_stat_access(const struct test *t)
124 if (access("/lib/modules/a", F_OK) < 0) {
125 ERR("access failed: %m\n");
129 if (stat("/lib/modules/a", &st) < 0) {
130 ERR("stat failed: %m\n");
136 DEFINE_TEST(testsuite_rootfs_stat_access,
137 .description = "test if rootfs works - stat() and access()",
139 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/",
143 static int testsuite_rootfs_opendir(const struct test *t)
147 d = opendir("/testdir");
149 ERR("opendir failed: %m\n");
156 DEFINE_TEST(testsuite_rootfs_opendir,
157 .description = "test if rootfs works - opendir()",
159 [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/",