tests: Migrate the torture library to cmockery.
Этот коммит содержится в:
родитель
17f592d4dd
Коммит
635a263f64
@ -1,80 +0,0 @@
|
||||
#include "config.h"
|
||||
#include "torture.h"
|
||||
|
||||
#ifdef HAVE_ARGP_H
|
||||
#include <argp.h>
|
||||
|
||||
|
||||
const char *argp_program_version = "check test 0.1";
|
||||
const char *argp_program_bug_address = "<csync-devel@csync.org>";
|
||||
|
||||
static char **cmdline;
|
||||
|
||||
/* Program documentation. */
|
||||
static char doc[] = "check test";
|
||||
|
||||
/* The options we understand. */
|
||||
static struct argp_option options[] = {
|
||||
{
|
||||
.name = "no-fork",
|
||||
.key = 'n',
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Don't fork the testcases",
|
||||
.group = 0
|
||||
},
|
||||
{
|
||||
.name = "verbose",
|
||||
.key = 'v',
|
||||
.arg = NULL,
|
||||
.flags = 0,
|
||||
.doc = "Make libssh test more verbose",
|
||||
.group = 0
|
||||
},
|
||||
{NULL, 0, NULL, 0, NULL, 0}
|
||||
};
|
||||
|
||||
/* Parse a single option. */
|
||||
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
|
||||
/* Get the input argument from argp_parse, which we
|
||||
* know is a pointer to our arguments structure.
|
||||
*/
|
||||
struct argument_s *arguments = state->input;
|
||||
|
||||
/* arg is currently not used */
|
||||
(void) arg;
|
||||
|
||||
switch (key) {
|
||||
case 'n':
|
||||
arguments->nofork = 1;
|
||||
break;
|
||||
case 'v':
|
||||
arguments->verbose++;
|
||||
break;
|
||||
case ARGP_KEY_ARG:
|
||||
/* End processing here. */
|
||||
cmdline = &state->argv [state->next - 1];
|
||||
state->next = state->argc;
|
||||
break;
|
||||
default:
|
||||
return ARGP_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Our argp parser. */
|
||||
/* static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL}; */
|
||||
static struct argp argp = {options, parse_opt, NULL, doc, NULL, NULL, NULL};
|
||||
#endif /* HAVE_ARGP_H */
|
||||
|
||||
void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments) {
|
||||
/*
|
||||
* Parse our arguments; every option seen by parse_opt will
|
||||
* be reflected in arguments.
|
||||
*/
|
||||
#ifdef HAVE_ARGP_H
|
||||
argp_parse(&argp, argc, argv, 0, 0, arguments);
|
||||
#endif /* HAVE_ARGP_H */
|
||||
}
|
||||
|
@ -2,52 +2,12 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void torture_create_case(Suite *s, const char *name, TFun function) {
|
||||
TCase *tc_new = tcase_create(name);
|
||||
tcase_set_timeout(tc_new, 30);
|
||||
suite_add_tcase (s, tc_new);
|
||||
tcase_add_test(tc_new, function);
|
||||
}
|
||||
|
||||
void torture_create_case_fixture(Suite *s, const char *name, TFun function, void (*setup)(void), void (*teardown)(void)) {
|
||||
TCase *tc_new = tcase_create(name);
|
||||
tcase_add_checked_fixture(tc_new, setup, teardown);
|
||||
tcase_set_timeout(tc_new, 30);
|
||||
suite_add_tcase (s, tc_new);
|
||||
tcase_add_test(tc_new, function);
|
||||
}
|
||||
|
||||
void torture_create_case_timeout(Suite *s, const char *name, TFun function, int timeout) {
|
||||
TCase *tc_new = tcase_create(name);
|
||||
tcase_set_timeout(tc_new, timeout);
|
||||
suite_add_tcase (s, tc_new);
|
||||
tcase_add_test(tc_new, function);
|
||||
}
|
||||
|
||||
static int verbosity = 0;
|
||||
|
||||
int torture_libssh_verbosity(void){
|
||||
return verbosity;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Suite *s = NULL;
|
||||
SRunner *sr = NULL;
|
||||
struct argument_s arguments;
|
||||
int nf;
|
||||
|
||||
memset(&arguments,0,sizeof(struct argument_s));
|
||||
|
||||
torture_cmdline_parse(argc, argv, &arguments);
|
||||
verbosity=arguments.verbose;
|
||||
s = torture_make_suite();
|
||||
|
||||
sr = srunner_create(s);
|
||||
if (arguments.nofork) {
|
||||
srunner_set_fork_status(sr, CK_NOFORK);
|
||||
}
|
||||
srunner_run_all(sr, CK_VERBOSE);
|
||||
nf = srunner_ntests_failed(sr);
|
||||
srunner_free(sr);
|
||||
|
||||
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
return torture_run_tests();
|
||||
}
|
||||
|
@ -7,33 +7,13 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <check.h>
|
||||
|
||||
/* Used by main to communicate with parse_opt. */
|
||||
struct argument_s {
|
||||
char *args[2];
|
||||
int nofork;
|
||||
int verbose;
|
||||
};
|
||||
|
||||
void torture_cmdline_parse(int argc, char **argv, struct argument_s *arguments);
|
||||
|
||||
/* create_case() with timeout of 30seconds (default) */
|
||||
void torture_create_case(Suite *s, const char *name, TFun function);
|
||||
|
||||
/* create_case() with timeout of 30seconds (default) and fixture */
|
||||
void torture_create_case_fixture(Suite *s, const char *name, TFun function,
|
||||
void (*setup)(void), void (*teardown)(void));
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <google/cmockery.h>
|
||||
|
||||
/*
|
||||
* create_case_timeout() allow to specific a specific timeout - intended for
|
||||
* breaking testcases which needs longer then 30seconds (default)
|
||||
*/
|
||||
void torture_create_case_timeout(Suite *s, const char *name, TFun function,
|
||||
int timeout);
|
||||
|
||||
/*
|
||||
* returns the verbosity level asked by user
|
||||
* Returns the verbosity level asked by user
|
||||
*/
|
||||
int torture_libssh_verbosity(void);
|
||||
|
||||
@ -41,7 +21,6 @@ int torture_libssh_verbosity(void);
|
||||
/*
|
||||
* This function must be defined in every unit test file.
|
||||
*/
|
||||
Suite *torture_make_suite(void);
|
||||
|
||||
int torture_run_tests(void);
|
||||
|
||||
#endif /* _TORTURE_H */
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user