summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2018-02-01 20:28:57 +0100
committerCedric BAIL <cedric@osg.samsung.com>2018-02-01 13:28:36 -0800
commitd4fcff7ed43bf5b4e6e44767c9f9a1acf5535137 (patch)
tree5e0ae30f03d6d3f5152d2975d27c30011f411b35
parenta89c9e037aeda8cddc132072675a5bbdea089ad7 (diff)
evil: final step : remove completely the binary, useless now that the unit test is theree
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/Makefile_Evil.am19
-rw-r--r--src/bin/evil/evil_suite.c205
-rw-r--r--src/bin/evil/evil_suite.h14
-rw-r--r--src/bin/evil/evil_test_pipe.c126
-rw-r--r--src/bin/evil/evil_test_pipe.h8
-rw-r--r--src/bin/evil/evil_test_util.c110
-rw-r--r--src/bin/evil/evil_test_util.h8
-rw-r--r--src/tests/evil/evil_suite.c5
-rw-r--r--src/tests/evil/evil_suite.h5
-rw-r--r--src/tests/evil/evil_test_unistd.c120
10 files changed, 124 insertions, 496 deletions
diff --git a/src/Makefile_Evil.am b/src/Makefile_Evil.am
index 95c6344495..edac73be1f 100644
--- a/src/Makefile_Evil.am
+++ b/src/Makefile_Evil.am
@@ -72,22 +72,6 @@ lib_evil_libevil_la_CPPFLAGS += \
72-I$(top_srcdir)/src/lib/evil/regex \ 72-I$(top_srcdir)/src/lib/evil/regex \
73-DPOSIX_MISTAKE 73-DPOSIX_MISTAKE
74 74
75### Binary
76
77bin_PROGRAMS += bin/evil/evil_suite
78
79bin_evil_evil_suite_SOURCES = \
80bin/evil/evil_suite.c \
81bin/evil/evil_test_pipe.c \
82bin/evil/evil_test_util.c \
83bin/evil/evil_suite.h \
84bin/evil/evil_test_pipe.h \
85bin/evil/evil_test_util.h
86
87bin_evil_evil_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EVIL_CFLAGS@
88bin_evil_evil_suite_LDADD = @USE_EVIL_LIBS@ -lm
89bin_evil_evil_suite_DEPENDENCIES = @USE_EVIL_INTERNAL_LIBS@
90
91### Unit tests 75### Unit tests
92 76
93if EFL_ENABLE_TESTS 77if EFL_ENABLE_TESTS
@@ -102,7 +86,8 @@ tests/evil/evil_test_dlfcn.c \
102tests/evil/evil_test_libgen.c \ 86tests/evil/evil_test_libgen.c \
103tests/evil/evil_test_main.c \ 87tests/evil/evil_test_main.c \
104tests/evil/evil_test_stdio.c \ 88tests/evil/evil_test_stdio.c \
105tests/evil/evil_test_stdlib.c 89tests/evil/evil_test_stdlib.c \
90tests/evil/evil_test_unistd.c
106 91
107tests_evil_evil_suite_CPPFLAGS = \ 92tests_evil_evil_suite_CPPFLAGS = \
108-I$(top_builddir)/src/lib/efl \ 93-I$(top_builddir)/src/lib/efl \
diff --git a/src/bin/evil/evil_suite.c b/src/bin/evil/evil_suite.c
deleted file mode 100644
index aa2e7f3cd4..0000000000
--- a/src/bin/evil/evil_suite.c
+++ /dev/null
@@ -1,205 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#define WIN32_LEAN_AND_MEAN
9#include <windows.h>
10#undef WIN32_LEAN_AND_MEAN
11
12#include "Evil.h"
13#include "evil_suite.h"
14#include "evil_test_pipe.h"
15#include "evil_test_util.h"
16
17
18typedef int(*function)(suite *s);
19
20struct test
21{
22 const char *name;
23 function fct;
24};
25
26struct list
27{
28 void *data;
29 int succeed;
30 list *next;
31};
32
33struct suite
34{
35 LARGE_INTEGER freq;
36 LARGE_INTEGER start;
37 LARGE_INTEGER end;
38
39 list *first;
40 list *l;
41
42 int tests_count;
43 int tests_success;
44};
45
46
47static suite *
48suite_new(void)
49{
50 suite *s;
51
52 s = (suite *)malloc(sizeof(suite));
53 if (!s) return NULL;
54
55 if (!QueryPerformanceFrequency(&s->freq))
56 {
57 free(s);
58 return NULL;
59 }
60
61 s->first = NULL;
62 s->l = NULL;
63
64 s->tests_count = 0;
65 s->tests_success = 0;
66
67 return s;
68}
69
70static void
71suite_del(suite *s)
72{
73 list *l;
74 list *tmp;
75
76 if (!s) return;
77
78 l = s->first;
79 while (l)
80 {
81 tmp = l->next;
82 free(l->data);
83 free(l);
84 l = tmp;
85 }
86
87 free(s);
88}
89
90void
91suite_time_start(suite *s)
92{
93 QueryPerformanceCounter(&s->start);
94}
95
96void
97suite_time_stop(suite *s)
98{
99 QueryPerformanceCounter(&s->end);
100}
101
102double
103suite_time_get(suite *s)
104{
105 return (double)(s->end.QuadPart - s->start.QuadPart) / (double)s->freq.QuadPart;
106}
107
108static void
109suite_test_add(suite *s, const char *name, function fct)
110{
111 test *t;
112 list *l;
113
114 t = (test *)malloc(sizeof(test));
115 if (!t) return;
116
117 l = (list *)malloc(sizeof(list));
118 if (!l)
119 {
120 free(t);
121 return;
122 }
123
124 t->name = name;
125 t->fct = fct;
126
127 l->data = t;
128 l->succeed = 0;
129 l->next = NULL;
130
131 if (!s->first) s->first = l;
132
133 if (!s->l)
134 s->l = l;
135 else
136 {
137 s->l->next = l;
138 s->l =l;
139 }
140}
141
142static void
143suite_run(suite *s)
144{
145 list *l;
146
147 l = s->first;
148 while (l)
149 {
150 test *t;
151
152 t = (test *)l->data;
153 l->succeed = t->fct(s);
154 printf("%s test: %s\n", t->name, l->succeed ? "success" : "failure");
155 s->tests_count++;
156 if (l->succeed)
157 s->tests_success++;
158 l = l->next;
159 }
160}
161
162static void
163suite_show(suite *s)
164{
165 printf ("\n%d/%d tests passed (%d%%)\n",
166 s->tests_success,
167 s->tests_count,
168 (100 * s->tests_success) / s->tests_count);
169}
170
171int
172main(void)
173{
174 test tests[] = {
175 { "pipe ", test_pipe },
176 { "util ", test_util },
177 { NULL, NULL },
178 };
179 suite *s;
180 int i;
181
182 if (!evil_init())
183 return EXIT_FAILURE;
184
185 s = suite_new();
186 if (!s)
187 {
188 evil_shutdown();
189 return EXIT_FAILURE;
190 }
191
192 for (i = 0; tests[i].name; ++i)
193 {
194 suite_test_add(s, tests[i].name, tests[i].fct);
195 }
196
197 suite_run(s);
198
199 suite_show(s);
200
201 suite_del(s);
202 evil_shutdown();
203
204 return EXIT_SUCCESS;
205}
diff --git a/src/bin/evil/evil_suite.h b/src/bin/evil/evil_suite.h
deleted file mode 100644
index d3284b4fbb..0000000000
--- a/src/bin/evil/evil_suite.h
+++ /dev/null
@@ -1,14 +0,0 @@
1#ifndef __EVIL_SUITE_H__
2#define __EVIL_SUITE_H__
3
4
5typedef struct test test;
6typedef struct list list;
7typedef struct suite suite;
8
9void suite_time_start(suite *s);
10void suite_time_stop(suite *s);
11double suite_time_get(suite *s);
12
13
14#endif /* __EVIL_SUITE_H__ */
diff --git a/src/bin/evil/evil_test_pipe.c b/src/bin/evil/evil_test_pipe.c
deleted file mode 100644
index e5cfdec4d1..0000000000
--- a/src/bin/evil/evil_test_pipe.c
+++ /dev/null
@@ -1,126 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <stdlib.h>
6#include <stdio.h>
7
8# define WIN32_LEAN_AND_MEAN
9# include <winsock2.h>
10# undef WIN32_LEAN_AND_MEAN
11
12#include <Evil.h>
13
14#include "evil_suite.h"
15#include "evil_test_pipe.h"
16
17
18#define FDREAD 0
19#define FDWRITE 1
20
21typedef struct
22{
23 int val;
24 int fd_write;
25} data;
26
27
28static DWORD WINAPI
29thread (void *param)
30{
31 data *d;
32 void *buf[1];
33
34 Sleep (2 * 1000);
35 d = (data *)param;
36 buf[0] = d;
37 send(d->fd_write, (char *)buf, sizeof(buf), 0);
38
39 return 0;
40}
41
42static int
43test_pipe_test(void)
44{
45 int sockets[2];
46 struct timeval t;
47 fd_set rfds;
48 int ret = 0;
49 data *d;
50 DWORD thread_id;
51 HANDLE h;
52
53 FD_ZERO(&rfds);
54
55 t.tv_sec = 5;
56 t.tv_usec = 0;
57
58 if (pipe(sockets) < 0)
59 return 0;
60
61 FD_SET(sockets[FDREAD], &rfds);
62 fcntl(sockets[FDREAD], F_SETFL, O_NONBLOCK);
63
64 d = (data *)malloc(sizeof (data));
65 if (!d)
66 return 0;
67
68 d->val = 14;
69 d->fd_write = sockets[FDWRITE];
70
71 h = CreateThread(NULL, 0, thread, d, 0, &thread_id);
72 if (!h)
73
74 ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t);
75
76 if (ret < 0)
77 goto free_d;
78 else if (ret == 0)
79 goto close_h;
80 else /* ret > 0 */
81 {
82 void *buf[1];
83 data *d2 = NULL;
84 int len;
85
86 while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0)
87 {
88 if (len == sizeof(buf))
89 {
90 d2 = (data *)buf[0];
91 break;
92 }
93 }
94 if (d2 && (d2->val == d->val))
95 ret = 1;
96 else
97 ret = 0;
98 }
99
100 CloseHandle(h);
101 free(d);
102
103 return ret;
104
105 close_h:
106 CloseHandle(h);
107 free_d:
108 free(d);
109 return 0;
110}
111
112static int
113test_pipe_run(suite *s)
114{
115 int res;
116
117 res = test_pipe_test();
118
119 return res;
120}
121
122int
123test_pipe(suite *s)
124{
125 return test_pipe_run(s);
126}
diff --git a/src/bin/evil/evil_test_pipe.h b/src/bin/evil/evil_test_pipe.h
deleted file mode 100644
index ff8041f716..0000000000
--- a/src/bin/evil/evil_test_pipe.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef __EVIL_TEST_PIPE_H__
2#define __EVIL_TEST_PIPE_H__
3
4
5int test_pipe(suite *s);
6
7
8#endif /* __EVIL_TEST_PIPE_H__ */
diff --git a/src/bin/evil/evil_test_util.c b/src/bin/evil/evil_test_util.c
deleted file mode 100644
index 3763f88b64..0000000000
--- a/src/bin/evil/evil_test_util.c
+++ /dev/null
@@ -1,110 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#include <string.h>
6
7#include <Evil.h>
8
9#include "evil_suite.h"
10#include "evil_test_util.h"
11
12
13static int test_path_absolute_test_1(void)
14{
15 char *path;
16 int result;
17
18 path = NULL;
19 result = evil_path_is_absolute(path);
20 if (result != 0)
21 return 0;
22
23 return 1;
24}
25
26static int test_path_absolute_test_2(void)
27{
28 char *path;
29 int result;
30
31 path = "1";
32 result = evil_path_is_absolute(path);
33 if (result != 0)
34 return 0;
35
36 return 1;
37}
38
39static int test_path_absolute_test_3(void)
40{
41 char *path;
42 int result;
43
44 path = "1:\\";
45 result = evil_path_is_absolute(path);
46 if (result != 0)
47 return 0;
48
49 return 1;
50}
51
52static int test_path_absolute_test_4(void)
53{
54 char *path;
55 int result;
56
57 path = "1/\\";
58 result = evil_path_is_absolute(path);
59 if (result != 0)
60 return 0;
61
62 return 1;
63}
64
65static int test_path_absolute_test_5(void)
66{
67 char *path;
68 int result;
69
70 path = "F:/foo";
71 result = evil_path_is_absolute(path);
72 if (result == 0)
73 return 0;
74
75 return 1;
76}
77
78static int test_path_absolute_test_6(void)
79{
80 char *path;
81 int result;
82
83 path = "C:\\foo";
84 result = evil_path_is_absolute(path);
85 if (result == 0)
86 return 0;
87
88 return 1;
89}
90
91static int
92test_path_absolute_run(suite *s)
93{
94 int res;
95
96 res = test_path_absolute_test_1();
97 res &= test_path_absolute_test_2();
98 res &= test_path_absolute_test_3();
99 res &= test_path_absolute_test_4();
100 res &= test_path_absolute_test_5();
101 res &= test_path_absolute_test_6();
102
103 return res;
104}
105
106int
107test_util(suite *s)
108{
109 return test_path_absolute_run(s);
110}
diff --git a/src/bin/evil/evil_test_util.h b/src/bin/evil/evil_test_util.h
deleted file mode 100644
index bee5c7a164..0000000000
--- a/src/bin/evil/evil_test_util.h
+++ /dev/null
@@ -1,8 +0,0 @@
1#ifndef __EVIL_TEST_UTIL_H__
2#define __EVIL_TEST_UTIL_H__
3
4
5int test_util(suite *s);
6
7
8#endif /* __EVIL_TEST_UTIL_H__ */
diff --git a/src/tests/evil/evil_suite.c b/src/tests/evil/evil_suite.c
index 454a217e64..36d86ac8e5 100644
--- a/src/tests/evil/evil_suite.c
+++ b/src/tests/evil/evil_suite.c
@@ -27,13 +27,10 @@
27#include "../efl_check.h" 27#include "../efl_check.h"
28 28
29static const Efl_Test_Case etc[] = { 29static const Efl_Test_Case etc[] = {
30 /* { "Dirent", evil_test_dirent }, */
31 { "Dlfcn", evil_test_dlfcn }, 30 { "Dlfcn", evil_test_dlfcn },
32 /* { "Fcntl", evil_test_fcntl }, */ 31 /* { "Fcntl", evil_test_fcntl }, */
33 /* { "Fnmatch", evil_test_fnmatch }, */ 32 /* { "Fnmatch", evil_test_fnmatch }, */
34 /* { "Inet", evil_test_inet }, */
35 /* { "Langinfo", evil_test_langinfo }, */ 33 /* { "Langinfo", evil_test_langinfo }, */
36 /* { "Link", evil_test_link }, */
37 { "Libgen", evil_test_libgen }, 34 { "Libgen", evil_test_libgen },
38 { "Main", evil_test_main }, 35 { "Main", evil_test_main },
39 /* { "Mman", evil_test_mman }, */ 36 /* { "Mman", evil_test_mman }, */
@@ -42,7 +39,7 @@ static const Efl_Test_Case etc[] = {
42 { "Stdlib", evil_test_stdlib }, 39 { "Stdlib", evil_test_stdlib },
43 /* { "String", evil_test_string }, */ 40 /* { "String", evil_test_string }, */
44 /* { "Time", evil_test_time }, */ 41 /* { "Time", evil_test_time }, */
45 /* { "Unistd", evil_test_unistd }, */ 42 { "Unistd", evil_test_unistd },
46 /* { "Util", evil_test_util }, */ 43 /* { "Util", evil_test_util }, */
47 { NULL, NULL } 44 { NULL, NULL }
48}; 45};
diff --git a/src/tests/evil/evil_suite.h b/src/tests/evil/evil_suite.h
index 20f8d03a60..b7ae5e8274 100644
--- a/src/tests/evil/evil_suite.h
+++ b/src/tests/evil/evil_suite.h
@@ -21,13 +21,10 @@
21 21
22#include <check.h> 22#include <check.h>
23 23
24/* void evil_test_dirent(TCase *tc); */
25void evil_test_dlfcn(TCase *tc); 24void evil_test_dlfcn(TCase *tc);
26/* void evil_test_fcntl(TCase *tc); */ 25/* void evil_test_fcntl(TCase *tc); */
27/* void evil_test_fnmatch(TCase *tc); */ 26/* void evil_test_fnmatch(TCase *tc); */
28/* void evil_test_inet(TCase *tc); */
29/* void evil_test_langinfo(TCase *tc); */ 27/* void evil_test_langinfo(TCase *tc); */
30/* void evil_test_link(TCase *tc); */
31void evil_test_libgen(TCase *tc); 28void evil_test_libgen(TCase *tc);
32void evil_test_main(TCase *tc); 29void evil_test_main(TCase *tc);
33/* void evil_test_mman(TCase *tc); */ 30/* void evil_test_mman(TCase *tc); */
@@ -36,7 +33,7 @@ void evil_test_stdio(TCase *tc);
36void evil_test_stdlib(TCase *tc); 33void evil_test_stdlib(TCase *tc);
37/* void evil_test_string(TCase *tc); */ 34/* void evil_test_string(TCase *tc); */
38/* void evil_test_time(TCase *tc); */ 35/* void evil_test_time(TCase *tc); */
39/* void evil_test_unistd(TCase *tc); */ 36void evil_test_unistd(TCase *tc);
40/* void evil_test_util(TCase *tc); */ 37/* void evil_test_util(TCase *tc); */
41 38
42#endif /* EVIL_SUITE_H_ */ 39#endif /* EVIL_SUITE_H_ */
diff --git a/src/tests/evil/evil_test_unistd.c b/src/tests/evil/evil_test_unistd.c
new file mode 100644
index 0000000000..0ab5f78146
--- /dev/null
+++ b/src/tests/evil/evil_test_unistd.c
@@ -0,0 +1,120 @@
1/* EVIL - EFL library for Windows port
2 * Copyright (C) 2017 Vincent Torri
3 *
4 * This library 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.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdlib.h>
24#include <stdio.h>
25
26# define WIN32_LEAN_AND_MEAN
27# include <winsock2.h>
28# undef WIN32_LEAN_AND_MEAN
29
30#include <Evil.h>
31
32#include "evil_suite.h"
33
34
35#define FDREAD 0
36#define FDWRITE 1
37
38typedef struct
39{
40 int val;
41 int fd_write;
42} data;
43
44
45static DWORD WINAPI
46thread(void *param)
47{
48 data *d;
49 void *buf[1];
50
51 Sleep (2 * 1000);
52 d = (data *)param;
53 buf[0] = param;
54 send(d->fd_write, (char *)buf, sizeof(buf), 0);
55
56 return 0;
57}
58
59START_TEST(evil_unistd_pipe)
60{
61 int sockets[2];
62 struct timeval t;
63 fd_set rfds;
64 int ret;
65 data *d;
66 DWORD thread_id;
67 HANDLE h;
68
69 ret = evil_init();
70 fail_if(ret == 0);
71
72 FD_ZERO(&rfds);
73 t.tv_sec = 5;
74 t.tv_usec = 0;
75
76 ret = pipe(sockets);
77 fail_if(ret < 0);
78
79 FD_SET(sockets[FDREAD], &rfds);
80 fcntl(sockets[FDREAD], F_SETFL, O_NONBLOCK);
81
82 d = (data *)malloc(sizeof (data));
83 fail_if(d == NULL);
84
85 d->val = 14;
86 d->fd_write = sockets[FDWRITE];
87
88 h = CreateThread(NULL, 0, thread, d, 0, &thread_id);
89 fail_if(h == NULL);
90
91 ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t);
92 fail_if(ret <= 0);
93
94 {
95 void *buf[1];
96 data *d2 = NULL;
97 int len;
98
99 while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0)
100 {
101 if (len == sizeof(buf))
102 {
103 d2 = (data *)buf[0];
104 break;
105 }
106 }
107 fail_if(!d2 || (d2->val != d->val));
108 }
109
110 CloseHandle(h);
111 free(d);
112
113 evil_shutdown();
114}
115END_TEST
116
117void evil_test_unistd(TCase *tc)
118{
119 tcase_add_test(tc, evil_unistd_pipe);
120}