Skip to content

Commit

Permalink
Annotations: Add more test cases, and document planned features in An…
Browse files Browse the repository at this point in the history
…notLangPlanned.java (contribute!)
  • Loading branch information
visq committed Apr 6, 2011
1 parent 975a1a3 commit a5f948a
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 3 deletions.
9 changes: 7 additions & 2 deletions java/target/src/test/wcet/devel/AnnotLang1.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* All tests take roughly 144 * 10K cycles to execute
*
* $test$> make jsim P1=test P2=wcet/devel P3=AnnotLang1
* $grep$> wcet[DfaLoopBound1#measure]: ^ 1431236
* $grep$> wcet[AnnotLang1]: ^ 1431236
*
* Test constant expressions takes ~ 24 * 10K
*
Expand All @@ -26,6 +26,11 @@
import com.jopdesign.sys.Const;
import com.jopdesign.sys.Native;

/**
* Testing new annotation language features (1)
* @author Benedikt Huber <benedikt.huber@gmail.com>
*
*/
public class AnnotLang1 {
int x;

Expand Down Expand Up @@ -74,7 +79,7 @@ public static void main(String[] args) {
invoke();
if (MEASURE) {
int dt = te-ts-to;
System.out.print("wcet[DfaLoopBound1#measure]:");
System.out.print("wcet[AnnotLang1]:");
System.out.println(dt);
}
}
Expand Down
86 changes: 86 additions & 0 deletions java/target/src/test/wcet/devel/AnnotLang2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package wcet.devel;
/* Automated Test Procedure:
*
* The compute method takes roughly 10K cycles
*
* $test$> make java_app wcet P1=test P2=wcet/devel P3=AnnotLang2 WCET_METHOD=compute1
* $grep$> wcet: (cost: ^ 9974 $ )
*
* All tests take roughly 24 * 10K cycles to execute
*
* $test$> make jsim P1=test P2=wcet/devel P3=AnnotLang2
* $grep$> wcet[AnnotLang2]: ^ 238470
*
* Test testConstantReference takes ~ 24 * 10K
*
* $test$> make wcet P1=test P2=wcet/devel P3=AnnotLang2 WCET_OPTIONS="--use-dfa no"
* $grep$> wcet: (cost: ^ 242359 $ , execution
*
*/

import com.jopdesign.sys.Const;
import com.jopdesign.sys.Native;

/**
* Testing new annotation language features (2)
* @author Benedikt Huber <benedikt.huber@gmail.com>
*
*/
public class AnnotLang2 {
public static final int L1 = 6;
public static final int L2 = 8;
public static class Inner {
public static class Constants {
public static final int L3 = 10;
}
}
int x;

/* test constant expressions (24 10K) */
private void testConstantReference() {
for(int j=0;j<L1;++j) // @WCA loop = L1
compute1();
for(int j=0;j<L2;++j) // @WCA loop = wcet.devel.AnnotLang2.L2
compute1();
for(int j=0;j<Inner.Constants.L3;++j) // @W C A loop = wcet.devel.AnnotLang2$Inner.L3
// @WCA loop = 10
compute1();
}


/* should have roughly 10K cycles to simplify the evaluation */
void compute1() {
for(int j=0;j<1;++j) // @WCA loop=1
for(int i= 7;i<167;++i) // @WCA loop=160
x = (x+1) * i;
}

/* testing wcet */
/** Set to false for the WCET analysis, true for measurement */
final static boolean MEASURE = true;
static int ts, te, to;
private static AnnotLang2 test;

public static void main(String[] args) {
ts = Native.rdMem(Const.IO_CNT);
te = Native.rdMem(Const.IO_CNT);
to = te-ts;
test = new AnnotLang2();
invoke();
if (MEASURE) {
int dt = te-ts-to;
System.out.print("wcet[AnnotLang2]:");
System.out.println(dt);
}
}

static void invoke() {
measure();
if (MEASURE) te = Native.rdMem(Const.IO_CNT);
}

static void measure() {
if (MEASURE) ts = Native.rdMem(Const.IO_CNT);
test.testConstantReference();
}
}
54 changes: 54 additions & 0 deletions java/target/src/test/wcet/devel/AnnotLangPlanned.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package wcet.devel;

import com.jopdesign.sys.Const;
import com.jopdesign.sys.Native;

/** Planned features of the annotation language
*
* @author the guys hacking on jop
*
*/
public class AnnotLangPlanned {
volatile int x;
int z = 3;

/* references to DFA results from arguments */
void testArgReference(int a, int b) {
for(int j=a;j<b;++j) // @WCA loop = $arg1 - $arg0
compute1();
for(int j=a;j<z;j+=2) // @WCA loop = ($this.z - $arg0) / 2
compute1();
}

/* references to system parameters provided by the analyzer*/
void testSysReference() {
ts = Native.rdMem(Const.IO_CNT);
te = Native.rdMem(Const.IO_CNT);
to = te - ts;
for(int j=0;j<to;++j) // @WCA loop <= @timer.overhead
compute1();
}

/* absolute loop bound in cycles or real time*/
void testAbsBound() {
ts = Native.rdMem(Const.IO_CNT);
long START_DELAY = 50000;
te = ts;
while((te - ts) < START_DELAY) { // @WCA loop cycles <= @lego.startDelay + @timer.overhead
te = Native.rdMem(Const.IO_CNT);
}
while(! isUART_Ready()) ; // @WCA loop time <= @uart.max_delay ms
}

static boolean isUART_Ready() {
return true;
}

/* should have roughly 10K cycles to simplify the evaluation */
void compute1() {
for(int j=0;j<1;++j) // @WCA loop=1
for(int i= 7;i<167;++i) // @WCA loop=160
x = (x+1) * i;
}
static int ts,te,to; /* measurement overhead */
}
153 changes: 153 additions & 0 deletions java/target/src/test/wcet/devel/BinarySearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package wcet.devel;

import com.jopdesign.sys.Const;
import com.jopdesign.sys.Native;

/**
* Binary search for the array of n integer elements.
*
* WCET aspect: Completely structured.
*
* Ported from C code written by Sung-Soo Lim for the SNU-RT benchmark suite with
* modifications by Jan Gustafsson. See <a
* href="http://www.mrtc.mdh.se/projects/wcet/benchmarks.html">Maelardalen WCET
* Benchmarks</a>.
* <p>
* Note: this implementation of binary search is both hard to analyze and
* inefficient. See rtlib/BinarySearch#bsearch for a fast and easy to
* analyze real-time variant.
* </p>
*/
public class BinarySearch
{
private static class Data
{
public int key;
public int value;

public Data(int key, int value)
{
this.key = key;
this.value = value;
}
}

public static final int MAX_SIZE = 128;

private Data[] data;
private int size;

public BinarySearch(int capacity)
{
data = new Data[capacity];

for (int i = 0; i < capacity; i++) // @WCA loop <= 129
// @WC3A loop <= $1
{
data[i] = new Data(i<<1, i * 100);
}
}
int loopCount;
public int binarySearch(int x)
{
int fvalue, mid, up, low;

low = 0;
up = size-1;
fvalue = -1; // all data are positive

/* Loop Bound <= floor ( log(up-low+1) / log 2 ) + 1
* Proof by induction:
* up-low = 0 => iterations <= 0 + 1 = 1
* Proof: Assume mid = low = up
* (a) up' = mid - 1 = low - 1 ==> up-low = -1
* (b) low' = mid + 1 = up + 1 ==> up-low = -1
* Assume for all k < n, up-low = k ==> iterations <= floor(ld [k+1]) + 1
* We have to show that ==> up-low = n ==> iterations <= floor(ld [n+1]) + 1
* Proof: Assume mid = (low + low + n) >> 1;
* mid = floor( (2 low + n) / 2 );
* mid = floor( low + n/2 ) = low + floor (n/2);
* (a) up' = mid - 1 = low + floor (n/2) - 1
* (up-low)' = low + floor (n/2) - 1 - low = floor (n/2) - 1
* ==> iterations <= floor(ld [floor(n/2) - 1 + 1]) + 1 + 1
* <= floor(ld [floor(n/2)]) + 2
* <= floor(ld(n/2)) + 2
* = floor(ld(n)) + 1
* <= floor(ld(n+1)) + 1
* (b) low' = mid + 1 = low + floor (n/2) + 1
* (up-low)' = low+n -low-floor(n/2)-1 = n-floor(n/2)-1
* ==> iterations <= (floor(ld [n-floor(n/2)-1 + 1]) + 1) + 1
* = floor(ld[n-floor(n/2)]) + 2
* <= floor(ld[n-(n-1)/2]) + 2
* = floor(ld[(n+1)/2]) + 2
* = floor(ld(n+1)) + 1
* <= floor(ld(n+1)) + 1
*/
loopCount = 0;
while (low <= up) // @WC1A loop <= bitlength(128)
// @WCA loop <= bitlength(MAX_SIZE)
// @WC3A: loop <= bitlength($this.size)
{
loopCount++;
mid = (low + up) >> 1;

if (data[mid].key == x) // @WC4A: WCA flow <= 1 loop
{
up = low - 1;
fvalue = data[mid].value;
}
else if (data[mid].key > x)
{
up = mid - 1;
}
else
{
low = mid + 1;
}
}
return fvalue;
}

/* testing wcet */
/** Set to false for the WCET analysis, true for measurement */
final static boolean MEASURE = true;
static int ts, te, to;
private static BinarySearch b;

public static void main(String[] args)
{
if(MEASURE) {
ts = Native.rdMem(Const.IO_CNT);
te = Native.rdMem(Const.IO_CNT);
to = te-ts;
}
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
b = new BinarySearch(MAX_SIZE);
for(int i = 1; i <= MAX_SIZE; i++) {
b.size = i;
// double lb = Math.floor ( Math.log(i) / Math.log(2) ) + 1;
int maxLb = 0;
for(int j = -1; j < (i<<1)+1;++j) {
if(MEASURE) ts = Native.rdMem(Const.IO_CNT);
b.binarySearch(j);
if(MEASURE) te = Native.rdMem(Const.IO_CNT);
if(b.loopCount > maxLb) maxLb = b.loopCount;
if (MEASURE) {
int dt = te-ts-to;
if(dt > max) max = dt;
if(dt < min) min = dt;
}
}
System.out.print("wcet[BinarySearch,n=");
System.out.print(i);
System.out.print("] ");
System.out.print(min);
System.out.print(" - ");
System.out.print(max);
System.out.print(", max. ");
System.out.print(maxLb);
System.out.println(" iterations");
}
}
}
1 change: 0 additions & 1 deletion support/run_inline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def match(ctx, expect, actual)
expect = $2.strip
postctx = ($3||"$")[1..-1].strip
context = Regexp.new(Regexp.escape(prectx)+"(.*)"+Regexp.escape(postctx))
puts "re: #{context.inspect}"
while line = stdout.gets
(actual = $1 ; break) if context =~ line.strip
end
Expand Down

0 comments on commit a5f948a

Please sign in to comment.