2015-12-23 18:18:13 +00:00
|
|
|
// Copyright 2015 syzkaller project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package prog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseSingle(t *testing.T) {
|
2018-05-04 18:06:00 +00:00
|
|
|
t.Parallel()
|
2017-09-14 17:25:01 +00:00
|
|
|
target, err := GetTarget("linux", "amd64")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2015-12-23 18:18:13 +00:00
|
|
|
const execLog = `getpid()
|
|
|
|
gettid()
|
|
|
|
`
|
2017-09-14 17:25:01 +00:00
|
|
|
entries := target.ParseLog([]byte(execLog))
|
2015-12-23 18:18:13 +00:00
|
|
|
if len(entries) != 1 {
|
|
|
|
t.Fatalf("got %v programs, want 1", len(entries))
|
|
|
|
}
|
|
|
|
ent := entries[0]
|
|
|
|
if ent.Start != 0 {
|
|
|
|
t.Fatalf("start offset %v, want 0", ent.Start)
|
|
|
|
}
|
|
|
|
if ent.End != len(execLog) {
|
|
|
|
t.Fatalf("end offset %v, want %v", ent.End, len(execLog))
|
|
|
|
}
|
|
|
|
if ent.Proc != 0 {
|
|
|
|
t.Fatalf("proc %v, want 0", ent.Proc)
|
|
|
|
}
|
2017-05-25 14:07:10 +00:00
|
|
|
if ent.Fault || ent.FaultCall != 0 || ent.FaultNth != 0 {
|
|
|
|
t.Fatalf("fault injection enabled")
|
|
|
|
}
|
2015-12-23 18:18:13 +00:00
|
|
|
want := "getpid-gettid"
|
|
|
|
got := ent.P.String()
|
|
|
|
if got != want {
|
|
|
|
t.Fatalf("bad program: %s, want %s", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseMulti(t *testing.T) {
|
2018-05-04 18:06:00 +00:00
|
|
|
t.Parallel()
|
2017-09-14 17:25:01 +00:00
|
|
|
target, err := GetTarget("linux", "amd64")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
entries := target.ParseLog([]byte(execLog))
|
2015-12-23 18:47:20 +00:00
|
|
|
if len(entries) != 5 {
|
|
|
|
for i, ent := range entries {
|
2018-04-24 11:22:19 +00:00
|
|
|
t.Logf("program #%v: %v\n", i, ent.P)
|
2015-12-23 18:47:20 +00:00
|
|
|
}
|
|
|
|
t.Fatalf("got %v programs, want 5", len(entries))
|
2015-12-23 18:18:13 +00:00
|
|
|
}
|
|
|
|
off := 0
|
|
|
|
for _, ent := range entries {
|
|
|
|
if off > ent.Start || ent.Start > ent.End || ent.End > len(execLog) {
|
|
|
|
t.Fatalf("bad offsets")
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 18:47:20 +00:00
|
|
|
if entries[0].Proc != 0 ||
|
|
|
|
entries[1].Proc != 1 ||
|
|
|
|
entries[2].Proc != 2 ||
|
|
|
|
entries[3].Proc != 33 ||
|
|
|
|
entries[4].Proc != 9 {
|
2015-12-23 18:18:13 +00:00
|
|
|
t.Fatalf("bad procs")
|
|
|
|
}
|
2017-05-25 14:07:10 +00:00
|
|
|
for i, ent := range entries {
|
|
|
|
if ent.Fault || ent.FaultCall != 0 || ent.FaultNth != 0 {
|
|
|
|
t.Fatalf("prog %v has fault injection enabled", i)
|
|
|
|
}
|
|
|
|
}
|
2015-12-23 18:47:20 +00:00
|
|
|
if s := entries[0].P.String(); s != "getpid-gettid" {
|
|
|
|
t.Fatalf("bad program 0: %s", s)
|
|
|
|
}
|
|
|
|
if s := entries[1].P.String(); s != "getpid-gettid-munlockall" {
|
2015-12-23 18:18:13 +00:00
|
|
|
t.Fatalf("bad program 0: %s", s)
|
|
|
|
}
|
2015-12-23 18:47:20 +00:00
|
|
|
if s := entries[2].P.String(); s != "getpid-gettid" {
|
2015-12-23 18:18:13 +00:00
|
|
|
t.Fatalf("bad program 1: %s", s)
|
|
|
|
}
|
2015-12-23 18:47:20 +00:00
|
|
|
if s := entries[3].P.String(); s != "gettid-getpid" {
|
2015-12-23 18:18:13 +00:00
|
|
|
t.Fatalf("bad program 2: %s", s)
|
|
|
|
}
|
2015-12-23 18:47:20 +00:00
|
|
|
if s := entries[4].P.String(); s != "munlockall" {
|
2015-12-23 18:18:13 +00:00
|
|
|
t.Fatalf("bad program 3: %s", s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const execLog = `
|
|
|
|
getpid()
|
2015-12-23 18:47:20 +00:00
|
|
|
gettid()
|
2015-12-23 18:18:13 +00:00
|
|
|
2015/12/21 12:18:05 executing program 1:
|
|
|
|
getpid()
|
|
|
|
[ 2351.935478] Modules linked in:
|
|
|
|
gettid()
|
|
|
|
munlockall()
|
|
|
|
2015/12/21 12:18:05 executing program 2:
|
|
|
|
[ 2351.935478] Modules linked in:
|
|
|
|
getpid()
|
|
|
|
gettid()
|
|
|
|
2015/12/21 12:18:05 executing program 33:
|
|
|
|
gettid()
|
|
|
|
getpid()
|
|
|
|
[ 2351.935478] Modules linked in:
|
|
|
|
2015/12/21 12:18:05 executing program 9:
|
|
|
|
munlockall()
|
|
|
|
`
|
2017-05-25 14:07:10 +00:00
|
|
|
|
|
|
|
func TestParseFault(t *testing.T) {
|
2018-05-04 18:06:00 +00:00
|
|
|
t.Parallel()
|
2017-09-14 17:25:01 +00:00
|
|
|
target, err := GetTarget("linux", "amd64")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2017-05-25 14:07:10 +00:00
|
|
|
const execLog = `2015/12/21 12:18:05 executing program 1 (fault-call:1 fault-nth:55):
|
|
|
|
gettid()
|
|
|
|
getpid()
|
|
|
|
`
|
2017-09-14 17:25:01 +00:00
|
|
|
entries := target.ParseLog([]byte(execLog))
|
2017-05-25 14:07:10 +00:00
|
|
|
if len(entries) != 1 {
|
|
|
|
t.Fatalf("got %v programs, want 1", len(entries))
|
|
|
|
}
|
|
|
|
ent := entries[0]
|
|
|
|
if !ent.Fault {
|
|
|
|
t.Fatalf("fault injection is not enabled")
|
|
|
|
}
|
|
|
|
if ent.FaultCall != 1 {
|
|
|
|
t.Fatalf("fault call: got %v, want 1", ent.FaultCall)
|
|
|
|
}
|
|
|
|
if ent.FaultNth != 55 {
|
|
|
|
t.Fatalf("fault nth: got %v, want 55", ent.FaultNth)
|
|
|
|
}
|
|
|
|
want := "gettid-getpid"
|
|
|
|
got := ent.P.String()
|
|
|
|
if got != want {
|
|
|
|
t.Fatalf("bad program: %s, want %s", got, want)
|
|
|
|
}
|
|
|
|
}
|