forked from nativelibs4java/nativelibs4java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBisect.scala
More file actions
142 lines (121 loc) · 4.37 KB
/
Bisect.scala
File metadata and controls
142 lines (121 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import scala.sys.process._
import System.{ getenv, getProperty }
import java.io.{ File, PrintWriter }
object Bisect extends App {
val minRev = 1183
val maxRev = 1241
def file(path: String) = new File(path)
implicit def fileImplicits(f: File) = new {
def /(subPath: String) = new File(f, subPath)
}
val homeDir = file(getProperty("user.home"))
val dyncallDir = homeDir / "src/dyncall"
val bridjDir = homeDir / "nativelibs4java/Runtime/BridJ"
def svnUpdate(dir: File, rev: Int): Unit = {
Process(Seq("svn", "update", "-r" + rev), Some(dir)) !!
//println("Svn tree '" + dir + "' updated to revision " + rev);
//if (ret != 0)
// throw new RuntimeException("svn update returned " + ret)
}
def svnLog(dir: File, rev: Int): String = {
Process(Seq("svn", "log", "-r" + rev), Some(dir)) !!
}
def svnDiff(dir: File, from: Int, to: Int): String = {
Process(Seq("svn", "diff", "-r" + from + ":" + to), Some(dir)) !!
}
def concatLogger = {
val builder = new StringBuilder
(ProcessLogger(s => builder.append(s).append('\n')), () => builder.toString)
}
sealed trait TestResult { def describe: String }
case class BuildFailure(out: String) extends TestResult { override def describe = "Broken" }
case class TestFailure(out: String) extends TestResult { override def describe = "Failure" }
object TestSuccess extends TestResult { override def describe = "Success" }
def test(rev: Int): TestResult = {
print("Updating to rev " + rev + "... ")
svnUpdate(dyncallDir, rev)
print("Building... ")
val ret = {
val (buildLog, buildOut) = concatLogger
val buildRet: Int =
(
Process(Seq("sh", "CleanNative"), Some(bridjDir)) #&&
Process(Seq("sh", "BuildNative"), Some(bridjDir))
) ! (buildLog)
if (buildRet != 0) {
BuildFailure(buildOut())
} else {
print("Testing... ")
val (testLog, testOut) = concatLogger
val testRet: Int =
Process(Seq("mvn", "test", "-o", "-Dtest=CallTest"), Some(bridjDir)) ! (testLog)
if (testRet == 0)
TestSuccess
else
TestFailure(testOut())
}
}
println(ret.describe + ".")
ret
//println("Res = " + res)
}
import scala.annotation.tailrec
@tailrec
case class BisectRes(firstFailedTest: Int, firstBrokenBuild: Option[Int] = None)
def bisect(fromOkRev: Int, toBadRev: Int): BisectRes = {
if (toBadRev <= fromOkRev + 1)
BisectRes(toBadRev)
else {
var pick = (fromOkRev + toBadRev) / 2
if (pick == fromOkRev)
pick += 1
test(pick) match {
case TestSuccess =>
bisect(pick, toBadRev)
case _: TestFailure =>
bisect(fromOkRev, pick)
case _: BuildFailure =>
val BisectRes(failed, broken) =
bisect(pick, toBadRev)
BisectRes(failed, Some(pick))
}
}
}
// sbt "run 1183 1241"
object SomeInt {
def unapply(s: String) =
try Some(s.toInt) catch { case _ => None }
}
args.toList match {
case SomeInt(fromRev) :: SomeInt(toRev) :: xargs =>
val (logFile, diffFile) = xargs match {
case l :: d :: Nil => (l, d)
case Nil => ("bisect.log", "bisect.diff")
}
println("Bisect from rev " + fromRev + " to rev " + toRev)
assert(test(fromRev) == TestSuccess, "Does not build at rev " + fromRev)
assert(test(toRev) != TestSuccess, "Already builds at rev " + toRev)
val bisection = bisect(fromRev, toRev)
//val bisection = BisectRes(1236,Some(1226))
val (revisions, (diffFrom, diffTo)) = bisection match {
case BisectRes(failed, Some(broken)) =>
println("Tests fail at revision " + failed + " but build broken since revision " + broken)
(broken to failed, (broken - 1, failed))
case BisectRes(failed, None) =>
println("Faulty revision is " + failed)
(Seq(failed), (failed - 1, failed))
}
val logOut = new PrintWriter(file(logFile))
for (rev <- revisions) {
val log = svnLog(dyncallDir, rev)
println(log)
logOut.println(log)
}
logOut.close
val diffOut = new PrintWriter(file(diffFile))
val diff = svnDiff(dyncallDir, diffFrom, diffTo)
println(diff)
diffOut.println(diff)
diffOut.close
}
}