[repacker] change run_resolve_overflow_test to check for graph equivalence.

Replaces a check for an exact match on the final serialized bytes. The previous check enforced equivalent topological sorting between result and expected, but we only really care that the graph's are equivalent and don't overflow.
pull/3787/head
Garret Rieger 2 years ago
parent 07fd0528c0
commit 1405f96b6f
  1. 33
      src/graph/graph.hh
  2. 50
      src/test-repacker.cc

@ -49,17 +49,27 @@ struct graph_t
unsigned end = 0;
unsigned priority = 0;
bool equals (vertex_t& other, graph_t& graph)
void normalize ()
{
if (as_bytes () != other.as_bytes ())
obj.real_links.qsort ();
for (auto& l : obj.real_links)
{
for (unsigned i = 0; i < l.width; i++)
{
obj.head[l.position + i] = 0;
}
}
}
bool equals (const vertex_t& other, const graph_t& graph) const
{
if (!(as_bytes () == other.as_bytes ()))
return false;
obj.real_links.qsort ();
other.obj.real_links.qsort ();
return links_equal (graph, obj.real_links, other.obj.real_links);
}
hb_bytes_t as_bytes ()
hb_bytes_t as_bytes () const
{
return hb_bytes_t (obj.head, table_size ());
}
@ -184,7 +194,7 @@ struct graph_t
}
private:
bool links_equal (graph_t& graph,
bool links_equal (const graph_t& graph,
const hb_vector_t<hb_serialize_context_t::object_t::link_t>& this_links,
const hb_vector_t<hb_serialize_context_t::object_t::link_t>& other_links) const
{
@ -281,9 +291,16 @@ struct graph_t
hb_free (b);
}
bool operator== (graph_t& other)
bool operator== (const graph_t& other) const
{
return root ().equals (other.root (), *this);
}
// Sorts links of all objects in a consistent manner and zeroes all offsets.
void normalize ()
{
return vertices_[root_idx ()].equals (other.vertices_[other.root_idx ()], *this);
for (auto& v : vertices_.writer ())
v.normalize ();
}
bool in_error () const

@ -309,44 +309,28 @@ static void run_resolve_overflow_test (const char* name,
name);
graph_t graph (overflowing.object_graph ());
graph_t expected_graph (expected.object_graph ());
// Check that overflow resolution succeeds
assert (overflowing.offset_overflow ());
hb_blob_t* out = hb_resolve_overflows (overflowing.object_graph (),
tag,
num_iterations,
recalculate_extensions);
assert (out);
hb_bytes_t result = out->as_bytes ();
assert (!expected.offset_overflow ());
hb_bytes_t expected_result = expected.copy_bytes ();
if (result.length != expected_result.length)
{
printf("result.length (%u) != expected.length (%u).\n",
result.length,
expected_result.length);
}
assert (result.length == expected_result.length);
bool equal = true;
for (unsigned i = 0; i < expected_result.length; i++)
{
if (result[i] != expected_result[i])
{
equal = false;
uint8_t a = result[i];
uint8_t b = expected_result[i];
printf("%08u: %x != %x\n", i, a, b);
}
}
assert (hb_resolve_graph_overflows (tag,
num_iterations,
recalculate_extensions,
graph));
assert (equal);
expected_result.fini ();
// Check the graphs can be serialized.
hb_blob_t* out = graph::serialize (graph);
assert (out);
hb_blob_destroy (out);
out = graph::serialize (expected_graph);
assert (out);
hb_blob_destroy (out);
// Check the graphs are equivalent
graph.normalize ();
expected_graph.normalize ();
assert (graph == expected_graph);
}
static void add_virtual_offset (unsigned id,

Loading…
Cancel
Save