Skip to content

Go: Initialisation of OFG for golang projects #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions agent/one_prompt_prototyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def _prompt_builder(self,
# For Python projects
return prompt_builder.DefaultPythonTemplateBuilder(
self.llm, benchmark, self.args.template_directory)

if benchmark.language == 'go':
# For golang projects
return prompt_builder.DefaultGoTemplateBuilder(
self.llm, benchmark, self.args.template_directory)

if benchmark.language == 'rust':
# For Rust projects
return prompt_builder.DefaultRustTemplateBuilder(
Expand Down
45 changes: 45 additions & 0 deletions benchmark-sets/go-small/atomic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"functions":
- "name": "run"
"params":
- "name": "args"
"type": "[]string"
"return_type": "error"
"signature": "run([]string) error"
- "name": "BenchmarkStress"
"params":
- "name": "b"
"type": "B"
- "name": "b"
"type": "B"
- "name": "b"
"type": "B"
- "name": "b"
"type": "B"
- "name": "pb"
"type": "PB"
"return_type": "void"
"signature": "BenchmarkStress(*testing.B,*testing.B,*testing.B,*testing.B,*testing.PB)"
- "name": "*stringList.Set"
"params":
- "name": "s"
"type": "string"
"return_type": "error"
"signature": "(*stringList) *stringList.Set(string) error"
- "name": "*Bool.Toggle"
"params":
- "name": "old"
"type": "bool"
"return_type": "(old bool)"
"signature": "(*Bool) *Bool.Toggle(bool) (old bool)"
- "name": "*String.CompareAndSwap"
"params":
- "name": "swapped"
"type": "bool"
- "name": "old"
"type": "string"
"return_type": "(swapped bool)"
"signature": "(*String) *String.CompareAndSwap(bool,string) (swapped bool)"
"language": "go"
"project": "atomic"
"target_name": "fuzz_test"
"target_path": "/src/atomic/fuzz_test.go"
49 changes: 49 additions & 0 deletions benchmark-sets/go-small/clock.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"functions":
- "name": "*clock.WithDeadline"
"params":
- "name": "parent"
"type": "Context"
- "name": "d"
"type": "Time"
- "name": "context.Context"
"type": "Context"
- "name": "context.CancelFunc"
"type": "CancelFunc"
"return_type": "(context.Context, context.CancelFunc)"
"signature": "(*clock) *clock.WithDeadline(context.Context,time.Time,context.Context,context.CancelFunc) (context.Context, context.CancelFunc)"
- "name": "*clock.WithTimeout"
"params":
- "name": "context.Context"
"type": "Context"
- "name": "context.CancelFunc"
"type": "CancelFunc"
- "name": "parent"
"type": "Context"
- "name": "t"
"type": "Duration"
"return_type": "(context.Context, context.CancelFunc)"
"signature": "(*clock) *clock.WithTimeout(context.Context,context.CancelFunc,context.Context,time.Duration) (context.Context, context.CancelFunc)"
- "name": "warnf"
"params":
- "name": "msg"
"type": "string"
- "name": "v"
"type": "interface{}"
"return_type": "void"
"signature": "warnf(string,interface{})"
- "name": "*clock.Until"
"params":
- "name": "t"
"type": "Time"
"return_type": "time.Duration"
"signature": "(*clock) *clock.Until(time.Time) time.Duration"
- "name": "*clock.Since"
"params":
- "name": "t"
"type": "Time"
"return_type": "time.Duration"
"signature": "(*clock) *clock.Since(time.Time) time.Duration"
"language": "go"
"project": "clock"
"target_name": "fuzz_test"
"target_path": "/src/clock/fuzz_test.go"
51 changes: 51 additions & 0 deletions benchmark-sets/go-small/nats.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"functions":
- "name": "*cluster.removeJetStream"
"params":
- "name": "s"
"type": "*Server"
"return_type": "void"
"signature": "(*cluster) *cluster.removeJetStream(*Server)"
- "name": "reloadUpdateConfig"
"params":
- "name": "t"
"type": "T"
- "name": "s"
"type": "*Server"
- "name": "conf"
"type": "string"
"return_type": "void"
"signature": "reloadUpdateConfig(*testing.T,*Server,string)"
- "name": "*Server.reloadConfig"
"params":
- "name": "sub"
"type": "*subscription"
- "name": "c"
"type": "*client"
- "name": "_"
"type": "*Account"
- "name": "subject"
"type": "string"
- "name": "hdr"
"type": "[]byte"
- "name": "any"
"type": "any"
- "name": "error"
"type": "error"
"return_type": "void"
"signature": "(*Server) *Server.reloadConfig(*subscription,*client,*Account,string,[]byte,any,error)"
- "name": "*Server.ReloadOptions"
"params":
- "name": "newOpts"
"type": "*Options"
"return_type": "error"
"signature": "(*Server) *Server.ReloadOptions(*Options) error"
- "name": "*Server.reloadOptions"
"params":
- "name": "curOpts"
"type": "*Options"
"return_type": "error"
"signature": "(*Server) *Server.reloadOptions(*Options) error"
"language": "go"
"project": "nats"
"target_name": "fuzz"
"target_path": "/src/nats-server/server/fuzz.go"
69 changes: 69 additions & 0 deletions benchmark-sets/go-small/roughtime.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"functions":
- "name": "FuzzParseRequest"
"params":
- "name": "f"
"type": "F"
- "name": "t"
"type": "T"
- "name": "data"
"type": "[]byte"
"return_type": "void"
"signature": "FuzzParseRequest(*testing.F,*testing.T,[]byte)"
- "name": "DoFromFile"
"params":
- "name": "configFile"
"type": "string"
- "name": "attempts"
"type": "int"
- "name": "timeout"
"type": "Duration"
- "name": "prev"
"type": "*Roughtime"
- "name": "[]Result"
"type": "[]Result"
- "name": "error"
"type": "error"
"return_type": "([]Result, error)"
"signature": "DoFromFile(string,int,time.Duration,*Roughtime,[]Result,error) ([]Result, error)"
- "name": "Do"
"params":
- "name": "servers"
"type": "Server"
- "name": "attempts"
"type": "int"
- "name": "timeout"
"type": "Duration"
- "name": "prev"
"type": "*Roughtime"
"return_type": "[]Result"
"signature": "Do([]config.Server,int,time.Duration,*Roughtime) []Result"
- "name": "Get"
"params":
- "name": "server"
"type": "Server"
- "name": "attempts"
"type": "int"
- "name": "timeout"
"type": "Duration"
- "name": "prev"
"type": "*Roughtime"
- "name": "*Roughtime"
"type": "*Roughtime"
- "name": "error"
"type": "error"
"return_type": "(*Roughtime, error)"
"signature": "Get(*config.Server,int,time.Duration,*Roughtime,*Roughtime,error) (*Roughtime, error)"
- "name": "createServerIdentity"
"params":
- "name": "t"
"type": "T"
- "name": "cert"
"type": "*Certificate"
- "name": "rootPublicKey"
"type": "[]byte"
"return_type": "(cert *Certificate, rootPublicKey []byte)"
"signature": "createServerIdentity(*testing.T,*Certificate,[]byte) (cert *Certificate, rootPublicKey []byte)"
"language": "go"
"project": "roughtime"
"target_name": "protocol_test"
"target_path": "/src/roughtime/protocol/protocol_test.go"
51 changes: 51 additions & 0 deletions benchmark-sets/go-small/smt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"functions":
- "name": "bulkOperations"
"params":
- "name": "t"
"type": "T"
- "name": "operations"
"type": "int"
- "name": "insert"
"type": "int"
- "name": "update"
"type": "int"
- "name": "delete"
"type": "int"
"return_type": "void"
"signature": "bulkOperations(*testing.T,int,int,int,int)"
- "name": "BenchmarkSparseMerkleTree_Delete"
"params":
- "name": "b"
"type": "B"
"return_type": "void"
"signature": "BenchmarkSparseMerkleTree_Delete(*testing.B)"
- "name": "bulkCheckAll"
"params":
- "name": "t"
"type": "T"
- "name": "smt"
"type": "*SparseMerkleTree"
- "name": "kv"
"type": "*map[string]string"
"return_type": "void"
"signature": "bulkCheckAll(*testing.T,*SparseMerkleTree,*map[string]string)"
- "name": "BenchmarkSparseMerkleTree_Update"
"params":
- "name": "b"
"type": "B"
"return_type": "void"
"signature": "BenchmarkSparseMerkleTree_Update(*testing.B)"
- "name": "*SparseMerkleTree.DeleteForRoot"
"params":
- "name": "[]byte"
"type": "[]byte"
- "name": "error"
"type": "error"
- "name": "key"
"type": "[]byte"
"return_type": "([]byte, error)"
"signature": "(*SparseMerkleTree) *SparseMerkleTree.DeleteForRoot([]byte,error,[]byte) ([]byte, error)"
"language": "go"
"project": "smt"
"target_name": "fuzz"
"target_path": "/src/smt/fuzz/delete/fuzz.go"
41 changes: 41 additions & 0 deletions benchmark-sets/go-small/time.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"functions":
- "name": "*SPTP.Run"
"params":
- "name": "ctx"
"type": "Context"
"return_type": "error"
"signature": "(*SPTP) *SPTP.Run(context.Context) error"
- "name": "*Server.Start"
"params":
- "name": "i"
"type": "int"
"return_type": "error"
"signature": "(*Server) *Server.Start(int) error"
- "name": "*Daemon.Run"
"params":
- "name": "ctx"
"type": "Context"
"return_type": "error"
"signature": "(*Daemon) *Daemon.Run(context.Context) error"
- "name": "runTrace"
"params":
- "name": "cfg"
"type": "Config"
- "name": "m"
"type": "MeasurementResult"
"return_type": "error"
"signature": "runTrace(*client.Config,*client.MeasurementResult) error"
- "name": "*Sender.Start"
"params":
- "name": "t"
"type": "traceTask"
- "name": "[]*PathInfo"
"type": "[]*PathInfo"
- "name": "error"
"type": "error"
"return_type": "([]*PathInfo, error)"
"signature": "(*Sender) *Sender.Start(traceTask,[]*PathInfo,error) ([]*PathInfo, error)"
"language": "go"
"project": "time"
"target_name": "ntp_test"
"target_path": "/src/time/ntp/protocol/ntp_test.go"
2 changes: 1 addition & 1 deletion data_prep/introspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ def populate_benchmarks_using_introspector(project: str, language: str,
logger.error('error: %s %s', filename, interesting.keys())
continue

elif (language not in ['rust'] and interesting and
elif (language not in ['rust', 'go'] and interesting and
filename not in [os.path.basename(i) for i in interesting.keys()]):
# TODO: Bazel messes up paths to include "/proc/self/cwd/..."
logger.error('error: %s %s', filename, interesting.keys())
Expand Down
10 changes: 10 additions & 0 deletions data_prep/project_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def _get_harness(src_file: str, out: str, language: str) -> tuple[str, str]:
if language.lower() == 'rust' and 'fuzz_target!' not in content:
return '', ''

if language.lower() == 'go' and any(
target not in content for target in ['testing.F', 'testing.T', '.Fuzz']):
return '', ''

short_path = src_file[len(out):]
return short_path, content

Expand Down Expand Up @@ -309,6 +313,12 @@ def _identify_fuzz_targets(out: str, interesting_filenames: list[str],
interesting_filepaths.append(path)
if path.endswith('.py'):
potential_harnesses.append(path)
elif language == 'go':
# For Rust
if path.endswith(tuple(interesting_filenames)):
interesting_filepaths.append(path)
if path.endswith(('.go', '.cgo')):
potential_harnesses.append(path)
elif language == 'rust':
# For Rust
if path.endswith(tuple(interesting_filenames)):
Expand Down
9 changes: 9 additions & 0 deletions experiment/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ def __init__(self,
# zipp-zipp.difference.
self.id = self.id.replace('._', '.')

if self.language == 'go':
# For golang projects, full signature of functions/methods can contains
# special characters that result in confusion in the directory name of
# benchmarks.
self.id = self.id.replace('*', '').replace('&', '')
self.id = self.id.replace('<', '').replace('>', '')
self.id = self.id.replace('[', '').replace(']', '')
self.id = self.id.replace('(', '_').replace(')', '').replace(',', '_')

if self.language == 'rust':
# For rust projects, double colon (::) is sometime used to identify
# crate, impl or trait name of a function. This could affect the
Expand Down
Loading