2 * Copyright (C) 2012 ProFUSION embedded systems
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
27 #include <sys/utsname.h>
30 #include "testsuite.h"
33 #define TEST_UNAME "4.0.20-kmod"
34 static __noreturn
int testsuite_uname(const struct test
*t
)
42 if (strcmp(u
.release
, TEST_UNAME
) != 0) {
43 char *ldpreload
= getenv("LD_PRELOAD");
44 ERR("u.release=%s should be %s\n", u
.release
, TEST_UNAME
);
45 ERR("LD_PRELOAD=%s\n", ldpreload
);
51 static DEFINE_TEST(testsuite_uname
,
52 .description
= "test if trap to uname() works",
54 [TC_UNAME_R
] = TEST_UNAME
,
58 static int testsuite_rootfs_fopen(const struct test
*t
)
64 fp
= fopen("/lib/modules/a", "r");
68 n
= fscanf(fp
, "%s", s
);
72 if (strcmp(s
, "kmod-test-chroot-works") != 0)
77 static DEFINE_TEST(testsuite_rootfs_fopen
,
78 .description
= "test if rootfs works - fopen()",
80 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
84 static int testsuite_rootfs_open(const struct test
*t
)
89 fd
= open("/lib/modules/a", O_RDONLY
);
94 int r
= read(fd
, buf
+ done
, sizeof(buf
) - 1 - done
);
97 if (r
== -EWOULDBLOCK
|| r
== -EAGAIN
)
105 if (strcmp(buf
, "kmod-test-chroot-works\n") != 0)
110 static DEFINE_TEST(testsuite_rootfs_open
,
111 .description
= "test if rootfs works - open()",
113 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
117 static int testsuite_rootfs_stat_access(const struct test
*t
)
121 if (access("/lib/modules/a", F_OK
) < 0) {
122 ERR("access failed: %m\n");
126 if (stat("/lib/modules/a", &st
) < 0) {
127 ERR("stat failed: %m\n");
133 static DEFINE_TEST(testsuite_rootfs_stat_access
,
134 .description
= "test if rootfs works - stat() and access()",
136 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
140 static int testsuite_rootfs_opendir(const struct test
*t
)
144 d
= opendir("/testdir");
146 ERR("opendir failed: %m\n");
153 static DEFINE_TEST(testsuite_rootfs_opendir
,
154 .description
= "test if rootfs works - opendir()",
156 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
160 static const struct test
*tests
[] = {
162 &stestsuite_rootfs_fopen
,
163 &stestsuite_rootfs_open
,
164 &stestsuite_rootfs_stat_access
,
165 &stestsuite_rootfs_opendir
,
169 TESTSUITE_MAIN(tests
);