Skip to content
Snippets Groups Projects
Commit 5ef34954 authored by chrg's avatar chrg
Browse files

The first steps towards a framework

parents
Branches
No related tags found
No related merge requests found
target
.jdtls
.metadata
.classpath
.project
.settings
LICENSE 0 → 100644
BSD 3-Clause License
Copyright © 2024, DTU
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# JPAMB: Java Program Analysis Micro Benchmarks
The goal of this benchmark suite is to make a collection of interesting
challenges of dynamic and static analysis.
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1685566663,
"narHash": "sha256-btHN1czJ6rzteeCuE/PNrdssqYD2nIA4w48miQAFloM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4ecab3273592f27479a583fb6d975d4aba3486fe",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "23.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}
{
description = "JPAMB: Java Program Analysis Micro Benchmarks";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/23.05";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
in {
devShells = {
default = pkgs.mkShell {
name = "jpamb";
packages = with pkgs; [
jdt-language-server
jdk
maven
(python3.withPackages (p: with p; []))
];
};
};
});
}
pom.xml 0 → 100644
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jpamb</groupId>
<artifactId>jpamb</artifactId>
<version>1.0-SNAPSHOT</version>
<name>jpamb</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
package jpamb;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import jpamb.utils.Case;
import jpamb.utils.CaseContent;
public class Runtime {
public static void main(String[] args) throws ClassNotFoundException {
var cls = Class.forName("jpamb.cases.Simple");
for (Method m : cls.getMethods()) {
var c = m.getAnnotation(Case.class);
if (c == null)
continue;
CaseContent content;
content = CaseContent.parse(c.value());
if (!Modifier.isStatic(m.getModifiers())) {
System.out.println("Method is not static");
continue;
}
String message = null;
try {
m.invoke(null, content.params());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
Class<? extends Throwable> clazz = e.getCause().getClass();
if (clazz.equals(content.raises())) {
message = "success";
} else {
message = e.toString();
}
}
if (message == null) {
message = "did not produce error";
}
System.out.println(cls.getName() + "." + m.getName() + ": " + message);
}
}
}
package jpamb.cases;
import jpamb.utils.Case;
public class Simple {
@Case("() -> assertion error")
public static void assertFalse() {
assert false;
}
@Case("(false) -> assertion error")
public static void assertBoolean(boolean shouldFail) {
assert shouldFail;
}
}
package jpamb.utils;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Case {
String value();
}
package jpamb.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public record CaseContent(
Object[] params,
Class<? extends Throwable> raises) {
public static CaseContent parse(String string) {
Pattern pattern = Pattern.compile("\\(([^)]*)\\)\\s*->\\s*(.+)");
Matcher matcher = pattern.matcher(string);
// Parse the expression
if (matcher.find()) {
String args = matcher.group(1);
String result = matcher.group(2);
ArrayList<Object> list = new ArrayList<>();
try (Scanner sc = new Scanner(args)) {
while (sc.hasNext()) {
if (sc.hasNextBoolean()) {
list.add(sc.nextBoolean());
} else {
String var = sc.next();
if (!var.equals(",")) {
throw new RuntimeException("Invalid case: " + string + " // unexpected " + var);
}
}
}
}
if (result.equals("assertion error")) {
return new CaseContent(list.toArray(), AssertionError.class);
} else {
throw new RuntimeException("Invalid case: " + string);
}
} else {
throw new RuntimeException("Invalid case: " + string);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment