Skip to content

Tests for collections and bug fixes of approximations #15

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

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
4464e95
[feat] added Spring approximations
MchKosticyn May 19, 2024
a589ca5
[feat] updated USVM API
MchKosticyn May 19, 2024
d5a5793
[feat] implemented encoders
MchKosticyn May 19, 2024
78514ad
[feat] added approximation for LogFactory
MchKosticyn May 19, 2024
8c11ebd
[feat] updated JDK version
MchKosticyn May 19, 2024
96ed364
[feat] updated usvm-api
MchKosticyn Aug 5, 2024
1693ca9
[fix] fixed approximations
MchKosticyn Aug 5, 2024
02da844
[feat] added 'warning as error'
MchKosticyn Aug 5, 2024
7ad1a1a
[fix] added 'typeIs' check for 'equals'
MchKosticyn Aug 5, 2024
b9fb015
updated jacodb version
MchKosticyn Aug 5, 2024
31b4597
[fix] implemented adding all elements via internal copy
MchKosticyn Aug 5, 2024
764d821
[feat] added Map.Entry encoder
MchKosticyn Aug 6, 2024
2634638
[feat] added 'Log' interface approximation
MchKosticyn Aug 7, 2024
78f8212
[fix] deleted 'PrimitiveTypeUtils'
MchKosticyn Aug 7, 2024
dbe75e1
[fix] fixed decoders
MchKosticyn Aug 13, 2024
65439c5
[fix] fixed System_PrintStream
MchKosticyn Aug 13, 2024
e643c72
[fix] fixed 'System' approximation
MchKosticyn Aug 13, 2024
3503d09
[fix] fixed spliterator approximation
MchKosticyn Aug 13, 2024
02c5271
[fix] fixed 'AtomicBoolean' approximation
MchKosticyn Aug 13, 2024
4dbc6fb
[fix] fixed 'Log' approximation
MchKosticyn Aug 13, 2024
31893f4
wip
MchKosticyn Aug 16, 2024
dd18040
wip
MchKosticyn Aug 21, 2024
771193d
Added approximations for some buffers
IgorFilimonov Aug 2, 2024
0153a4b
Added Engine.assume
IgorFilimonov Aug 8, 2024
9965e16
Added tests from OpenJDK repo
IgorFilimonov Aug 12, 2024
889f4bd
Added ReadableImpl
IgorFilimonov Aug 14, 2024
d7144a8
At least some of tests can be passed now
IgorFilimonov Aug 22, 2024
3c3ee6f
Trying to get tests to work
IgorFilimonov Aug 26, 2024
113bc56
Trying to fix ArrayList decoder
IgorFilimonov Aug 27, 2024
dc24083
Some fixes
IgorFilimonov Aug 28, 2024
ab7dd93
Changes for tests + fixed AbstractListImpl
IgorFilimonov Sep 1, 2024
1609cd1
Fixed a bunch of bugs and added a lot of tests
IgorFilimonov Sep 25, 2024
789440a
Renamed all methods of abstract lists
IgorFilimonov Sep 25, 2024
6928282
Renamed all methods of abstract set
IgorFilimonov Sep 25, 2024
934cd16
Renamed all methods of abstact maps
IgorFilimonov Sep 25, 2024
f49abe2
Reverted renaming
IgorFilimonov Sep 28, 2024
4c4471e
Properly renamed all methods of abstract lists
IgorFilimonov Sep 28, 2024
3a635b2
Properly renamed all methods of abstract maps
IgorFilimonov Sep 28, 2024
5f09630
Properly renamed all methods of abstract sets
IgorFilimonov Sep 28, 2024
9eaf076
Added a lot of tests and fixed last bugs for now
IgorFilimonov Oct 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 10 additions & 2 deletions approximations/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
plugins {
java
`maven-publish`
id("org.springframework.boot") version "3.2.0" apply false
}

