evil: final step : remove completely the binary, useless now that the unit test is theree

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Vincent Torri 2018-02-01 20:28:57 +01:00 committed by Cedric BAIL
parent a89c9e037a
commit d4fcff7ed4
10 changed files with 124 additions and 496 deletions

View File

@ -72,22 +72,6 @@ lib_evil_libevil_la_CPPFLAGS += \
-I$(top_srcdir)/src/lib/evil/regex \
-DPOSIX_MISTAKE
### Binary
bin_PROGRAMS += bin/evil/evil_suite
bin_evil_evil_suite_SOURCES = \
bin/evil/evil_suite.c \
bin/evil/evil_test_pipe.c \
bin/evil/evil_test_util.c \
bin/evil/evil_suite.h \
bin/evil/evil_test_pipe.h \
bin/evil/evil_test_util.h
bin_evil_evil_suite_CPPFLAGS = -I$(top_builddir)/src/lib/efl @EVIL_CFLAGS@
bin_evil_evil_suite_LDADD = @USE_EVIL_LIBS@ -lm
bin_evil_evil_suite_DEPENDENCIES = @USE_EVIL_INTERNAL_LIBS@
### Unit tests
if EFL_ENABLE_TESTS
@ -102,7 +86,8 @@ tests/evil/evil_test_dlfcn.c \
tests/evil/evil_test_libgen.c \
tests/evil/evil_test_main.c \
tests/evil/evil_test_stdio.c \
tests/evil/evil_test_stdlib.c
tests/evil/evil_test_stdlib.c \
tests/evil/evil_test_unistd.c
tests_evil_evil_suite_CPPFLAGS = \
-I$(top_builddir)/src/lib/efl \

View File

@ -1,205 +0,0 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <stdio.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#include "Evil.h"
#include "evil_suite.h"
#include "evil_test_pipe.h"
#include "evil_test_util.h"
typedef int(*function)(suite *s);
struct test
{
const char *name;
function fct;
};
struct list
{
void *data;
int succeed;
list *next;
};
struct suite
{
LARGE_INTEGER freq;
LARGE_INTEGER start;
LARGE_INTEGER end;
list *first;
list *l;
int tests_count;
int tests_success;
};
static suite *
suite_new(void)
{
suite *s;
s = (suite *)malloc(sizeof(suite));
if (!s) return NULL;
if (!QueryPerformanceFrequency(&s->freq))
{
free(s);
return NULL;
}
s->first = NULL;
s->l = NULL;
s->tests_count = 0;
s->tests_success = 0;
return s;
}
static void
suite_del(suite *s)
{
list *l;
list *tmp;
if (!s) return;
l = s->first;
while (l)
{
tmp = l->next;
free(l->data);
free(l);
l = tmp;
}
free(s);
}
void
suite_time_start(suite *s)
{
QueryPerformanceCounter(&s->start);
}
void
suite_time_stop(suite *s)
{
QueryPerformanceCounter(&s->end);
}
double
suite_time_get(suite *s)
{
return (double)(s->end.QuadPart - s->start.QuadPart) / (double)s->freq.QuadPart;
}
static void
suite_test_add(suite *s, const char *name, function fct)
{
test *t;
list *l;
t = (test *)malloc(sizeof(test));
if (!t) return;
l = (list *)malloc(sizeof(list));
if (!l)
{
free(t);
return;
}
t->name = name;
t->fct = fct;
l->data = t;
l->succeed = 0;
l->next = NULL;
if (!s->first) s->first = l;
if (!s->l)
s->l = l;
else
{
s->l->next = l;
s->l =l;
}
}
static void
suite_run(suite *s)
{
list *l;
l = s->first;
while (l)
{
test *t;
t = (test *)l->data;
l->succeed = t->fct(s);
printf("%s test: %s\n", t->name, l->succeed ? "success" : "failure");
s->tests_count++;
if (l->succeed)
s->tests_success++;
l = l->next;
}
}
static void
suite_show(suite *s)
{
printf ("\n%d/%d tests passed (%d%%)\n",
s->tests_success,
s->tests_count,
(100 * s->tests_success) / s->tests_count);
}
int
main(void)
{
test tests[] = {
{ "pipe ", test_pipe },
{ "util ", test_util },
{ NULL, NULL },
};
suite *s;
int i;
if (!evil_init())
return EXIT_FAILURE;
s = suite_new();
if (!s)
{
evil_shutdown();
return EXIT_FAILURE;
}
for (i = 0; tests[i].name; ++i)
{
suite_test_add(s, tests[i].name, tests[i].fct);
}
suite_run(s);
suite_show(s);
suite_del(s);
evil_shutdown();
return EXIT_SUCCESS;
}

