Skip to content

Commit 7cba22e

Browse files
committed
Rid off all dependencies of core-api
1 parent 286a62a commit 7cba22e

File tree

18 files changed

+203
-186
lines changed

18 files changed

+203
-186
lines changed

utbot-go/src/main/kotlin/org/utbot/go/GoEngine.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ class GoEngine(
5555
serverSocket.accept()
5656
} catch (e: SocketTimeoutException) {
5757
val processHasExited = process.waitFor(timeoutMillis, TimeUnit.MILLISECONDS)
58-
if (!processHasExited) {
58+
if (processHasExited) {
59+
val processOutput = InputStreamReader(process.inputStream).readText()
60+
throw TimeoutException("Timeout exceeded: Worker not connected. Process output: $processOutput")
61+
} else {
5962
process.destroy()
6063
}
6164
throw TimeoutException("Timeout exceeded: Worker not connected")
@@ -89,7 +92,7 @@ class GoEngine(
8992
eachExecutionTimeoutsMillisConfig[methodUnderTest],
9093
)
9194
if (executionResult.trace.isEmpty()) {
92-
logger.error { "Coverage is empty for [${methodUnderTest.name}] with ${values.map { it.model }}" }
95+
logger.error { "Coverage is empty for [${methodUnderTest.name}] with $values}" }
9396
if (executionResult is GoUtPanicFailure) {
9497
logger.error { "Execution completed with panic: ${executionResult.panicValue}" }
9598
}

utbot-go/src/main/kotlin/org/utbot/go/GoLanguage.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package org.utbot.go
22

3-
import org.utbot.fuzzer.FuzzedValue
43
import org.utbot.fuzzing.*
54
import org.utbot.fuzzing.utils.Trie
65
import org.utbot.go.api.GoUtFunction
76
import org.utbot.go.framework.api.go.GoTypeId
7+
import org.utbot.go.framework.api.go.GoUtModel
88
import org.utbot.go.fuzzer.providers.GoArrayValueProvider
99
import org.utbot.go.fuzzer.providers.GoPrimitivesValueProvider
1010
import org.utbot.go.fuzzer.providers.GoStructValueProvider
@@ -25,8 +25,8 @@ class GoDescription(
2525

2626
suspend fun runGoFuzzing(
2727
methodUnderTest: GoUtFunction,
28-
providers: List<ValueProvider<GoTypeId, FuzzedValue, GoDescription>> = goDefaultValueProviders(),
29-
exec: suspend (description: GoDescription, values: List<FuzzedValue>) -> BaseFeedback<Trie.Node<GoInstruction>, GoTypeId, FuzzedValue>
28+
providers: List<ValueProvider<GoTypeId, GoUtModel, GoDescription>> = goDefaultValueProviders(),
29+
exec: suspend (description: GoDescription, values: List<GoUtModel>) -> BaseFeedback<Trie.Node<GoInstruction>, GoTypeId, GoUtModel>
3030
) {
3131
BaseFuzzing(providers, exec).fuzz(GoDescription(methodUnderTest, Trie(GoInstruction::lineNumber)))
3232
}

utbot-go/src/main/kotlin/org/utbot/go/api/GoTypesApi.kt

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ import org.utbot.go.framework.api.go.GoTypeId
77
* Represents real Go primitive type.
88
*/
99
class GoPrimitiveTypeId(name: String) : GoTypeId(name) {
10+
override val packageName: String = ""
1011
override val canonicalName: String = simpleName
1112

1213
override fun getRelativeName(packageName: String): String = simpleName
14+
15+
override fun equals(other: Any?): Boolean {
16+
if (this === other) return true
17+
if (other !is GoPrimitiveTypeId) return false
18+
19+
return name == other.name
20+
}
21+
22+
override fun hashCode(): Int = name.hashCode()
1323
}
1424

1525
class GoStructTypeId(
@@ -21,30 +31,66 @@ class GoStructTypeId(
2131
) : GoTypeId(name, implementsError = implementsError) {
2232
override val canonicalName: String = "$packageName.$name"
2333

24-
override fun getRelativeName(packageName: String): String =
25-
if (this.packageName != packageName) {
26-
canonicalName
27-
} else {
28-
simpleName
29-
}
34+
override fun getRelativeName(packageName: String): String = if (this.packageName != packageName) {
35+
canonicalName
36+
} else {
37+
simpleName
38+
}
39+
40+
override fun equals(other: Any?): Boolean {
41+
if (this === other) return true
42+
if (other !is GoStructTypeId) return false
43+
44+
return packagePath == other.packagePath && packageName == other.packageName && name == other.name
45+
}
46+
47+
override fun hashCode(): Int = 31 * name.hashCode() + packagePath.hashCode()
3048
}
3149

3250
class GoArrayTypeId(
3351
name: String,
3452
elementTypeId: GoTypeId,
3553
val length: Int
36-
) : GoTypeId(name, elementClassId = elementTypeId) {
54+
) : GoTypeId(name, elementTypeId = elementTypeId) {
3755
override val canonicalName: String = "[$length]${elementTypeId.canonicalName}"
38-
val elementTypeId: GoTypeId = elementClassId as GoTypeId
3956

40-
override fun getRelativeName(packageName: String): String = "[$length]${elementTypeId.getRelativeName(packageName)}"
57+
override fun getRelativeName(packageName: String): String =
58+
"[$length]${elementTypeId!!.getRelativeName(packageName)}"
59+
60+
override fun equals(other: Any?): Boolean {
61+
if (this === other) return true
62+
if (other !is GoArrayTypeId) return false
63+
64+
return elementTypeId == other.elementTypeId && length == other.length
65+
}
66+
67+
override fun hashCode(): Int = 31 * elementTypeId.hashCode() + length
4168
}
4269

4370
class GoInterfaceTypeId(
4471
name: String,
45-
implementsError: Boolean
72+
implementsError: Boolean,
73+
override val packageName: String,
74+
val packagePath: String,
4675
) : GoTypeId(name, implementsError = implementsError) {
47-
override fun getRelativeName(packageName: String): String {
48-
TODO("Not yet implemented")
76+
override val canonicalName: String = if (packageName != "") {
77+
"$packageName.$name"
78+
} else {
79+
simpleName
4980
}
81+
82+
override fun getRelativeName(packageName: String): String = if (this.packageName != packageName) {
83+
canonicalName
84+
} else {
85+
simpleName
86+
}
87+
88+
override fun equals(other: Any?): Boolean {
89+
if (this === other) return true
90+
if (other !is GoStructTypeId) return false
91+
92+
return packagePath == other.packagePath && packageName == other.packageName && name == other.name
93+
}
94+
95+
override fun hashCode(): Int = 31 * name.hashCode() + packagePath.hashCode()
5096
}

utbot-go/src/main/kotlin/org/utbot/go/api/GoUtFunctionApi.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.utbot.go.api
22

33
import org.utbot.fuzzer.FuzzedConcreteValue
4-
import org.utbot.fuzzer.FuzzedValue
54
import org.utbot.go.framework.api.go.GoTypeId
5+
import org.utbot.go.framework.api.go.GoUtModel
66
import java.io.File
77
import java.nio.file.Paths
88

@@ -27,12 +27,12 @@ data class GoUtFunction(
2727
fun getPackageName(): String = sourceFile.packageName
2828
}
2929

30-
data class GoUtFuzzedFunction(val function: GoUtFunction, val fuzzedParametersValues: List<FuzzedValue>)
30+
data class GoUtFuzzedFunction(val function: GoUtFunction, val parametersValues: List<GoUtModel>)
3131

3232
data class GoUtFuzzedFunctionTestCase(
3333
val fuzzedFunction: GoUtFuzzedFunction,
3434
val executionResult: GoUtExecutionResult,
3535
) {
3636
val function: GoUtFunction get() = fuzzedFunction.function
37-
val fuzzedParametersValues: List<FuzzedValue> get() = fuzzedFunction.fuzzedParametersValues
37+
val parametersValues: List<GoUtModel> get() = fuzzedFunction.parametersValues
3838
}

utbot-go/src/main/kotlin/org/utbot/go/api/GoUtModelsApi.kt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ open class GoUtPrimitiveModel(
2626
},
2727
private val requiredImports: Set<String> = emptySet(),
2828
) : GoUtModel(typeId) {
29-
override val classId: GoPrimitiveTypeId
30-
get() = super.classId as GoPrimitiveTypeId
29+
override val typeId: GoPrimitiveTypeId
30+
get() = super.typeId as GoPrimitiveTypeId
3131

3232
override fun getRequiredImports(): Set<String> = requiredImports
3333

@@ -38,8 +38,8 @@ open class GoUtPrimitiveModel(
3838
ExplicitCastMode.DEPENDS, ExplicitCastMode.NEVER -> toValueGoCode()
3939
}
4040

41-
open fun toValueGoCode(): String = if (classId == goStringTypeId) "\"$value\"" else "$value"
42-
fun toCastedValueGoCode(): String = "$classId(${toValueGoCode()})"
41+
open fun toValueGoCode(): String = if (typeId == goStringTypeId) "\"$value\"" else "$value"
42+
fun toCastedValueGoCode(): String = "$typeId(${toValueGoCode()})"
4343
}
4444

4545
abstract class GoUtCompositeModel(
@@ -52,29 +52,29 @@ class GoUtStructModel(
5252
typeId: GoStructTypeId,
5353
packageName: String,
5454
) : GoUtCompositeModel(typeId, packageName) {
55-
override val classId: GoStructTypeId
56-
get() = super.classId as GoStructTypeId
55+
override val typeId: GoStructTypeId
56+
get() = super.typeId as GoStructTypeId
5757

5858
override fun getRequiredImports(): Set<String> {
59-
val imports = if (classId.packageName != packageName) {
60-
mutableSetOf(classId.packagePath)
59+
val imports = if (typeId.packageName != packageName) {
60+
mutableSetOf(typeId.packagePath)
6161
} else {
6262
mutableSetOf()
6363
}
64-
value.filter { packageName == classId.packageName || it.fieldId.isExported }
65-
.map { it.model.getRequiredImports() }
64+
value.filter { packageName == typeId.packageName || it.fieldId.isExported }
65+
.map { it.getRequiredImports() }
6666
.forEach { imports += it }
6767
return imports
6868
}
6969

70-
override fun isComparable(): Boolean = value.all { it.model.isComparable() }
70+
override fun isComparable(): Boolean = value.all { it.isComparable() }
7171

7272
fun toStringWithoutStructName(): String =
73-
value.filter { packageName == classId.packageName || it.fieldId.isExported }
73+
value.filter { packageName == typeId.packageName || it.fieldId.isExported }
7474
.joinToString(prefix = "{", postfix = "}") { "${it.fieldId.name}: ${it.model}" }
7575

7676
override fun toString(): String =
77-
"${classId.getRelativeName(packageName)}${toStringWithoutStructName()}"
77+
"${typeId.getRelativeName(packageName)}${toStringWithoutStructName()}"
7878
}
7979

8080
class GoUtArrayModel(
@@ -84,17 +84,17 @@ class GoUtArrayModel(
8484
) : GoUtCompositeModel(typeId, packageName) {
8585
val length: Int = typeId.length
8686

87-
override val classId: GoArrayTypeId
88-
get() = super.classId as GoArrayTypeId
87+
override val typeId: GoArrayTypeId
88+
get() = super.typeId as GoArrayTypeId
8989

9090
override fun getRequiredImports(): Set<String> {
91-
val elementStructTypeId = classId.elementTypeId as? GoStructTypeId
91+
val elementStructTypeId = typeId.elementTypeId as? GoStructTypeId
9292
val imports = if (elementStructTypeId != null && elementStructTypeId.packageName != packageName) {
9393
mutableSetOf(elementStructTypeId.packagePath)
9494
} else {
9595
mutableSetOf()
9696
}
97-
value.entries.map { it.value.getRequiredImports() }.forEach { imports += it }
97+
value.values.map { it.getRequiredImports() }.forEach { imports += it }
9898
return imports
9999
}
100100

@@ -104,7 +104,7 @@ class GoUtArrayModel(
104104
value[it] ?: typeId.goDefaultValueModel(packageName)
105105
}
106106

107-
fun toStringWithoutTypeName(): String = when (val typeId = classId.elementTypeId) {
107+
fun toStringWithoutTypeName(): String = when (val typeId = typeId.elementTypeId!!) {
108108
is GoStructTypeId -> getElements(typeId).joinToString(prefix = "{", postfix = "}") {
109109
(it as GoUtStructModel).toStringWithoutStructName()
110110
}
@@ -116,7 +116,7 @@ class GoUtArrayModel(
116116
else -> getElements(typeId).joinToString(prefix = "{", postfix = "}")
117117
}
118118

119-
override fun toString(): String = when (val typeId = classId.elementTypeId) {
119+
override fun toString(): String = when (val typeId = typeId.elementTypeId!!) {
120120
is GoStructTypeId -> getElements(typeId)
121121
.joinToString(prefix = "[$length]${typeId.getRelativeName(packageName)}{", postfix = "}") {
122122
(it as GoUtStructModel).toStringWithoutStructName()
Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,21 @@
11
package org.utbot.go.framework.api.go
22

3-
import org.utbot.framework.plugin.api.*
4-
53
/**
64
* Parent class for all Go types for compatibility with UTBot framework.
75
*
86
* To see its children check GoTypesApi.kt at org.utbot.go.api.
97
*/
108
abstract class GoTypeId(
11-
name: String, elementClassId: GoTypeId? = null, val implementsError: Boolean = false
12-
) : ClassId(name, elementClassId) {
13-
override val isNullable: Boolean
14-
get() = error("not supported")
15-
override val canonicalName: String
16-
get() = error("not supported")
17-
override val simpleName: String
18-
get() = name
19-
override val packageName: String
20-
get() = error("not supported")
21-
override val isInDefaultPackage: Boolean
22-
get() = error("not supported")
23-
override val isAnonymous: Boolean
24-
get() = error("not supported")
25-
override val isLocal: Boolean
26-
get() = error("not supported")
27-
override val isInner: Boolean
28-
get() = error("not supported")
29-
override val isNested: Boolean
30-
get() = error("not supported")
31-
override val isSynthetic: Boolean
32-
get() = error("not supported")
33-
override val allMethods: Sequence<MethodId>
34-
get() = error("not supported")
35-
override val allConstructors: Sequence<ConstructorId>
36-
get() = error("not supported")
37-
override val typeParameters: TypeParameters
38-
get() = error("not supported")
39-
override val outerClass: Class<*>?
40-
get() = error("not supported")
9+
val name: String,
10+
val elementTypeId: GoTypeId? = null,
11+
val implementsError: Boolean = false
12+
) {
13+
open val packageName: String = ""
14+
val simpleName: String = name
15+
abstract val canonicalName: String
4116

4217
abstract fun getRelativeName(packageName: String): String
18+
override fun toString(): String = canonicalName
4319
}
4420

4521
/**
@@ -48,11 +24,10 @@ abstract class GoTypeId(
4824
* To see its children check GoUtModelsApi.kt at org.utbot.go.api.
4925
*/
5026
abstract class GoUtModel(
51-
override val classId: GoTypeId,
52-
) : UtModel(classId) {
27+
open val typeId: GoTypeId,
28+
) {
5329
open fun getRequiredImports(): Set<String> = emptySet()
5430
abstract fun isComparable(): Boolean
55-
override fun toString(): String = error("not supported")
5631
}
5732

5833
/**
@@ -61,13 +36,16 @@ abstract class GoUtModel(
6136
class GoUtFieldModel(
6237
val model: GoUtModel,
6338
val fieldId: GoFieldId,
64-
) : UtModel(fieldId.declaringClass)
39+
) : GoUtModel(fieldId.declaringType) {
40+
override fun getRequiredImports(): Set<String> = model.getRequiredImports()
41+
override fun isComparable(): Boolean = model.isComparable()
42+
}
6543

6644
/**
6745
* Class for Go struct field.
6846
*/
6947
class GoFieldId(
70-
declaringClass: GoTypeId, name: String, val isExported: Boolean
71-
) : FieldId(declaringClass, name) {
72-
override fun toString(): String = "$name: $declaringClass"
73-
}
48+
val declaringType: GoTypeId,
49+
val name: String,
50+
val isExported: Boolean
51+
)

0 commit comments

Comments
 (0)