here, remove the bitrotted tests memexpr_test and bytecode_test.
* check: Deleted.
* Makefile.am: Unhook Check suite from build.
* configure.ac: Remove tests for things needed only for Check suite.
* memexpr_test.c: Delete.
* bytecode_test.c: Delete.
* libyasm/tests/Makefile.inc: Delete commented-out references to above.
* bitvect_test.c: Rewrite to not use Check suite.
* floatnum_test.c: Likewise.
* libyasm/tests/Makefile.inc: Don't reference Check suite.
svn path=/trunk/yasm/; revision=1178
# automake doesn't distribute mkinstalldirs?
EXTRA_DIST += config/mkinstalldirs
-EXTRA_DIST += check/Makefile.inc
EXTRA_DIST += tools/Makefile.inc
EXTRA_DIST += libyasm/Makefile.inc
EXTRA_DIST += modules/Makefile.inc
EXTRA_DIST += frontends/Makefile.inc
-include check/Makefile.inc
include tools/Makefile.inc
include libyasm/Makefile.inc
include modules/Makefile.inc
+++ /dev/null
-# $Id$
-
-CHECKFILES = check/check.c
-CHECKFILES += check/check_run.c
-CHECKFILES += check/check.h
-CHECKFILES += check/check_impl.h
-CHECKFILES += check/check_msg.c
-CHECKFILES += check/check_msg.h
-CHECKFILES += check/check_log.c
-CHECKFILES += check/check_log.h
-CHECKFILES += check/check_print.c
-CHECKFILES += check/check_print.h
-CHECKFILES += check/error.c
-CHECKFILES += check/error.h
-CHECKFILES += check/list.c
-CHECKFILES += check/list.h
-
-EXTRA_DIST += check/NEWS
-EXTRA_DIST += check/README
+++ /dev/null
-Thu Aug 23, 2001:
-Released Check 0.7.3
-
-Fixed the Autoconf Lyx check in acinclude.m4 so that configure works
-on Solaris systems (and hopefully others), and cleaned up a minor
-problem in Debian packaging.
-
-Fri Aug 17, 2001:
-Released Check 0.7.2
-
-Automated RPM packaging, and included debian packaging. The makefiles
-now has an rpm target (the RPMFLAGS variable can be set to add
-additional flags to RPM). Debian packages are built the ordinary way
-(dpkg-buildpackage).
-
-Moved the example*.* files to tutorial*.*, since the docs really are
-tutorials. Beefed up the tutorial docs to add clarity to the behavior
-of fixture setup/teardown (based on a helpful critique by Fred Drake),
-and to document the static nature of unit tests demanded by the bug
-fix below.
-
-Many bugfixes: added -Wall to the CCFLAGS for gcc, and fixed a mess of
-warnings that resulted. Changed a bizarre naming mismatch in
-tcase_set_fixture (masked by the lack of compile warnings), and made
-unit tests static (both bugfixes suggested by Fred Drake). Also added
-a more sophisticated test of Lyx to (hopefully) ensure that Lyx
-supports linuxdoc (but it's not clear to me how to test that for
-sure).
-
-
-Wed Jul 30, 2001:
-Released Check 0.7.1
-
-Reorganized printing and logging functions to allow for a less
-primitive logging function. Logging is now documented in the tutorial
-documentation.
-
-Wed Jul 11, 2001:
-Released Check 0.7.0
-
-Included a primitive logging function (at the moment, it only prints a
-copy of the CRVERBOSE output to the log file), added the ability for
-an SRunner to run multiple suites (and reorganized the Check tests to
-take advantage of that), and added the magic to allow Check to be used
-with C++.
-
-Also added Doxygen markup to the header file, but I'm not terribly
-satisfied withe clarity of the output. I may switch to CWEB... Next
-release should include API docs and improved logging, if nothing else
-comes up...
-
-
-Wed Jun 27, 2001:
-
-Released Check 0.6.1
-
-Bug fix for srunner_failures (bad version actually returned all
-results), added srunner_results to do what srunner_failures used to
-do, and added corrected unit tests for both.
-
-Also changed the API for reporting the number of failed tests from
-srunner_nfailed to srunner_ntests_failed, to harmonized better with
-new function srunner_ntests_run. This unfortunately may break some
-unit tests slightly -- that's why the major release number is 0 :-)
-
-Thu Jun 21, 2001:
-Released Check 0.6.0
-
-Features improved unit test reporting options, more complete unit
-tests, and end-to-end test, and a full API into TestResults
-
-Check 0.5.2
-Minor edits
-Check 0.5.1
-GPL compliance release
-Check 0.5.0
-Initial public release
+++ /dev/null
-Check is a unit test framework for C. It features a simple interface
-for defining unit tests, putting little in the way of the
-developer. Tests are run in a separate address space, so Check can
-catch both assertion failures and code errors that cause segmentation
-faults or other signals. The output from unit tests can be used within
-source code editors and IDEs.
-
-See http://check.sourceforge.net for more information, including a
-tutorial.
+++ /dev/null
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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 <stdio.h>
-
-#ifdef STDC_HEADERS
-# include <string.h>
-# include <stdlib.h>
-#endif
-
-#include "error.h"
-#include "list.h"
-#include "check.h"
-#include "check_impl.h"
-#include "check_msg.h"
-
-#ifndef USE_FORKWAITMSG
-extern int nofork_exit_status;
-#endif
-
-Suite *suite_create (const char *name)
-{
- Suite *s;
- s = emalloc (sizeof(Suite)); /* freed in suite_free */
- if (name == NULL)
- s->name = "";
- else
- s->name = name;
- s->tclst = list_create();
- return s;
-}
-
-void suite_free (Suite *s)
-{
- List *l;
- if (s == NULL)
- return;
- for (l = s->tclst; !list_at_end(l); list_advance (l)) {
- tcase_free (list_val(l));
- }
- list_free (s->tclst);
- free(s);
-}
-
-TCase *tcase_create (const char *name)
-{
- TCase *tc = emalloc (sizeof(TCase)); /*freed in tcase_free */
- if (name == NULL)
- tc->name = "";
- else
- tc->name = name;
- tc->tflst = list_create();
- tc->setup = tc->teardown = NULL;
-
- return tc;
-}
-
-
-void tcase_free (TCase *tc)
-{
- List *l;
- l = tc->tflst;
- for (list_front(l); !list_at_end(l); list_advance(l)) {
- free (list_val(l));
- }
- list_free(tc->tflst);
- free(tc);
-}
-
-void suite_add_tcase (Suite *s, TCase *tc)
-{
- if (s == NULL || tc == NULL)
- return;
- list_add_end (s->tclst, tc);
-}
-
-void tcase_add_test_ (TCase *tc, TFun fn, const char *name)
-{
- TF * tf;
- if (tc == NULL || fn == NULL || name == NULL)
- return;
- tf = emalloc (sizeof(TF)); /* freed in tcase_free */
- tf->fn = fn;
- tf->name = name;
- list_add_end (tc->tflst, tf);
-}
-
-void tcase_set_fixture (TCase *tc, SFun setup, SFun teardown)
-{
- tc->setup = setup;
- tc->teardown = teardown;
-}
-
-
-void tcase_fn_start (int msqid, const char *fname, const char *file, int line)
-{
- send_last_loc_msg (msqid, file, line);
-}
-
-void mark_point_ (int msqid, char *file, int line)
-{
- send_last_loc_msg (msqid, file, line);
-}
-
-int fail_unless_ (int msqid, int result, const char *file, int line,
- const char * msg)
-{
- if (line > MAXLINE)
- eprintf ("Line number %d too large to use", line);
-
- send_last_loc_msg (msqid, file, line);
- if (!result) {
- send_failure_msg (msqid, msg);
-#ifdef USE_FORKWAITMSG
- exit(1);
-#else
- nofork_exit_status = 1;
- return 1;
-#endif
- }
- return 0;
-}
+++ /dev/null
-#ifndef CHECK_H
-#define CHECK_H
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-/* Comments are in Doxygen format: see http://www.stack.nl/~dimitri/doxygen/ */
-
-/*! \mainpage Check: a unit test framework for C
-
-\section overview
-
-Overview Check is a unit test framework for C. It features a simple
-interface for defining unit tests, putting little in the way of the
-developer. Tests are run in a separate address space, so Check can
-catch both assertion failures and code errors that cause segmentation
-faults or other signals. The output from unit tests can be used within
-source code editors and IDEs.
-
-\section quickref Quick Reference
-
-\subsection creating Creating
-
-\par
-
-Unit tests are created with the #START_TEST/#END_TEST macro pair. The
-#fail_unless and #fail macros are used for creating checks within unit
-tests; the #mark_point macro is useful for trapping the location of
-signals and/or early exits.
-
-\subsection managing Managing test cases and suites
-
-\par
-
-Test cases are created with #tcase_create, unit tests are added
-with #tcase_add_test
-
-\par
-
-Suites are created with #suite_create, freed with #suite_free; test
-cases are added with #suite_add_tcase
-
-\subsection running Running suites
-
-\par
-
-Suites are run through an SRunner, which is created with
-#srunner_create, freed with #srunner_free. Additional suites can be
-added to an SRunner with #srunner_add_suite.
-
-\par
-
-Use #srunner_run_all to run a suite and print results.
-
-*/
-
-/*! \file check.h */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*! Magic values */
-enum {
- CMAXMSG = 100 /*!< maximum length of a message, including terminating nul */
-};
-
-/*! \defgroup check_core Check Core
- Core suite/test case types and functions
- @{
-*/
-
-/*! \brief opaque type for a test suite */
-typedef struct Suite Suite;
-
-/*! \brief opaque type for a test case
-
-A TCase represents a test case. Create with #tcase_create, free with
-#tcase_free. For the moment, test cases can only be run through a
-suite
-*/
-
-typedef struct TCase TCase;
-
-/*! type for a test function */
-typedef void (*TFun) (int);
-
-/*! type for a setup/teardown function */
-typedef void (*SFun) (void);
-
-/*! Create a test suite */
-Suite *suite_create (const char *name);
-
-/*! Free a test suite
- (For the moment, this also frees all contained test cases) */
-void suite_free (Suite *s);
-
-/*! Create a test case */
-TCase *tcase_create (const char *name);
-
-/*! Free a test case
- (Note that as it stands, one will normally free the contaning suite) */
-void tcase_free (TCase *tc);
-
-/*! Add a test case to a suite */
-void suite_add_tcase (Suite *s, TCase *tc);
-
-/*! Add a test function to a test case
- (macro version) */
-#define tcase_add_test(tc,tf) tcase_add_test_(tc,tf,"" # tf "")
-/*! Add a test function to a test case
- (function version -- use this when the macro won't work */
-void tcase_add_test_ (TCase *tc, TFun tf, const char *fname);
-
-/*!
-
-Add fixture setup/teardown functions to a test case Note that
-setup/teardown functions are not run in a separate address space, like
-test functions, and so must not exit or signal (e.g., segfault)
-
-*/
-void tcase_set_fixture(TCase *tc, SFun setup, SFun teardown);
-
-/*! Internal function to mark the start of a test function */
-void tcase_fn_start (int msqid, const char *fname, const char *file, int line);
-
-/*! Start a unit test with START_TEST(unit_name), end with END_TEST
- One must use braces within a START_/END_ pair to declare new variables */
-#define START_TEST(testname__)\
-static void testname__ (int msqid__)\
-{\
- tcase_fn_start (msqid__,""# testname__, __FILE__, __LINE__);
-
-/*! End a unit test */
-#define END_TEST }
-
-
-/*! Fail the test case unless result is true */
-#define fail_unless(result,msg) \
- if(fail_unless_(msqid__,result,__FILE__,__LINE__,msg)) return;
-
-/*! Non macro version of #fail_unless, with more complicated interface */
-int fail_unless_ (int msqid, int result, const char *file, int line,
- const char *msg);
-
-/*! Always fail */
-#define fail(msg) fail_unless_(msqid__,0,__FILE__,__LINE__,msg)
-
-/*! Mark the last point reached in a unit test
- (useful for tracking down where a segfault, etc. occurs */
-#define mark_point() mark_point_(msqid__,__FILE__,__LINE__)
-/*! Non macro version of #mark_point */
-void mark_point_ (int msqid, char *file, int line);
-
-/*! @} */
-
-/*! \defgroup check_run Suite running functions
- @{
-*/
-
-
-/*! Result of a test */
-enum test_result {
- CRPASS, /*!< Test passed*/
- CRFAILURE, /*!< Test completed but failed */
- CRERROR /*!< Test failed to complete (signal or non-zero early exit) */
-};
-
-/*! Specifies the verbosity of srunner printing */
-enum print_verbosity {
- CRSILENT, /*!< No output */
- CRMINIMAL, /*!< Only summary output */
- CRNORMAL, /*!< All failed tests */
- CRVERBOSE, /*!< All tests */
- CRLAST
-};
-
-
-/*! Holds state for a running of a test suite */
-typedef struct SRunner SRunner;
-
-/*! Opaque type for a test failure */
-typedef struct TestResult TestResult;
-
-/* accessors for tr fields */
-
-/*! Type of result */
-int tr_rtype (TestResult *tr);
-/*! Failure message */
-char *tr_msg (TestResult *tr);
-/*! Line number at which failure occured */
-int tr_lno (TestResult *tr);
-/*! File name at which failure occured */
-char *tr_lfile (TestResult *tr);
-/*! Test case in which unit test was run */
-const char *tr_tcname (TestResult *tr);
-
-/*! Creates an SRunner for the given suite */
-SRunner *srunner_create (Suite *s);
-
-/*! Adds a Suite to an SRunner */
-void srunner_add_suite (SRunner *sr, Suite *s);
-
-/*! Frees an SRunner */
-void srunner_free (SRunner *sr);
-
-/* Test running */
-
-/*! Runs an SRunner, printing results as specified
- (see enum #print_verbosity)*/
-void srunner_run_all (SRunner *sr, int print_mode);
-
-/* Next functions are valid only after the suite has been
- completely run, of course */
-
-/*! Number of failed tests in a run suite
- Includes failures + errors */
-int srunner_ntests_failed (SRunner *sr);
-
-/*! Total number of tests run in a run suite */
-int srunner_ntests_run (SRunner *sr);
-
-/*! \brief Return an array of results for all failures
-
- Number of failures is equal to #srunner_nfailed_tests. Memory is
- alloc'ed and must be freed, but individual TestResults must not */
-
-TestResult **srunner_failures (SRunner *sr);
-
-/*! \brief Return an array of results for all run tests
-
-Number of failrues is equal to #srunner_ntests_run Memory is alloc'ed
-and must be freed, but individual TestResults must not */
-
-TestResult **srunner_results (SRunner *sr);
- /* Printing */
-
-/*! Print the results contained in an SRunner
-
-\param sr SRunner for which results are printed
-
-\param print_mode Specification of print verbosity, constrainted to
-enum #print_verbosity
-*/
- void srunner_print (SRunner *sr, int print_mode);
-
-/*! @} */
-
-
-/*! \defgroup check_log Logging functions
- @{
-*/
-
-/*! Set a log file to which to write during test running.
- Log file setting is an initialize only operation -- it should be done
- immediatly after SRunner creation, and the log file can't be changed
- after being set.
- \param sr The SRunner for which to enable logging
- \param fname The file name to which to write the log
- */
-void srunner_set_log (SRunner *sr, char *fname);
-
-/*! Does the SRunner have a log file?
- \param sr The SRunner to test
- \return True if logging, False otherwise
-*/
-int srunner_has_log (SRunner *sr);
-
-/*! Return the name of the log file, or NULL if none
- \param sr The SRunner to query
- \return The current log file, or NULL if not logging
-*/
-char *srunner_log_fname (SRunner *sr);
-
-/*! @} */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* CHECK_H */
+++ /dev/null
-#ifndef CHECK_IMPL_H
-#define CHECK_IMPL_H
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-/* This header should be included by any module that needs
- to know the implementation details of the check structures
- Include stdio.h & list.h before this header
-*/
-
-/* magic values */
-
-enum {
- MAXLINE = 9999 /* maximum line no */
-};
-
-typedef struct TF {
- TFun fn;
- const char *name;
-} TF;
-
-struct Suite {
- const char *name;
- List *tclst; /* List of test cases */
-};
-
-struct TCase {
- const char *name;
- List *tflst; /* list of test functions */
- SFun setup;
- SFun teardown;
-};
-
-typedef struct TestStats {
- int n_checked;
- int n_failed;
- int n_errors;
-} TestStats;
-
-struct TestResult {
- int rtype; /* Type of result */
- char *file; /* File where the test occured */
- int line; /* Line number where the test occurred */
- const char *tcname; /* Test case that generated the result */
- const char *tfname; /* Test function that generated the result */
- char *msg; /* Failure message */
-};
-
-enum cl_event {
- CLSTART_SR,
- CLSTART_S,
- CLEND_SR,
- CLEND_S,
- CLEND_T
-};
-
-typedef void (*LFun) (SRunner *, FILE*, enum print_verbosity,
- void *, enum cl_event);
-
-typedef struct Log {
- FILE *lfile;
- LFun lfun;
- int close;
- enum print_verbosity mode;
-} Log;
-
-struct SRunner {
- List *slst;
- TestStats *stats;
- List *resultlst;
- char *log_fname;
- List *loglst;
-};
-
-
-#endif /* CHECK_IMPL_H */
+++ /dev/null
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef STDC_HEADERS
-# include <stdlib.h>
-#endif
-
-#include <stdio.h>
-#include <check.h>
-#include "list.h"
-#include "error.h"
-#include "check_impl.h"
-#include "check_log.h"
-#include "check_print.h"
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt);
-
-void srunner_set_log (SRunner *sr, char *fname)
-{
- if (sr->log_fname)
- return;
- sr->log_fname = fname;
-}
-
-int srunner_has_log (SRunner *sr)
-{
- return sr->log_fname != NULL;
-}
-
-char *srunner_log_fname (SRunner *sr)
-{
- return sr->log_fname;
-}
-
-void srunner_register_lfun (SRunner *sr, FILE *lfile, int doclose,
- LFun lfun, enum print_verbosity printmode)
-{
- Log *l = emalloc (sizeof(Log));
- l->lfile = lfile;
- l->lfun = lfun;
- l->close = doclose;
- l->mode = printmode;
- list_add_end (sr->loglst, l);
- return;
-}
-
-void log_srunner_start (SRunner *sr)
-{
- srunner_send_evt (sr, NULL, CLSTART_SR);
-}
-
-void log_srunner_end (SRunner *sr)
-{
- srunner_send_evt (sr, NULL, CLEND_SR);
-}
-
-void log_suite_start (SRunner *sr, Suite *s)
-{
- srunner_send_evt (sr, s, CLSTART_S);
-}
-
-void log_suite_end (SRunner *sr, Suite *s)
-{
- srunner_send_evt (sr, s, CLEND_S);
-}
-
-void log_test_end (SRunner *sr, TestResult *tr)
-{
- srunner_send_evt (sr, tr, CLEND_T);
-}
-
-static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt)
-{
- List *l;
- Log *lg;
- l = sr->loglst;
- for (list_front(l); !list_at_end(l); list_advance(l)) {
- lg = list_val(l);
- fflush(lg->lfile);
- lg->lfun (sr, lg->lfile, lg->mode, obj, evt);
- fflush(lg->lfile);
- }
-}
-
-void stdout_lfun (SRunner *sr, FILE *file, enum print_verbosity printmode,
- void *obj, enum cl_event evt)
-{
- TestResult *tr;
- Suite *s;
-
- switch (evt) {
- case CLSTART_SR:
- if (printmode > CRSILENT) {
- fprintf(file, "Running suite(s):");
- }
- break;
- case CLSTART_S:
- s = obj;
- if (printmode > CRSILENT) {
- fprintf(file, " %s", s->name);
- }
- break;
- case CLEND_SR:
- if (printmode > CRSILENT) {
- fprintf (file, "\n");
- srunner_fprint (file, sr, printmode);
- }
- break;
- case CLEND_S:
- s = obj;
- break;
- case CLEND_T:
- tr = obj;
- break;
- default:
- eprintf("Bad event type received in stdout_lfun");
- }
-
-
-}
-
-void lfile_lfun (SRunner *sr, FILE *file, enum print_verbosity printmode,
- void *obj, enum cl_event evt)
-{
- TestResult *tr;
- Suite *s;
-
- switch (evt) {
- case CLSTART_SR:
- break;
- case CLSTART_S:
- s = obj;
- fprintf(file, "Running suite %s\n", s->name);
- break;
- case CLEND_SR:
- fprintf (file, "Results for all suites run:\n");
- srunner_fprint (file, sr, CRMINIMAL);
- break;
- case CLEND_S:
- s = obj;
- break;
- case CLEND_T:
- tr = obj;
- tr_fprint(file, tr, CRVERBOSE);
- break;
- default:
- eprintf("Bad event type received in stdout_lfun");
- }
-
-
-}
-
-FILE *srunner_open_lfile (SRunner *sr)
-{
- FILE *f = NULL;
- if (srunner_has_log (sr)) {
- f = fopen(sr->log_fname, "w");
- if (f == NULL)
- eprintf ("Could not open log file %s:", sr->log_fname);
- }
- return f;
-}
-
-void srunner_init_logging (SRunner *sr, enum print_verbosity print_mode)
-{
- FILE *f;
- sr->loglst = list_create();
- srunner_register_lfun (sr, stdout, 0, stdout_lfun, print_mode);
- f = srunner_open_lfile (sr);
- if (f) {
- srunner_register_lfun (sr, f, 1, lfile_lfun, print_mode);
- }
-}
-
-void srunner_end_logging (SRunner *sr)
-{
- List *l;
- int rval;
-
- l = sr->loglst;
- for (list_front(l); !list_at_end(l); list_advance(l)) {
- Log *lg = list_val(l);
- if (lg->close) {
- rval = fclose (lg->lfile);
- if (rval != 0)
- eprintf ("Error closing log file:");
- }
- free (lg);
- }
- list_free(l);
- sr->loglst = NULL;
-}
+++ /dev/null
-#ifndef CHECK_LOG_H
-#define CHECK_LOG_H
-
-void log_srunner_start (SRunner *sr);
-void log_srunner_end (SRunner *sr);
-void log_suite_start (SRunner *sr, Suite *s);
-void log_suite_end (SRunner *sr, Suite *s);
-void log_test_end (SRunner *sr, TestResult *tr);
-
-void stdout_lfun (SRunner *sr, FILE *file, enum print_verbosity,
- void *obj, enum cl_event evt);
-
-void lfile_lfun (SRunner *sr, FILE *file, enum print_verbosity,
- void *obj, enum cl_event evt);
-
-void srunner_register_lfun (SRunner *sr, FILE *lfile, int doclose,
- LFun lfun, enum print_verbosity);
-
-FILE *srunner_open_lfile (SRunner *sr);
-void srunner_init_logging (SRunner *sr, enum print_verbosity print_mode);
-void srunner_end_logging (SRunner *sr);
-
-#endif /* CHECK_LOG_H */
+++ /dev/null
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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 <stdio.h>
-
-#ifdef STDC_HEADERS
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#endif
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_IPC_H
-# include <sys/ipc.h>
-#endif
-
-#ifdef HAVE_SYS_MSG_H
-# include <sys/msg.h>
-#endif
-
-#include "list.h"
-#include "error.h"
-#include "check.h"
-#include "check_impl.h"
-#include "check_msg.h"
-
-#ifndef USE_FORKWAITMSG
-static LastLocMsg *nofork_lastlocmsg;
-static FailureMsg *nofork_failuremsg;
-#endif
-
-enum {
- LASTLOCMSG = 1,
- FAILUREMSG = 2
-};
-static LastLocMsg *create_last_loc_msg (const char *file, int line);
-static FailureMsg *create_failure_msg (const char *msg);
-
-static FailureMsg *create_failure_msg (const char *msg)
-{
- FailureMsg *m = emalloc (sizeof(FailureMsg));
- m->message_type = (long int) FAILUREMSG;
- strncpy(m->msg, msg, CMAXMSG);
- return m;
-}
-
-
-static LastLocMsg *create_last_loc_msg (const char *file, int line)
-{
- LastLocMsg *m = emalloc (sizeof(LastLocMsg));
- m->message_type = (long int) LASTLOCMSG;
-#ifdef HAVE_SNPRINTF
- snprintf(m->msg, CMAXMSG, "%s\n%d", file, line);
-#else
- sprintf(m->msg, "%s\n%d", file, line);
-#endif
-
- return m;
-}
-
-char *last_loc_file (LastLocMsg *msg)
-{
- int i;
- char *rmsg = emalloc (CMAXMSG); /* caller responsible for freeing */
- char *mmsg = msg->msg;
- if (msg == NULL)
- return NULL;
- for (i = 0; mmsg[i] != '\n'; i++) {
- if (mmsg[i] == '\0')
- eprintf ("Badly formated last loc message");
- rmsg[i] = mmsg[i];
- }
- rmsg[i] = '\0';
- return rmsg;
-}
-
-int last_loc_line (LastLocMsg *msg)
-{
- char *rmsg;
- if (msg == NULL)
- return -1;
- rmsg = msg->msg;
- while (*rmsg != '\n') {
- if (*rmsg == '\0')
- eprintf ("Badly formated last loc message");
- rmsg++;
- }
- rmsg++; /*advance past \n */
- return atoi (rmsg);
-}
-
-
-void send_last_loc_msg (int msqid, const char * file, int line)
-{
-#ifdef USE_FORKWAITMSG
- int rval;
- LastLocMsg *rmsg = create_last_loc_msg(file, line);
- rval = msgsnd(msqid, (void *) rmsg, CMAXMSG, IPC_NOWAIT);
- if (rval == -1) {
- eprintf ("send_last_loc_msg:Failed to send message, msqid = %d:",msqid);
- }
- free(rmsg);
-#else
- nofork_lastlocmsg = create_last_loc_msg(file, line);
-#endif
-}
-
-int create_msq (void) {
-#ifdef USE_FORKWAITMSG
- int msqid;
- msqid = msgget((key_t) 1, 0666 | IPC_CREAT);
- if (msqid == -1)
- eprintf ("Unable to create message queue:");
- return msqid;
-#else
- return 0;
-#endif
-}
-
-void delete_msq (int msqid)
-{
-#ifdef USE_FORKWAITMSG
- if (msgctl (msqid, IPC_RMID, NULL) == -1)
- eprintf ("Failed to free message queue:");
-#endif
-}
-
-
-void send_failure_msg (int msqid, const char *msg)
-{
-#ifdef USE_FORKWAITMSG
- int rval;
-
- FailureMsg *rmsg = create_failure_msg(msg);
-
- rval = msgsnd(msqid, (void *) rmsg, CMAXMSG, IPC_NOWAIT);
- if (rval == -1)
- eprintf ("send_failure_msg:Failed to send message:");
- free(rmsg);
-#else
- nofork_failuremsg = create_failure_msg(msg);
-#endif
-}
-
-LastLocMsg *receive_last_loc_msg (int msqid)
-{
-#ifdef USE_FORKWAITMSG
- LastLocMsg *rmsg = emalloc(sizeof(LastLocMsg)); /* caller responsible for freeing */
- while (1) {
- int rval;
- rval = msgrcv(msqid, (void *) rmsg, CMAXMSG, LASTLOCMSG, IPC_NOWAIT);
- if (rval == -1) {
- if (errno == ENOMSG)
- break;
- eprintf ("receive_last_loc_msg:Failed to receive message:");
- }
- }
- return rmsg;
-#else
- LastLocMsg *rmsg = nofork_lastlocmsg;
- nofork_lastlocmsg = NULL;
- return rmsg;
-#endif
-}
-
-FailureMsg *receive_failure_msg (int msqid)
-{
-#ifdef USE_FORKWAITMSG
- FailureMsg *rmsg = emalloc(sizeof(FailureMsg));
- int rval;
- rval = msgrcv(msqid, (void *) rmsg, CMAXMSG, FAILUREMSG, IPC_NOWAIT);
- if (rval == -1) {
- if (errno == ENOMSG)
- return NULL;
- eprintf ("receive_failure_msg:Failed to receive message:");
- }
- return rmsg;
-#else
- FailureMsg *rmsg = nofork_failuremsg;
- nofork_failuremsg = NULL;
- return rmsg;
-#endif
-}
-
+++ /dev/null
-#ifndef CHECK_MSG_H
-#define CHECK_MSG_H
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-/* Functions implementing messaging during test runs */
-/* check.h must be included before this header */
-
-
-typedef struct LastLocMsg {
- long int message_type;
- char msg[CMAXMSG]; /* Format: filename\nlineno\0 */
-} LastLocMsg;
-
-typedef struct FailureMsg {
- long int message_type;
- char msg[CMAXMSG];
-} FailureMsg;
-
-int create_msq (void);
-void delete_msq (int msqid);
-
-void send_failure_msg (int msqid, const char *msg);
-void send_last_loc_msg (int msqid, const char * file, int line);
-
-/* malloc'd return value which caller is responsible for
- freeing in each of the next two functions */
-FailureMsg *receive_failure_msg (int msqid);
-LastLocMsg *receive_last_loc_msg (int msqid);
-
-/* file name contained in the LastLocMsg */
-/* return value is malloc'd, caller responsible for freeing */
-char *last_loc_file(LastLocMsg *msg);
-int last_loc_line(LastLocMsg *msg);
-
-#endif /*CHECK_MSG_H */
+++ /dev/null
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-#include <stdio.h>
-#include <check.h>
-#include "list.h"
-#include "check_impl.h"
-#include "check_print.h"
-#include "error.h"
-
-static void srunner_fprint_summary (FILE *file, SRunner *sr, int print_mode);
-static void srunner_fprint_results (FILE *file, SRunner *sr, int print_mode);
-
-static int percent_passed (TestStats *t);
-static const char *rtype_to_string (int rtype);
-
-void srunner_print (SRunner *sr, int print_mode)
-{
- srunner_fprint (stdout, sr, print_mode);
-}
-
-void srunner_fprint (FILE *file, SRunner *sr, int print_mode)
-{
- srunner_fprint_summary (file, sr, print_mode);
- srunner_fprint_results (file, sr, print_mode);
-}
-
-static void srunner_fprint_summary (FILE *file, SRunner *sr, int print_mode)
-{
- TestStats *ts = sr->stats;
- if (print_mode >= CRMINIMAL) {
- fprintf (file, "%d%%: Checks: %d, Failures: %d, Errors: %d\n",
- percent_passed (ts), ts->n_checked, ts->n_failed,
- ts->n_errors);
- }
- return;
-}
-
-static void srunner_fprint_results (FILE *file, SRunner *sr, int print_mode)
-{
- List *resultlst;
-
- resultlst = sr->resultlst;
-
- for (list_front(resultlst); !list_at_end(resultlst); list_advance(resultlst)) {
- TestResult *tr = list_val(resultlst);
- tr_fprint (file, tr, print_mode);
- }
- return;
-}
-
-void tr_fprint (FILE *file, TestResult *tr, int print_mode)
-{
- const char *exact_msg;
- exact_msg = (tr->rtype == CRERROR) ? "(after this point) ": "";
- if ((print_mode >= CRVERBOSE && tr->rtype == CRPASS) ||
- (tr->rtype != CRPASS && print_mode >= CRNORMAL)) {
- fprintf (file, "%s:%d:%s:%s:%s: %s%s\n",
- tr->file, tr->line,
- rtype_to_string(tr->rtype), tr->tcname,
- tr->tfname,
- exact_msg, tr->msg);
- }
-}
-
-static int percent_passed (TestStats *t)
-{
- if (t->n_failed == 0 && t->n_errors == 0)
- return 100;
- else
- return (int) ( (float) (t->n_checked - (t->n_failed + t->n_errors)) /
- (float) t->n_checked * 100);
-}
-
-static const char *rtype_to_string (int rtype)
-{
- switch (rtype) {
- case CRPASS:
- return "P";
- break;
- case CRFAILURE:
- return "F";
- break;
- case CRERROR:
- return "E";
- break;
- default:
- eprintf("Bad argument %d to rtype_to_string", rtype);
- return NULL;
- }
-}
+++ /dev/null
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-#ifndef CHECK_PRINT_H
-#define CHECK_PRINT_H
-
-void tr_fprint (FILE *file, TestResult *tr, int print_mode);
-void srunner_fprint (FILE *file, SRunner *sr, int print_mode);
-
-
-#endif /* CHECK_PRINT_H */
+++ /dev/null
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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
-
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_SYS_WAIT_H
-# include <sys/wait.h>
-#endif
-#ifndef WIFSIGNALED
-# define WIFSIGNALED(stat_val) \
- (((stat_val) & 255) != 255 && \
- ((stat_val) & 255) != 0)
-#endif
-#ifndef WTERMSIG
-# define WTERMSIG(stat_val) ((stat_val) & 255)
-#endif
-#ifndef WIFEXITED
-# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
-#endif
-#ifndef WEXITSTATUS
-# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
-#endif
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-#include <stdio.h>
-
-#ifdef STDC_HEADERS
-# include <stdlib.h>
-# include <stdarg.h>
-#endif
-
-#include "error.h"
-#include "list.h"
-#include "check.h"
-#include "check_impl.h"
-#include "check_msg.h"
-#include "check_log.h"
-
-#ifndef USE_FORKWAITMSG
-int nofork_exit_status;
-#endif
-
-static void srunner_run_tcase (SRunner *sr, TCase *tc);
-static void srunner_add_failure (SRunner *sr, TestResult *tf);
-static TestResult *tfun_run (int msqid, const char *tcname, TF *tf);
-static TestResult *receive_result_info (int msqid, int status,
- const char *tcname,
- const char *tfname);
-static void receive_last_loc_info (int msqid, TestResult *tr);
-static void receive_failure_info (int msqid, int status, TestResult *tr);
-static List *srunner_resultlst (SRunner *sr);
-
-
-#ifdef USE_FORKWAITMSG
-static char *signal_msg (int sig);
-#endif
-static char *exit_msg (int exitstatus);
-static int non_pass (int val);
-
-
-SRunner *srunner_create (Suite *s)
-{
- SRunner *sr = emalloc (sizeof(SRunner)); /* freed in srunner_free */
- sr->slst = list_create();
- list_add_end(sr->slst, s);
- sr->stats = emalloc (sizeof(TestStats)); /* freed in srunner_free */
- sr->stats->n_checked = sr->stats->n_failed = sr->stats->n_errors = 0;
- sr->resultlst = list_create();
- sr->log_fname = NULL;
- sr->loglst = NULL;
- return sr;
-}
-
-void srunner_add_suite (SRunner *sr, Suite *s)
-{
- list_add_end(sr->slst, s);
-}
-
-void srunner_free (SRunner *sr)
-{
- List *l;
- TestResult *tr;
- if (sr == NULL)
- return;
-
- free (sr->stats);
- list_free(sr->slst);
-
- l = sr->resultlst;
- for (list_front(l); !list_at_end(l); list_advance(l)) {
- tr = list_val(l);
- free(tr->file);
- free(tr->msg);
- free(tr);
- }
- list_free (sr->resultlst);
-
- free (sr);
-}
-
-
-
-void srunner_run_all (SRunner *sr, int print_mode)
-{
- List *slst;
- List *tcl;
- TCase *tc;
- if (sr == NULL)
- return;
- if (print_mode < 0 || print_mode >= CRLAST)
- eprintf("Bad print_mode argument to srunner_run_all: %d", print_mode);
-
- srunner_init_logging (sr, print_mode);
-
- log_srunner_start (sr);
-
- slst = sr->slst;
-
- for (list_front(slst); !list_at_end(slst); list_advance(slst)) {
- Suite *s = list_val(slst);
-
- log_suite_start (sr, s);
-
- tcl = s->tclst;
-
- for (list_front(tcl);!list_at_end (tcl); list_advance (tcl)) {
- tc = list_val (tcl);
- srunner_run_tcase (sr, tc);
- }
- }
-
- log_srunner_end (sr);
-
- srunner_end_logging (sr);
-}
-
-static void srunner_add_failure (SRunner *sr, TestResult *tr)
-{
- sr->stats->n_checked++;
- list_add_end (sr->resultlst, tr);
- switch (tr->rtype) {
-
- case CRPASS:
- return;
- case CRFAILURE:
- sr->stats->n_failed++;
- return;
- case CRERROR:
- sr->stats->n_errors++;
- return;
- }
-}
-
-
-static void srunner_run_tcase (SRunner *sr, TCase *tc)
-{
- List *tfl;
- TF *tfun;
- TestResult *tr;
- int msqid;
-
- if (tc->setup)
- tc->setup();
- msqid = create_msq();
- tfl = tc->tflst;
-
- for (list_front(tfl); !list_at_end (tfl); list_advance (tfl)) {
- tfun = list_val (tfl);
- tr = tfun_run (msqid, tc->name, tfun);
- srunner_add_failure (sr, tr);
- log_test_end(sr, tr);
- }
- delete_msq(msqid);
- if (tc->teardown)
- tc->teardown();
-}
-
-static void receive_last_loc_info (int msqid, TestResult *tr)
-{
- LastLocMsg *lmsg;
- lmsg = receive_last_loc_msg (msqid);
- tr->file = last_loc_file (lmsg);
- tr->line = last_loc_line (lmsg);
- free (lmsg);
-}
-
-static void receive_failure_info (int msqid, int status, TestResult *tr)
-{
- FailureMsg *fmsg;
-#ifdef USE_FORKWAITMSG
- if (WIFSIGNALED(status)) {
- tr->rtype = CRERROR;
- tr->msg = signal_msg (WTERMSIG(status));
- return;
- }
-
- if (WIFEXITED(status)) {
-
- if (WEXITSTATUS(status) == 0) {
- tr->rtype = CRPASS;
- tr->msg = emalloc(strlen("Test passed") + 1);
- strcpy (tr->msg, "Test passed");
- }
- else {
-
- fmsg = receive_failure_msg (msqid);
- if (fmsg == NULL) { /* implies early exit */
- tr->rtype = CRERROR;
- tr->msg = exit_msg (WEXITSTATUS(status));
- }
- else {
- tr->rtype = CRFAILURE;
- tr->msg = emalloc(strlen(fmsg->msg) + 1);
- strcpy (tr->msg, fmsg->msg);
- free (fmsg);
- }
- }
- } else {
- eprintf ("Bad status from wait() call\n");
- }
-#else
- if (status == 0) {
- tr->rtype = CRPASS;
- tr->msg = emalloc(strlen("Test passed") + 1);
- strcpy (tr->msg, "Test passed");
- }
- else {
- fmsg = receive_failure_msg (msqid);
- if (fmsg == NULL) { /* implies early exit */
- tr->rtype = CRERROR;
- tr->msg = exit_msg (status);
- }
- else {
- tr->rtype = CRFAILURE;
- tr->msg = emalloc(strlen(fmsg->msg) + 1);
- strcpy (tr->msg, fmsg->msg);
- free (fmsg);
- }
- }
-#endif
-}
-
-static TestResult *receive_result_info (int msqid, int status,
- const char *tcname, const char *tfname)
-{
- TestResult *tr = emalloc (sizeof(TestResult));
-
- tr->tcname = tcname;
- tr->tfname = tfname;
- receive_last_loc_info (msqid, tr);
- receive_failure_info (msqid, status, tr);
- return tr;
-}
-
-static TestResult *tfun_run (int msqid, const char *tcname, TF *tfun)
-{
-#ifdef USE_FORKWAITMSG
- pid_t pid;
-#endif
- int status = 0;
-
-#ifdef USE_FORKWAITMSG
- pid = fork();
- if (pid == -1)
- eprintf ("Unable to fork:");
- if (pid == 0) {
- tfun->fn(msqid);
- _exit(EXIT_SUCCESS);
- }
- (void) wait(&status);
-#else
- nofork_exit_status = 0;
- tfun->fn(msqid);
- status = nofork_exit_status;
-#endif
- return receive_result_info(msqid, status, tcname, tfun->name);
-}
-
-
-
-
-int srunner_ntests_failed (SRunner *sr)
-{
- return sr->stats->n_failed + sr->stats->n_errors;
-}
-
-int srunner_ntests_run (SRunner *sr)
-{
- return sr->stats->n_checked;
-}
-
-TestResult **srunner_failures (SRunner *sr)
-{
- int i = 0;
- TestResult **trarray;
- List *rlst;
- trarray = malloc (sizeof(trarray[0]) * srunner_ntests_failed (sr));
-
- rlst = srunner_resultlst (sr);
- for (list_front(rlst); !list_at_end(rlst); list_advance(rlst)) {
- TestResult *tr = list_val(rlst);
- if (non_pass(tr->rtype))
- trarray[i++] = tr;
-
- }
- return trarray;
-}
-
-TestResult **srunner_results (SRunner *sr)
-{
- int i = 0;
- TestResult **trarray;
- List *rlst;
-
- trarray = malloc (sizeof(trarray[0]) * srunner_ntests_run (sr));
-
- rlst = srunner_resultlst (sr);
- for (list_front(rlst); !list_at_end(rlst); list_advance(rlst)) {
- trarray[i++] = list_val(rlst);
- }
- return trarray;
-}
-
-static List *srunner_resultlst (SRunner *sr)
-{
- return sr->resultlst;
-}
-
-char *tr_msg (TestResult *tr)
-{
- return tr->msg;
-}
-
-int tr_lno (TestResult *tr)
-{
- return tr->line;
-}
-
-char *tr_lfile (TestResult *tr)
-{
- return tr->file;
-}
-
-int tr_rtype (TestResult *tr)
-{
- return tr->rtype;
-}
-
-const char *tr_tcname (TestResult *tr)
-{
- return tr->tcname;
-}
-
-#ifdef USE_FORKWAITMSG
-static char *signal_msg (int signal)
-{
- char *msg = emalloc (CMAXMSG); /* free'd by caller */
-#ifdef HAVE_SNPRINTF
- snprintf(msg, CMAXMSG, "Received signal %d", signal);
-#else
- sprintf(msg, "Received signal %d", signal);
-#endif
- return msg;
-}
-#endif
-
-static char *exit_msg (int exitval)
-{
- char *msg = emalloc(CMAXMSG); /* free'd by caller */
-#ifdef HAVE_SNPRINTF
- snprintf(msg, CMAXMSG,
- "Early exit with return value %d", exitval);
-#else
- sprintf(msg, "Early exit with return value %d", exitval);
-#endif
- return msg;
-}
-
-static int non_pass (int val)
-{
- return val == CRFAILURE || val == CRERROR;
-}
-
+++ /dev/null
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-
-#ifdef STDC_HEADERS
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#endif
-
-#include "error.h"
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-void eprintf (const char *fmt, ...)
-{
- va_list args;
- fflush(stdout);
-
- va_start(args, fmt);
- vfprintf(stderr, fmt, args);
- va_end(args);
-
- /*include system error information if format ends in colon */
-#ifdef HAVE_STRERROR
- if (fmt[0] != '\0' && fmt[strlen(fmt)-1] == ':')
- fprintf(stderr, " %s", strerror(errno));
-#endif
- fprintf(stderr, "\n");
-
- exit(2);
-}
-
-void *emalloc (size_t n)
-{
- void *p;
- p = malloc(n);
- if (p == NULL)
- eprintf("malloc of %u bytes failed:", n);
- return p;
-}
-
-void *erealloc (void * ptr, size_t n)
-{
- void *p;
- p = realloc (ptr, n);
- if (p == NULL)
- eprintf("realloc of %u bytes failed:", n);
- return p;
-}
+++ /dev/null
-#ifndef CHECK_ERROR_H
-#define CHECK_ERROR_H
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-/* Include stdlib.h beforehand */
-
-/* Print error message and die
- If fmt ends in colon, include system error information */
-void eprintf (const char *fmt, ...);
-/* malloc or die */
-void *emalloc(size_t n);
-void *erealloc(void *, size_t n);
-
-#endif /*CHECK_ERROR_H*/
+++ /dev/null
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#ifdef STDC_HEADERS
-# include <stdlib.h>
-#endif
-
-#include "list.h"
-#include "error.h"
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-enum {
- LINIT = 1,
- LGROW = 2
-};
-
-struct List {
- int n_elts;
- int max_elts;
- int current; /* pointer to the current node */
- int last; /* pointer to the node before END */
- void **data;
-};
-
-static void maybe_grow (List *lp)
-{
- if (lp->n_elts >= lp->max_elts) {
- lp->max_elts *= LGROW;
- lp->data = erealloc (lp->data, lp->max_elts * sizeof(lp->data[0]));
- }
-}
-
-List *list_create (void)
-{
- List *lp;
- lp = emalloc (sizeof(List));
- lp->n_elts = 0;
- lp->max_elts = LINIT;
- lp->data = emalloc(sizeof(lp->data[0]) * LINIT);
- lp->current = lp->last = -1;
- return lp;
-}
-
-void list_add_end (List *lp, void *val)
-{
- if (lp == NULL)
- return;
- maybe_grow(lp);
- lp->last++;
- lp->n_elts++;
- lp->current = lp->last;
- lp->data[lp->current] = val;
-}
-
-int list_at_end (List *lp)
-{
- if (lp->current == -1)
- return 1;
- else
- return (lp->current > lp->last);
-}
-
-void list_front (List *lp)
-{
- if (lp->current == -1)
- return;
- lp->current = 0;
-}
-
-
-void list_free (List *lp)
-{
- if (lp == NULL)
- return;
-
- free(lp->data);
- free (lp);
-}
-
-void *list_val (List *lp)
-{
- if (lp == NULL)
- return NULL;
- if (lp->current == -1 || lp->current > lp->last)
- return NULL;
-
- return lp->data[lp->current];
-}
-
-void list_advance (List *lp)
-{
- if (lp == NULL)
- return;
- if (list_at_end(lp))
- return;
- lp->current++;
-}
-
-
-
-
+++ /dev/null
-#ifndef CHECK_LIST_H
-#define CHECK_LIST_H
-
-/*
- Check: a unit test framework for C
- Copyright (C) 2001, Arien Malec
-
- This program 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.
-
- This program 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.
-*/
-
-typedef struct List List;
-
-/* Create an empty list */
-List * list_create (void);
-
-/* Is list at end? */
-int list_at_end (List * lp);
-
-/* Position list at front */
-void list_front(List *lp);
-
-
-/* Add a value to the end of the list,
- positioning newly added value as current value */
-void list_add_end (List *lp, void *val);
-
-/* Give the value of the current node */
-void *list_val (List * lp);
-
-/* Position the list at the next node */
-void list_advance (List * lp);
-
-/* Free a list, but don't free values */
-void list_free (List * lp);
-
-/* Free a list, freeing values using a freeing function */
-/* void list_vfree (List * lp, void (*fp) (void *)); */
-
-#endif /*CHECK_LIST_H*/
#
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
-AC_CHECK_HEADERS([alloca.h limits.h sys/cdefs.h sys/ipc.h sys/msg.h sys/param.h sys/types.h sys/queue.h unistd.h libgen.h])
+AC_CHECK_HEADERS([limits.h sys/param.h unistd.h libgen.h])
# REQUIRE standard C headers
if test "$ac_cv_header_stdc" != yes; then
AC_C_CONST
AC_C_INLINE
AC_C_PROTOTYPES
-# PID_T is used by the test suite (not required).
-AC_TYPE_PID_T
AC_TYPE_SIZE_T
#
# Checks for library functions.
#
-AC_FUNC_FORK
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([abort memcpy memmove strrchr toascii vsnprintf])
AC_CHECK_FUNCS([strsep mergesort])
# Look for the case-insensitive comparison functions
AC_CHECK_FUNCS([strcasecmp strncasecmp stricmp strcmpi])
-# Check for stuff wanted by the test suite. None of this is required.
-AC_CHECK_FUNCS([msgctl msgget msgrcv msgsnd strerror snprintf wait])
AC_REPLACE_FUNCS([basename dirname])
AC_LIB_LTDL
# Add some more CFLAGS for various options.
#
-# "Check" tests can use fork/wait/msg* if ALL are available.
-AH_TEMPLATE([USE_FORKWAITMSG], [Combined test for fork/wait/msg*])
-if ${check}; then
- if test "$ac_cv_func_fork" = yes &&
- test "$ac_cv_func_wait" = yes &&
- test "$ac_cv_func_msgctl" = yes &&
- test "$ac_cv_func_msgget" = yes &&
- test "$ac_cv_func_msgrcv" = yes &&
- test "$ac_cv_func_msgsnd" = yes; then
- AC_DEFINE([USE_FORKWAITMSG])
- AC_DEFINE([_GNU_SOURCE], 1,
- [Make sure we see all GNU extensions.])
- AC_DEFINE([_SVID_SOURCE], 1,
- [Make sure we see all SVID extensions.])
- fi
-fi
-
if test "$debugging" = "no" ; then
changequote(,)
CFLAGS="`echo $CFLAGS' ' | sed -e 's/-g[0-9] //g' | sed -e 's/-g//g'`"
bitvect_test_CFLAGS =
bitvect_test_SOURCES = libyasm/tests/bitvect_test.c
-bitvect_test_SOURCES += $(CHECKFILES)
bitvect_test_LDFLAGS =
bitvect_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@
-#bytecode_test_CFLAGS =
-#bytecode_test_SOURCES = src/tests/bytecode_test.c
-#bytecode_test_SOURCES += $(YASMPARSERFILES)
-#bytecode_test_SOURCES += $(YASMPREPROCFILES)
-#bytecode_test_SOURCES += $(YASMOPTIMIZERFILES)
-#bytecode_test_SOURCES += $(YASMOBJFMTFILES)
-#bytecode_test_SOURCES += $(YASMARCHFILES)
-#bytecode_test_SOURCES += $(CHECKFILES)
-#bytecode_test_LDFLAGS =
-#bytecode_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@
-
floatnum_test_CFLAGS =
floatnum_test_SOURCES = libyasm/tests/floatnum_test.c
-floatnum_test_SOURCES += $(CHECKFILES)
floatnum_test_LDFLAGS =
floatnum_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@
-#memexpr_test_CFLAGS =
-#memexpr_test_SOURCES = src/tests/memexpr_test.c
-#memexpr_test_SOURCES += $(YASMPARSERFILES)
-#memexpr_test_SOURCES += $(YASMPREPROCFILES)
-#memexpr_test_SOURCES += $(YASMOPTIMIZERFILES)
-#memexpr_test_SOURCES += $(YASMOBJFMTFILES)
-#memexpr_test_SOURCES += $(YASMARCHFILES)
-#memexpr_test_SOURCES += $(CHECKFILES)
-#memexpr_test_LDFLAGS =
-#memexpr_test_LDADD = libyasm.la @LIBLTDL@ $(INTLLIBS) @LIBADD_DL@
#include <stdio.h>
-#include "check.h"
-
#include "libyasm/bitvect.h"
-START_TEST(test_boot)
+static int
+test_boot()
{
- fail_unless(BitVector_Boot() == ErrCode_Ok, "failed to Boot()");
+ if (BitVector_Boot() != ErrCode_Ok)
+ return 1;
+ return 0;
}
-END_TEST
typedef struct Val_s {
const char *ascii;
return ret;
}
-START_TEST(test_oct_small_num)
+static int
+test_oct_small_num()
{
Val *vals = oct_small_vals;
int i, num = sizeof(oct_small_vals)/sizeof(Val);
- for (i=0; i<num; i++)
- fail_unless(num_check(&vals[i]) == 0, result_msg);
+ for (i=0; i<num; i++) {
+ if (num_check(&vals[i]) != 0)
+ return 1;
+ }
+ return 0;
}
-END_TEST
-START_TEST(test_oct_large_num)
+static int
+test_oct_large_num()
{
Val *vals = oct_large_vals;
int i, num = sizeof(oct_large_vals)/sizeof(Val);
- for (i=0; i<num; i++)
- fail_unless(num_check(&vals[i]) == 0, result_msg);
+ for (i=0; i<num; i++) {
+ if (num_check(&vals[i]) != 0)
+ return 1;
+ }
+ return 0;
}
-END_TEST
-static Suite *
-bitvect_suite(void)
+static int
+runtest_(char *testname, int (*testfunc)(), void (*setup)(),
+ void (*teardown)())
{
- Suite *s = suite_create("BitVector");
- TCase *tc_boot = tcase_create("Boot");
- TCase *tc_from_oct = tcase_create("from_Oct");
-
- suite_add_tcase(s, tc_boot);
- tcase_add_test(tc_boot, test_boot);
-
- suite_add_tcase(s, tc_from_oct);
- tcase_add_test(tc_from_oct, test_oct_small_num);
- tcase_add_test(tc_from_oct, test_oct_large_num);
- tcase_set_fixture(tc_from_oct, num_family_setup, num_family_teardown);
-
- return s;
+ int nf;
+ printf("bitvect_test: Testing libyasm bitvect for %s ... ", testname);
+ fflush(stdout);
+ if (setup)
+ setup();
+ nf = testfunc();
+ if (teardown)
+ teardown();
+ printf("%s.\n", nf>0 ? "FAIL":"PASS");
+ return nf;
}
+#define runtest(x,y,z) runtest_(#x,test_##x,y,z)
int
main(void)
{
- int nf;
- Suite *s = bitvect_suite();
- SRunner *sr = srunner_create(s);
- srunner_run_all(sr, CRNORMAL);
- nf = srunner_ntests_failed(sr);
- srunner_free(sr);
- suite_free(s);
+ int nf = 0;
+ nf += runtest(boot, NULL, NULL);
+ nf += runtest(oct_small_num, num_family_setup, num_family_teardown);
+ nf += runtest(oct_large_num, num_family_setup, num_family_teardown);
+ printf("bitvect_test: %d%%: Checks: 3, Failures: %d\n",
+ 100*(3-nf)/3, nf);
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
+++ /dev/null
-/* $Id$
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#include "util.h"
-
-#include "check.h"
-
-#include "bytecode.h"
-#include "bc-int.h"
-#include "arch.h"
-#include "x86arch.h"
-
-START_TEST(test_x86_ea_new_reg)
-{
- effaddr *ea;
- x86_effaddr_data *ead;
- int i;
-
- /* Test with NULL */
- ea = x86_ea_new_reg(1);
- fail_unless(ea != NULL, "Should die if out of memory (not return NULL)");
-
- /* Test structure values function should set */
- fail_unless(ea->len == 0, "len should be 0");
- ead = ea_get_data(ea);
- fail_unless(ead->segment == 0, "Should be no segment override");
- fail_unless(ead->valid_modrm == 1, "Mod/RM should be valid");
- fail_unless(ead->need_modrm == 1, "Mod/RM should be needed");
- fail_unless(ead->valid_sib == 0, "SIB should be invalid");
- fail_unless(ead->need_sib == 0, "SIB should not be needed");
-
- free(ea);
-
- /* Exhaustively test generated Mod/RM byte with register values */
- for(i=0; i<8; i++) {
- ea = x86_ea_new_reg(i);
- ead = ea_get_data(ea);
- fail_unless(ead->modrm == (0xC0 | (i & 0x07)),
- "Invalid Mod/RM byte generated");
- free(ea);
- }
-}
-END_TEST
-
-static 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_x86_ea_new_reg);
-
- 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;
-}
#include <stdio.h>
-#include "check.h"
-
#include "libyasm/floatnum.c"
/* constants describing parameters of internal floating point format.
return 0;
}
-START_TEST(test_new_normalized)
+static int
+test_new_normalized()
{
Init_Entry *vals = normalized_vals;
int i, num = sizeof(normalized_vals)/sizeof(Init_Entry);
for (i=0; i<num; i++) {
new_setup(vals, i);
- fail_unless(new_check_flt(&vals[i]) == 0, result_msg);
+ if (new_check_flt(&vals[i]) != 0)
+ return 1;
yasm_floatnum_destroy(flt);
}
+ return 0;
}
-END_TEST
-START_TEST(test_new_normalized_edgecase)
+static int
+test_new_normalized_edgecase()
{
Init_Entry *vals = normalized_edgecase_vals;
int i, num = sizeof(normalized_edgecase_vals)/sizeof(Init_Entry);
for (i=0; i<num; i++) {
new_setup(vals, i);
- fail_unless(new_check_flt(&vals[i]) == 0, result_msg);
+ if (new_check_flt(&vals[i]) != 0)
+ return 1;
yasm_floatnum_destroy(flt);
}
+ return 0;
}
-END_TEST
static void
get_family_setup(void)
* get_single tests
*/
-START_TEST(test_get_single_normalized)
+static int
+test_get_single_normalized()
{
unsigned char outval[4];
Init_Entry *vals = normalized_vals;
for (i=0; i<num; i++) {
get_common_setup(vals, i);
- fail_unless(yasm_floatnum_get_sized(flt, outval, 4, 32, 0, 0, 0, 0) ==
- vals[i].ret32, ret_msg);
- fail_unless(get_common_check_result(4, outval, vals[i].result32) == 0,
- result_msg);
+ if (yasm_floatnum_get_sized(flt, outval, 4, 32, 0, 0, 0, 0) !=
+ vals[i].ret32)
+ return 1;
+ if (get_common_check_result(4, outval, vals[i].result32) != 0)
+ return 1;
}
+ return 0;
}
-END_TEST
-START_TEST(test_get_single_normalized_edgecase)
+static int
+test_get_single_normalized_edgecase()
{
unsigned char outval[4];
Init_Entry *vals = normalized_edgecase_vals;
for (i=0; i<num; i++) {
get_common_setup(vals, i);
- fail_unless(yasm_floatnum_get_sized(flt, outval, 4, 32, 0, 0, 0, 0) ==
- vals[i].ret32, ret_msg);
- fail_unless(get_common_check_result(4, outval, vals[i].result32) == 0,
- result_msg);
+ if (yasm_floatnum_get_sized(flt, outval, 4, 32, 0, 0, 0, 0) !=
+ vals[i].ret32)
+ return 1;
+ if (get_common_check_result(4, outval, vals[i].result32) != 0)
+ return 1;
}
+ return 0;
}
-END_TEST
/*
* get_double tests
*/
-START_TEST(test_get_double_normalized)
+static int
+test_get_double_normalized()
{
unsigned char outval[8];
Init_Entry *vals = normalized_vals;
for (i=0; i<num; i++) {
get_common_setup(vals, i);
- fail_unless(yasm_floatnum_get_sized(flt, outval, 8, 64, 0, 0, 0, 0) ==
- vals[i].ret64, ret_msg);
- fail_unless(get_common_check_result(8, outval, vals[i].result64) == 0,
- result_msg);
+ if (yasm_floatnum_get_sized(flt, outval, 8, 64, 0, 0, 0, 0) !=
+ vals[i].ret64)
+ return 1;
+ if (get_common_check_result(8, outval, vals[i].result64) != 0)
+ return 1;
}
+ return 0;
}
-END_TEST
-START_TEST(test_get_double_normalized_edgecase)
+static int
+test_get_double_normalized_edgecase()
{
unsigned char outval[8];
Init_Entry *vals = normalized_edgecase_vals;
for (i=0; i<num; i++) {
get_common_setup(vals, i);
- fail_unless(yasm_floatnum_get_sized(flt, outval, 8, 64, 0, 0, 0, 0) ==
- vals[i].ret64, ret_msg);
- fail_unless(get_common_check_result(8, outval, vals[i].result64) == 0,
- result_msg);
+ if (yasm_floatnum_get_sized(flt, outval, 8, 64, 0, 0, 0, 0) !=
+ vals[i].ret64)
+ return 1;
+ if (get_common_check_result(8, outval, vals[i].result64) != 0)
+ return 1;
}
+ return 0;
}
-END_TEST
/*
* get_extended tests
*/
-START_TEST(test_get_extended_normalized)
+static int
+test_get_extended_normalized()
{
unsigned char outval[10];
Init_Entry *vals = normalized_vals;
for (i=0; i<num; i++) {
get_common_setup(vals, i);
- fail_unless(yasm_floatnum_get_sized(flt, outval, 10, 80, 0, 0, 0, 0) ==
- vals[i].ret80, ret_msg);
- fail_unless(get_common_check_result(10, outval, vals[i].result80) == 0,
- result_msg);
+ if (yasm_floatnum_get_sized(flt, outval, 10, 80, 0, 0, 0, 0) !=
+ vals[i].ret80)
+ return 1;
+ if (get_common_check_result(10, outval, vals[i].result80) != 0)
+ return 1;
}
+ return 0;
}
-END_TEST
-START_TEST(test_get_extended_normalized_edgecase)
+static int
+test_get_extended_normalized_edgecase()
{
unsigned char outval[10];
Init_Entry *vals = normalized_edgecase_vals;
for (i=0; i<num; i++) {
get_common_setup(vals, i);
- fail_unless(yasm_floatnum_get_sized(flt, outval, 10, 80, 0, 0, 0, 0) ==
- vals[i].ret80, ret_msg);
- fail_unless(get_common_check_result(10, outval, vals[i].result80) == 0,
- result_msg);
+ if (yasm_floatnum_get_sized(flt, outval, 10, 80, 0, 0, 0, 0) !=
+ vals[i].ret80)
+ return 1;
+ if (get_common_check_result(10, outval, vals[i].result80) != 0)
+ return 1;
}
+ return 0;
}
-END_TEST
-static Suite *
-floatnum_suite(void)
+static int
+runtest_(char *testname, int (*testfunc)(), void (*setup)(),
+ void (*teardown)())
{
- Suite *s = suite_create("floatnum");
- TCase *tc_new = tcase_create("new");
- TCase *tc_get_single = tcase_create("get_single");
- TCase *tc_get_double = tcase_create("get_double");
- TCase *tc_get_extended = tcase_create("get_extended");
-
- suite_add_tcase(s, tc_new);
- tcase_add_test(tc_new, test_new_normalized);
- tcase_add_test(tc_new, test_new_normalized_edgecase);
-
- suite_add_tcase(s, tc_get_single);
- tcase_add_test(tc_get_single, test_get_single_normalized);
- tcase_add_test(tc_get_single, test_get_single_normalized_edgecase);
- tcase_set_fixture(tc_get_single, get_family_setup, get_family_teardown);
-
- suite_add_tcase(s, tc_get_double);
- tcase_add_test(tc_get_double, test_get_double_normalized);
- tcase_add_test(tc_get_double, test_get_double_normalized_edgecase);
- tcase_set_fixture(tc_get_double, get_family_setup, get_family_teardown);
-
- suite_add_tcase(s, tc_get_extended);
- tcase_add_test(tc_get_extended, test_get_extended_normalized);
- tcase_add_test(tc_get_extended, test_get_extended_normalized_edgecase);
- tcase_set_fixture(tc_get_extended, get_family_setup, get_family_teardown);
-
- return s;
+ int nf;
+ printf("floatnum_test: Testing for %s ... ", testname);
+ fflush(stdout);
+ if (setup)
+ setup();
+ nf = testfunc();
+ if (teardown)
+ teardown();
+ printf("%s.\n", nf>0 ? "FAIL":"PASS");
+ return nf;
}
+#define runtest(x,y,z) runtest_(#x,test_##x,y,z)
int
main(void)
{
- int nf;
- Suite *s = floatnum_suite();
- SRunner *sr = srunner_create(s);
- BitVector_Boot();
+ int nf = 0;
+ if (BitVector_Boot() != ErrCode_Ok)
+ return EXIT_FAILURE;
yasm_floatnum_initialize();
- srunner_run_all(sr, CRNORMAL);
- nf = srunner_ntests_failed(sr);
- srunner_free(sr);
- suite_free(s);
+ nf += runtest(new_normalized, NULL, NULL);
+ nf += runtest(new_normalized_edgecase, NULL, NULL);
+ nf += runtest(get_single_normalized, get_family_setup, get_family_teardown);
+ nf += runtest(get_single_normalized_edgecase, get_family_setup, get_family_teardown);
+ nf += runtest(get_double_normalized, get_family_setup, get_family_teardown);
+ nf += runtest(get_double_normalized_edgecase, get_family_setup, get_family_teardown);
+ nf += runtest(get_extended_normalized, get_family_setup, get_family_teardown);
+ nf += runtest(get_extended_normalized_edgecase, get_family_setup, get_family_teardown);
+ printf("floatnum_test: %d%%: Checks: 8, Failures: %d\n",
+ 100*(3-nf)/3, nf);
return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
+++ /dev/null
-/* $Id$
- *
- * Copyright (C) 2001 Peter Johnson
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-#include "util.h"
-
-#include "check.h"
-
-#include "bitvect.h"
-
-#include "errwarn.h"
-
-#include "expr.h"
-#include "intnum.h"
-#include "floatnum.h"
-
-#include "bytecode.h"
-#include "arch.h"
-#include "x86arch.h"
-
-typedef enum {
- REG_AX = 0,
- REG_CX = 1,
- REG_DX = 2,
- REG_BX = 3,
- REG_SP = 4,
- REG_BP = 5,
- REG_SI = 6,
- REG_DI = 7
-} reg16type;
-
-/* Memory expression building functions.
- * These try to exactly match how a parser will build up the expr for _in,
- * and exactly what the output expr should be for _out.
- */
-
-/* [5] */
-static expr *
-gen_5_in(void)
-{
- return expr_new_ident(ExprInt(intnum_new_uint(5)));
-}
-#define gen_5_out gen_5_in
-/* [1.2] */
-static expr *
-gen_1pt2_in(void)
-{
- return expr_new_ident(ExprFloat(floatnum_new("1.2")));
-}
-/* No _out, it's invalid */
-/* [ecx] */
-static expr *
-gen_ecx_in(void)
-{
- return expr_new_ident(ExprReg(REG_CX, 32));
-}
-#define gen_ecx_out NULL
-/* [di] */
-static expr *
-gen_di_in(void)
-{
- return expr_new_ident(ExprReg(REG_DI, 16));
-}
-#define gen_di_out NULL
-/* [di-si+si+126] */
-static expr *
-gen_dimsipsip126_in(void)
-{
- return expr_new_tree(
- expr_new_tree(
- expr_new_tree(
- expr_new_ident(ExprReg(REG_DI, 16)),
- EXPR_SUB,
- expr_new_ident(ExprReg(REG_SI, 16))),
- EXPR_ADD,
- expr_new_ident(ExprReg(REG_SI, 16))),
- EXPR_ADD,
- expr_new_ident(ExprInt(intnum_new_uint(126))));
-}
-#define gen_dimsipsip126_out NULL
-/* [bx-(bx-di)+bx-2] */
-static expr *
-gen_bxmqbxmdiqpbxm2_in(void)
-{
- return expr_new_tree(
- expr_new_tree(
- expr_new_tree(
- expr_new_ident(ExprReg(REG_BX, 16)),
- EXPR_SUB,
- expr_new_tree(
- expr_new_ident(ExprReg(REG_BX, 16)),
- EXPR_SUB,
- expr_new_ident(ExprReg(REG_DI, 16)))),
- EXPR_ADD,
- expr_new_ident(ExprReg(REG_BX, 16))),
- EXPR_SUB,
- expr_new_ident(ExprInt(intnum_new_uint(2))));
-}
-static expr *
-gen_bxmqbxmdiqpbxm2_out(void)
-{
- return expr_new_ident(ExprInt(intnum_new_int(-2)));
-}
-/* [bp] */
-static expr *
-gen_bp_in(void)
-{
- return expr_new_ident(ExprReg(REG_BP, 16));
-}
-#define gen_bp_out NULL
-/* [bp*1+500] */
-static expr *
-gen_bpx1p500_in(void)
-{
- return expr_new_tree(
- expr_new_tree(
- expr_new_ident(ExprReg(REG_BP, 16)),
- EXPR_MUL,
- expr_new_ident(ExprInt(intnum_new_uint(1)))),
- EXPR_ADD,
- expr_new_ident(ExprInt(intnum_new_uint(500))));
-}
-static expr *
-gen_bpx1p500_out(void)
-{
- return expr_new_ident(ExprInt(intnum_new_uint(500)));
-}
-
-typedef struct CheckEA_InOut {
- /* Function to generate input/output expr. */
- expr *(*expr_gen)(void);
- unsigned char addrsize;
- unsigned char bits;
- unsigned char nosplit;
- unsigned char displen;
- unsigned char modrm;
- unsigned char v_modrm;
- unsigned char n_modrm;
- unsigned char sib;
- unsigned char v_sib;
- unsigned char n_sib;
-} CheckEA_InOut;
-
-typedef struct CheckEA_Entry {
- const char *ascii; /* Text description of input */
- CheckEA_InOut in; /* Input Parameter Values */
- int retval; /* Return value */
- CheckEA_InOut out; /* Correct output Parameter Values
- (N/A if retval=0) */
-} CheckEA_Entry;
-
-/* Values used for tests */
-static CheckEA_Entry bits16_vals[] = {
- {
- "[5]",
- {gen_5_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_5_out, 16, 16, 0, 2, 0x06, 1, 1, 0, 0, 0}
- },
- {
- "a16 [5]",
- {gen_5_in , 16, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_5_out, 16, 16, 0, 2, 0x06, 1, 1, 0, 0, 0}
- },
- {
- "a32 [5]",
- {gen_5_in , 32, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_5_out, 32, 16, 0, 4, 0x05, 1, 1, 0x25, 1, 1}
- },
- {
- "[word 5]",
- {gen_5_in , 0, 16, 0, 2, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_5_out, 16, 16, 0, 2, 0x06, 1, 1, 0, 0, 0}
- },
- {
- "[dword 5]",
- {gen_5_in , 0, 16, 0, 4, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_5_out, 32, 16, 0, 4, 0x05, 1, 1, 0x25, 1, 1}
- },
- {
- "a16 [dword 5]",
- {gen_5_in, 16, 16, 0, 4, 0, 0, 1, 0, 0, 0xff},
- 0,
- {NULL , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- },
- /* should error */
- {
- "[di+1.2]",
- {gen_1pt2_in, 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 0,
- {NULL , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- },
- {
- "[ecx]",
- {gen_ecx_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_ecx_out, 32, 16, 0, 0, 0x01, 1, 1, 0, 0, 0}
- },
- /* should error */
- {
- "a16 [ecx]",
- {gen_ecx_in, 16, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 0,
- {NULL , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- },
- {
- "[di]",
- {gen_di_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_di_out, 16, 16, 0, 0, 0x05, 1, 1, 0, 0, 0}
- },
- {
- "[di-si+si+126]",
- {gen_dimsipsip126_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_dimsipsip126_out, 16, 16, 0, 1, 0x45, 1, 1, 0, 0, 0}
- },
- {
- "[bx-(bx-di)+bx-2]",
- {gen_bxmqbxmdiqpbxm2_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_bxmqbxmdiqpbxm2_out, 16, 16, 0, 1, 0x41, 1, 1, 0, 0, 0}
- },
- {
- "[bp]",
- {gen_bp_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_bp_out, 16, 16, 0, 1, 0x46, 1, 1, 0, 0, 0}
- },
- {
- "[bp*1+500]",
- {gen_bpx1p500_in , 0, 16, 0, 0, 0, 0, 1, 0, 0, 0xff},
- 1,
- {gen_bpx1p500_out, 16, 16, 0, 2, 0x86, 1, 1, 0, 0, 0}
- },
-};
-
-/* input expression */
-expr *expn;
-
-/* failure messages */
-static char result_msg[1024];
-
-int error_triggered;
-
-/* Replace errwarn functions */
-void InternalError_(const char *file, unsigned int line, const char *msg)
-{
- exit(EXIT_FAILURE);
-}
-
-void
-Fatal(fatal_num num)
-{
- exit(EXIT_FAILURE);
-}
-
-void
-Error(const char *msg, ...)
-{
- error_triggered = 1;
-}
-
-void
-Warning(const char *msg, ...)
-{
-}
-
-void
-ErrorAt(const char *filename, unsigned long line, const char *fmt, ...)
-{
- error_triggered = 1;
-}
-
-void
-WarningAt(const char *filename, unsigned long line, const char *fmt, ...)
-{
-}
-
-static int
-x86_checkea_check(CheckEA_Entry *val)
-{
- CheckEA_InOut chk = val->in; /* local structure copy of inputs */
- int retval;
-
- error_triggered = 0;
-
- /* execute function and check return value */
- retval = x86_expr_checkea(&expn, &chk.addrsize, chk.bits, chk.nosplit,
- &chk.displen, &chk.modrm, &chk.v_modrm,
- &chk.n_modrm, &chk.sib, &chk.v_sib, &chk.n_sib);
- if (retval != val->retval) {
- sprintf(result_msg, "%s: incorrect %s (expected %d, got %d)",
- val->ascii, "return value", val->retval, retval);
- return 1;
- }
-
- /* If returned 0 (failure), check to see if ErrorAt() was called */
- if (retval == 0) {
- if (error_triggered == 0) {
- sprintf(result_msg, "%s: didn't call ErrorAt() and returned 0",
- val->ascii);
- return 1;
- }
-
- return 0; /* don't check other return values */
- }
-
- /* check expr result */
- /* TODO */
-
- /* Check other outputs */
- if (chk.addrsize != val->out.addrsize) {
- sprintf(result_msg, "%s: incorrect %s (expected %d, got %d)",
- val->ascii, "addrsize", (int)val->out.addrsize,
- (int)chk.addrsize);
- return 1;
- }
- if (chk.displen != val->out.displen) {
- sprintf(result_msg, "%s: incorrect %s (expected %d, got %d)",
- val->ascii, "displen", (int)val->out.displen,
- (int)chk.displen);
- return 1;
- }
- if (chk.modrm != val->out.modrm) {
- sprintf(result_msg, "%s: incorrect %s (expected %03o, got %03o)",
- val->ascii, "modrm", (int)val->out.modrm, (int)chk.modrm);
- return 1;
- }
- if (chk.v_modrm != val->out.v_modrm) {
- sprintf(result_msg, "%s: incorrect %s (expected %d, got %d)",
- val->ascii, "v_modrm", (int)val->out.v_modrm,
- (int)chk.v_modrm);
- return 1;
- }
- if (chk.n_modrm != val->out.n_modrm) {
- sprintf(result_msg, "%s: incorrect %s (expected %d, got %d)",
- val->ascii, "n_modrm", (int)val->out.n_modrm,
- (int)chk.n_modrm);
- return 1;
- }
- if (chk.sib != val->out.sib) {
- sprintf(result_msg, "%s: incorrect %s (expected %03o, got %03o)",
- val->ascii, "sib", (int)val->out.sib, (int)chk.sib);
- return 1;
- }
- if (chk.v_sib != val->out.v_sib) {
- sprintf(result_msg, "%s: incorrect %s (expected %d, got %d)",
- val->ascii, "v_sib", (int)val->out.v_sib, (int)chk.v_sib);
- return 1;
- }
- if (chk.n_sib != val->out.n_sib) {
- sprintf(result_msg, "%s: incorrect %s (expected %x, got %x)",
- val->ascii, "n_sib", (int)val->out.n_sib, (int)chk.n_sib);
- return 1;
- }
- return 0;
-}
-
-START_TEST(test_x86_checkea_bits16)
-{
- CheckEA_Entry *vals = bits16_vals;
- int i, num = sizeof(bits16_vals)/sizeof(CheckEA_Entry);
-
- for (i=0; i<num; i++) {
- expn = vals[i].in.expr_gen();
- fail_unless(x86_checkea_check(&vals[i]) == 0, result_msg);
- expr_delete(expn);
- }
-}
-END_TEST
-
-static Suite *
-memexpr_suite(void)
-{
- Suite *s = suite_create("memexpr");
- TCase *tc_x86_checkea = tcase_create("x86_checkea");
-
- suite_add_tcase(s, tc_x86_checkea);
- tcase_add_test(tc_x86_checkea, test_x86_checkea_bits16);
-
- return s;
-}
-
-int
-main(void)
-{
- int nf;
- Suite *s = memexpr_suite();
- SRunner *sr = srunner_create(s);
- BitVector_Boot();
- srunner_run_all(sr, CRNORMAL);
- nf = srunner_ntests_failed(sr);
- srunner_free(sr);
- suite_free(s);
- return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}