View File

@ -1,14 +0,0 @@
#ifndef __EVIL_SUITE_H__
#define __EVIL_SUITE_H__
typedef struct test test;
typedef struct list list;
typedef struct suite suite;
void suite_time_start(suite *s);
void suite_time_stop(suite *s);
double suite_time_get(suite *s);
#endif /* __EVIL_SUITE_H__ */

View File

@ -1,126 +0,0 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdlib.h>
#include <stdio.h>
# define WIN32_LEAN_AND_MEAN
# include <winsock2.h>
# undef WIN32_LEAN_AND_MEAN
#include <Evil.h>
#include "evil_suite.h"
#include "evil_test_pipe.h"
#define FDREAD 0
#define FDWRITE 1
typedef struct
{
int val;
int fd_write;
} data;
static DWORD WINAPI
thread (void *param)
{
data *d;
void *buf[1];
Sleep (2 * 1000);
d = (data *)param;
buf[0] = d;
send(d->fd_write, (char *)buf, sizeof(buf), 0);
return 0;
}
static int
test_pipe_test(void)
{
int sockets[2];
struct timeval t;
fd_set rfds;
int ret = 0;
data *d;
DWORD thread_id;
HANDLE h;
FD_ZERO(&rfds);
t.tv_sec = 5;
t.tv_usec = 0;
if (pipe(sockets) < 0)
return 0;
FD_SET(sockets[FDREAD], &rfds);
fcntl(sockets[FDREAD], F_SETFL, O_NONBLOCK);
d = (data *)malloc(sizeof (data));
if (!d)
return 0;
d->val = 14;
d->fd_write = sockets[FDWRITE];
h = CreateThread(NULL, 0, thread, d, 0, &thread_id);
if (!h)
ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t);
if (ret < 0)
goto free_d;
else if (ret == 0)
goto close_h;
else /* ret > 0 */
{
void *buf[1];
data *d2 = NULL;
int len;
while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0)
{
if (len == sizeof(buf))
{
d2 = (data *)buf[0];
break;
}
}
if (d2 && (d2->val == d->val))
ret = 1;
else
ret = 0;
}
CloseHandle(h);
free(d);
return ret;
close_h:
CloseHandle(h);
free_d:
free(d);
return 0;
}
static int
test_pipe_run(suite *s)
{
int res;
res = test_pipe_test();
return res;
}
int
test_pipe(suite *s)
{
return test_pipe_run(s);
}

View File

@ -1,8 +0,0 @@
#ifndef __EVIL_TEST_PIPE_H__
#define __EVIL_TEST_PIPE_H__
int test_pipe(suite *s);
#endif /* __EVIL_TEST_PIPE_H__ */

View File

@ -1,110 +0,0 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
#include <string.h>
#include <Evil.h>
#include "evil_suite.h"
#include "evil_test_util.h"
static int test_path_absolute_test_1(void)
{
char *path;
int result;
path = NULL;
result = evil_path_is_absolute(path);
if (result != 0)
return 0;
return 1;
}
static int test_path_absolute_test_2(void)
{
char *path;
int result;
path = "1";
result = evil_path_is_absolute(path);
if (result != 0)
return 0;
return 1;
}
static int test_path_absolute_test_3(void)
{
char *path;
int result;
path = "1:\\";
result = evil_path_is_absolute(path);
if (result != 0)
return 0;
return 1;
}
static int test_path_absolute_test_4(void)
{
char *path;
int result;
path = "1/\\";
result = evil_path_is_absolute(path);
if (result != 0)
return 0;
return 1;
}
static int test_path_absolute_test_5(void)
{
char *path;
int result;
path = "F:/foo";
result = evil_path_is_absolute(path);
if (result == 0)
return 0;
return 1;
}
static int test_path_absolute_test_6(void)
{
char *path;
int result;
path = "C:\\foo";
result = evil_path_is_absolute(path);
if (result == 0)
return 0;
return 1;
}
static int
test_path_absolute_run(suite *s)
{
int res;
res = test_path_absolute_test_1();
res &= test_path_absolute_test_2();
res &= test_path_absolute_test_3();
res &= test_path_absolute_test_4();
res &= test_path_absolute_test_5();
res &= test_path_absolute_test_6();
return res;
}
int
test_util(suite *s)
{
return test_path_absolute_run(s);
}

