mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-02-04 01:47:02 +03:00
test: Disable catalogs with xmlCatalogSetDefaults
Disable catalogs instead of tracking catalog allocations, simplifying memory leak detection. Also stop using xmlNoNetExternalEntityLoader.
This commit is contained in:
parent
64ad272525
commit
89743f8b0c
41
runsuite.c
41
runsuite.c
@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <libxml/catalog.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/parserInternals.h>
|
||||
#include <libxml/tree.h>
|
||||
@ -76,7 +77,6 @@ static int nb_internals = 0;
|
||||
static int nb_schematas = 0;
|
||||
static int nb_unimplemented = 0;
|
||||
static int nb_leaks = 0;
|
||||
static int extraMemoryFromResolver = 0;
|
||||
|
||||
static int
|
||||
fatalError(void) {
|
||||
@ -113,13 +113,8 @@ static int addEntity(char *name, char *content) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to trap calls to the resolver to not account memory for the catalog
|
||||
* which is shared to the current running test. We also don't want to have
|
||||
* network downloads modifying tests.
|
||||
*/
|
||||
static xmlParserInputPtr
|
||||
testExternalEntityLoader(const char *URL, const char *ID,
|
||||
testExternalEntityLoader(const char *URL, const char *ID ATTRIBUTE_UNUSED,
|
||||
xmlParserCtxtPtr ctxt) {
|
||||
xmlParserInputPtr ret;
|
||||
int i;
|
||||
@ -135,20 +130,8 @@ testExternalEntityLoader(const char *URL, const char *ID,
|
||||
return(ret);
|
||||
}
|
||||
}
|
||||
if (checkTestFile(URL)) {
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
} else {
|
||||
int memused = xmlMemUsed();
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
extraMemoryFromResolver += xmlMemUsed() - memused;
|
||||
}
|
||||
#if 0
|
||||
if (ret == NULL) {
|
||||
fprintf(stderr, "Failed to find resource %s\n", URL);
|
||||
}
|
||||
#endif
|
||||
|
||||
return(ret);
|
||||
return(xmlNewInputFromFile(ctxt, URL));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -220,6 +203,10 @@ initializeLibxml2(void) {
|
||||
xmlXPathRegisterNs(ctxtXPath, BAD_CAST "xlink",
|
||||
BAD_CAST "http://www.w3.org/1999/xlink");
|
||||
xmlSetGenericErrorFunc(NULL, testErrorHandler);
|
||||
#ifdef LIBXML_CATALOG_ENABLED
|
||||
xmlInitializeCatalog();
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
|
||||
#endif
|
||||
#ifdef LIBXML_SCHEMAS_ENABLED
|
||||
xmlSchemaInitTypes();
|
||||
xmlRelaxNGInitTypes();
|
||||
@ -308,7 +295,6 @@ xsdIncorrectTestCase(xmlNodePtr cur) {
|
||||
}
|
||||
|
||||
memt = xmlMemUsed();
|
||||
extraMemoryFromResolver = 0;
|
||||
/*
|
||||
* dump the schemas to a buffer, then reparse it and compile the schemas
|
||||
*/
|
||||
@ -337,7 +323,7 @@ done:
|
||||
if (rng != NULL)
|
||||
xmlRelaxNGFree(rng);
|
||||
xmlResetLastError();
|
||||
if ((memt < xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
|
||||
if (memt != xmlMemUsed()) {
|
||||
test_log("Validation of tests starting line %ld leaked %d\n",
|
||||
xmlGetLineNo(cur), xmlMemUsed() - memt);
|
||||
nb_leaks++;
|
||||
@ -443,7 +429,6 @@ xsdTestCase(xmlNodePtr tst) {
|
||||
}
|
||||
|
||||
memt = xmlMemUsed();
|
||||
extraMemoryFromResolver = 0;
|
||||
/*
|
||||
* dump the schemas to a buffer, then reparse it and compile the schemas
|
||||
*/
|
||||
@ -459,8 +444,6 @@ xsdTestCase(xmlNodePtr tst) {
|
||||
pctxt);
|
||||
rng = xmlRelaxNGParse(pctxt);
|
||||
xmlRelaxNGFreeParserCtxt(pctxt);
|
||||
if (extraMemoryFromResolver)
|
||||
memt = 0;
|
||||
|
||||
if (rng == NULL) {
|
||||
test_log("Failed to parse RNGtest line %ld\n",
|
||||
@ -490,7 +473,6 @@ xsdTestCase(xmlNodePtr tst) {
|
||||
* We are ready to run the test
|
||||
*/
|
||||
mem = xmlMemUsed();
|
||||
extraMemoryFromResolver = 0;
|
||||
doc = xmlReadMemory((const char *)buf->content, buf->use,
|
||||
"test", NULL, 0);
|
||||
if (doc == NULL) {
|
||||
@ -516,7 +498,7 @@ xsdTestCase(xmlNodePtr tst) {
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
xmlResetLastError();
|
||||
if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
|
||||
if (mem != xmlMemUsed()) {
|
||||
test_log("Validation of instance line %ld leaked %d\n",
|
||||
xmlGetLineNo(tmp), xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
@ -544,7 +526,6 @@ xsdTestCase(xmlNodePtr tst) {
|
||||
* We are ready to run the test
|
||||
*/
|
||||
mem = xmlMemUsed();
|
||||
extraMemoryFromResolver = 0;
|
||||
doc = xmlReadMemory((const char *)buf->content, buf->use,
|
||||
"test", NULL, 0);
|
||||
if (doc == NULL) {
|
||||
@ -570,7 +551,7 @@ xsdTestCase(xmlNodePtr tst) {
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
xmlResetLastError();
|
||||
if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
|
||||
if (mem != xmlMemUsed()) {
|
||||
test_log("Validation of instance line %ld leaked %d\n",
|
||||
xmlGetLineNo(tmp), xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
@ -962,7 +943,7 @@ done:
|
||||
if (validity != NULL) xmlFree(validity);
|
||||
if (schemas != NULL) xmlSchemaFree(schemas);
|
||||
xmlResetLastError();
|
||||
if ((mem != xmlMemUsed()) && (extraMemoryFromResolver == 0)) {
|
||||
if (mem != xmlMemUsed()) {
|
||||
test_log("Processing test line %ld %s leaked %d\n",
|
||||
xmlGetLineNo(cur), path, xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
|
54
runtest.c
54
runtest.c
@ -211,7 +211,6 @@ static void globfree(glob_t *pglob) {
|
||||
static int nb_tests = 0;
|
||||
static int nb_errors = 0;
|
||||
static int nb_leaks = 0;
|
||||
static int extraMemoryFromResolver = 0;
|
||||
|
||||
static int
|
||||
fatalError(void) {
|
||||
@ -219,27 +218,6 @@ fatalError(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to trap calls to the resolver to not account memory for the catalog
|
||||
* which is shared to the current running test. We also don't want to have
|
||||
* network downloads modifying tests.
|
||||
*/
|
||||
static xmlParserInputPtr
|
||||
testExternalEntityLoader(const char *URL, const char *ID,
|
||||
xmlParserCtxtPtr ctxt) {
|
||||
xmlParserInputPtr ret;
|
||||
|
||||
if (checkTestFile(URL)) {
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
} else {
|
||||
int memused = xmlMemUsed();
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
extraMemoryFromResolver += xmlMemUsed() - memused;
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Trapping the error messages at the generic level to grab the equivalent of
|
||||
* stderr messages on CLI tools.
|
||||
@ -286,7 +264,15 @@ initializeLibxml2(void) {
|
||||
xmlMemStrdup = NULL;
|
||||
xmlInitParser();
|
||||
xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
|
||||
xmlSetExternalEntityLoader(testExternalEntityLoader);
|
||||
#ifdef LIBXML_CATALOG_ENABLED
|
||||
#ifdef _WIN32
|
||||
putenv("XML_CATALOG_FILES=");
|
||||
#else
|
||||
setenv("XML_CATALOG_FILES", "", 1);
|
||||
#endif
|
||||
xmlInitializeCatalog();
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
|
||||
#endif
|
||||
#ifdef LIBXML_SCHEMAS_ENABLED
|
||||
xmlSchemaInitTypes();
|
||||
xmlRelaxNGInitTypes();
|
||||
@ -4340,7 +4326,13 @@ threadsTest(const char *filename ATTRIBUTE_UNUSED,
|
||||
const char *resul ATTRIBUTE_UNUSED,
|
||||
const char *err ATTRIBUTE_UNUSED,
|
||||
int options ATTRIBUTE_UNUSED) {
|
||||
return(testThread());
|
||||
int ret;
|
||||
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_ALL);
|
||||
ret = testThread();
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -4993,7 +4985,6 @@ launchTests(testDescPtr tst) {
|
||||
error = NULL;
|
||||
}
|
||||
mem = xmlMemUsed();
|
||||
extraMemoryFromResolver = 0;
|
||||
testErrorsSize = 0;
|
||||
testErrors[0] = 0;
|
||||
res = tst->func(globbuf.gl_pathv[i], result, error,
|
||||
@ -5006,13 +4997,10 @@ launchTests(testDescPtr tst) {
|
||||
err++;
|
||||
}
|
||||
else if (xmlMemUsed() != mem) {
|
||||
if ((xmlMemUsed() != mem) &&
|
||||
(extraMemoryFromResolver == 0)) {
|
||||
fprintf(stderr, "File %s leaked %d bytes\n",
|
||||
globbuf.gl_pathv[i], xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
err++;
|
||||
}
|
||||
fprintf(stderr, "File %s leaked %d bytes\n",
|
||||
globbuf.gl_pathv[i], xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
err++;
|
||||
}
|
||||
testErrorsSize = 0;
|
||||
if (result)
|
||||
@ -5024,8 +5012,8 @@ launchTests(testDescPtr tst) {
|
||||
} else {
|
||||
testErrorsSize = 0;
|
||||
testErrors[0] = 0;
|
||||
extraMemoryFromResolver = 0;
|
||||
res = tst->func(NULL, NULL, NULL, tst->options);
|
||||
xmlResetLastError();
|
||||
if (res != 0) {
|
||||
nb_errors++;
|
||||
err++;
|
||||
|
20
runxmlconf.c
20
runxmlconf.c
@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <libxml/catalog.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/parserInternals.h>
|
||||
#include <libxml/tree.h>
|
||||
@ -81,20 +82,6 @@ static int nb_tests = 0;
|
||||
static int nb_errors = 0;
|
||||
static int nb_leaks = 0;
|
||||
|
||||
/*
|
||||
* We need to trap calls to the resolver to not account memory for the catalog
|
||||
* and not rely on any external resources.
|
||||
*/
|
||||
static xmlParserInputPtr
|
||||
testExternalEntityLoader(const char *URL, const char *ID ATTRIBUTE_UNUSED,
|
||||
xmlParserCtxtPtr ctxt) {
|
||||
xmlParserInputPtr ret;
|
||||
|
||||
ret = xmlNewInputFromFile(ctxt, (const char *) URL);
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Trapping the error messages at the generic level to grab the equivalent of
|
||||
* stderr messages on CLI tools.
|
||||
@ -151,7 +138,10 @@ static void
|
||||
initializeLibxml2(void) {
|
||||
xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
|
||||
xmlInitParser();
|
||||
xmlSetExternalEntityLoader(testExternalEntityLoader);
|
||||
#ifdef LIBXML_CATALOG_ENABLED
|
||||
xmlInitializeCatalog();
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
|
||||
#endif
|
||||
ctxtXPath = xmlXPathNewContext(NULL);
|
||||
/*
|
||||
* Deactivate the cache if created; otherwise we have to create/free it
|
||||
|
24
testlimits.c
24
testlimits.c
@ -16,6 +16,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <libxml/catalog.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/parserInternals.h>
|
||||
#include <libxml/tree.h>
|
||||
@ -370,30 +371,15 @@ crazyRead(void *context, char *buffer, int len)
|
||||
static int nb_tests = 0;
|
||||
static int nb_errors = 0;
|
||||
static int nb_leaks = 0;
|
||||
static int extraMemoryFromResolver = 0;
|
||||
|
||||
/*
|
||||
* We need to trap calls to the resolver to not account memory for the catalog
|
||||
* which is shared to the current running test. We also don't want to have
|
||||
* network downloads modifying tests.
|
||||
*/
|
||||
static xmlParserInputPtr
|
||||
testExternalEntityLoader(const char *URL, const char *ID,
|
||||
xmlParserCtxtPtr ctxt) {
|
||||
xmlParserInputPtr ret;
|
||||
int memused = xmlMemUsed();
|
||||
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
extraMemoryFromResolver += xmlMemUsed() - memused;
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
initializeLibxml2(void) {
|
||||
xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
|
||||
xmlInitParser();
|
||||
xmlSetExternalEntityLoader(testExternalEntityLoader);
|
||||
#ifdef LIBXML_CATALOG_ENABLED
|
||||
xmlInitializeCatalog();
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
|
||||
#endif
|
||||
/*
|
||||
* register the new I/O handlers
|
||||
*/
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <libxml/catalog.h>
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/parserInternals.h>
|
||||
#include <libxml/tree.h>
|
||||
@ -330,7 +331,6 @@ hugeRead(void *context, char *buffer, int len)
|
||||
static int nb_tests = 0;
|
||||
static int nb_errors = 0;
|
||||
static int nb_leaks = 0;
|
||||
static int extraMemoryFromResolver = 0;
|
||||
|
||||
static int
|
||||
fatalError(void) {
|
||||
@ -338,32 +338,14 @@ fatalError(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to trap calls to the resolver to not account memory for the catalog
|
||||
* which is shared to the current running test. We also don't want to have
|
||||
* network downloads modifying tests.
|
||||
*/
|
||||
static xmlParserInputPtr
|
||||
testExternalEntityLoader(const char *URL, const char *ID,
|
||||
xmlParserCtxtPtr ctxt) {
|
||||
xmlParserInputPtr ret;
|
||||
|
||||
if (checkTestFile(URL)) {
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
} else {
|
||||
int memused = xmlMemUsed();
|
||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||
extraMemoryFromResolver += xmlMemUsed() - memused;
|
||||
}
|
||||
|
||||
return(ret);
|
||||
}
|
||||
|
||||
static void
|
||||
initializeLibxml2(void) {
|
||||
xmlMemSetup(xmlMemFree, xmlMemMalloc, xmlMemRealloc, xmlMemoryStrdup);
|
||||
xmlInitParser();
|
||||
xmlSetExternalEntityLoader(testExternalEntityLoader);
|
||||
#ifdef LIBXML_CATALOG_ENABLED
|
||||
xmlInitializeCatalog();
|
||||
xmlCatalogSetDefaults(XML_CATA_ALLOW_NONE);
|
||||
#endif
|
||||
/*
|
||||
* register the new I/O handlers
|
||||
*/
|
||||
@ -835,7 +817,6 @@ launchTests(testDescPtr tst) {
|
||||
fprintf(stderr, "Missing error file %s\n", error);
|
||||
} else {
|
||||
mem = xmlMemUsed();
|
||||
extraMemoryFromResolver = 0;
|
||||
res = tst->func(globbuf.gl_pathv[i], result, error,
|
||||
tst->options | XML_PARSE_COMPACT);
|
||||
xmlResetLastError();
|
||||
@ -846,13 +827,10 @@ launchTests(testDescPtr tst) {
|
||||
err++;
|
||||
}
|
||||
else if (xmlMemUsed() != mem) {
|
||||
if ((xmlMemUsed() != mem) &&
|
||||
(extraMemoryFromResolver == 0)) {
|
||||
fprintf(stderr, "File %s leaked %d bytes\n",
|
||||
globbuf.gl_pathv[i], xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
err++;
|
||||
}
|
||||
fprintf(stderr, "File %s leaked %d bytes\n",
|
||||
globbuf.gl_pathv[i], xmlMemUsed() - mem);
|
||||
nb_leaks++;
|
||||
err++;
|
||||
}
|
||||
}
|
||||
if (result)
|
||||
@ -862,7 +840,6 @@ launchTests(testDescPtr tst) {
|
||||
}
|
||||
globfree(&globbuf);
|
||||
} else {
|
||||
extraMemoryFromResolver = 0;
|
||||
res = tst->func(NULL, NULL, NULL, tst->options);
|
||||
if (res != 0) {
|
||||
nb_errors++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user