Merge lp:~colin-king/ecryptfs/gcov-coverage into lp:ecryptfs

Proposed by Colin Ian King
Status: Merged
Merged at revision: 765
Proposed branch: lp:~colin-king/ecryptfs/gcov-coverage
Merge into: lp:ecryptfs
Diff against target: 594 lines (+516/-2)
8 files modified
tests/kernel/Makefile.am (+11/-1)
tests/kernel/link.sh (+83/-0)
tests/kernel/mknod.sh (+64/-0)
tests/kernel/mmap-bmap.sh (+58/-0)
tests/kernel/mmap-bmap/test.c (+132/-0)
tests/kernel/tests.rc (+1/-1)
tests/kernel/xattr.sh (+56/-0)
tests/kernel/xattr/test.c (+111/-0)
To merge this branch: bzr merge lp:~colin-king/ecryptfs/gcov-coverage
Reviewer Review Type Date Requested Status
eCryptfs Pending
Review via email: mp+144989@code.launchpad.net

Description of the change

I ran the current eCryptfs tests on 3.8-rc4 with kernel gcov enabled and spotted a few trivial areas where it would be useful to up the test coverage on the code. So here are a few very simple additional tests to exercise eCryptfs a little further.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/kernel/Makefile.am'
2--- tests/kernel/Makefile.am 2012-11-02 23:20:18 +0000
3+++ tests/kernel/Makefile.am 2013-01-25 17:05:31 +0000
4@@ -8,6 +8,7 @@
5 file-concurrent.sh \
6 inode-race-stat.sh \
7 inotify.sh \
8+ link.sh \
9 llseek.sh \
10 lp-1009207.sh \
11 lp-469664.sh \
12@@ -23,6 +24,8 @@
13 lp-926292.sh \
14 lp-994247.sh \
15 miscdev-bad-count.sh \
16+ mknod.sh \
17+ mmap-bmap.sh \
18 mmap-close.sh \
19 mmap-dir.sh \
20 read-dir.sh \
21@@ -42,10 +45,12 @@
22 lp-870326/test \
23 lp-994247/test \
24 miscdev-bad-count/test \
25+ mmap-bmap/test \
26 mmap-close/test \
27 mmap-dir/test \
28 read-dir/test \
29- trunc-file/test
30+ trunc-file/test \
31+ xattr/test
32 endif
33
34 directory_concurrent_test_SOURCES = directory-concurrent/test.c
35@@ -73,6 +78,8 @@
36 miscdev_bad_count_test_SOURCES = miscdev-bad-count/test.c
37 miscdev_bad_count_test_LDADD = $(top_builddir)/src/libecryptfs/libecryptfs.la
38
39+mmap_bmap_test_SOURCES = mmap-bmap/test.c
40+
41 mmap_close_test_SOURCES = mmap-close/test.c
42
43 mmap_dir_test_SOURCES = mmap-dir/test.c
44@@ -80,3 +87,6 @@
45 read_dir_test_SOURCES = read-dir/test.c
46
47 trunc_file_test_SOURCES = trunc-file/test.c
48+
49+xattr_test_SOURCES = xattr/test.c
50+
51
52=== added file 'tests/kernel/link.sh'
53--- tests/kernel/link.sh 1970-01-01 00:00:00 +0000
54+++ tests/kernel/link.sh 2013-01-25 17:05:31 +0000
55@@ -0,0 +1,83 @@
56+#!/bin/bash
57+#
58+# link.sh : Simple hard link sanity check
59+#
60+# Author: Colin Ian King <colin.king@canonical.com>
61+#
62+# Copyright (C) 2013 Canonical Ltd.
63+#
64+# This program is free software; you can redistribute it and/or
65+# modify it under the terms of the GNU General Public License
66+# as published by the Free Software Foundation version 2
67+# of the License.
68+#
69+# This program is distributed in the hope that it will be useful,
70+# but WITHOUT ANY WARRANTY; without even the implied warranty of
71+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72+# GNU General Public License for more details.
73+#
74+# You should have received a copy of the GNU General Public License
75+# along with this program; if not, write to the Free Software
76+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
77+
78+test_script_dir=$(dirname $0)
79+rc=1
80+test_dir=0
81+
82+. ${test_script_dir}/../lib/etl_funcs.sh
83+
84+test_cleanup()
85+{
86+ etl_remove_test_dir $test_dir
87+ etl_umount
88+ etl_lumount
89+ etl_unlink_keys
90+ exit $rc
91+}
92+trap test_cleanup 0 1 2 3 15
93+
94+# TEST
95+etl_add_keys || exit
96+etl_lmount || exit
97+etl_mount_i || exit
98+test_dir=$(etl_create_test_dir) || exit
99+test_file1="${test_dir}/test1"
100+test_file2="${test_dir}/test2"
101+
102+echo "Testing 1 2 3" > $test_file1
103+
104+ln $test_file1 $test_file2
105+
106+rc=0
107+#
108+# Contents should be the same
109+#
110+diff $test_file1 $test_file2 > /dev/null 2>&1
111+if [ $? -ne 0 ]; then
112+ rc=1
113+fi
114+
115+#
116+# Size should be the same
117+#
118+test_file1_size=$(stat -c%s $test_file1)
119+test_file2_size=$(stat -c%s $test_file2)
120+if [ $test_file1_size -ne $test_file2_size ]; then
121+ rc=1
122+fi
123+
124+#
125+# Link count should be 2 for both
126+#
127+test_file1_links=$(stat -c%h $test_file1)
128+test_file2_links=$(stat -c%h $test_file2)
129+if [ $test_file1_links -ne 2 -a $test_file2_links -ne 2 ]; then
130+ rc=1
131+fi
132+
133+rm -f $test_file1 $test_file2
134+
135+etl_umount || exit
136+etl_mount_i || exit
137+
138+exit
139
140=== added file 'tests/kernel/mknod.sh'
141--- tests/kernel/mknod.sh 1970-01-01 00:00:00 +0000
142+++ tests/kernel/mknod.sh 2013-01-25 17:05:31 +0000
143@@ -0,0 +1,64 @@
144+#!/bin/bash
145+#
146+# mknod.sh : Simple mknod sanity check
147+#
148+# Author: Colin Ian King <colin.king@canonical.com>
149+#
150+# Copyright (C) 2013 Canonical Ltd.
151+#
152+# This program is free software; you can redistribute it and/or
153+# modify it under the terms of the GNU General Public License
154+# as published by the Free Software Foundation version 2
155+# of the License.
156+#
157+# This program is distributed in the hope that it will be useful,
158+# but WITHOUT ANY WARRANTY; without even the implied warranty of
159+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160+# GNU General Public License for more details.
161+#
162+# You should have received a copy of the GNU General Public License
163+# along with this program; if not, write to the Free Software
164+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
165+
166+test_script_dir=$(dirname $0)
167+rc=1
168+test_dir=0
169+
170+. ${test_script_dir}/../lib/etl_funcs.sh
171+
172+test_cleanup()
173+{
174+ etl_remove_test_dir $test_dir
175+ etl_umount
176+ etl_lumount
177+ etl_unlink_keys
178+ exit $rc
179+}
180+trap test_cleanup 0 1 2 3 15
181+
182+# TEST
183+etl_add_keys || exit
184+etl_lmount || exit
185+etl_mount_i || exit
186+test_dir=$(etl_create_test_dir) || exit
187+test_file="${test_dir}/full"
188+
189+mknod $test_file c 1 7
190+#
191+# Check to see if mknod succeeded as expected
192+#
193+if [ $? -eq 0 ]; then
194+ dev=$(stat $test_file -c%t:%T)
195+ if [ $? -eq 0 ]; then
196+ if [ x$dev == x1:7 ]; then
197+ rc=0
198+ fi
199+ fi
200+fi
201+
202+rm -f $test_file
203+
204+etl_umount || exit
205+etl_mount_i || exit
206+
207+exit
208
209=== added directory 'tests/kernel/mmap-bmap'
210=== added file 'tests/kernel/mmap-bmap.sh'
211--- tests/kernel/mmap-bmap.sh 1970-01-01 00:00:00 +0000
212+++ tests/kernel/mmap-bmap.sh 2013-01-25 17:05:31 +0000
213@@ -0,0 +1,58 @@
214+#!/bin/bash
215+#
216+# mmap-bmap.sh : Test to see if bmap from upper is a subset of the lower
217+#
218+# Author: Colin Ian King <colin.king@canonical.com>
219+#
220+# Copyright (C) 2013 Canonical Ltd.
221+#
222+# This program is free software; you can redistribute it and/or
223+# modify it under the terms of the GNU General Public License
224+# as published by the Free Software Foundation version 2
225+# of the License.
226+#
227+# This program is distributed in the hope that it will be useful,
228+# but WITHOUT ANY WARRANTY; without even the implied warranty of
229+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
230+# GNU General Public License for more details.
231+#
232+# You should have received a copy of the GNU General Public License
233+# along with this program; if not, write to the Free Software
234+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
235+
236+test_script_dir=$(dirname $0)
237+rc=1
238+test_dir=0
239+
240+. ${test_script_dir}/../lib/etl_funcs.sh
241+
242+test_cleanup()
243+{
244+ etl_remove_test_dir $test_dir
245+ etl_umount
246+ etl_lumount
247+ etl_unlink_keys
248+ exit $rc
249+}
250+trap test_cleanup 0 1 2 3 15
251+
252+# TEST
253+etl_add_keys || exit
254+etl_lmount || exit
255+etl_mount_i || exit
256+test_dir=$(etl_create_test_dir) || exit
257+test_file="${test_dir}/test_file"
258+
259+dd if=/dev/zero of=$test_file bs=1M count=1 > /dev/null 2>&1 || exit
260+lower_test_file=$(etl_find_lower_path $test_file)
261+if [ $? -ne 0 ] || [ -z "$lower_test_file" ]; then
262+ rc=1
263+ exit
264+fi
265+${test_script_dir}/mmap-bmap/test $lower_test_file $test_file || exit
266+rc=$?
267+
268+etl_umount || exit
269+etl_mount_i || exit
270+
271+exit
272
273=== added file 'tests/kernel/mmap-bmap/test.c'
274--- tests/kernel/mmap-bmap/test.c 1970-01-01 00:00:00 +0000
275+++ tests/kernel/mmap-bmap/test.c 2013-01-25 17:05:31 +0000
276@@ -0,0 +1,132 @@
277+/*
278+ * Author: Colin King <colin.king@canonical.com>
279+ *
280+ * Copyright (C) 2013 Canonical, Ltd.
281+ *
282+ * This program is free software; you can redistribute it and/or
283+ * modify it under the terms of the GNU General Public License
284+ * as published by the Free Software Foundation; either version 2
285+ * of the License, or (at your option) any later version.
286+ *
287+ * This program is distributed in the hope that it will be useful,
288+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
289+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
290+ * GNU General Public License for more details.
291+ *
292+ * You should have received a copy of the GNU General Public License
293+ * along with this program; if not, write to the Free Software
294+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
295+ */
296+
297+#include <stdio.h>
298+#include <stdlib.h>
299+#include <stdbool.h>
300+#include <string.h>
301+#include <unistd.h>
302+#include <errno.h>
303+#include <fcntl.h>
304+#include <sys/ioctl.h>
305+#include <sys/types.h>
306+#include <sys/stat.h>
307+#include <linux/fs.h>
308+
309+static int *get_blocks(const char *filename, int *num_blocks)
310+{
311+ int fd, block_size, i;
312+ int *blocks;
313+ struct stat statinfo;
314+
315+ if ((fd = open(filename, O_RDONLY)) < 0) {
316+ fprintf(stderr, "Cannot open %s\n", filename);
317+ return NULL;
318+ }
319+
320+ if (ioctl(fd, FIGETBSZ, &block_size) < 0) {
321+ fprintf(stderr, "Cannot get block size\n");
322+ close(fd);
323+ return NULL;
324+ }
325+
326+ if (fstat(fd, &statinfo) < 0) {
327+ fprintf(stderr, "Cannot stat %s\n", filename);
328+ close(fd);
329+ return NULL;
330+ }
331+
332+ *num_blocks = (statinfo.st_size + block_size - 1) / block_size;
333+
334+ blocks = malloc(sizeof(int) * *num_blocks);
335+ if (!blocks) {
336+ fprintf(stderr, "Cannot allocate buffer for %d blocks\n", *num_blocks);
337+ close(fd);
338+ return NULL;
339+ }
340+
341+ /*
342+ * Collect blocks, some file systems may not support FIBMAP, so
343+ * silently ignore errors.
344+ */
345+ for (i = 0; i < *num_blocks; i++) {
346+ blocks[i] = i;
347+ if (ioctl(fd, FIBMAP, &blocks[i]) < 0)
348+ blocks[i] = 0;
349+ }
350+ close(fd);
351+
352+ return blocks;
353+}
354+
355+int check_blocks(
356+ int *lower_blocks, int lower_num_blocks,
357+ int *upper_blocks, int upper_num_blocks)
358+{
359+ int i, j;
360+
361+ /* Upper must not have more blocks than lower */
362+ if (upper_num_blocks > lower_num_blocks)
363+ return EXIT_FAILURE;
364+
365+ /* Upper must have blocks that are in the lower */
366+ for (i = 0; i < upper_num_blocks; i++) {
367+ bool found = false;
368+ for (j = 0; j < lower_num_blocks; j++) {
369+ if (upper_blocks[i] == lower_blocks[j]) {
370+ found = true;
371+ break;
372+ }
373+ }
374+ if (!found)
375+ return EXIT_FAILURE;
376+ }
377+ return EXIT_SUCCESS;
378+}
379+
380+int main(int argc, char **argv) {
381+
382+ int *lower_blocks, *upper_blocks;
383+ int lower_num_blocks, upper_num_blocks;
384+ int rc = EXIT_SUCCESS;
385+
386+ if (argc != 3) {
387+ fprintf(stderr, "Usage: %s lower-file upper-file\n", argv[0]);
388+ exit(EXIT_FAILURE);
389+ }
390+
391+ lower_blocks = get_blocks(argv[1], &lower_num_blocks);
392+ if (!lower_blocks)
393+ exit(EXIT_FAILURE);
394+
395+ upper_blocks = get_blocks(argv[2], &upper_num_blocks);
396+ if (!upper_blocks) {
397+ free(lower_blocks);
398+ exit(EXIT_FAILURE);
399+ }
400+
401+ rc = check_blocks(lower_blocks, lower_num_blocks,
402+ upper_blocks, upper_num_blocks);
403+
404+ free(upper_blocks);
405+ free(lower_blocks);
406+
407+ exit(rc);
408+}
409
410=== modified file 'tests/kernel/tests.rc'
411--- tests/kernel/tests.rc 2012-11-02 23:20:18 +0000
412+++ tests/kernel/tests.rc 2013-01-25 17:05:31 +0000
413@@ -1,2 +1,2 @@
414 destructive="miscdev-bad-count.sh extend-file-random.sh trunc-file.sh directory-concurrent.sh file-concurrent.sh lp-994247.sh"
415-safe="llseek.sh lp-469664.sh lp-524919.sh lp-509180.sh lp-613873.sh lp-745836.sh lp-870326.sh lp-885744.sh lp-926292.sh inotify.sh mmap-close.sh mmap-dir.sh read-dir.sh setattr-flush-dirty.sh inode-race-stat.sh lp-1009207.sh enospc.sh lp-911507.sh lp-872905.sh lp-561129.sh"
416+safe="llseek.sh lp-469664.sh lp-524919.sh lp-509180.sh lp-613873.sh lp-745836.sh lp-870326.sh lp-885744.sh lp-926292.sh inotify.sh mmap-bmap.sh mmap-close.sh mmap-dir.sh read-dir.sh setattr-flush-dirty.sh inode-race-stat.sh lp-1009207.sh enospc.sh lp-911507.sh lp-872905.sh lp-561129.sh mknod.sh link.sh xattr.sh"
417
418=== added directory 'tests/kernel/xattr'
419=== added file 'tests/kernel/xattr.sh'
420--- tests/kernel/xattr.sh 1970-01-01 00:00:00 +0000
421+++ tests/kernel/xattr.sh 2013-01-25 17:05:31 +0000
422@@ -0,0 +1,56 @@
423+#!/bin/bash
424+#
425+# xattr.sh : Simple xattr checks.
426+#
427+# Author: Colin Ian King <colin.king@canonical.com>
428+#
429+# Copyright (C) 2013 Canonical Ltd.
430+#
431+# This program is free software; you can redistribute it and/or
432+# modify it under the terms of the GNU General Public License
433+# as published by the Free Software Foundation version 2
434+# of the License.
435+#
436+# This program is distributed in the hope that it will be useful,
437+# but WITHOUT ANY WARRANTY; without even the implied warranty of
438+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
439+# GNU General Public License for more details.
440+#
441+# You should have received a copy of the GNU General Public License
442+# along with this program; if not, write to the Free Software
443+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
444+
445+test_script_dir=$(dirname $0)
446+rc=1
447+test_dir=0
448+
449+. ${test_script_dir}/../lib/etl_funcs.sh
450+
451+test_cleanup()
452+{
453+ etl_remove_test_dir $test_dir
454+ etl_umount
455+ etl_lumount
456+ etl_unlink_keys
457+ exit $rc
458+}
459+trap test_cleanup 0 1 2 3 15
460+
461+# TEST
462+etl_add_keys || exit
463+etl_lmount || exit
464+etl_mount_i || exit
465+test_dir=$(etl_create_test_dir) || exit
466+test_file="${test_dir}/test"
467+
468+echo "testing 1 2 3" > $test_file
469+
470+${test_script_dir}/xattr/test $test_file || exit
471+rc=$?
472+
473+rm -f $test_file1
474+
475+etl_umount || exit
476+etl_mount_i || exit
477+
478+exit
479
480=== added file 'tests/kernel/xattr/test.c'
481--- tests/kernel/xattr/test.c 1970-01-01 00:00:00 +0000
482+++ tests/kernel/xattr/test.c 2013-01-25 17:05:31 +0000
483@@ -0,0 +1,111 @@
484+/*
485+ * Author: Colin King <colin.king@canonical.com>
486+ *
487+ * Copyright (C) 2013 Canonical, Ltd.
488+ *
489+ * This program is free software; you can redistribute it and/or
490+ * modify it under the terms of the GNU General Public License
491+ * as published by the Free Software Foundation; either version 2
492+ * of the License, or (at your option) any later version.
493+ *
494+ * This program is distributed in the hope that it will be useful,
495+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
496+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
497+ * GNU General Public License for more details.
498+ *
499+ * You should have received a copy of the GNU General Public License
500+ * along with this program; if not, write to the Free Software
501+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
502+ */
503+
504+#include <stdio.h>
505+#include <stdlib.h>
506+#include <stdbool.h>
507+#include <string.h>
508+#include <unistd.h>
509+#include <errno.h>
510+#include <sys/xattr.h>
511+
512+static const char *names[] = {
513+ "user.test1",
514+ "user.test2",
515+ "user.test3",
516+ NULL
517+};
518+
519+static const char *values[] = {
520+ "test value #1",
521+ "test value #2",
522+ "test value #3",
523+ NULL
524+};
525+
526+int main(int argc, char **argv)
527+{
528+ ssize_t len, names_len = 0;
529+ int i, rc;
530+ char buffer[1024];
531+ char *ptr = buffer;
532+
533+ if (argc != 2) {
534+ fprintf(stderr, "Usage: %s file\n", argv[0]);
535+ exit(EXIT_FAILURE);
536+ }
537+
538+ for (i = 0; names[i]; i++) {
539+ if (setxattr(argv[1], names[i], values[i], strlen(values[i]), 0) < 0)
540+ exit(EXIT_FAILURE);
541+ names_len += 1 + strlen(names[i]);
542+ }
543+
544+ /*
545+ * Sanity check that listxattr returns correct length
546+ */
547+ len = listxattr(argv[1], NULL, 0);
548+ if (len != names_len)
549+ exit(EXIT_FAILURE);
550+
551+ len = listxattr(argv[1], buffer, sizeof(buffer));
552+ if (len < 0)
553+ exit(EXIT_FAILURE);
554+
555+ /*
556+ * Check listxattr names match what has been just set
557+ */
558+ for (i = 0; names[i]; i++) {
559+ if (strcmp(names[i], ptr))
560+ exit(EXIT_FAILURE);
561+ ptr += strlen(ptr) + 1;
562+ }
563+
564+ /*
565+ * Check contents of xattr
566+ */
567+ for (i = 0; names[i]; i++) {
568+ len = getxattr(argv[1], names[i], buffer, sizeof(buffer));
569+ if (len < 0)
570+ exit(EXIT_FAILURE);
571+ buffer[len] = '\0';
572+
573+ if (strcmp(values[i], buffer))
574+ exit(EXIT_FAILURE);
575+ }
576+
577+ /*
578+ * Remove xattr
579+ */
580+ for (i = 0; names[i]; i++) {
581+ rc = removexattr(argv[1], names[i]);
582+ if (rc < 0)
583+ exit(EXIT_FAILURE);
584+ }
585+
586+ /*
587+ * ..and there should be no xattrs left
588+ */
589+ len = listxattr(argv[1], NULL, 0);
590+ if (len != 0)
591+ exit(EXIT_FAILURE);
592+
593+ exit(EXIT_SUCCESS);
594+}

Subscribers

People subscribed via source and target branches