From e858def5cd6fc1c38eb1cac90cb7962b0ccf04f4 Mon Sep 17 00:00:00 2001 From: shixiaowei4 Date: Tue, 25 Jun 2024 09:14:27 +0800 Subject: [PATCH] Add Deque and Queue Signed-off-by: shixiaowei4 --- Sources/FuzzilliCli/Profiles/ArkProfile.swift | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Sources/FuzzilliCli/Profiles/ArkProfile.swift b/Sources/FuzzilliCli/Profiles/ArkProfile.swift index 602ac3a..10a4c81 100644 --- a/Sources/FuzzilliCli/Profiles/ArkProfile.swift +++ b/Sources/FuzzilliCli/Profiles/ArkProfile.swift @@ -27,7 +27,7 @@ fileprivate let RunNearStackLimitGenerator = CodeGenerator("RunNearStackLimitGen /// ArkTS Generators fileprivate let ArkTSObjectInstanceGenerator = ValueGenerator("ArkTSObjectInstanceGenerator") { b, n in - let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet", "LinkedList", "List", "ArrayList", "TreeMap", "TreeSet", "LightWeightMap", "LightWeightSet"]) + let builtin = chooseUniform(from: ["Stack", "HashMap", "HashSet", "LinkedList", "List", "ArrayList", "TreeMap", "TreeSet", "LightWeightMap", "LightWeightSet" , "Deque", "Queue"]) let constructor = b.loadBuiltin(builtin) if ["TreeMap", "TreeSet"].contains(builtin) && probability(0.2) { //custom comparator for TreeMap and TreeSet will be generated only in 20% of cases let comparator = b.buildPlainFunction(with: .parameters(n: 2)) { args in @@ -81,6 +81,10 @@ fileprivate let arkTSTreeSet = ILType.iterable + ILType.object(ofGroup: "TreeSet fileprivate let arkTSLightWeightMap = ILType.iterable + ILType.object(ofGroup: "LightWeightMap", withProperties: ["length"], withMethods: ["isEmpty", "hasAll", "hasKey", "hasValue", "increaseCapacityTo", "get", "getIndexOfKey", "getIndexOfValue", "getKeyAt", "setAll", "set", "remove", "removeAt", "setValueAt", "getValueAt", "clear", "keys", "values", "forEach", "entries", "toString"]) /// Type of a ArkTS LightWeightSet object. fileprivate let arkTSLightWeightSet = ILType.iterable + ILType.object(ofGroup: "LightWeightSet", withProperties: ["length"], withMethods: ["isEmpty", "add", "addAll", "hasAll", "has", "equal", "increaseCapacityTo", "getIndexOf", "remove", "removeAt", "getValueAt", "clear", "toString", "toArray", "values", "forEach", "entries"]) +/// Type of a ArkTS Deque object. +fileprivate let arkTSDeque = ILType.iterable + ILType.object(ofGroup: "Deque", withProperties: ["length"], withMethods: ["insertFront", "insertEnd", "has", "popFirst", "popLast", "forEach", "getFirst", "getLast", "entries"]) +/// Type of a ArkTS Queue object. +fileprivate let arkTSQueue = ILType.iterable + ILType.object(ofGroup: "Queue", withProperties: ["length"], withMethods: ["add", "pop", "getFirst", "forEach", "entries"]) /// Tpye of a ArkTS CollectionsMap object fileprivate let collectionsMap = ILType.iterable + ILType.object(ofGroup: "SharedMap", withProperties: ["size"], withMethods: ["entries", "keys", "values", "clear", "delete", "forEach", "get", "has", "set"]) @@ -115,6 +119,10 @@ fileprivate let arkTSTreeSetConstructor = ILType.constructor([.opt(.function([.a fileprivate let arkTSLightWeightMapConstructor = ILType.constructor([] => arkTSLightWeightMap) /// Type of the ArkTS LightWeightSet constructor builtin. fileprivate let arkTSLightWeightSetConstructor = ILType.constructor([] => arkTSLightWeightSet) +/// Type of the ArkTS Deque constructor builtin. +fileprivate let arkTSDequeConstructor = ILType.constructor([] => arkTSDeque) +/// Type of the ArkTS Queue constructor builtin. +fileprivate let arkTSQueueConstructor = ILType.constructor([] => arkTSQueue) /// Type of the ArkTs CollectionsMap constructor builtin. fileprivate let collectionsMapConstructor = ILType.constructor([.object()] => collectionsMap) @@ -521,6 +529,39 @@ fileprivate let arkTSLightWeightSets = ObjectGroup( ] ) +/// ObjectGroup modelling ArkTS Deque objects +fileprivate let arkTSDeques = ObjectGroup( + name: "Deque", + instanceType: arkTSDeque, + properties: [ + "length" : .number, + ], + methods: [ + "insertFront" : [.anything] => .undefined, + "insertEnd" : [.anything] => .undefined, + "has" : [.anything] => .boolean, + "popFirst" : [] => .anything, + "popLast" : [] => .anything, + "forEach" : [.function([.anything, .opt(.number), .opt(arkTSDeque)] => .undefined), .opt(.object())] => .undefined, + "getFirst" : [] => .anything, + "getLast" : [] => .anything, + ] +) + +/// ObjectGroup modelling ArkTS Queue objects +fileprivate let arkTSQueues = ObjectGroup( + name: "Queue", + instanceType: arkTSQueue, + properties: [ + "length" : .number, + ], + methods: [ + "add" : [.anything] => .undefined, + "pop" : [] => .anything, + "getFirst" : [] => .anything, + "forEach" : [.function([.anything, .opt(.number), .opt(arkTSQueue)] => .undefined), .opt(.object())] => .undefined, + ] +) let arkProfile = Profile( processArgs: { randomize in @@ -549,6 +590,8 @@ let arkProfile = Profile( var TreeSet = arkPrivate.Load(arkPrivate.TreeSet); var LightWeightMap = arkPrivate.Load(arkPrivate.LightWeightMap); var LightWeightSet = arkPrivate.Load(arkPrivate.LightWeightSet); + var Deque = arkPrivate.Load(arkPrivate.Deque); + var Queue = arkPrivate.Load(arkPrivate.Queue); function bgc() { for(let i=0; i<0x10000; i+=1) {new String();} @@ -614,6 +657,8 @@ let arkProfile = Profile( "TreeSet" : arkTSTreeSetConstructor, "LightWeightMap" : arkTSLightWeightMapConstructor, "LightWeightSet" : arkTSLightWeightSetConstructor, + "Deque" : arkTSDequeConstructor, + "Queue" : arkTSQueueConstructor, ], additionalObjectGroups: [ @@ -638,6 +683,8 @@ let arkProfile = Profile( arkTSTreeSets, arkTSLightWeightMaps, arkTSLightWeightSets, + arkTSDeques, + arkTSQueues, ], optionalPostProcessor: nil -- Gitee