Browse Source

Adds test coverage with gcov & lcov ++

Yann Weber 2 years ago
parent
commit
a57e875b07
9 changed files with 118 additions and 17 deletions
  1. 24
    1
      Makefile.am
  2. 5
    5
      child.s
  3. 1
    9
      compile.c
  4. 4
    1
      tests/regen.sh
  5. 2
    0
      tests/samples/procfs_pid_maps_sm
  6. 15
    0
      tests/tests_asm_env.c
  7. 1
    0
      tests/tests_compile.c
  8. 8
    0
      tests/tests_logger.c
  9. 58
    1
      tests/tests_mmap.c

+ 24
- 1
Makefile.am View File

@@ -1,5 +1,4 @@
1 1
 bin_PROGRAMS = asmsh child
2
-noinst_LIBRARIES = libcheck_asmsh.a
3 2
 
4 3
 libcheck_asmsh_a_SOURCES = mmap_parse.c asm_env.c compile.c logger.c
5 4
 
@@ -8,8 +7,32 @@ child_SOURCES = child.s
8 7
 
9 8
 SUBDIRS = 
10 9
 if CHECK
10
+noinst_LIBRARIES = libcheck_asmsh.a
11
+libcheck_asmsh_a_CFLAGS = @CFLAGS@ -fprofile-arcs -ftest-coverage
11 12
 SUBDIRS += tests
13
+
14
+LCOV_INFO=lcov.info
15
+LCOV_HTML=lcov_html
16
+
17
+checks: check coverage
18
+
19
+coverage: $(LCOV_HTML)
20
+
21
+$(LCOV_INFO): gcov
22
+	lcov --capture --directory . --output-file $@
23
+
24
+$(LCOV_HTML): $(LCOV_INFO)
25
+	genhtml $< --output-directory $@
26
+
27
+gcov: *.gcno
28
+	gcov -j $^
29
+
30
+clean-local:
31
+	-rm -rf *.gcov *.gcda *.gcno $(LCOV_INFO) $(LCOV_HTML)
32
+
12 33
 endif
13 34
 
14 35
 child$(EXEEXT): $(child_SOURCES:.s=.o)
15 36
 	ld $(child_LDFLAGS) -o $@ $<
37
+
38
+

+ 5
- 5
child.s View File

@@ -18,13 +18,13 @@ _start:
18 18
 	jle .errmap
19 19
 
20 20
 	push %rax
21
-	xor %rax, %rax
22
-	push %rax
21
+	#xor %rax, %rax
22
+	#push %rax
23 23
 
24 24
 
25
-	mov $-1, %r15
26
-	mov $34, %rax # sys_pause
27
-	syscall
25
+	#mov $-1, %r15
26
+	#mov $34, %rax # sys_pause
27
+	#syscall
28 28
 
29 29
 	jmp *(%rsp)
30 30
 

+ 1
- 9
compile.c View File

@@ -86,15 +86,7 @@ void asmsh_asmc_ctx_free(asmsh_asmc_ctx_t *ctx)
86 86
 				ctx->child.pid = 0;
87 87
 			}
88 88
 		}
89
-		if(ctx->child.pid > 0)
90
-		{
91
-			if(kill(ctx->child.pid, SIGKILL) == -1)
92
-			{
93
-				perror("Unable to kill child process");
94
-			}
95
-		}
96
-		ctx->child.pid = 0;
97
-		close(ctx->child.pipe_stdin);
89
+		_child_cleanup(&ctx->child);
98 90
 	}
99 91
 	if(ctx->respath)
100 92
 	{

+ 4
- 1
tests/regen.sh View File

@@ -14,6 +14,9 @@ SUBDIRS  = samples
14 14
 TESTLIB_NAME=libcheck_asmsh.a
15 15
 TESTLIB=\$(top_builddir)/\$(TESTLIB_NAME)
16 16
 
17
+clean-local:
18
+	-rm -rf *.gcov *.gcda *.gcno
19
+
17 20
 \$(TESTLIB):
18 21
 	make -C \$(top_builddir) \$(TESTLIB_NAME)
19 22
 
@@ -24,7 +27,7 @@ for p in $progs
24 27
 do
25 28
 	cat << __EOF__ >> Makefile.am
26 29
 ${p}_SOURCES = ${p}.c
27
-${p}_CFLAGS = @CHECK_CFLAGS@
30
+${p}_CFLAGS = @CHECK_CFLAGS@ -fprofile-arcs -ftest-coverage
28 31
 ${p}_LDADD = \$(TESTLIB) @CHECK_LIBS@
29 32
 __EOF__
30 33
 

+ 2
- 0
tests/samples/procfs_pid_maps_sm View File

@@ -0,0 +1,2 @@
1
+00400000-00452000 r-xp 00000000 08:02 173521      /usr/bin/dbus-daemon
2
+00651000-00652000 r--p 00051000 08:02 173521      /usr/bin/dbus-daemon

+ 15
- 0
tests/tests_asm_env.c View File

@@ -35,8 +35,23 @@ START_TEST(test_asm_stamps)
35 35
 }
36 36
 END_TEST
37 37
 
