changeset 25453:e255f09dc70e

initial framework for testing MEX files * test/mex/bug-51725.tst, test/mex/bug-54096.tst, test/mex/bug_51725.c, test/mex/bug_54096.c: New tests. * test/mex/module.mk: New file. * test/module.mk: Include %reldir%/mex/module.mk. (run-octave-tests): Add $(abs_top_builddir)/%reldir%/mex to Octave load path when running tests. (%canon_reldir%_EXTRA_DIST): Include $(noinst_TEST_FILES) and $(MEX_TEST_SRC) in the list. * Makefile.am (noinst_TEST_FILES): Initialize new variable.
author John W. Eaton <jwe@octave.org>
date Tue, 12 Jun 2018 00:32:26 -0400
parents 582f343e9022
children b09f306fcd12
files Makefile.am test/mex/bug-51725.tst test/mex/bug-54096.tst test/mex/bug_51725.c test/mex/bug_54096.c test/mex/module.mk test/module.mk
diffstat 7 files changed, 125 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.am	Tue Jun 12 10:30:56 2018 -0400
+++ b/Makefile.am	Tue Jun 12 00:32:26 2018 -0400
@@ -148,6 +148,7 @@
 info_TEXINFOS =
 BUILT_SOURCES =
 TEST_FILES =
