File: test_ossfuzz.cpp

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (50 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "catch.hpp"
#include "duckdb/common/file_system.hpp"
#include "test_helpers.hpp"

#include <fstream>
#include <streambuf>
#include <sstream>
#include <string>

using namespace duckdb;
using namespace std;

constexpr const char *QUERY_DIRECTORY = "test/ossfuzz/cases";

static void test_runner() {
	duckdb::unique_ptr<FileSystem> fs = FileSystem::CreateLocal();
	auto file_name = Catch::getResultCapture().getCurrentTestName();

	duckdb::unique_ptr<QueryResult> result;
	DuckDB db(nullptr);
	Connection con(db);
	std::ifstream t(file_name);
	duckdb::stringstream buffer;
	buffer << t.rdbuf();
	auto query = buffer.str();
	result = con.Query(query.c_str());

	unordered_set<string> internal_error_messages = {"Unoptimized Result differs from original result!", "INTERNAL"};
	if (result->HasError()) {
		if (TestIsInternalError(internal_error_messages, result->GetError())) {
			result->Print();
			REQUIRE(!result->GetErrorObject().HasError());
		}
	}

	// we don't know whether the query fails or not and we don't know the
	// correct result we just don't want it to crash
	REQUIRE(1 == 1);
}

struct RegisterOssfuzzTests {
	RegisterOssfuzzTests() {
		// Register a separate test for each file in the QUERY_DIRECTORY.
		duckdb::unique_ptr<FileSystem> fs = FileSystem::CreateLocal();
		fs->ListFiles(QUERY_DIRECTORY, [&](string path, bool) {
			REGISTER_TEST_CASE(test_runner, string(QUERY_DIRECTORY) + "/" + path, "[ossfuzz][.]");
		});
	}
};
RegisterOssfuzzTests register_ossfuzz_test;