Add explicit test for file not found

...caching the metadata moved where ParquetTable did I/O,
which introduced a segfault on not found
This commit is contained in:
Colin Dellow 2018-03-18 11:58:23 -04:00
parent 4cbde9fc09
commit 3b557f7fb0
3 changed files with 39 additions and 6 deletions

View File

@ -80,27 +80,26 @@ static int parquetConnect(
// Remove the delimiting single quotes // Remove the delimiting single quotes
std::string fname = argv[3]; std::string fname = argv[3];
fname = fname.substr(1, fname.length() - 2); fname = fname.substr(1, fname.length() - 2);
std::unique_ptr<ParquetTable> table(new ParquetTable(fname));
std::unique_ptr<sqlite3_vtab_parquet, void(*)(void*)> vtab( std::unique_ptr<sqlite3_vtab_parquet, void(*)(void*)> vtab(
(sqlite3_vtab_parquet*)sqlite3_malloc(sizeof(sqlite3_vtab_parquet)), (sqlite3_vtab_parquet*)sqlite3_malloc(sizeof(sqlite3_vtab_parquet)),
sqlite3_free); sqlite3_free);
memset(vtab.get(), 0, sizeof(*vtab.get())); memset(vtab.get(), 0, sizeof(*vtab.get()));
try { try {
std::unique_ptr<ParquetTable> table(new ParquetTable(fname));
std::string create = table->CreateStatement(); std::string create = table->CreateStatement();
int rc = sqlite3_declare_vtab(db, create.data()); int rc = sqlite3_declare_vtab(db, create.data());
if(rc) if(rc)
return rc; return rc;
vtab->table = table.release();
*ppVtab = (sqlite3_vtab*)vtab.release();
return SQLITE_OK;
} catch (const std::exception& e) { } catch (const std::exception& e) {
*pzErr = sqlite3_mprintf(e.what()); *pzErr = sqlite3_mprintf(e.what());
return SQLITE_ERROR; return SQLITE_ERROR;
} }
vtab->table = table.release();
*ppVtab = (sqlite3_vtab*)vtab.release();
return SQLITE_OK;
} }
/* /*

View File

@ -4,6 +4,7 @@ set -euo pipefail
here=$(dirname "${BASH_SOURCE[0]}") here=$(dirname "${BASH_SOURCE[0]}")
set -x set -x
"$here"/test-non-existent
"$here"/test-unsupported "$here"/test-unsupported
"$here"/test-supported "$here"/test-supported
"$here"/test-queries "$here"/test-queries

33
tests/test-non-existent Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
set -euo pipefail
# Verify that loading a non existent file is an error, not a segfault
load_nonexistent() {
cat <<EOF
.echo on
.load parquet/libparquet
.testcase notfound
.bail on
CREATE VIRTUAL TABLE test USING parquet('$root/doesnotexist.parquet');
SELECT 123;
EOF
}
main() {
root=$(dirname "${BASH_SOURCE[0]}")/..
root=$(readlink -f "$root")
cd "$root"
#This line will exit with non-zero in case of a segfault.
"$root"/sqlite/sqlite3 -init <(load_nonexistent) < /dev/null > /dev/null 2> testcase-stderr.txt
# We expect the 'SELECT 123' command to NOT have been run
if grep -q 123 testcase-out.txt; then
echo "...FAILED; expected an error message. Check testcase-{out,err}.txt" >&2
exit 1
fi
}
main "$@"