+noinst_TEST_FILES =
 
 DOC_IMAGES_SRC =
 BUILT_DOC_IMAGES =
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mex/bug-51725.tst	Tue Jun 12 00:32:26 2018 -0400
@@ -0,0 +1,20 @@
+## Copyright (C) 2018 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave 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 3 of the License, or
+## (at your option) any later version.
+##
+## Octave 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 Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+%!assert (bug_51725 (), [])
+%!error <element number 2 undefined in return list> [x,y,z] = bug_51725 ();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mex/bug-54096.tst	Tue Jun 12 00:32:26 2018 -0400
@@ -0,0 +1,22 @@
+## Copyright (C) 2018 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave 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 3 of the License, or
+## (at your option) any later version.
+##
+## Octave 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 Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+%!test
+%! s = bug_54096 ();
+%! assert (s, struct ("field", []))
+%! assert (s.field, [])
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mex/bug_51725.c	Tue Jun 12 00:32:26 2018 -0400
@@ -0,0 +1,10 @@
+#include "mex.h"
+
+void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+{
+  if (nlhs > 0)
+    plhs[0] = mxCreateDoubleMatrix (0, 0, mxREAL);
+
+  if (nlhs > 2)
+    plhs[2] = mxCreateDoubleMatrix (0, 0, mxREAL);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mex/bug_54096.c	Tue Jun 12 00:32:26 2018 -0400
@@ -0,0 +1,19 @@
+#include "mex.h"
+
+static const char* field_names[] = {"field"};
+
+void mexFunction (int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+{
+  mxArray *tmp_val;
+
+  plhs[0] = mxCreateStructMatrix (1, 1, 1, field_names);
+
+  mxSetFieldByNumber (plhs[0], 0, 0, NULL);
+
+  tmp_val = mxGetFieldByNumber (plhs[0], 0, 0);
+
+  if (tmp_val)
+    mexErrMsgTxt ("struct elements set to NULL should be NULL internally");
+
+  /* But in the interpreter, they should appear as [].  */
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/mex/module.mk	Tue Jun 12 00:32:26 2018 -0400
@@ -0,0 +1,47 @@
+mex_TEST_FILES = \
+  %reldir%/bug-54096.tst \
+  %reldir%/bug-51725.tst \
+  $(MEX_TEST_SRC)
+
+MEX_TEST_SRC = \
+  %reldir%/bug_54096.c \
+  %reldir%/bug_51725.c
+
+MEX_TEST_FUNCTIONS = $(MEX_TEST_SRC:%.c=%.mex)
+
+## Since these definitions for MKOCTFILE and MKMEXFILE are only used
+## here, defining them in this file is probably OK.  If there are ever
+## used elsewhre, maybe then they could be moved to build-aux/module.mk
+## or the main Makefile.am file.  The MKOCTFILE variables are included
+## for completeness, in case we someday want to test building .oct
+## files as well.
+
+AM_V_mkmexfile = $(am__v_mkmexfile_@AM_V@)
+am__v_mkmexfile_ = $(am__v_mkmexfile_@AM_DEFAULT_V@)
+am__v_mkmexfile_0 = @echo "  MKMEXFILE     " $@;
+am__v_mkmexfile_1 =
+
+AM_VOPT_mkmexfile = $(am__vopt_mkmexfile_@AM_V@)
+am__vopt_mkmexfile_ = $(am__vopt_mkmexfile_@AM_DEFAULT_V@)
+am__vopt_mkmexfile_0 =
+am__vopt_mkmexfile_1 = -v
+
+## And probably many others...
+MKOCTFILECPPFLAGS = \
+  -I$(top_srcdir)/libinterp/corefcn \
+  -Ilibinterp/corefcn
+
+MKOCTFILE = $(top_builddir)/src/mkoctfile $(MKOCTFILECPPFLAGS)
+
+MKMEXFILECPPFLAGS = \
+  -I$(top_srcdir)/libinterp/corefcn \
+  -Ilibinterp/corefcn
+
+MKMEXFILE = $(top_builddir)/src/mkoctfile --mex $(MKMEXFILECPPFLAGS)
+
+%.mex : %.c
+	$(AM_V_mkmexfile)$(MKMEXFILE) $(AM_VOPT_mkmexfile) $< -o $@ || rm -f $@
+
+## Until we decide how to handle installing the executable MEX files,
+## don't install them or the associated test files.
+noinst_TEST_FILES += $(mex_TEST_FILES)
--- a/test/module.mk	Tue Jun 12 10:30:56 2018 -0400
+++ b/test/module.mk	Tue Jun 12 00:32:26 2018 -0400
@@ -75,12 +75,13 @@
 include %reldir%/ctor-vs-method/module.mk
 include %reldir%/fcn-handle-derived-resolution/module.mk
 include %reldir%/local-functions/module.mk
+include %reldir%/mex/module.mk
 include %reldir%/nest/module.mk
 include %reldir%/publish/module.mk
 include %reldir%/pkg/module.mk
 
 define run-octave-tests
-  ( cd %reldir% && $(SHELL) ../run-octave $(RUN_OCTAVE_OPTIONS) $(1) --norc --silent --no-history $(abs_top_srcdir)/%reldir%/fntests.m $(abs_top_srcdir)/%reldir% ); \
+  ( cd %reldir% && $(SHELL) ../run-octave $(RUN_OCTAVE_OPTIONS) $(1) --norc --silent --no-history -p $(abs_top_builddir)/%reldir%/mex $(abs_top_srcdir)/%reldir%/fntests.m $(abs_top_srcdir)/%reldir% ); \
   if $(AM_V_P); then \
     echo ""; \
     if [ -f %reldir%/fntests.log ]; then \
@@ -93,7 +94,7 @@
   fi
 endef
 
-check-local: $(GENERATED_TEST_FILES) | $(OCTAVE_INTERPRETER_TARGETS) %reldir%/$(octave_dirstamp)
+check-local: $(GENERATED_TEST_FILES) $(MEX_TEST_FUNCTIONS) | $(OCTAVE_INTERPRETER_TARGETS) %reldir%/$(octave_dirstamp)
 	$(AM_V_at)$(call run-octave-tests)
 
 if AMCOND_HAVE_LLVM
@@ -190,7 +191,9 @@
   %reldir%/mk-sparse-tst.sh \
   %reldir%/mk_bc_overloads_expected.m \
   %reldir%/show-failures.awk \
-  $(TEST_FILES)
+  $(TEST_FILES) \
+  $(noinst_TEST_FILES) \
+  $(MEX_TEST_SRC)
 
 EXTRA_DIST += $(%canon_reldir%_EXTRA_DIST)