def TestOneInput(data): """Test randomized fuzzing input for tf.raw_ops.Acos.""" fh = FuzzingHelper(data) # tf.raw_ops.Acos takes tf.bfloat16, tf.half, tf.float32, tf.float64, tf.int8, # tf.int16, tf.int32, tf.int64, tf.complex64, tf.complex128, but # get_random_numeric_tensor only generates tf.float16, tf.float32, tf.float64, # tf.int32, tf.int64 input_tensor = fh.get_random_numeric_tensor() _ = tf.raw_ops.Acos(x=input_tensor)
def TestOneInput(data): """Test randomized fuzzing input for tf.raw_ops.Acosh.""" fh = FuzzingHelper(data) # tf.raw_ops.Acos takes tf.bfloat16, tf.half, tf.float32, tf.float64, # tf.complex64, tf.complex128, but get_random_numeric_tensor only generates # tf.float16, tf.float32, tf.float64, tf.int32, tf.int64 dtype = fh.get_tf_dtype(allowed_set=[tf.float16, tf.float32, tf.float64]) input_tensor = fh.get_random_numeric_tensor(dtype=dtype) _ = tf.raw_ops.Acosh(x=input_tensor)
def TestOneInput(input_bytes): """Test randomized integer/float fuzzing input for tf.raw_ops.RaggedCountSparseOutput.""" fh = FuzzingHelper(input_bytes) splits = fh.get_int_list() values = fh.get_int_or_float_list() weights = fh.get_int_list() try: _, _, _, = tf.raw_ops.RaggedCountSparseOutput( splits=splits, values=values, weights=weights, binary_output=False) except tf.errors.InvalidArgumentError: pass
def TestOneInput(input_bytes): """Test randomized integer fuzzing input for tf.raw_ops.SparseCountSparseOutput.""" fh = FuzzingHelper(input_bytes) shape1 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) shape2 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) shape3 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) shape4 = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) seed = fh.get_int() indices = tf.random.uniform( shape=shape1, minval=0, maxval=1000, dtype=tf.int64, seed=seed) values = tf.random.uniform( shape=shape2, minval=0, maxval=1000, dtype=tf.int64, seed=seed) dense_shape = tf.random.uniform( shape=shape3, minval=0, maxval=1000, dtype=tf.int64, seed=seed) weights = tf.random.uniform( shape=shape4, minval=0, maxval=1000, dtype=tf.int64, seed=seed) binary_output = fh.get_bool() minlength = fh.get_int() maxlength = fh.get_int() name = fh.get_string() try: _, _, _, = tf.raw_ops.SparseCountSparseOutput( indices=indices, values=values, dense_shape=dense_shape, weights=weights, binary_output=binary_output, minlength=minlength, maxlength=maxlength, name=name) except tf.errors.InvalidArgumentError: pass
def TestOneInput(data): """Test numeric randomized fuzzing input for tf.raw_ops.Add.""" fh = FuzzingHelper(data) # tf.raw_ops.Add also takes tf.bfloat16, tf.half, tf.float32, tf.float64, # tf.uint8, tf.int8, tf.int16, tf.int32, tf.int64, tf.complex64, # tf.complex128, but get_random_numeric_tensor only generates tf.float16, # tf.float32, tf.float64, tf.int32, tf.int64 input_tensor_x = fh.get_random_numeric_tensor() input_tensor_y = fh.get_random_numeric_tensor() try: _ = tf.raw_ops.Add(x=input_tensor_x, y=input_tensor_y) except (tf.errors.InvalidArgumentError, tf.errors.UnimplementedError): pass
def TestOneInput(input_bytes): """Test randomized integer fuzzing input for tf.raw_ops.ImmutableConst.""" fh = FuzzingHelper(input_bytes) dtype = fh.get_tf_dtype() shape = fh.get_int_list() try: with open(_DEFAULT_FILENAME, 'w') as f: f.write(fh.get_string()) _ = tf.raw_ops.ImmutableConst(dtype=dtype, shape=shape, memory_region_name=_DEFAULT_FILENAME) except (tf.errors.InvalidArgumentError, tf.errors.InternalError, UnicodeEncodeError, UnicodeDecodeError): pass
def TestOneInput(input_bytes): """Test randomized integer fuzzing input for tf.raw_ops.DataFormatVecPermute.""" fh = FuzzingHelper(input_bytes) dtype = fh.get_tf_dtype() # Max shape can be 8 in length and randomized from 0-8 without running into # a OOM error. shape = fh.get_int_list(min_length=0, max_length=8, min_int=0, max_int=8) seed = fh.get_int() try: x = tf.random.uniform(shape=shape, dtype=dtype, seed=seed) src_format_digits = str(fh.get_int(min_int=0, max_int=999999999)) dest_format_digits = str(fh.get_int(min_int=0, max_int=999999999)) _ = tf.raw_ops.DataFormatVecPermute(x, src_format=src_format_digits, dst_format=dest_format_digits, name=fh.get_string()) except (tf.errors.InvalidArgumentError, ValueError, TypeError): pass
def TestOneInput(input_bytes): """Test randomized integer fuzzing input for v1 vs v2 APIs.""" fh = FuzzingHelper(input_bytes) # Comparing tf.math.angle with tf.compat.v1.angle. input_supported_dtypes = [tf.float32, tf.float64] random_dtype_index = fh.get_int(min_int=0, max_int=1) input_dtype = input_supported_dtypes[random_dtype_index] input_shape = fh.get_int_list(min_length=0, max_length=6, min_int=0, max_int=10) seed = fh.get_int() input_tensor = tf.random.uniform(shape=input_shape, dtype=input_dtype, seed=seed, maxval=10) name = fh.get_string(5) v2_output = tf.math.angle(input=input_tensor, name=name) v1_output = tf.compat.v1.angle(input=input_tensor, name=name) try: tf.debugging.assert_equal(v1_output, v2_output) tf.debugging.assert_equal(v1_output.shape, v2_output.shape) except Exception as e: # pylint: disable=broad-except print("Input tensor: {}".format(input_tensor)) print("Input dtype: {}".format(input_dtype)) print("v1_output: {}".format(v1_output)) print("v2_output: {}".format(v2_output)) raise e # Comparing tf.debugging.assert_integer with tf.compat.v1.assert_integer. x_supported_dtypes = [ tf.float16, tf.float32, tf.float64, tf.int32, tf.int64, tf.string ] random_dtype_index = fh.get_int(min_int=0, max_int=5) x_dtype = x_supported_dtypes[random_dtype_index] x_shape = fh.get_int_list(min_length=0, max_length=6, min_int=0, max_int=10) seed = fh.get_int() try: x = tf.random.uniform(shape=x_shape, dtype=x_dtype, seed=seed, maxval=10) except ValueError: x = tf.constant(["test_string"]) message = fh.get_string(128) name = fh.get_string(128) try: v2_output = tf.debugging.assert_integer(x=x, message=message, name=name) except Exception as e: # pylint: disable=broad-except v2_output = e try: v1_output = tf.compat.v1.assert_integer(x=x, message=message, name=name) except Exception as e: # pylint: disable=broad-except v1_output = e if v1_output and v2_output: assert type(v2_output) == type(v1_output) # pylint: disable=unidiomatic-typecheck assert v2_output.args == v1_output.args