38
+START_TEST(test_env_update)
39
+{
40
+	asmsh_env_t *env = asmsh_env("samples/asm_env_stamps");
41
+
42
+	ck_assert_ptr_nonnull(env);
43
+
44
+	asmsh_env_update_maps(env);
45
+
46
+	ck_assert_mem_eq(&stamp1, &(env->regs.r15), 8);
47
+	ck_assert_mem_eq(&stamp2, &(env->regs.r14), 8);
48
+
49
+	asmsh_env_free(env);
50
+}
51
+
38 52
 ASMSH_CHECK_START("Testing asm env", "testing asm environment")
39 53
 	ASMSH_ADD_TEST(test_env);
40 54
 	ASMSH_ADD_TEST(test_asm_stamps);
55
+	ASMSH_ADD_TEST(test_env_update);
41 56
 ASMSH_CHECK_END
42 57
 

+ 1
- 0
tests/tests_compile.c View File

@@ -29,6 +29,7 @@ START_TEST(test_syntax_valid)
29 29
 END_TEST
30 30
 
31 31
 static const char *invalid_syntax[] = {
32
+	"mov %al,\x0A %ah",
32 33
 	"mov %rax, %rbx;",
33 34
 	"mov %al, %ah\n",
34 35
 	"#add 1, %rbx",

+ 8
- 0
tests/tests_logger.c View File

@@ -52,6 +52,13 @@ START_TEST(test_log_default_fmt)
52 52
 }
53 53
 END_TEST
54 54
 
55
+START_TEST(test_logger_setup)
56
+{
57
+	int ret = asmsh_logger_setup(NULL);
58
+
59
+	ck_assert_int_eq(ret, 0);
60
+}
61
+END_TEST
55 62
 
56 63
 START_TEST(test_log_function_lvl_nolog)
57 64
 {
@@ -242,6 +249,7 @@ END_TEST
242 249
 ASMSH_CHECK_START("logger tests", "unit tests various logger function")
243 250
 	ASMSH_ADD_TEST(test_logger_new);
244 251
 	ASMSH_ADD_TEST(test_log_default_fmt);
252
+	ASMSH_ADD_TEST(test_logger_setup);
245 253
 	ASMSH_ADD_TEST(test_log_function_lvl_nolog);
246 254
 	ASMSH_ADD_LOOP_TEST(test_log_function_lvl_singlelog, 0, msg_samples_sz);
247 255
 	ASMSH_ADD_TEST(test_log_function_lvl_logs);

+ 58
- 1
tests/tests_mmap.c View File

@@ -8,6 +8,7 @@
8 8
 #include "mmap_parse.h"
9 9
 
10 10
 #define PARSE_FD_SAMPLE "samples/procfs_pid_maps"
11
+#define PARSE_FD_SAMPLE_SM "samples/procfs_pid_maps_sm"
11 12
 
12 13
 typedef struct {
13 14
 	child_mmap_t map;
@@ -75,7 +76,7 @@ START_TEST (test_parse_fd)
75 76
 		 ""},
76 77
 	};
77 78
 
78
-	bzero(&maps, sizeof(child_mmap_l));
79
+	child_mmap_init(&maps);
79 80
 	fd = open(PARSE_FD_SAMPLE, O_RDONLY);
80 81
 	if(fd < 0)
81 82
 	{
@@ -91,8 +92,64 @@ START_TEST (test_parse_fd)
91 92
 }
92 93
 END_TEST
93 94
 
95
+START_TEST(test_mmap_get_invalid)
96
+{
97
+	child_mmap_l maps;
98
+	int ret = child_mmap_get(-1, &maps);
99
+	ck_assert_int_eq(ret, -1);
100
+}
101
+END_TEST
102
+
103
+START_TEST(test_mmap_get_self)
104
+{
105
+	child_mmap_l maps;
106
+	pid_t spid = getpid();
107
+	child_mmap_init(&maps);
108
+	int ret = child_mmap_get(spid, &maps);
109
+
110
+	ck_assert_int_eq(ret, 0);
111
+
112
+}
113
+END_TEST
114
+
115
+START_TEST(test_shrink_map)
116
+{
117
+	child_mmap_l maps;
118
+	int ret, fd;
119
+
120
+	fd = open(PARSE_FD_SAMPLE, O_RDONLY);
121
+	if(fd < 0)
122
+	{
123
+		perror("Unable to open sample");
124
+		ck_abort_msg("Unable to open sample");
125
+	}
126
+
127
+	child_mmap_init(&maps);
128
+	ret = child_mmap_get_fd(fd, &maps);
129
+
130
+	ck_assert_int_eq(ret, 0);
131
+
132
+	close(fd);
133
+
134
+	fd = open(PARSE_FD_SAMPLE_SM, O_RDONLY);
135
+	if(fd < 0)
136
+	{
137
+		perror("Unable to open sample");
138
+		ck_abort_msg("Unable to open sample");
139
+	}
140
+
141
+	ret = child_mmap_get_fd(fd, &maps);
142
+
143
+	ck_assert_int_eq(ret, 0);
144
+
145
+	close(fd);
146
+}
147
+
94 148
 ASMSH_CHECK_START("/proc/[pid]/map file parser", "parsing tests")
95 149
 	ASMSH_ADD_TEST(test_parse_line);
96 150
 	ASMSH_ADD_TEST(test_parse_fd);
151
+	ASMSH_ADD_TEST(test_mmap_get_invalid);
152
+	ASMSH_ADD_TEST(test_mmap_get_self);
153
+	ASMSH_ADD_TEST(test_shrink_map);
97 154
 ASMSH_CHECK_END
98 155
 

Loading…
Cancel
Save