1 // Copyright 2017 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package vcs 5 6 import ( 7 "reflect" 8 "strings" 9 "testing" 10 "time" 11 ) 12 13 func TestGitParseCommit(t *testing.T) { 14 tests := map[string]*Commit{ 15 `2075b16e32c26e4031b9fd3cbe26c54676a8fcb5 16 rbtree: include rcu.h 17 foobar (a] foobar.de 18 Fri May 11 16:02:14 2018 -0700 19 Since commit c1adf20052d8 ("Introduce rb_replace_node_rcu()") 20 rbtree_augmented.h uses RCU related data structures but does not include 21 the header file. It works as long as it gets somehow included before 22 that and fails otherwise. 23 24 Link: http://lkml.kernel.org/r/20180504103159.19938-1-bigeasy@linutronix.de 25 Signed-off-by: Foo Bad Baz <another (a] email.de> 26 Reviewed-by: <yetanother (a] email.org> 27 Cc: Unrelated Guy <somewhere (a] email.com> 28 Acked-by: Subsystem reviewer <Subsystem (a] reviewer.com> 29 Reported-and-tested-by: and (a] me.com 30 Reported-and-Tested-by: Name-name <name (a] name.com> 31 Tested-by: Must be correct <mustbe (a] correct.com> 32 Signed-off-by: Linux Master <linux (a] linux-foundation.org> 33 `: { 34 Hash: "2075b16e32c26e4031b9fd3cbe26c54676a8fcb5", 35 Title: "rbtree: include rcu.h", 36 Author: "foobar (a] foobar.de", 37 CC: []string{ 38 "and (a] me.com", 39 "foobar (a] foobar.de", 40 "mustbe (a] correct.com", 41 "name (a] name.com", 42 "subsystem (a] reviewer.com", 43 "yetanother (a] email.org", 44 }, 45 Date: time.Date(2018, 5, 11, 16, 02, 14, 0, time.FixedZone("", -7*60*60)), 46 }, 47 } 48 for input, com := range tests { 49 res, err := gitParseCommit([]byte(input)) 50 if err != nil && com != nil { 51 t.Fatalf("want %+v, got error: %v", com, err) 52 } 53 if err == nil && com == nil { 54 t.Fatalf("want error, got commit %+v", res) 55 } 56 if com == nil { 57 continue 58 } 59 if com.Hash != res.Hash { 60 t.Fatalf("want hash %q, got %q", com.Hash, res.Hash) 61 } 62 if com.Title != res.Title { 63 t.Fatalf("want title %q, got %q", com.Title, res.Title) 64 } 65 if com.Author != res.Author { 66 t.Fatalf("want author %q, got %q", com.Author, res.Author) 67 } 68 if !reflect.DeepEqual(com.CC, res.CC) { 69 t.Fatalf("want CC %q, got %q", com.CC, res.CC) 70 } 71 if !com.Date.Equal(res.Date) { 72 t.Fatalf("want date %v, got %v", com.Date, res.Date) 73 } 74 } 75 } 76 77 func TestGitParseReleaseTags(t *testing.T) { 78 input := ` 79 v3.1 80 v2.6.12 81 v2.6.39 82 v3.0 83 v3.10 84 v2.6.13 85 v3.11 86 v3.19 87 v3.9 88 v3.2 89 v4.9 90 v2.6.32 91 v4.0 92 voo 93 v1.foo 94 v10.2.foo 95 v1.2. 96 v1. 97 ` 98 want := []string{ 99 "v4.9", 100 "v4.0", 101 "v3.19", 102 "v3.11", 103 "v3.10", 104 "v3.9", 105 "v3.2", 106 "v3.1", 107 "v3.0", 108 "v2.6.39", 109 "v2.6.32", 110 "v2.6.13", 111 "v2.6.12", 112 } 113 got, err := gitParseReleaseTags([]byte(input)) 114 if err != nil { 115 t.Fatal(err) 116 } 117 if !reflect.DeepEqual(got, want) { 118 t.Fatalf("got bad tags\ngot: %+v\nwant: %+v", got, want) 119 } 120 } 121 122 func TestGitExtractFixTags(t *testing.T) { 123 commits, err := gitExtractFixTags(strings.NewReader(extractFixTagsInput), extractFixTagsEmail) 124 if err != nil { 125 t.Fatal(err) 126 } 127 if !reflect.DeepEqual(commits, extractFixTagsOutput) { 128 t.Fatalf("got : %+v\twant: %+v", commits, extractFixTagsOutput) 129 } 130 } 131 132 const extractFixTagsEmail = "\"syzbot\" <syzbot (a] my.mail.com>" 133 134 var extractFixTagsOutput = []FixCommit{ 135 {"8e4090902540da8c6e8f", "dashboard/app: bump max repros per bug to 10"}, 136 {"8e4090902540da8c6e8f", "executor: remove dead code"}, 137 {"a640a0fc325c29c3efcb", "executor: remove dead code"}, 138 {"8e4090902540da8c6e8fa640a0fc325c29c3efcb", "pkg/csource: fix string escaping bug"}, 139 } 140 141 var extractFixTagsInput = ` 142 commit 73aba437a774237b1130837b856f3b40b3ec3bf0 (HEAD -> master, origin/master) 143 Author: me <foo (a] bar.com> 144 Date: Fri Dec 22 19:59:56 2017 +0100 145 146 dashboard/app: bump max repros per bug to 10 147 148 Reported-by: syzbot+8e4090902540da8c6e8f (a] my.mail.com 149 150 commit 26cd53f078db858a6ccca338e13e7f4d1d291c22 151 Author: me <foo (a] bar.com> 152 Date: Fri Dec 22 13:42:27 2017 +0100 153 154 executor: remove dead code 155 156 Reported-by: syzbot+8e4090902540da8c6e8f (a] my.mail.com 157 Reported-by: syzbot <syzbot+a640a0fc325c29c3efcb (a] my.mail.com> 158 159 commit 7b62abdb0abadbaf7b3f3a23ab4d78485fbf9059 160 Author: Dmitry Vyukov <dvyukov (a] google.com> 161 Date: Fri Dec 22 11:59:09 2017 +0100 162 163 pkg/csource: fix string escaping bug 164 165 Reported-and-tested-by: syzbot+8e4090902540da8c6e8fa640a0fc325c29c3efcb (a] my.mail.com 166 ` 167