repositories {
mavenCentral()
maven("https://jitpack.io")
}

private val jacodbPackage = "com.github.UnitTestBot.jacodb"
private val jacodbVersion = "890624770b" // jacodb neo branch
private val jacodbPackage = "org.jacodb"
private val jacodbVersion = "00164e304b" // jacodb neo branch

dependencies {
compileOnly("$jacodbPackage:jacodb-api-jvm:$jacodbVersion")
compileOnly("$jacodbPackage:jacodb-approximations:$jacodbVersion")
compileOnly(files(rootDir.resolve("usvm-api/usvm-api.jar")))
compileOnly("org.springframework.boot:spring-boot-starter-web:3.2.0")
compileOnly("org.springframework.boot:spring-boot-starter-test:3.2.0")
compileOnly("org.springframework.boot:spring-boot-starter-data-jpa:3.2.0")
// Fixes "unknown enum constant 'When.MAYBE'" warning
compileOnly("com.google.code.findbugs:jsr305:3.0.2")
}

group = "org.usvm.approximations.java.stdlib"
Expand All @@ -28,6 +34,8 @@ tasks.withType<JavaCompile> {
options.compilerArgs.add("-source")
options.compilerArgs.add("1.8")
options.compilerArgs.add("-Xlint:unchecked")
options.compilerArgs.add("-Xlint:all")
options.compilerArgs.add("-Werror")
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.util.Collections;
import java.util.List;

@SuppressWarnings("ForLoopReplaceableByForEach")
@SuppressWarnings({"ForLoopReplaceableByForEach", "removal"})
@DecoderFor(SecurityManager.class)
public final class SecurityManager_Decoder implements ObjectDecoder {
private volatile JcMethod cached_SecurityManager_ctor = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public <T> T createInstance(final JcClassOrInterface approx,

List<JcParameter> params = m.getParameters();
if (params.size() != 1) continue;
if (!"java.lang.Object".equals(params.get(0).getType().getTypeName())) continue;
//if (!"java.lang.Object".equals(params.get(0).getType().getTypeName())) continue;

cached_ArrayList_add = m_add = m;
}
Expand All @@ -68,7 +68,7 @@ public <T> void initializeInstance(final JcClassOrInterface approx,
JcField f_storage = cached_ArrayList_storage;
// TODO: add synchronization if needed
if (f_storage == null) {
final List<JcField> fields = approx.getDeclaredFields();
final List<JcField> fields = getAllFields(approx);
for (int i = 0, c = fields.size(); i < c; i++) {
JcField f = fields.get(i);
if ("storage".equals(f.getName())) {
Expand All @@ -93,4 +93,21 @@ public <T> void initializeInstance(final JcClassOrInterface approx,
decoder.invokeMethod(cached_ArrayList_add, args);
}
}

public List<JcField> getAllFields(JcClassOrInterface type) {
List<JcClassOrInterface> typesToCheck = new ArrayList<>();
typesToCheck.add(type);
List<JcField> allFields = new ArrayList<>();
while (!typesToCheck.isEmpty()) {
int lastIndex = typesToCheck.size() - 1;
JcClassOrInterface current = typesToCheck.remove(lastIndex);
allFields.addAll(current.getDeclaredFields());

JcClassOrInterface superClass = current.getSuperClass();
if (superClass != null) {
typesToCheck.add(superClass);
}
}
return allFields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public <T> void initializeInstance(final JcClassOrInterface approximation,
decoder.invokeMethod(m_add, args);

map.remove(key);
length -= 1;
length--;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public <T> void initializeInstance(final JcClassOrInterface approximation,
decoder.invokeMethod(m_add, args);

map.remove(key);
length -= 1;
length--;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public <T> T createInstance(final JcClassOrInterface approximation,

if ("value".equals(name)) {
f_value = f;
} else if ("present".equals(name)) {
} else if ("isPresent".equals(name)) {
f_present = f;
}

Expand Down Expand Up @@ -92,4 +92,4 @@ public <T> void initializeInstance(final JcClassOrInterface approximation,
final DecoderApi<T> decoder) {
// nothing
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public <T> T createInstance(final JcClassOrInterface approx,
// NOTE: this is an example on how to join discovery process for multiple targets
if ("value".equals(name)) {
f_value = f;
} else if ("present".equals(name)) {
} else if ("isPresent".equals(name)) {
f_present = f;
}
if (f_value != null && f_present != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public <T> T createInstance(final JcClassOrInterface approx,

if ("value".equals(name)) {
f_value = f;
} else if ("present".equals(name)) {
} else if ("isPresent".equals(name)) {
f_present = f;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package encoders.java.util;

import generated.java.util.map.AbstractMap_EntryImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;
import stub.java.util.map.AbstractMap_Entry;

import java.util.Map;

@EncoderFor(AbstractMap_Entry.class)
public class AbstractMap_Entry_Encoder implements ObjectEncoder {

@Override
public Object encode(Object list) {
return new AbstractMap_EntryImpl<>((Map.Entry<?, ?>) list);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package encoders.java.util;

import generated.java.util.list.ArrayListImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.ArrayList;

@EncoderFor(ArrayList.class)
public class ArrayList_Encoder implements ObjectEncoder {

@Override
public Object encode(Object list) {
ArrayListImpl<Object> result = new ArrayListImpl<>();
result.addAll(((ArrayList<?>) list).stream().toList());
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package encoders.java.util;

import generated.java.util.map.ConcurrentHashMapImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.concurrent.ConcurrentHashMap;

@EncoderFor(ConcurrentHashMap.class)
public class ConcurrentHashMap_Encoder implements ObjectEncoder {

@SuppressWarnings("unchecked")
@Override
public Object encode(Object object) {
ConcurrentHashMap<Object, Object> map = (ConcurrentHashMap<Object, Object>) object;
return new ConcurrentHashMapImpl<>(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package encoders.java.util;

import generated.java.util.map.HashMapImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.HashMap;

@SuppressWarnings("unused")
@EncoderFor(HashMap.class)
public class HashMap_Encoder implements ObjectEncoder {

@SuppressWarnings("unchecked")
@Override
public Object encode(Object object) {
HashMap<Object, Object> map = (HashMap<Object, Object>) object;
return new HashMapImpl<>(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package encoders.java.util;

import generated.java.util.set.HashSetImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@EncoderFor(HashSet.class)
public class HashSet_Encoder implements ObjectEncoder {

@Override
public Object encode(Object object) {
HashSetImpl<Object> result = new HashSetImpl<>();
result.addAll(Arrays.asList(((Set<?>) object).toArray()));
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package encoders.java.util;

import generated.java.util.map.LinkedHashMapImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

import java.util.LinkedHashMap;

@SuppressWarnings("unused")
@EncoderFor(LinkedHashMap.class)
public class LinkedHashMap_Encoder implements ObjectEncoder {

@SuppressWarnings("unchecked")
@Override
public Object encode(Object object) {
LinkedHashMap<Object, Object> map = (LinkedHashMap<Object, Object>) object;
return new LinkedHashMapImpl<>(map);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package encoders.java.util;

import generated.java.lang.StringImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

@EncoderFor(java.lang.String.class)
public class String_Encoder implements ObjectEncoder {

@Override
public Object encode(Object object) {
return new StringImpl(((String) object).getBytes());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package encoders.java.util;

import generated.java.lang.ThreadLocalImpl;
import org.usvm.api.encoder.EncoderFor;
import org.usvm.api.encoder.ObjectEncoder;

@EncoderFor(java.lang.ThreadLocal.class)
public class ThreadLocal_Encoder implements ObjectEncoder {

@Override
public Object encode(Object object) {
return new ThreadLocalImpl<>();
}
}
Loading