View File

@ -1,8 +0,0 @@
#ifndef __EVIL_TEST_UTIL_H__
#define __EVIL_TEST_UTIL_H__
int test_util(suite *s);
#endif /* __EVIL_TEST_UTIL_H__ */

View File

@ -27,13 +27,10 @@
#include "../efl_check.h"
static const Efl_Test_Case etc[] = {
/* { "Dirent", evil_test_dirent }, */
{ "Dlfcn", evil_test_dlfcn },
/* { "Fcntl", evil_test_fcntl }, */
/* { "Fnmatch", evil_test_fnmatch }, */
/* { "Inet", evil_test_inet }, */
/* { "Langinfo", evil_test_langinfo }, */
/* { "Link", evil_test_link }, */
{ "Libgen", evil_test_libgen },
{ "Main", evil_test_main },
/* { "Mman", evil_test_mman }, */
@ -42,7 +39,7 @@ static const Efl_Test_Case etc[] = {
{ "Stdlib", evil_test_stdlib },
/* { "String", evil_test_string }, */
/* { "Time", evil_test_time }, */
/* { "Unistd", evil_test_unistd }, */
{ "Unistd", evil_test_unistd },
/* { "Util", evil_test_util }, */
{ NULL, NULL }
};

View File

@ -21,13 +21,10 @@
#include <check.h>
/* void evil_test_dirent(TCase *tc); */
void evil_test_dlfcn(TCase *tc);
/* void evil_test_fcntl(TCase *tc); */
/* void evil_test_fnmatch(TCase *tc); */
/* void evil_test_inet(TCase *tc); */
/* void evil_test_langinfo(TCase *tc); */
/* void evil_test_link(TCase *tc); */
void evil_test_libgen(TCase *tc);
void evil_test_main(TCase *tc);
/* void evil_test_mman(TCase *tc); */
@ -36,7 +33,7 @@ void evil_test_stdio(TCase *tc);
void evil_test_stdlib(TCase *tc);
/* void evil_test_string(TCase *tc); */
/* void evil_test_time(TCase *tc); */
/* void evil_test_unistd(TCase *tc); */
void evil_test_unistd(TCase *tc);
/* void evil_test_util(TCase *tc); */
#endif /* EVIL_SUITE_H_ */

View File

@ -0,0 +1,120 @@
/* EVIL - EFL library for Windows port
* Copyright (C) 2017 Vincent Torri
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library;
* if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdlib.h>
#include <stdio.h>
# define WIN32_LEAN_AND_MEAN
# include <winsock2.h>
# undef WIN32_LEAN_AND_MEAN
#include <Evil.h>
#include "evil_suite.h"
#define FDREAD 0
#define FDWRITE 1
typedef struct
{
int val;
int fd_write;
} data;
static DWORD WINAPI
thread(void *param)
{
data *d;
void *buf[1];
Sleep (2 * 1000);
d = (data *)param;
buf[0] = param;
send(d->fd_write, (char *)buf, sizeof(buf), 0);
return 0;
}
START_TEST(evil_unistd_pipe)
{
int sockets[2];
struct timeval t;
fd_set rfds;
int ret;
data *d;
DWORD thread_id;
HANDLE h;
ret = evil_init();
fail_if(ret == 0);
FD_ZERO(&rfds);
t.tv_sec = 5;
t.tv_usec = 0;
ret = pipe(sockets);
fail_if(ret < 0);
FD_SET(sockets[FDREAD], &rfds);
fcntl(sockets[FDREAD], F_SETFL, O_NONBLOCK);
d = (data *)malloc(sizeof (data));
fail_if(d == NULL);
d->val = 14;
d->fd_write = sockets[FDWRITE];
h = CreateThread(NULL, 0, thread, d, 0, &thread_id);
fail_if(h == NULL);
ret = select(sockets[FDREAD] + 1, &rfds, NULL, NULL, &t);
fail_if(ret <= 0);
{
void *buf[1];
data *d2 = NULL;
int len;
while ((len = recv(sockets[FDREAD], (char *)buf, sizeof(buf), 0)) > 0)
{
if (len == sizeof(buf))
{
d2 = (data *)buf[0];
break;
}
}
fail_if(!d2 || (d2->val != d->val));
}
CloseHandle(h);
free(d);
evil_shutdown();
}
END_TEST
void evil_test_unistd(TCase *tc)
{
tcase_add_test(tc, evil_unistd_pipe);
}