.. _stdlib_fuzzer: ====== Fuzzer ====== .. include:: detail/fuzzer.rst FUZZER 模块实现了模糊测试的工具。 模糊测试背后的想法是将随机数据提供给 testing 函数,并查看它是否崩溃。 `panic` 被认为是一种有效的行为,实际上被忽略了。 模糊测试与消毒剂(asan、ubsan 等)结合使用效果非常好。 所有函数和符号都在 “fuzzer” 模块中,使用 require 来访问它。 :: require daslib/fuzzer ++++++++++++ Fuzzer 测试 ++++++++++++ * :ref:`fuzz (blk:block\<\> const) : void ` * :ref:`fuzz (fuzz_count:int const;blk:block\<\> const) : void ` * :ref:`fuzz_debug (blk:block\<\> const) : void ` * :ref:`fuzz_debug (fuzz_count:int const;blk:block\<\> const) : void ` * :ref:`fuzz_numeric_and_vector_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_and_vector_signed_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_and_storage_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_all_ints_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_all_unsigned_ints_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_float_double_or_float_vec_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_float_or_float_vec_op1 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_float_or_float_vec_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_float_double_or_float_vec_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_and_vector_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_and_vector_op2_no_unint_vec (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_compareable_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_eq_neq_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_vec_scal_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_scal_vec_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_int_vector_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_shift_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_rotate_op2 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_op3 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_vec_op3 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_vec_mad_op3 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_float_double_or_float_vec_op3 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` * :ref:`fuzz_numeric_op4 (t:testing::T? const;fake:faker::Faker -const;funcname:string const) : void ` .. _function-_at_fuzzer_c__c_fuzz_C_builtin_: .. das:function:: fuzz(blk: block<> const) +--------+-------------+ +argument+argument type+ +========+=============+ +blk +block<> const+ +--------+-------------+ 运行 block 多少次 忽略 panic,这样我们就可以看到运行时崩溃了 .. _function-_at_fuzzer_c__c_fuzz_Ci_C_builtin_: .. das:function:: fuzz(fuzz_count: int const; blk: block<> const) +----------+-------------+ +argument +argument type+ +==========+=============+ +fuzz_count+int const + +----------+-------------+ +blk +block<> const+ +----------+-------------+ 运行 block 多少次 忽略 panic,这样我们就可以看到运行时崩溃了 .. _function-_at_fuzzer_c__c_fuzz_debug_C_builtin_: .. das:function:: fuzz_debug(blk: block<> const) +--------+-------------+ +argument+argument type+ +========+=============+ +blk +block<> const+ +--------+-------------+ 运行 block 多少次 不要忽略 panic,这样我们才能看到 runtime 失败的地方 这是为了方便调试,可以很容易地将 `fuzz` 替换为 `fuzz_debug` .. _function-_at_fuzzer_c__c_fuzz_debug_Ci_C_builtin_: .. das:function:: fuzz_debug(fuzz_count: int const; blk: block<> const) +----------+-------------+ +argument +argument type+ +==========+=============+ +fuzz_count+int const + +----------+-------------+ +blk +block<> const+ +----------+-------------+ 运行 block 多少次 不要忽略 panic,这样我们才能看到 runtime 失败的地方 这是为了方便调试,可以很容易地将 `fuzz` 替换为 `fuzz_debug` .. _function-_at_fuzzer_c__c_fuzz_numeric_and_vector_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_and_vector_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double, string, int2, int3, int4, uint2, uint3, uint4, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_and_vector_signed_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_and_vector_signed_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double, string, int2, int3, int4, uint2, uint3, uint4, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double .. _function-_at_fuzzer_c__c_fuzz_numeric_and_storage_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_and_storage_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: int, uint, int8, uint8, int16, uint16, int64, uint64, float, double .. _function-_at_fuzzer_c__c_fuzz_all_ints_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_all_ints_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: int, uint, int64, uint64 .. _function-_at_fuzzer_c__c_fuzz_all_unsigned_ints_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_all_unsigned_ints_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: uint, uint64 .. _function-_at_fuzzer_c__c_fuzz_float_double_or_float_vec_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_float_double_or_float_vec_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: float, double, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_float_or_float_vec_op1_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_float_or_float_vec_op1(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收单一数值或向量参数的通用函数进行模糊测试。 参数是: float, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_float_or_float_vec_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_float_or_float_vec_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: float, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_float_double_or_float_vec_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_float_double_or_float_vec_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: float, double, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_and_vector_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_and_vector_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double, int2, int3, int4, uint2, uint3, uint4, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_and_vector_op2_no_unint_vec_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_and_vector_op2_no_unint_vec(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double, int2, int3, int4, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double .. _function-_at_fuzzer_c__c_fuzz_compareable_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_compareable_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double, int64, uint64, string .. _function-_at_fuzzer_c__c_fuzz_eq_neq_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_eq_neq_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, int64, uint64, float, double, string, int2, int3, int4, uint2, uint3, uint4, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_vec_scal_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_vec_scal_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 模糊通用函数,在右侧接收向量和匹配标量 参数对是: int2,int; int3,int; uint2,uint; uint3,uint; uint4,uint; int4,int; float2,float; float3,float; float4,float .. _function-_at_fuzzer_c__c_fuzz_numeric_scal_vec_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_scal_vec_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 模糊通用函数,在左侧接收向量和匹配标量 参数对是: int2,int; int3,int; uint2,uint; uint3,uint; uint4,uint; int4,int; float2,float; float3,float; float4,float .. _function-_at_fuzzer_c__c_fuzz_int_vector_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_int_vector_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收两个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, int2, int3, int4, uint2, uint3, uint4 .. _function-_at_fuzzer_c__c_fuzz_shift_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_shift_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 模糊处理接收数字或向量参数的通用函数,右侧为匹配的移位类型。 参数是: int, uint, int2, int3, int4, uint2, uint3, uint4 .. _function-_at_fuzzer_c__c_fuzz_rotate_op2_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_rotate_op2(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 模糊处理接收数字或向量参数的通用函数,右侧为匹配的旋转类型。 参数是: int, uint .. _function-_at_fuzzer_c__c_fuzz_numeric_op3_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_op3(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收三个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double .. _function-_at_fuzzer_c__c_fuzz_vec_op3_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_vec_op3(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收三个数字或向量参数的通用函数进行模糊测试。 参数是: float2, float3, float4, int2, int3, int4, uint2, uint3, uint4 .. _function-_at_fuzzer_c__c_fuzz_vec_mad_op3_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_vec_mad_op3(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收三个数字或向量参数的通用函数进行模糊测试。 参数是: float2, float3, float4, int2, int3, int4, uint2, uint3, uint4 second argument is float, int, uint accordingly .. _function-_at_fuzzer_c__c_fuzz_float_double_or_float_vec_op3_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_float_double_or_float_vec_op3(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对接收三个数字或向量参数的通用函数进行模糊测试。 参数是: float, double, float2, float3, float4 .. _function-_at_fuzzer_c__c_fuzz_numeric_op4_C1_ls_S_ls_testing_c__c_T_gr__gr__qm__S_ls_faker_c__c_Faker_gr__Cs: .. das:function:: fuzz_numeric_op4(t: T? const; fake: Faker; funcname: string const) +--------+---------------------------------------------+ +argument+argument type + +========+=============================================+ +t + :ref:`testing::T ` ? const+ +--------+---------------------------------------------+ +fake + :ref:`faker::Faker ` + +--------+---------------------------------------------+ +funcname+string const + +--------+---------------------------------------------+ 对包含四个数字或向量参数的通用函数进行模糊测试。 参数是: int, uint, float, double