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
=== modified file 'tests/kernel/Makefile.am'
--- tests/kernel/Makefile.am 2012-11-02 23:20:18 +0000
+++ tests/kernel/Makefile.am 2013-01-25 17:05:31 +0000
@@ -8,6 +8,7 @@
8 file-concurrent.sh \8 file-concurrent.sh \
9 inode-race-stat.sh \9 inode-race-stat.sh \
10 inotify.sh \10 inotify.sh \
11 link.sh \
11 llseek.sh \12 llseek.sh \
12 lp-1009207.sh \13 lp-1009207.sh \
13 lp-469664.sh \14 lp-469664.sh \
@@ -23,6 +24,8 @@
23 lp-926292.sh \24 lp-926292.sh \
24 lp-994247.sh \25 lp-994247.sh \
25 miscdev-bad-count.sh \26 miscdev-bad-count.sh \
27 mknod.sh \
28 mmap-bmap.sh \
26 mmap-close.sh \29 mmap-close.sh \
27 mmap-dir.sh \30 mmap-dir.sh \
28 read-dir.sh \31 read-dir.sh \
@@ -42,10 +45,12 @@
42 lp-870326/test \45 lp-870326/test \
43 lp-994247/test \46 lp-994247/test \
44 miscdev-bad-count/test \47 miscdev-bad-count/test \
48 mmap-bmap/test \
45 mmap-close/test \49 mmap-close/test \
46 mmap-dir/test \50 mmap-dir/test \
47 read-dir/test \51 read-dir/test \
48 trunc-file/test52 trunc-file/test \
53 xattr/test
49endif54endif
5055
51directory_concurrent_test_SOURCES = directory-concurrent/test.c56directory_concurrent_test_SOURCES = directory-concurrent/test.c
@@ -73,6 +78,8 @@
73miscdev_bad_count_test_SOURCES = miscdev-bad-count/test.c78miscdev_bad_count_test_SOURCES = miscdev-bad-count/test.c
74miscdev_bad_count_test_LDADD = $(top_builddir)/src/libecryptfs/libecryptfs.la79miscdev_bad_count_test_LDADD = $(top_builddir)/src/libecryptfs/libecryptfs.la
7580
81mmap_bmap_test_SOURCES = mmap-bmap/test.c
82
76mmap_close_test_SOURCES = mmap-close/test.c83mmap_close_test_SOURCES = mmap-close/test.c
7784
78mmap_dir_test_SOURCES = mmap-dir/test.c85mmap_dir_test_SOURCES = mmap-dir/test.c
@@ -80,3 +87,6 @@
80read_dir_test_SOURCES = read-dir/test.c87read_dir_test_SOURCES = read-dir/test.c
8188
82trunc_file_test_SOURCES = trunc-file/test.c89trunc_file_test_SOURCES = trunc-file/test.c
90
91xattr_test_SOURCES = xattr/test.c
92
8393
=== added file 'tests/kernel/link.sh'
--- tests/kernel/link.sh 1970-01-01 00:00:00 +0000
+++ tests/kernel/link.sh 2013-01-25 17:05:31 +0000
@@ -0,0 +1,83 @@
1#!/bin/bash
2#
3# link.sh : Simple hard link sanity check
4#
5# Author: Colin Ian King <colin.king@canonical.com>
6#
7# Copyright (C) 2013 Canonical Ltd.
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation version 2
12# of the License.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
23test_script_dir=$(dirname $0)
24rc=1
25test_dir=0
26
27. ${test_script_dir}/../lib/etl_funcs.sh
28
29test_cleanup()
30{
31 etl_remove_test_dir $test_dir
32 etl_umount
33 etl_lumount
34 etl_unlink_keys
35 exit $rc
36}
37trap test_cleanup 0 1 2 3 15
38
39# TEST
40etl_add_keys || exit
41etl_lmount || exit
42etl_mount_i || exit
43test_dir=$(etl_create_test_dir) || exit
44test_file1="${test_dir}/test1"
45test_file2="${test_dir}/test2"
46
47echo "Testing 1 2 3" > $test_file1
48
49ln $test_file1 $test_file2
50
51rc=0
52#
53# Contents should be the same
54#
55diff $test_file1 $test_file2 > /dev/null 2>&1
56if [ $? -ne 0 ]; then
57 rc=1
58fi
59
60#
61# Size should be the same
62#
63test_file1_size=$(stat -c%s $test_file1)
64test_file2_size=$(stat -c%s $test_file2)
65if [ $test_file1_size -ne $test_file2_size ]; then
66 rc=1
67fi
68
69#
70# Link count should be 2 for both
71#
72test_file1_links=$(stat -c%h $test_file1)
73test_file2_links=$(stat -c%h $test_file2)
74if [ $test_file1_links -ne 2 -a $test_file2_links -ne 2 ]; then
75 rc=1
76fi
77
78rm -f $test_file1 $test_file2
79
80etl_umount || exit
81etl_mount_i || exit
82
83exit
084
=== added file 'tests/kernel/mknod.sh'
--- tests/kernel/mknod.sh 1970-01-01 00:00:00 +0000
+++ tests/kernel/mknod.sh 2013-01-25 17:05:31 +0000
@@ -0,0 +1,64 @@
1#!/bin/bash
2#
3# mknod.sh : Simple mknod sanity check
4#
5# Author: Colin Ian King <colin.king@canonical.com>
6#
7# Copyright (C) 2013 Canonical Ltd.
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation version 2
12# of the License.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
23test_script_dir=$(dirname $0)
24rc=1
25test_dir=0
26
27. ${test_script_dir}/../lib/etl_funcs.sh
28
29test_cleanup()
30{
31 etl_remove_test_dir $test_dir
32 etl_umount
33 etl_lumount
34 etl_unlink_keys
35 exit $rc
36}
37trap test_cleanup 0 1 2 3 15
38
39# TEST
40etl_add_keys || exit
41etl_lmount || exit
42etl_mount_i || exit
43test_dir=$(etl_create_test_dir) || exit
44test_file="${test_dir}/full"
45
46mknod $test_file c 1 7
47#
48# Check to see if mknod succeeded as expected
49#
50if [ $? -eq 0 ]; then
51 dev=$(stat $test_file -c%t:%T)
52 if [ $? -eq 0 ]; then
53 if [ x$dev == x1:7 ]; then
54 rc=0
55 fi
56 fi
57fi
58
59rm -f $test_file
60
61etl_umount || exit
62etl_mount_i || exit
63
64exit
065
=== added directory 'tests/kernel/mmap-bmap'
=== added file 'tests/kernel/mmap-bmap.sh'
--- tests/kernel/mmap-bmap.sh 1970-01-01 00:00:00 +0000
+++ tests/kernel/mmap-bmap.sh 2013-01-25 17:05:31 +0000
@@ -0,0 +1,58 @@
1#!/bin/bash
2#
3# mmap-bmap.sh : Test to see if bmap from upper is a subset of the lower
4#
5# Author: Colin Ian King <colin.king@canonical.com>
6#
7# Copyright (C) 2013 Canonical Ltd.
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation version 2
12# of the License.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
23test_script_dir=$(dirname $0)
24rc=1
25test_dir=0
26
27. ${test_script_dir}/../lib/etl_funcs.sh
28
29test_cleanup()
30{
31 etl_remove_test_dir $test_dir
32 etl_umount
33 etl_lumount
34 etl_unlink_keys
35 exit $rc
36}
37trap test_cleanup 0 1 2 3 15
38
39# TEST
40etl_add_keys || exit
41etl_lmount || exit
42etl_mount_i || exit
43test_dir=$(etl_create_test_dir) || exit
44test_file="${test_dir}/test_file"
45
46dd if=/dev/zero of=$test_file bs=1M count=1 > /dev/null 2>&1 || exit
47lower_test_file=$(etl_find_lower_path $test_file)
48if [ $? -ne 0 ] || [ -z "$lower_test_file" ]; then
49 rc=1
50 exit
51fi
52${test_script_dir}/mmap-bmap/test $lower_test_file $test_file || exit
53rc=$?
54
55etl_umount || exit
56etl_mount_i || exit
57
58exit
059
=== added file 'tests/kernel/mmap-bmap/test.c'
--- tests/kernel/mmap-bmap/test.c 1970-01-01 00:00:00 +0000
+++ tests/kernel/mmap-bmap/test.c 2013-01-25 17:05:31 +0000
@@ -0,0 +1,132 @@
1/*
2 * Author: Colin King <colin.king@canonical.com>
3 *
4 * Copyright (C) 2013 Canonical, Ltd.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <stdbool.h>
24#include <string.h>
25#include <unistd.h>
26#include <errno.h>
27#include <fcntl.h>
28#include <sys/ioctl.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <linux/fs.h>
32
33static int *get_blocks(const char *filename, int *num_blocks)
34{
35 int fd, block_size, i;
36 int *blocks;
37 struct stat statinfo;
38
39 if ((fd = open(filename, O_RDONLY)) < 0) {
40 fprintf(stderr, "Cannot open %s\n", filename);
41 return NULL;
42 }
43
44 if (ioctl(fd, FIGETBSZ, &block_size) < 0) {
45 fprintf(stderr, "Cannot get block size\n");
46 close(fd);
47 return NULL;
48 }
49
50 if (fstat(fd, &statinfo) < 0) {
51 fprintf(stderr, "Cannot stat %s\n", filename);
52 close(fd);
53 return NULL;
54 }
55
56 *num_blocks = (statinfo.st_size + block_size - 1) / block_size;
57
58 blocks = malloc(sizeof(int) * *num_blocks);
59 if (!blocks) {
60 fprintf(stderr, "Cannot allocate buffer for %d blocks\n", *num_blocks);
61 close(fd);
62 return NULL;
63 }
64
65 /*
66 * Collect blocks, some file systems may not support FIBMAP, so
67 * silently ignore errors.
68 */
69 for (i = 0; i < *num_blocks; i++) {
70 blocks[i] = i;
71 if (ioctl(fd, FIBMAP, &blocks[i]) < 0)
72 blocks[i] = 0;
73 }
74 close(fd);
75
76 return blocks;
77}
78
79int check_blocks(
80 int *lower_blocks, int lower_num_blocks,
81 int *upper_blocks, int upper_num_blocks)
82{
83 int i, j;
84
85 /* Upper must not have more blocks than lower */
86 if (upper_num_blocks > lower_num_blocks)
87 return EXIT_FAILURE;
88
89 /* Upper must have blocks that are in the lower */
90 for (i = 0; i < upper_num_blocks; i++) {
91 bool found = false;
92 for (j = 0; j < lower_num_blocks; j++) {
93 if (upper_blocks[i] == lower_blocks[j]) {
94 found = true;
95 break;
96 }
97 }
98 if (!found)
99 return EXIT_FAILURE;
100 }
101 return EXIT_SUCCESS;
102}
103
104int main(int argc, char **argv) {
105
106 int *lower_blocks, *upper_blocks;
107 int lower_num_blocks, upper_num_blocks;
108 int rc = EXIT_SUCCESS;
109
110 if (argc != 3) {
111 fprintf(stderr, "Usage: %s lower-file upper-file\n", argv[0]);
112 exit(EXIT_FAILURE);
113 }
114
115 lower_blocks = get_blocks(argv[1], &lower_num_blocks);
116 if (!lower_blocks)
117 exit(EXIT_FAILURE);
118
119 upper_blocks = get_blocks(argv[2], &upper_num_blocks);
120 if (!upper_blocks) {
121 free(lower_blocks);
122 exit(EXIT_FAILURE);
123 }
124
125 rc = check_blocks(lower_blocks, lower_num_blocks,
126 upper_blocks, upper_num_blocks);
127
128 free(upper_blocks);
129 free(lower_blocks);
130
131 exit(rc);
132}
0133
=== modified file 'tests/kernel/tests.rc'
--- tests/kernel/tests.rc 2012-11-02 23:20:18 +0000
+++ tests/kernel/tests.rc 2013-01-25 17:05:31 +0000
@@ -1,2 +1,2 @@
1destructive="miscdev-bad-count.sh extend-file-random.sh trunc-file.sh directory-concurrent.sh file-concurrent.sh lp-994247.sh"1destructive="miscdev-bad-count.sh extend-file-random.sh trunc-file.sh directory-concurrent.sh file-concurrent.sh lp-994247.sh"
2safe="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"2safe="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"
33
=== added directory 'tests/kernel/xattr'
=== added file 'tests/kernel/xattr.sh'
--- tests/kernel/xattr.sh 1970-01-01 00:00:00 +0000
+++ tests/kernel/xattr.sh 2013-01-25 17:05:31 +0000
@@ -0,0 +1,56 @@
1#!/bin/bash
2#
3# xattr.sh : Simple xattr checks.
4#
5# Author: Colin Ian King <colin.king@canonical.com>
6#
7# Copyright (C) 2013 Canonical Ltd.
8#
9# This program is free software; you can redistribute it and/or
10# modify it under the terms of the GNU General Public License
11# as published by the Free Software Foundation version 2
12# of the License.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
23test_script_dir=$(dirname $0)
24rc=1
25test_dir=0
26
27. ${test_script_dir}/../lib/etl_funcs.sh
28
29test_cleanup()
30{
31 etl_remove_test_dir $test_dir
32 etl_umount
33 etl_lumount
34 etl_unlink_keys
35 exit $rc
36}
37trap test_cleanup 0 1 2 3 15
38
39# TEST
40etl_add_keys || exit
41etl_lmount || exit
42etl_mount_i || exit
43test_dir=$(etl_create_test_dir) || exit
44test_file="${test_dir}/test"
45
46echo "testing 1 2 3" > $test_file
47
48${test_script_dir}/xattr/test $test_file || exit
49rc=$?
50
51rm -f $test_file1
52
53etl_umount || exit
54etl_mount_i || exit
55
56exit
057
=== added file 'tests/kernel/xattr/test.c'
--- tests/kernel/xattr/test.c 1970-01-01 00:00:00 +0000
+++ tests/kernel/xattr/test.c 2013-01-25 17:05:31 +0000
@@ -0,0 +1,111 @@
1/*
2 * Author: Colin King <colin.king@canonical.com>
3 *
4 * Copyright (C) 2013 Canonical, Ltd.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <stdbool.h>
24#include <string.h>
25#include <unistd.h>
26#include <errno.h>
27#include <sys/xattr.h>
28
29static const char *names[] = {
30 "user.test1",
31 "user.test2",
32 "user.test3",
33 NULL
34};
35
36static const char *values[] = {
37 "test value #1",
38 "test value #2",
39 "test value #3",
40 NULL
41};
42
43int main(int argc, char **argv)
44{
45 ssize_t len, names_len = 0;
46 int i, rc;
47 char buffer[1024];
48 char *ptr = buffer;
49
50 if (argc != 2) {
51 fprintf(stderr, "Usage: %s file\n", argv[0]);
52 exit(EXIT_FAILURE);
53 }
54
55 for (i = 0; names[i]; i++) {
56 if (setxattr(argv[1], names[i], values[i], strlen(values[i]), 0) < 0)
57 exit(EXIT_FAILURE);
58 names_len += 1 + strlen(names[i]);
59 }
60
61 /*
62 * Sanity check that listxattr returns correct length
63 */
64 len = listxattr(argv[1], NULL, 0);
65 if (len != names_len)
66 exit(EXIT_FAILURE);
67
68 len = listxattr(argv[1], buffer, sizeof(buffer));
69 if (len < 0)
70 exit(EXIT_FAILURE);
71
72 /*
73 * Check listxattr names match what has been just set
74 */
75 for (i = 0; names[i]; i++) {
76 if (strcmp(names[i], ptr))
77 exit(EXIT_FAILURE);
78 ptr += strlen(ptr) + 1;
79 }
80
81 /*
82 * Check contents of xattr
83 */
84 for (i = 0; names[i]; i++) {
85 len = getxattr(argv[1], names[i], buffer, sizeof(buffer));
86 if (len < 0)
87 exit(EXIT_FAILURE);
88 buffer[len] = '\0';
89
90 if (strcmp(values[i], buffer))
91 exit(EXIT_FAILURE);
92 }
93
94 /*
95 * Remove xattr
96 */
97 for (i = 0; names[i]; i++) {
98 rc = removexattr(argv[1], names[i]);
99 if (rc < 0)
100 exit(EXIT_FAILURE);
101 }
102
103 /*
104 * ..and there should be no xattrs left
105 */
106 len = listxattr(argv[1], NULL, 0);
107 if (len != 0)
108 exit(EXIT_FAILURE);
109
110 exit(EXIT_SUCCESS);
111}

Subscribers

People subscribed via source and target branches