]> granicus.if.org Git - yasm/commitdiff
Add unit test framework using Check (http://check.sourceforge.net/).
authorPeter Johnson <peter@tortall.net>
Tue, 18 Sep 2001 17:38:45 +0000 (17:38 -0000)
committerPeter Johnson <peter@tortall.net>
Tue, 18 Sep 2001 17:38:45 +0000 (17:38 -0000)
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

18 files changed:
Makefile.am
check/Makefile.am [new file with mode: 0644]
configure.ac
configure.in
frontends/yasm/yasm.c
libyasm/linemgr.c [new file with mode: 0644]
libyasm/tests/.cvsignore [new file with mode: 0644]
libyasm/tests/Makefile.am [new file with mode: 0644]
libyasm/tests/bytecode_test.c [new file with mode: 0644]
src/Makefile.am
src/globals.c [new file with mode: 0644]
src/linemgr.c [new file with mode: 0644]
src/main.c
src/tests/.cvsignore [new file with mode: 0644]
src/tests/Makefile.am [new file with mode: 0644]
src/tests/bytecode_test.c [new file with mode: 0644]
tests/.cvsignore [new file with mode: 0644]
tests/Makefile.am [new file with mode: 0644]

index 7ca62e4d16fc220f21cbf10d75d521a407518e06..222c63ac7ba7b219203b8b536437469938d08b81 100644 (file)
@@ -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 (file)
index 0000000..a889646
--- /dev/null
@@ -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
index 86969bd8b290ffd33e309c33889e324502bd3d38..62d8d6251c3f4c9b2b5d30f82251db7c7ec5389c 100644 (file)
@@ -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
 )
index 86969bd8b290ffd33e309c33889e324502bd3d38..62d8d6251c3f4c9b2b5d30f82251db7c7ec5389c 100644 (file)
@@ -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
 )
index eb8ce5686ced1244c9b7d93d85cdec0e2d6b6ac9..440f977ee9142e6687e54db984d14926356b461d 100644 (file)
@@ -32,6 +32,8 @@
 # include <string.h>
 #endif
 
+#include "globals.h"
+
 #include "bytecode.h"
 #include "section.h"
 #include "objfmt.h"
 
 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 (file)
index 0000000..424c3e8
--- /dev/null
@@ -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 <stdio.h>
+
+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 (file)
index 0000000..328232a
--- /dev/null
@@ -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 (file)
index 0000000..bb97bc2
--- /dev/null
@@ -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 (file)
index 0000000..7569749
--- /dev/null
@@ -0,0 +1,42 @@
+/* $IdPath$
+ *
+ */
+#include <stdlib.h>
+#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;
+}
index 22c133cea37788c2be4f12bc1d7cbf441cd771c5..36de584df8e648fc9f2057d5658dc2391a2f04e6 100644 (file)
@@ -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 (file)
index 0000000..424c3e8
--- /dev/null
@@ -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 <stdio.h>
+
+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 (file)
index 0000000..424c3e8
--- /dev/null
@@ -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 <stdio.h>
+
+RCSID("$IdPath$");
+
+char *filename = (char *)NULL;
+unsigned int line_number = 1;
+unsigned int mode_bits = 32;
index eb8ce5686ced1244c9b7d93d85cdec0e2d6b6ac9..440f977ee9142e6687e54db984d14926356b461d 100644 (file)
@@ -32,6 +32,8 @@
 # include <string.h>
 #endif
 
+#include "globals.h"
+
 #include "bytecode.h"
 #include "section.h"
 #include "objfmt.h"
 
 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 (file)
index 0000000..328232a
--- /dev/null
@@ -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 (file)
index 0000000..bb97bc2
--- /dev/null
@@ -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 (file)
index 0000000..7569749
--- /dev/null
@@ -0,0 +1,42 @@
+/* $IdPath$
+ *
+ */
+#include <stdlib.h>
+#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 (file)
index 0000000..de85485
--- /dev/null
@@ -0,0 +1,4 @@
+.*.sw?
+Makefile.in
+Makefile
+.deps
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..ab95ecb
--- /dev/null
@@ -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)
+