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, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 #include <sys/types.h>
28 #include <sys/utsname.h>
31 #include "testsuite.h"
34 #define TEST_UNAME "4.0.20-kmod"
35 static noreturn
int testsuite_uname(const struct test
*t
)
43 if (strcmp(u
.release
, TEST_UNAME
) != 0) {
44 char *ldpreload
= getenv("LD_PRELOAD");
45 ERR("u.release=%s should be %s\n", u
.release
, TEST_UNAME
);
46 ERR("LD_PRELOAD=%s\n", ldpreload
);
52 static DEFINE_TEST(testsuite_uname
,
53 .description
= "test if trap to uname() works",
55 [TC_UNAME_R
] = TEST_UNAME
,
59 static int testsuite_rootfs_fopen(const struct test
*t
)
65 fp
= fopen("/lib/modules/a", "r");
69 n
= fscanf(fp
, "%s", s
);
73 if (strcmp(s
, "kmod-test-chroot-works") != 0)
78 static DEFINE_TEST(testsuite_rootfs_fopen
,
79 .description
= "test if rootfs works - fopen()",
81 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
85 static int testsuite_rootfs_open(const struct test
*t
)
90 fd
= open("/lib/modules/a", O_RDONLY
);
95 int r
= read(fd
, buf
+ done
, sizeof(buf
) - 1 - done
);
98 if (r
== -EWOULDBLOCK
|| r
== -EAGAIN
)
106 if (strcmp(buf
, "kmod-test-chroot-works\n") != 0)
111 static DEFINE_TEST(testsuite_rootfs_open
,
112 .description
= "test if rootfs works - open()",
114 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
118 static int testsuite_rootfs_stat_access(const struct test
*t
)
122 if (access("/lib/modules/a", F_OK
) < 0) {
123 ERR("access failed: %m\n");
127 if (stat("/lib/modules/a", &st
) < 0) {
128 ERR("stat failed: %m\n");
134 static DEFINE_TEST(testsuite_rootfs_stat_access
,
135 .description
= "test if rootfs works - stat() and access()",
137 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
141 static int testsuite_rootfs_opendir(const struct test
*t
)
145 d
= opendir("/testdir");
147 ERR("opendir failed: %m\n");
154 static DEFINE_TEST(testsuite_rootfs_opendir
,
155 .description
= "test if rootfs works - opendir()",
157 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
161 static const struct test
*tests
[] = {
163 &stestsuite_rootfs_fopen
,
164 &stestsuite_rootfs_open
,
165 &stestsuite_rootfs_stat_access
,
166 &stestsuite_rootfs_opendir
,
170 TESTSUITE_MAIN(tests
);