From 9397744af867ec09efba347cb46a1c7256f62514 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 18 Sep 2001 17:38:45 +0000 Subject: [PATCH] Add unit test framework using Check (http://check.sourceforge.net/). Only test included right now is a tiny one for one bytecode function, but will grow as time goes on. TODO: check for non ANSI C things required by Check. svn path=/trunk/yasm/; revision=190 --- Makefile.am | 2 +- check/Makefile.am | 23 +++++++++++++++++++ configure.ac | 3 +++ configure.in | 3 +++ frontends/yasm/yasm.c | 6 ++--- libyasm/linemgr.c | 34 ++++++++++++++++++++++++++++ libyasm/tests/.cvsignore | 5 +++++ libyasm/tests/Makefile.am | 21 ++++++++++++++++++ libyasm/tests/bytecode_test.c | 42 +++++++++++++++++++++++++++++++++++ src/Makefile.am | 25 ++++++++++++--------- src/globals.c | 34 ++++++++++++++++++++++++++++ src/linemgr.c | 34 ++++++++++++++++++++++++++++ src/main.c | 6 ++--- src/tests/.cvsignore | 5 +++++ src/tests/Makefile.am | 21 ++++++++++++++++++ src/tests/bytecode_test.c | 42 +++++++++++++++++++++++++++++++++++ tests/.cvsignore | 4 ++++ tests/Makefile.am | 16 +++++++++++++ 18 files changed, 307 insertions(+), 19 deletions(-) create mode 100644 check/Makefile.am create mode 100644 libyasm/linemgr.c create mode 100644 libyasm/tests/.cvsignore create mode 100644 libyasm/tests/Makefile.am create mode 100644 libyasm/tests/bytecode_test.c create mode 100644 src/globals.c create mode 100644 src/linemgr.c create mode 100644 src/tests/.cvsignore create mode 100644 src/tests/Makefile.am create mode 100644 src/tests/bytecode_test.c create mode 100644 tests/.cvsignore create mode 100644 tests/Makefile.am diff --git a/Makefile.am b/Makefile.am index 7ca62e4d..222c63ac 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # $IdPath$ -SUBDIRS = intl src po doc +SUBDIRS = check intl src po doc tests EXTRA_DIST = config/install-sh config/missing config/mkinstalldirs \ config/config.guess config/config.sub diff --git a/check/Makefile.am b/check/Makefile.am new file mode 100644 index 00000000..a8896465 --- /dev/null +++ b/check/Makefile.am @@ -0,0 +1,23 @@ +# $IdPath$ + +noinst_LIBRARIES=libcheck.a + +libcheck_a_SOURCES = \ + check.c \ + check_run.c \ + check.h \ + check_impl.h \ + check_msg.c \ + check_msg.h \ + check_log.c \ + check_log.h \ + check_print.c \ + check_print.h \ + error.c \ + error.h \ + list.c \ + list.h + +if DEV +CFLAGS = -ansi -pedantic -Wall -g +endif diff --git a/configure.ac b/configure.ac index 86969bd8..62d8d625 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,7 @@ case "$host" in esac AC_OUTPUT(Makefile + check/Makefile intl/Makefile po/Makefile.in src/Makefile @@ -97,8 +98,10 @@ AC_OUTPUT(Makefile src/optimizers/dbg/Makefile src/objfmts/Makefile src/objfmts/dbg/Makefile + src/tests/Makefile doc/Makefile doc/user/Makefile doc/programmer/Makefile doc/programmer/queue/Makefile + tests/Makefile ) diff --git a/configure.in b/configure.in index 86969bd8..62d8d625 100644 --- a/configure.in +++ b/configure.in @@ -86,6 +86,7 @@ case "$host" in esac AC_OUTPUT(Makefile + check/Makefile intl/Makefile po/Makefile.in src/Makefile @@ -97,8 +98,10 @@ AC_OUTPUT(Makefile src/optimizers/dbg/Makefile src/objfmts/Makefile src/objfmts/dbg/Makefile + src/tests/Makefile doc/Makefile doc/user/Makefile doc/programmer/Makefile doc/programmer/queue/Makefile + tests/Makefile ) diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c index eb8ce568..440f977e 100644 --- a/frontends/yasm/yasm.c +++ b/frontends/yasm/yasm.c @@ -32,6 +32,8 @@ # include #endif +#include "globals.h" + #include "bytecode.h" #include "section.h" #include "objfmt.h" @@ -40,10 +42,6 @@ RCSID("$IdPath$"); -char *filename = (char *)NULL; -unsigned int line_number = 1; -unsigned int mode_bits = 32; - int main(int argc, char *argv[]) { diff --git a/libyasm/linemgr.c b/libyasm/linemgr.c new file mode 100644 index 00000000..424c3e89 --- /dev/null +++ b/libyasm/linemgr.c @@ -0,0 +1,34 @@ +/* $IdPath$ + * Global variables + * + * Copyright (C) 2001 Peter Johnson + * + * This file is part of YASM. + * + * YASM is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * YASM 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "util.h" + +#include + +RCSID("$IdPath$"); + +char *filename = (char *)NULL; +unsigned int line_number = 1; +unsigned int mode_bits = 32; diff --git a/libyasm/tests/.cvsignore b/libyasm/tests/.cvsignore new file mode 100644 index 00000000..328232a9 --- /dev/null +++ b/libyasm/tests/.cvsignore @@ -0,0 +1,5 @@ +.*.sw? +Makefile.in +Makefile +.deps +bytecode_test diff --git a/libyasm/tests/Makefile.am b/libyasm/tests/Makefile.am new file mode 100644 index 00000000..bb97bc20 --- /dev/null +++ b/libyasm/tests/Makefile.am @@ -0,0 +1,21 @@ +# $IdPath$ + +TESTS = \ + bytecode_test + +noinst_PROGRAMS = \ + bytecode_test + +bytecode_test_SOURCES = \ + bytecode_test.c + +INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/check +LDADD = \ + $(top_builddir)/check/libcheck.a \ + $(top_builddir)/src/parsers/nasm/libparser.a \ + $(top_builddir)/src/preprocs/raw/libpreproc.a \ + $(top_builddir)/src/optimizers/dbg/liboptimizer.a \ + $(top_builddir)/src/objfmts/dbg/libobjfmt.a \ + $(top_builddir)/src/libyasm.a \ + $(INTLLIBS) + diff --git a/libyasm/tests/bytecode_test.c b/libyasm/tests/bytecode_test.c new file mode 100644 index 00000000..75697494 --- /dev/null +++ b/libyasm/tests/bytecode_test.c @@ -0,0 +1,42 @@ +/* $IdPath$ + * + */ +#include +#include "check.h" + +#include "util.h" + +#include "bytecode.h" + +START_TEST(test_ConvertRegToEA) +{ + effaddr static_val, *allocp, *retp; + + /* Test with static passing */ + fail_unless(ConvertRegToEA(&static_val, 1) == &static_val, + "No allocation should be performed if non-NULL passed in ptr"); +} +END_TEST + +Suite *bytecode_suite(void) +{ + Suite *s = suite_create("bytecode"); + TCase *tc_conversion = tcase_create("Conversion"); + + suite_add_tcase(s, tc_conversion); + tcase_add_test(tc_conversion, test_ConvertRegToEA); + + return s; +} + +int main(void) +{ + int nf; + Suite *s = bytecode_suite(); + SRunner *sr = srunner_create(s); + srunner_run_all(sr, CRNORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + suite_free(s); + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/src/Makefile.am b/src/Makefile.am index 22c133ce..36de584d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,21 +1,33 @@ # $IdPath$ -SUBDIRS = parsers preprocs optimizers objfmts +SUBDIRS = parsers preprocs optimizers objfmts . tests INCLUDES = -I$(top_builddir)/intl bin_PROGRAMS = yasm -yasm_SOURCES = \ +yasm_SOURCES = main.c + +yasm_LDADD = \ + parsers/nasm/libparser.a \ + preprocs/raw/libpreproc.a \ + optimizers/dbg/liboptimizer.a \ + objfmts/dbg/libobjfmt.a \ + libyasm.a \ + $(INTLLIBS) + +noinst_LIBRARIES = libyasm.a + +libyasm_a_SOURCES = \ bytecode.c \ bytecode.h \ errwarn.c \ errwarn.h \ expr.c \ expr.h \ - main.c \ symrec.c \ symrec.h \ + globals.c \ globals.h \ util.h \ section.h \ @@ -26,13 +38,6 @@ yasm_SOURCES = \ optimizer.h \ strcasecmp.c -yasm_LDADD = \ - parsers/nasm/libparser.a \ - preprocs/raw/libpreproc.a \ - optimizers/dbg/liboptimizer.a \ - objfmts/dbg/libobjfmt.a \ - $(INTLLIBS) - if DEV CFLAGS = -ansi -pedantic -Wall -g endif diff --git a/src/globals.c b/src/globals.c new file mode 100644 index 00000000..424c3e89 --- /dev/null +++ b/src/globals.c @@ -0,0 +1,34 @@ +/* $IdPath$ + * Global variables + * + * Copyright (C) 2001 Peter Johnson + * + * This file is part of YASM. + * + * YASM is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * YASM 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "util.h" + +#include + +RCSID("$IdPath$"); + +char *filename = (char *)NULL; +unsigned int line_number = 1; +unsigned int mode_bits = 32; diff --git a/src/linemgr.c b/src/linemgr.c new file mode 100644 index 00000000..424c3e89 --- /dev/null +++ b/src/linemgr.c @@ -0,0 +1,34 @@ +/* $IdPath$ + * Global variables + * + * Copyright (C) 2001 Peter Johnson + * + * This file is part of YASM. + * + * YASM is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * YASM 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "util.h" + +#include + +RCSID("$IdPath$"); + +char *filename = (char *)NULL; +unsigned int line_number = 1; +unsigned int mode_bits = 32; diff --git a/src/main.c b/src/main.c index eb8ce568..440f977e 100644 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,8 @@ # include #endif +#include "globals.h" + #include "bytecode.h" #include "section.h" #include "objfmt.h" @@ -40,10 +42,6 @@ RCSID("$IdPath$"); -char *filename = (char *)NULL; -unsigned int line_number = 1; -unsigned int mode_bits = 32; - int main(int argc, char *argv[]) { diff --git a/src/tests/.cvsignore b/src/tests/.cvsignore new file mode 100644 index 00000000..328232a9 --- /dev/null +++ b/src/tests/.cvsignore @@ -0,0 +1,5 @@ +.*.sw? +Makefile.in +Makefile +.deps +bytecode_test diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am new file mode 100644 index 00000000..bb97bc20 --- /dev/null +++ b/src/tests/Makefile.am @@ -0,0 +1,21 @@ +# $IdPath$ + +TESTS = \ + bytecode_test + +noinst_PROGRAMS = \ + bytecode_test + +bytecode_test_SOURCES = \ + bytecode_test.c + +INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/check +LDADD = \ + $(top_builddir)/check/libcheck.a \ + $(top_builddir)/src/parsers/nasm/libparser.a \ + $(top_builddir)/src/preprocs/raw/libpreproc.a \ + $(top_builddir)/src/optimizers/dbg/liboptimizer.a \ + $(top_builddir)/src/objfmts/dbg/libobjfmt.a \ + $(top_builddir)/src/libyasm.a \ + $(INTLLIBS) + diff --git a/src/tests/bytecode_test.c b/src/tests/bytecode_test.c new file mode 100644 index 00000000..75697494 --- /dev/null +++ b/src/tests/bytecode_test.c @@ -0,0 +1,42 @@ +/* $IdPath$ + * + */ +#include +#include "check.h" + +#include "util.h" + +#include "bytecode.h" + +START_TEST(test_ConvertRegToEA) +{ + effaddr static_val, *allocp, *retp; + + /* Test with static passing */ + fail_unless(ConvertRegToEA(&static_val, 1) == &static_val, + "No allocation should be performed if non-NULL passed in ptr"); +} +END_TEST + +Suite *bytecode_suite(void) +{ + Suite *s = suite_create("bytecode"); + TCase *tc_conversion = tcase_create("Conversion"); + + suite_add_tcase(s, tc_conversion); + tcase_add_test(tc_conversion, test_ConvertRegToEA); + + return s; +} + +int main(void) +{ + int nf; + Suite *s = bytecode_suite(); + SRunner *sr = srunner_create(s); + srunner_run_all(sr, CRNORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + suite_free(s); + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/tests/.cvsignore b/tests/.cvsignore new file mode 100644 index 00000000..de85485e --- /dev/null +++ b/tests/.cvsignore @@ -0,0 +1,4 @@ +.*.sw? +Makefile.in +Makefile +.deps diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 00000000..ab95ecbf --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,16 @@ +# $IdPath$ + +#TESTS = \ + +#noinst_PROGRAMS = \ + +INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/src -I$(top_srcdir)/check +LDADD = \ + $(top_builddir)/check/libcheck.a \ + $(top_builddir)/src/parsers/nasm/libparser.a \ + $(top_builddir)/src/preprocs/raw/libpreproc.a \ + $(top_builddir)/src/optimizers/dbg/liboptimizer.a \ + $(top_builddir)/src/objfmts/dbg/libobjfmt.a \ + $(top_builddir)/src/libyasm.a \ + $(INTLLIBS) + -- 2.40.0