Files
mercury/tests/valid_seq/xmlreader.m
Zoltan Somogyi e0cdfc2fe2 Make the tests really work in parallel.
There was a bug that prevented the tests in each directory from being run
in parallel, even when the mmake was invoked with e.g. -j4. The bug
was the absence of a '+' on an action that invoked tests/run_one_test.
Without that +, the make process inside the "mmake -j4 runtests_local"
command issued by bootcheck screwed up its connection with the recursive
make invoked by run_one_test, and apparently decided to stop using
parallelism. It was telling us this all this time but its messages,
which looked like this:

    make[2]: warning: -jN forced in submake: disabling jobserver mode.

were lost in the sea of other bootcheck output until my recent change
to run_one_test.

A single-character change fixes the bug; the rest of this big change is
dealing with the consequences of fixing the bug. Many test cases in
the hard_coded and valid directories contain nested modules, which
need to be compiled sequentially.

tests/Mmake.common:
    Fix the bug.

    Delete the duplicate "ALL TESTS SUCCEEDED" message from the runtests
    target, since the runtests_local target already prints a message
    to that effect. Make this message more emphatic.

tests/run_one_test:
    Make the output a bit easier to understand.

tests/hard_coded/*.{m,exp}:
tests/submodules/*.{m,exp}:
    Move the source files and expected output files of the test cases that
    use nested modules from hard_coded to submodules, since most of the tests
    in the hard_coded can be done in parallel, while the ones in submodules
    are already done in sequence.

tests/hard_coded/Mmakefile:
tests/hard_coded/Mercury.options:
tests/submodules/Mmakefile:
tests/submodules/Mercury.options:
    Move the Mmakefile and Mercury.options entries of the moved test cases
    from hard_coded to submodules.

tests/valid_seq:
    A new test directory, to hold the test cases originally in tests/valid
    that contain nested modules. Moving these to a new directory, which
    forces -j1, allows us to execute the remaining ones in parallel.

tests/valid/*.m:
tests/valid_seq/*.m:
    Move the source files of the test cases that use nested modules
    from valid to valid_seq.

    In a few cases, clean up the test cases a bit.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid_seq/Mmakefile:
tests/valid_seq/Mercury.options:
tests/valid/Mmake.valid.common:
    Add valid_seq/Mmakefile to list the test cases now in valid_seq,
    and add valid_seq/Mercury.options to hold their option values.
    Delete the entries of those tests from valid/Mmakefile, and their option
    values from valid/Mercury.options. Unlike valid/Mmakefile,
    valid_seq/Mmakefile forces -j1.

    To avoid unnecessary duplication between the two Makefiles, put
    all the rules that both need into valid/Mmake.valid.common, and
    include this in both Mmakefiles.

tests/string_format/Mmakefile:
    Force -j1, since these tests share a library module.

tests/Mmakefile:
    List the new valid_seq directory among the others.

tests/bootcheck:
    Execute the tests in the new valid_seq directory as well as the others.

    Record when the execution of the test suite is started.

    Comment out invocations of set -x, since they add no useful information
    in the vast majority of cases. The comment sign can be removed if and
    when the information *would* be useful.

    Don't try to copy a nonexistent file. (The error message about this
    was also lost in the noise.)
2015-08-26 01:01:54 +10:00

152 lines
3.6 KiB
Mathematica

% vim: ts=4 sw=4 et ft=mercury
% Binding to xmlReader by Daniel Veillard
:- module xmlreader.
:- interface.
:- import_module bool.
:- import_module io.
:- import_module maybe.
:- import_module string.
:- type xmlreader.
:- pred open_file(string::in, maybe(xmlreader)::uo, io::di, io::uo) is det.
:- pred close_reader(xmlreader::di, io::di, io::uo) is det.
:- type evt
---> node(
depth :: int,
nodetype :: int,
name :: string,
is_empty :: bool,
value :: maybe(string)
)
; error(int)
; eof.
:- pred read(evt::out, xmlreader::di, xmlreader::uo) is det.
:- implementation.
:- pragma foreign_decl(c, "
/*
#include <stdio.h>
#include <libxml/xmlreader.h>
*/
").
% The original code used this, but it breaks compiling this test
% with --intermodule-optimization since xmlTextReaderPtr is undefined.
%:- pragma foreign_type("C", xmlreader, "xmlTextReaderPtr",
% [can_pass_as_mercury_type]).
:- pragma foreign_type("C", xmlreader, "MR_Word",
[can_pass_as_mercury_type]).
:- initialise c_init_xml_reader/2.
:- pred c_init_xml_reader(io::di, io::uo) is det.
:- pragma foreign_proc(c,
c_init_xml_reader(IIO::di, OIO::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
** this initialize the library and check potential ABI mismatches
** between the version it was compiled for and the actual shared
** library used.
LIBXML_TEST_VERSION
*/
LIBXML_TEST_VERSION = 1;
MR_update_io(IIO, OIO);
").
open_file(FN, MayReader, !IO) :-
c_open_file(FN, OK, Rdr, !IO),
( OK = yes ->
MayReader = unsafe_promise_unique(yes(Rdr))
;
MayReader = unsafe_promise_unique(no)
).
:- pred c_open_file(string::in, bool::out, xmlreader::out,
io::di, io::uo) is det.
:- pragma foreign_proc(c,
c_open_file(FN::in, OK::out, Rdr::out, IIO::di, OIO::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
Rdr = xmlReaderForFile(FN, NULL, 0);
*/
if (Rdr == NULL) {
OK = 0;
} else {
OK = 1;
}
MR_update_io(IIO, OIO);
").
:- pragma foreign_proc(c,
close_reader(Rdr::di, IIO::di, OIO::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
xmlFreeTextReader(Rdr);
*/
MR_update_io(IIO, OIO);
").
read(Evt, !Rdr) :-
c_read(Ret, !Rdr),
( Ret = 1 ->
c_get(Depth, NodeType, Name, Empty, GotVal, Val, !Rdr),
( GotVal = yes ->
MayVal = yes(Val)
;
MayVal = no
),
Evt = node(Depth, NodeType, Name, Empty, MayVal)
; Ret = 0 ->
Evt = eof
;
Evt = error(Ret)
).
:- pred c_read(int::out, xmlreader::di, xmlreader::uo) is det.
:- pragma foreign_proc(c,
c_read(Ret::out, IRdr::di, ORdr::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
Ret = xmlTextReaderRead(IRdr);
*/
ORdr = IRdr;
").
:- pred c_get(int::out, int::out, string::out, bool::out,
bool::out, string::out, xmlreader::di, xmlreader::uo) is det.
:- pragma foreign_proc(c,
c_get(Depth::out, NodeType::out, Name::out, Empty::out, GotVal::out,
Val::out, IRdr::di, ORdr::uo),
[promise_pure, will_not_call_mercury, thread_safe],
"
/*
Name = xmlTextReaderConstName(IRdr);
if (Name == NULL)
Name = BAD_CAST ""--"";
Val = xmlTextReaderConstValue(IRdr);
Depth = xmlTextReaderDepth(IRdr);
NodeType = xmlTextReaderNodeType(IRdr);
Empty = xmlTextReaderIsEmptyElement(IRdr);
GotVal = xmlTextReaderHasValue(IRdr);
ORdr = IRdr;
*/
").