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>
32 #include "testsuite.h"
35 #define TEST_UNAME "4.0.20-kmod"
36 static noreturn
int testsuite_uname(const struct test
*t
)
44 if (strcmp(u
.release
, TEST_UNAME
) != 0) {
45 char *ldpreload
= getenv("LD_PRELOAD");
46 ERR("u.release=%s should be %s\n", u
.release
, TEST_UNAME
);
47 ERR("LD_PRELOAD=%s\n", ldpreload
);
53 DEFINE_TEST(testsuite_uname
,
54 .description
= "test if trap to uname() works",
56 [TC_UNAME_R
] = TEST_UNAME
,
60 static int testsuite_rootfs_fopen(const struct test
*t
)
66 fp
= fopen("/lib/modules/a", "r");
70 n
= fscanf(fp
, "%s", s
);
74 if (strcmp(s
, "kmod-test-chroot-works") != 0)
79 DEFINE_TEST(testsuite_rootfs_fopen
,
80 .description
= "test if rootfs works - fopen()",
82 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
86 static int testsuite_rootfs_open(const struct test
*t
)
91 fd
= open("/lib/modules/a", O_RDONLY
);
96 int r
= read(fd
, buf
+ done
, sizeof(buf
) - 1 - done
);
99 if (r
== -EWOULDBLOCK
|| r
== -EAGAIN
)
107 if (strcmp(buf
, "kmod-test-chroot-works\n") != 0)
112 DEFINE_TEST(testsuite_rootfs_open
,
113 .description
= "test if rootfs works - open()",
115 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
119 static int testsuite_rootfs_stat_access(const struct test
*t
)
123 if (access("/lib/modules/a", F_OK
) < 0) {
124 ERR("access failed: %m\n");
128 if (stat("/lib/modules/a", &st
) < 0) {
129 ERR("stat failed: %m\n");
135 DEFINE_TEST(testsuite_rootfs_stat_access
,
136 .description
= "test if rootfs works - stat() and access()",
138 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
142 static int testsuite_rootfs_opendir(const struct test
*t
)
146 d
= opendir("/testdir");
148 ERR("opendir failed: %m\n");
155 DEFINE_TEST(testsuite_rootfs_opendir
,
156 .description
= "test if rootfs works - opendir()",
158 [TC_ROOTFS
] = TESTSUITE_ROOTFS
"test-rootfs/",
162 static const struct test
*tests
[] = {
164 &stestsuite_rootfs_fopen
,
165 &stestsuite_rootfs_open
,
166 &stestsuite_rootfs_stat_access
,
167 &stestsuite_rootfs_opendir
,
171 TESTSUITE_MAIN(tests
);