X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=test%2Fbreak-loader.c;h=542f36ffd12d8a85a38fa89aab2e9646a6827435;hb=88498b706a39bbe520f9591d8d52b54fb1f8e378;hp=e2ce6819816f96e2b0725b9a3e2bc2dd16def695;hpb=fa05de9230d62e7c427b5313796fc6ccd4d0ff60;p=platform%2Fupstream%2Fdbus.git diff --git a/test/break-loader.c b/test/break-loader.c index e2ce681..542f36f 100644 --- a/test/break-loader.c +++ b/test/break-loader.c @@ -1,9 +1,9 @@ -/* -*- mode: C; c-file-style: "gnu" -*- */ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ /* dbus-break-loader.c Program to find byte streams that break the message loader * * Copyright (C) 2003 Red Hat Inc. * - * Licensed under the Academic Free License version 1.2 + * Licensed under the Academic Free License version 2.1 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,10 +17,11 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#include #include #include #include @@ -36,7 +37,7 @@ #include #include #include -#include +#include #undef DBUS_COMPILATION static DBusString failure_dir; @@ -160,7 +161,7 @@ try_mutated_data (const DBusString *data) printf ("Child failed, writing %s\n", _dbus_string_get_const_data (&filename)); dbus_error_init (&error); - if (!_dbus_string_save_to_file (data, &filename, &error)) + if (!_dbus_string_save_to_file (data, &filename, FALSE, &error)) { fprintf (stderr, "Failed to save failed message data: %s\n", error.message); @@ -287,8 +288,8 @@ randomly_add_one_byte (const DBusString *orig_data, i = random_int_in_range (0, _dbus_string_get_length (mutated)); - _dbus_string_insert_byte (mutated, i, - random_int_in_range (0, 256)); + _dbus_string_insert_bytes (mutated, i, 1, + random_int_in_range (0, 256)); } static void @@ -347,10 +348,12 @@ randomly_set_extreme_ints (const DBusString *orig_data, _DBUS_UINT_MAX - 1, _DBUS_INT_MAX - 2, _DBUS_UINT_MAX - 2, - (unsigned int) (_DBUS_INT_MAX + 1), - (unsigned int) (_DBUS_UINT_MAX + 1), - _DBUS_INT_MAX + 2, - _DBUS_UINT_MAX + 2, + _DBUS_INT_MAX - 17, + _DBUS_UINT_MAX - 17, + _DBUS_INT_MAX / 2, + _DBUS_INT_MAX / 3, + _DBUS_UINT_MAX / 2, + _DBUS_UINT_MAX / 3, 0, 1, 2, 3, (unsigned int) -1, (unsigned int) -2, @@ -390,7 +393,69 @@ randomly_set_extreme_ints (const DBusString *orig_data, extreme_ints[which]); } -static int times_we_did_each_thing[6] = { 0, }; +static int +random_type (void) +{ + const char types[] = { + DBUS_TYPE_INVALID, + DBUS_TYPE_NIL, + DBUS_TYPE_BYTE, + DBUS_TYPE_BOOLEAN, + DBUS_TYPE_INT32, + DBUS_TYPE_UINT32, + DBUS_TYPE_INT64, + DBUS_TYPE_UINT64, + DBUS_TYPE_DOUBLE, + DBUS_TYPE_STRING, + DBUS_TYPE_CUSTOM, + DBUS_TYPE_ARRAY, + DBUS_TYPE_DICT, + DBUS_TYPE_OBJECT_PATH + }; + + _dbus_assert (_DBUS_N_ELEMENTS (types) == DBUS_NUMBER_OF_TYPES + 1); + + return types[ random_int_in_range (0, _DBUS_N_ELEMENTS (types)) ]; +} + +static void +randomly_change_one_type (const DBusString *orig_data, + DBusString *mutated) +{ + int i; + int len; + + if (orig_data != mutated) + { + _dbus_string_set_length (mutated, 0); + + if (!_dbus_string_copy (orig_data, 0, mutated, 0)) + _dbus_assert_not_reached ("out of mem"); + } + + if (_dbus_string_get_length (mutated) == 0) + return; + + len = _dbus_string_get_length (mutated); + i = random_int_in_range (0, len); + + /* Look for a type starting at a random location, + * and replace with a different type + */ + while (i < len) + { + int b; + b = _dbus_string_get_byte (mutated, i); + if (dbus_type_is_valid (b)) + { + _dbus_string_set_byte (mutated, i, random_type ()); + return; + } + ++i; + } +} + +static int times_we_did_each_thing[7] = { 0, }; static void randomly_do_n_things (const DBusString *orig_data, @@ -406,7 +471,8 @@ randomly_do_n_things (const DBusString *orig_data, randomly_add_one_byte, randomly_remove_one_byte, randomly_modify_length, - randomly_set_extreme_ints + randomly_set_extreme_ints, + randomly_change_one_type }; _dbus_string_set_length (mutated, 0); @@ -457,6 +523,7 @@ find_breaks_based_on (const DBusString *filename, goto failed; } + printf (" changing one random byte 100 times\n"); i = 0; while (i < 100) { @@ -466,6 +533,7 @@ find_breaks_based_on (const DBusString *filename, ++i; } + printf (" changing length 50 times\n"); i = 0; while (i < 50) { @@ -474,7 +542,8 @@ find_breaks_based_on (const DBusString *filename, ++i; } - + + printf (" removing one byte 50 times\n"); i = 0; while (i < 50) { @@ -484,6 +553,7 @@ find_breaks_based_on (const DBusString *filename, ++i; } + printf (" adding one byte 50 times\n"); i = 0; while (i < 50) { @@ -493,6 +563,7 @@ find_breaks_based_on (const DBusString *filename, ++i; } + printf (" changing ints to boundary values 50 times\n"); i = 0; while (i < 50) { @@ -501,7 +572,18 @@ find_breaks_based_on (const DBusString *filename, ++i; } - + + printf (" changing typecodes 50 times\n"); + i = 0; + while (i < 50) + { + randomly_change_one_type (&orig_data, &mutated); + try_mutated_data (&mutated); + + ++i; + } + + printf (" changing message length 15 times\n"); i = 0; while (i < 15) { @@ -511,6 +593,7 @@ find_breaks_based_on (const DBusString *filename, ++i; } + printf (" randomly making 2 of above modifications 42 times\n"); i = 0; while (i < 42) { @@ -520,6 +603,7 @@ find_breaks_based_on (const DBusString *filename, ++i; } + printf (" randomly making 3 of above modifications 42 times\n"); i = 0; while (i < 42) { @@ -529,6 +613,7 @@ find_breaks_based_on (const DBusString *filename, ++i; } + printf (" randomly making 4 of above modifications 42 times\n"); i = 0; while (i < 42) { @@ -657,14 +742,15 @@ main (int argc, return 1; } - printf (" did %d random mutations: %d %d %d %d %d %d\n", + printf (" did %d random mutations: %d %d %d %d %d %d %d\n", _DBUS_N_ELEMENTS (times_we_did_each_thing), times_we_did_each_thing[0], times_we_did_each_thing[1], times_we_did_each_thing[2], times_we_did_each_thing[3], times_we_did_each_thing[4], - times_we_did_each_thing[5]); + times_we_did_each_thing[5], + times_we_did_each_thing[6]); printf ("Found %d failures with seed %u stored in %s\n", failures_this_iteration, seed, failure_dir_c);