]>
Commit | Line | Data |
---|---|---|
e701e381 | 1 | /* |
e6b0e49b | 2 | * Copyright (C) 2012-2013 ProFUSION embedded systems |
e701e381 | 3 | * |
e1b1ab24 LDM |
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. | |
e701e381 LDM |
8 | * |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
e1b1ab24 LDM |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. | |
e701e381 | 13 | * |
e1b1ab24 | 14 | * You should have received a copy of the GNU Lesser General Public |
dea2dfee | 15 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
e701e381 LDM |
16 | */ |
17 | ||
c2e4286b LDM |
18 | #include <dirent.h> |
19 | #include <errno.h> | |
20 | #include <stddef.h> | |
ab253110 LDM |
21 | #include <stdio.h> |
22 | #include <stdlib.h> | |
ab253110 | 23 | #include <string.h> |
ab253110 | 24 | #include <unistd.h> |
1426a613 LDM |
25 | #include <sys/stat.h> |
26 | #include <sys/types.h> | |
ab253110 | 27 | #include <sys/utsname.h> |
c2e4286b | 28 | |
5c42c5fc LDM |
29 | #include <shared/util.h> |
30 | ||
f357866d | 31 | #include <libkmod/libkmod.h> |
ab253110 LDM |
32 | |
33 | #include "testsuite.h" | |
34 | ||
35 | ||
36 | #define TEST_UNAME "4.0.20-kmod" | |
d96ca9c4 | 37 | static noreturn int testsuite_uname(const struct test *t) |
ab253110 LDM |
38 | { |
39 | struct utsname u; | |
40 | int err = uname(&u); | |
41 | ||
42 | if (err < 0) | |
43 | exit(EXIT_FAILURE); | |
44 | ||
5c42c5fc | 45 | if (!streq(u.release, TEST_UNAME)) { |
ab253110 LDM |
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); | |
49 | exit(EXIT_FAILURE); | |
50 | } | |
51 | ||
52 | exit(EXIT_SUCCESS); | |
53 | } | |
f1155c15 | 54 | DEFINE_TEST(testsuite_uname, |
ab253110 | 55 | .description = "test if trap to uname() works", |
ab253110 LDM |
56 | .config = { |
57 | [TC_UNAME_R] = TEST_UNAME, | |
58 | }, | |
c5d81989 | 59 | .need_spawn = true); |
ab253110 | 60 | |
6afc9cd6 LDM |
61 | static int testsuite_rootfs_fopen(const struct test *t) |
62 | { | |
63 | FILE *fp; | |
64 | char s[100]; | |
65 | int n; | |
66 | ||
67 | fp = fopen("/lib/modules/a", "r"); | |
68 | if (fp == NULL) | |
69 | return EXIT_FAILURE;; | |
70 | ||
71 | n = fscanf(fp, "%s", s); | |
72 | if (n != 1) | |
73 | return EXIT_FAILURE; | |
74 | ||
5c42c5fc | 75 | if (!streq(s, "kmod-test-chroot-works")) |
6afc9cd6 LDM |
76 | return EXIT_FAILURE; |
77 | ||
78 | return EXIT_SUCCESS; | |
79 | } | |
f1155c15 | 80 | DEFINE_TEST(testsuite_rootfs_fopen, |
6afc9cd6 | 81 | .description = "test if rootfs works - fopen()", |
6afc9cd6 LDM |
82 | .config = { |
83 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
84 | }, | |
c5d81989 | 85 | .need_spawn = true); |
6afc9cd6 | 86 | |
7fa8c2d2 LDM |
87 | static int testsuite_rootfs_open(const struct test *t) |
88 | { | |
89 | char buf[100]; | |
90 | int fd, done; | |
91 | ||
92 | fd = open("/lib/modules/a", O_RDONLY); | |
93 | if (fd < 0) | |
94 | return EXIT_FAILURE; | |
95 | ||
96 | for (done = 0;;) { | |
97 | int r = read(fd, buf + done, sizeof(buf) - 1 - done); | |
98 | if (r == 0) | |
99 | break; | |
a6ede6c7 | 100 | if (r == -EAGAIN) |
7fa8c2d2 LDM |
101 | continue; |
102 | ||
103 | done += r; | |
104 | } | |
105 | ||
106 | buf[done] = '\0'; | |
107 | ||
5c42c5fc | 108 | if (!streq(buf, "kmod-test-chroot-works\n")) |
7fa8c2d2 LDM |
109 | return EXIT_FAILURE; |
110 | ||
111 | return EXIT_SUCCESS; | |
112 | } | |
f1155c15 | 113 | DEFINE_TEST(testsuite_rootfs_open, |
7fa8c2d2 | 114 | .description = "test if rootfs works - open()", |
7fa8c2d2 LDM |
115 | .config = { |
116 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
117 | }, | |
c5d81989 | 118 | .need_spawn = true); |
7fa8c2d2 | 119 | |
1426a613 LDM |
120 | static int testsuite_rootfs_stat_access(const struct test *t) |
121 | { | |
122 | struct stat st; | |
123 | ||
124 | if (access("/lib/modules/a", F_OK) < 0) { | |
125 | ERR("access failed: %m\n"); | |
126 | return EXIT_FAILURE; | |
127 | } | |
128 | ||
129 | if (stat("/lib/modules/a", &st) < 0) { | |
130 | ERR("stat failed: %m\n"); | |
131 | return EXIT_FAILURE; | |
132 | } | |
133 | ||
134 | return EXIT_SUCCESS; | |
135 | } | |
f1155c15 | 136 | DEFINE_TEST(testsuite_rootfs_stat_access, |
1426a613 | 137 | .description = "test if rootfs works - stat() and access()", |
1426a613 LDM |
138 | .config = { |
139 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
140 | }, | |
c5d81989 | 141 | .need_spawn = true); |
1426a613 | 142 | |
4e36cb18 LDM |
143 | static int testsuite_rootfs_opendir(const struct test *t) |
144 | { | |
145 | DIR *d; | |
146 | ||
147 | d = opendir("/testdir"); | |
148 | if (d == NULL) { | |
149 | ERR("opendir failed: %m\n"); | |
150 | return EXIT_FAILURE; | |
151 | } | |
152 | ||
153 | closedir(d); | |
154 | return EXIT_SUCCESS; | |
155 | } | |
f1155c15 | 156 | DEFINE_TEST(testsuite_rootfs_opendir, |
4e36cb18 | 157 | .description = "test if rootfs works - opendir()", |
4e36cb18 LDM |
158 | .config = { |
159 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
160 | }, | |
c5d81989 | 161 | .need_spawn = true); |
4e36cb18 | 162 | |
43289820 | 163 | TESTSUITE_MAIN(); |