]>
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 LDM |
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 | |
e701e381 LDM |
17 | */ |
18 | ||
c2e4286b LDM |
19 | #include <dirent.h> |
20 | #include <errno.h> | |
21 | #include <stddef.h> | |
ab253110 LDM |
22 | #include <stdio.h> |
23 | #include <stdlib.h> | |
ab253110 | 24 | #include <string.h> |
ab253110 | 25 | #include <unistd.h> |
1426a613 LDM |
26 | #include <sys/stat.h> |
27 | #include <sys/types.h> | |
ab253110 | 28 | #include <sys/utsname.h> |
c2e4286b | 29 | |
ab253110 LDM |
30 | #include <libkmod.h> |
31 | ||
32 | #include "testsuite.h" | |
33 | ||
34 | ||
35 | #define TEST_UNAME "4.0.20-kmod" | |
d96ca9c4 | 36 | static noreturn int testsuite_uname(const struct test *t) |
ab253110 LDM |
37 | { |
38 | struct utsname u; | |
39 | int err = uname(&u); | |
40 | ||
41 | if (err < 0) | |
42 | exit(EXIT_FAILURE); | |
43 | ||
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); | |
48 | exit(EXIT_FAILURE); | |
49 | } | |
50 | ||
51 | exit(EXIT_SUCCESS); | |
52 | } | |
f1155c15 | 53 | DEFINE_TEST(testsuite_uname, |
ab253110 | 54 | .description = "test if trap to uname() works", |
ab253110 LDM |
55 | .config = { |
56 | [TC_UNAME_R] = TEST_UNAME, | |
57 | }, | |
c5d81989 | 58 | .need_spawn = true); |
ab253110 | 59 | |
6afc9cd6 LDM |
60 | static int testsuite_rootfs_fopen(const struct test *t) |
61 | { | |
62 | FILE *fp; | |
63 | char s[100]; | |
64 | int n; | |
65 | ||
66 | fp = fopen("/lib/modules/a", "r"); | |
67 | if (fp == NULL) | |
68 | return EXIT_FAILURE;; | |
69 | ||
70 | n = fscanf(fp, "%s", s); | |
71 | if (n != 1) | |
72 | return EXIT_FAILURE; | |
73 | ||
74 | if (strcmp(s, "kmod-test-chroot-works") != 0) | |
75 | return EXIT_FAILURE; | |
76 | ||
77 | return EXIT_SUCCESS; | |
78 | } | |
f1155c15 | 79 | DEFINE_TEST(testsuite_rootfs_fopen, |
6afc9cd6 | 80 | .description = "test if rootfs works - fopen()", |
6afc9cd6 LDM |
81 | .config = { |
82 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
83 | }, | |
c5d81989 | 84 | .need_spawn = true); |
6afc9cd6 | 85 | |
7fa8c2d2 LDM |
86 | static int testsuite_rootfs_open(const struct test *t) |
87 | { | |
88 | char buf[100]; | |
89 | int fd, done; | |
90 | ||
91 | fd = open("/lib/modules/a", O_RDONLY); | |
92 | if (fd < 0) | |
93 | return EXIT_FAILURE; | |
94 | ||
95 | for (done = 0;;) { | |
96 | int r = read(fd, buf + done, sizeof(buf) - 1 - done); | |
97 | if (r == 0) | |
98 | break; | |
99 | if (r == -EWOULDBLOCK || r == -EAGAIN) | |
100 | continue; | |
101 | ||
102 | done += r; | |
103 | } | |
104 | ||
105 | buf[done] = '\0'; | |
106 | ||
107 | if (strcmp(buf, "kmod-test-chroot-works\n") != 0) | |
108 | return EXIT_FAILURE; | |
109 | ||
110 | return EXIT_SUCCESS; | |
111 | } | |
f1155c15 | 112 | DEFINE_TEST(testsuite_rootfs_open, |
7fa8c2d2 | 113 | .description = "test if rootfs works - open()", |
7fa8c2d2 LDM |
114 | .config = { |
115 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
116 | }, | |
c5d81989 | 117 | .need_spawn = true); |
7fa8c2d2 | 118 | |
1426a613 LDM |
119 | static int testsuite_rootfs_stat_access(const struct test *t) |
120 | { | |
121 | struct stat st; | |
122 | ||
123 | if (access("/lib/modules/a", F_OK) < 0) { | |
124 | ERR("access failed: %m\n"); | |
125 | return EXIT_FAILURE; | |
126 | } | |
127 | ||
128 | if (stat("/lib/modules/a", &st) < 0) { | |
129 | ERR("stat failed: %m\n"); | |
130 | return EXIT_FAILURE; | |
131 | } | |
132 | ||
133 | return EXIT_SUCCESS; | |
134 | } | |
f1155c15 | 135 | DEFINE_TEST(testsuite_rootfs_stat_access, |
1426a613 | 136 | .description = "test if rootfs works - stat() and access()", |
1426a613 LDM |
137 | .config = { |
138 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
139 | }, | |
c5d81989 | 140 | .need_spawn = true); |
1426a613 | 141 | |
4e36cb18 LDM |
142 | static int testsuite_rootfs_opendir(const struct test *t) |
143 | { | |
144 | DIR *d; | |
145 | ||
146 | d = opendir("/testdir"); | |
147 | if (d == NULL) { | |
148 | ERR("opendir failed: %m\n"); | |
149 | return EXIT_FAILURE; | |
150 | } | |
151 | ||
152 | closedir(d); | |
153 | return EXIT_SUCCESS; | |
154 | } | |
f1155c15 | 155 | DEFINE_TEST(testsuite_rootfs_opendir, |
4e36cb18 | 156 | .description = "test if rootfs works - opendir()", |
4e36cb18 LDM |
157 | .config = { |
158 | [TC_ROOTFS] = TESTSUITE_ROOTFS "test-rootfs/", | |
159 | }, | |
c5d81989 | 160 | .need_spawn = true); |
4e36cb18 | 161 | |
43289820 | 162 | TESTSUITE_MAIN(); |