diff options
Diffstat (limited to 'tests/test-rollsum.c')
-rw-r--r-- | tests/test-rollsum.c | 90 |
1 files changed, 55 insertions, 35 deletions
diff --git a/tests/test-rollsum.c b/tests/test-rollsum.c index 57f7aa06..a454e626 100644 --- a/tests/test-rollsum.c +++ b/tests/test-rollsum.c @@ -19,22 +19,23 @@ #include "config.h" -#include "libglnx.h" #include "bsdiff/bsdiff.h" #include "bsdiff/bspatch.h" +#include "bupsplit.h" +#include "libglnx.h" +#include "ostree-rollsum.h" +#include <gio/gio.h> #include <glib.h> #include <stdlib.h> -#include <gio/gio.h> #include <string.h> -#include "ostree-rollsum.h" -#include "bupsplit.h" static void -test_rollsum_helper (const unsigned char *a, gsize size_a, const unsigned char *b, gsize size_b, gboolean expected_match) +test_rollsum_helper (const unsigned char *a, gsize size_a, const unsigned char *b, gsize size_b, + gboolean expected_match) { gsize i; - g_autoptr(GBytes) bytes_a = g_bytes_new_static (a, size_a); - g_autoptr(GBytes) bytes_b = g_bytes_new_static (b, size_b); + g_autoptr (GBytes) bytes_a = g_bytes_new_static (a, size_a); + g_autoptr (GBytes) bytes_b = g_bytes_new_static (b, size_b); OstreeRollsumMatches *matches; GPtrArray *matchlist; guint64 sum_matched = 0; @@ -75,16 +76,34 @@ test_rollsum (void) int len; g_autofree unsigned char *a = g_malloc (MAX_BUFFER_SIZE); g_autofree unsigned char *b = g_malloc (MAX_BUFFER_SIZE); - g_autoptr(GRand) rand = g_rand_new (); + g_autoptr (GRand) rand = g_rand_new (); /* These two buffers produce the same crc32. */ - const unsigned char conflicting_a[] = {0x35, 0x9b, 0x94, 0x5a, 0xa0, 0x5a, 0x34, 0xdc, 0x5c, 0x3, 0x46, 0xe, 0x34, 0x53, 0x85, 0x73, 0x64, 0xcc, 0x47, 0x10, 0x23, 0x8e, 0x7e, 0x6a, 0xca, 0xda, 0x7c, 0x12, 0x8a, 0x59, 0x7f, 0x7f, 0x4d, 0x1, 0xd8, 0xcc, 0x81, 0xcf, 0x2c, 0x7f, 0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70, 0xd5, 0xf3, 0x8d, 0xdc, 0xad, 0x68, 0x63, 0xa5, 0x72, 0xce, 0x6b, 0x9, 0x2b, 0x60, 0x1b, 0x99, 0xd7, 0x86}; + const unsigned char conflicting_a[] + = { 0x35, 0x9b, 0x94, 0x5a, 0xa0, 0x5a, 0x34, 0xdc, 0x5c, 0x3, 0x46, 0xe, 0x34, 0x53, 0x85, + 0x73, 0x64, 0xcc, 0x47, 0x10, 0x23, 0x8e, 0x7e, 0x6a, 0xca, 0xda, 0x7c, 0x12, 0x8a, 0x59, + 0x7f, 0x7f, 0x4d, 0x1, 0xd8, 0xcc, 0x81, 0xcf, 0x2c, 0x7f, 0x10, 0xc2, 0xb4, 0x40, 0x1f, + 0x2a, 0x0, 0x37, 0x85, 0xde, 0xfe, 0xa5, 0xc, 0x7c, 0xa1, 0x8, 0xd6, 0x75, 0xfd, 0x2, + 0xcf, 0x2d, 0x53, 0x1b, 0x8a, 0x6b, 0x35, 0xad, 0xa, 0x8f, 0xad, 0x2d, 0x91, 0x87, 0x2b, + 0x97, 0xcf, 0x1d, 0x7c, 0x61, 0xc4, 0xb2, 0x5e, 0xc3, 0xba, 0x5d, 0x2f, 0x3a, 0xeb, 0x41, + 0x61, 0x4c, 0xa2, 0x34, 0xd, 0x43, 0xce, 0x10, 0xa3, 0x47, 0x4, 0xa0, 0x39, 0x77, 0xc2, + 0xe8, 0x36, 0x1d, 0x87, 0xd1, 0x8f, 0x4d, 0x13, 0xa1, 0x34, 0xc3, 0x2c, 0xee, 0x1a, 0x10, + 0x79, 0xb7, 0x97, 0x29, 0xe8, 0xf0, 0x5, 0xfc, 0xe6, 0x14, 0x87, 0x9c, 0x8f, 0x97, 0x23, + 0xac, 0x1, 0xf2, 0xee, 0x69, 0xb2, 0xe5 }; + + const unsigned char conflicting_b[] + = { 0xb2, 0x54, 0x81, 0x7d, 0x31, 0x83, 0xc7, 0xc, 0xcf, 0x7d, 0x90, 0x1c, 0x6b, 0xf6, 0x4e, + 0xff, 0x49, 0xd1, 0xb6, 0xc, 0x9e, 0x85, 0xe3, 0x2d, 0xdb, 0x94, 0x8e, 0x1a, 0x17, 0x3f, + 0x63, 0x59, 0xf9, 0x4b, 0x5f, 0x47, 0x97, 0x9c, 0x1c, 0xd7, 0x24, 0xd9, 0x42, 0x6, 0x1e, + 0xf, 0x98, 0x10, 0xb4, 0xc, 0x50, 0xcb, 0xc5, 0x62, 0x53, 0x1, 0xd1, 0x5f, 0x16, 0x97, + 0xaa, 0xd7, 0x57, 0x5e, 0xf2, 0xde, 0xae, 0x53, 0x58, 0x6, 0xb7, 0x9b, 0x8d, 0x2b, 0xd6, + 0xb4, 0x55, 0x29, 0x3b, 0x27, 0x70, 0xd5, 0xf3, 0x8d, 0xdc, 0xad, 0x68, 0x63, 0xa5, 0x72, + 0xce, 0x6b, 0x9, 0x2b, 0x60, 0x1b, 0x99, 0xd7, 0x86 }; + + test_rollsum_helper (conflicting_a, sizeof conflicting_a, conflicting_b, sizeof conflicting_b, + FALSE); - test_rollsum_helper (conflicting_a, sizeof conflicting_a, conflicting_b, sizeof conflicting_b, FALSE); - - for (i = 0; i < MAX_BUFFER_SIZE; i++) + for (i = 0; i < MAX_BUFFER_SIZE; i++) { a[i] = g_rand_int (rand); b[i] = a[i]; @@ -139,32 +158,33 @@ test_rollsum (void) #define BUP_SELFTEST_SIZE 100000 static void -test_bupsplit_sum(void) +test_bupsplit_sum (void) { - g_autofree uint8_t *buf = g_malloc (BUP_SELFTEST_SIZE); - uint32_t sum1a, sum1b, sum2a, sum2b, sum3a, sum3b; - unsigned count; - - for (count = 0; count < BUP_SELFTEST_SIZE; count++) - buf[count] = g_random_int_range (0, 256); - - sum1a = bupsplit_sum(buf, 0, BUP_SELFTEST_SIZE); - sum1b = bupsplit_sum(buf, 1, BUP_SELFTEST_SIZE); - sum2a = bupsplit_sum(buf, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE*5/2, - BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); - sum2b = bupsplit_sum(buf, 0, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); - sum3a = bupsplit_sum(buf, 0, BUP_WINDOWSIZE+3); - sum3b = bupsplit_sum(buf, 3, BUP_WINDOWSIZE+3); - - g_assert_cmpint (sum1a, ==, sum1b); - g_assert_cmpint (sum2a, ==, sum2b); - g_assert_cmpint (sum3a, ==, sum3b); + g_autofree uint8_t *buf = g_malloc (BUP_SELFTEST_SIZE); + uint32_t sum1a, sum1b, sum2a, sum2b, sum3a, sum3b; + unsigned count; + + for (count = 0; count < BUP_SELFTEST_SIZE; count++) + buf[count] = g_random_int_range (0, 256); + + sum1a = bupsplit_sum (buf, 0, BUP_SELFTEST_SIZE); + sum1b = bupsplit_sum (buf, 1, BUP_SELFTEST_SIZE); + sum2a = bupsplit_sum (buf, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE * 5 / 2, + BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); + sum2b = bupsplit_sum (buf, 0, BUP_SELFTEST_SIZE - BUP_WINDOWSIZE); + sum3a = bupsplit_sum (buf, 0, BUP_WINDOWSIZE + 3); + sum3b = bupsplit_sum (buf, 3, BUP_WINDOWSIZE + 3); + + g_assert_cmpint (sum1a, ==, sum1b); + g_assert_cmpint (sum2a, ==, sum2b); + g_assert_cmpint (sum3a, ==, sum3b); } -int main (int argc, char **argv) +int +main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); g_test_add_func ("/rollsum", test_rollsum); g_test_add_func ("/bupsum", test_bupsplit_sum); - return g_test_run(); + return g_test_run (); } |