Skip to content

Commit 0cde2cf

Browse files
committed
tools: Add fuzzing driver for clusterization
We use a similar basic mesh construction from simplifyfuzz and test both clusterizers with various vertex/triangle limits.
1 parent d249d26 commit 0cde2cf

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ codectest: tools/codectest.cpp $(LIBRARY)
228228
codecfuzz: tools/codecfuzz.cpp src/vertexcodec.cpp src/indexcodec.cpp
229229
$(CXX) $^ -fsanitize=fuzzer,address,undefined -O1 -g -o $@
230230

231+
clusterfuzz: tools/clusterfuzz.cpp src/clusterizer.cpp
232+
$(CXX) $^ -fsanitize=fuzzer,address,undefined -O1 -g -o $@
233+
231234
simplifyfuzz: tools/simplifyfuzz.cpp src/simplifier.cpp
232235
$(CXX) $^ -fsanitize=fuzzer,address,undefined -O1 -g -o $@
233236

tools/clusterfuzz.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "../src/meshoptimizer.h"
2+
3+
#include <float.h>
4+
#include <stdint.h>
5+
#include <stdlib.h>
6+
7+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* buffer, size_t size)
8+
{
9+
if (size == 0)
10+
return 0;
11+
12+
srand(buffer[0]);
13+
14+
float vb[100][4];
15+
16+
for (int i = 0; i < 100; ++i)
17+
{
18+
vb[i][0] = rand() % 10;
19+
vb[i][1] = rand() % 10;
20+
vb[i][2] = rand() % 10;
21+
vb[i][3] = rand() % 10;
22+
}
23+
24+
unsigned int ib[999];
25+
int indices = (size - 1) < 999 ? (size - 1) / 3 * 3 : 999;
26+
27+
for (int i = 0; i < indices; ++i)
28+
ib[i] = buffer[1 + i] % 100;
29+
30+
meshopt_Meshlet ml[333];
31+
unsigned int mv[333 * 3];
32+
unsigned char mt[333 * 4];
33+
34+
meshopt_buildMeshlets(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 4, /* max_triangles= */ 4, 0.f);
35+
36+
meshopt_buildMeshletsScan(ml, mv, mt, ib, indices, 100, /* max_vertices= */ 4, /* max_triangles= */ 4);
37+
meshopt_buildMeshletsScan(ml, mv, mt, ib, indices, 100, /* max_vertices= */ 4, /* max_triangles= */ 8);
38+
39+
meshopt_buildMeshletsFlex(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 4, /* min_triangles= */ 4, /* max_triangles= */ 8, 0.f, 2.f);
40+
meshopt_buildMeshletsFlex(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 8, /* min_triangles= */ 8, /* max_triangles= */ 16, 0.f, 2.f);
41+
meshopt_buildMeshletsFlex(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 16, /* min_triangles= */ 8, /* max_triangles= */ 32, 0.f, 2.f);
42+
meshopt_buildMeshletsFlex(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 16, /* min_triangles= */ 16, /* max_triangles= */ 32, 0.f, 2.f);
43+
44+
meshopt_buildMeshletsSplit(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 4, /* min_triangles= */ 4, /* max_triangles= */ 8);
45+
meshopt_buildMeshletsSplit(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 8, /* min_triangles= */ 4, /* max_triangles= */ 32);
46+
meshopt_buildMeshletsSplit(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 8, /* min_triangles= */ 8, /* max_triangles= */ 32);
47+
meshopt_buildMeshletsSplit(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 8, /* min_triangles= */ 12, /* max_triangles= */ 32);
48+
meshopt_buildMeshletsSplit(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 16, /* min_triangles= */ 16, /* max_triangles= */ 32);
49+
meshopt_buildMeshletsSplit(ml, mv, mt, ib, indices, vb[0], 100, sizeof(float) * 4, /* max_vertices= */ 16, /* min_triangles= */ 32, /* max_triangles= */ 32);
50+
51+
return 0;
52+
}

0 commit comments

Comments
 (0)