resess / ARDiff

MIT License
6 stars 4 forks source link

The issue with the ARDiff testing program reporting errors. #3

Open LuMingYinDetect opened 5 months ago

LuMingYinDetect commented 5 months ago

Hello! I've utilized ARDiff to test a program I've written myself. Below is the old version of the program: public class oldV{ public static int snippet(int num, int den) { int ratio; if (num < 0 || den < 0) { ratio = -1; } else if (den == 0 || num == 0) { ratio = 0; } else if (den > 200 || num > 200) { ratio = 200; } else if (den < 2) { ratio = 2 * num; } else if (den < 4) { ratio = num - den; } else if (den < 8) { if (num < den) { ratio = num; } else { ratio = den; } } else if (den < 16) { if (num > den) { ratio = num; } else { ratio = den; } } else if (den < 32) { ratio = 32; for (int i = 2; i < 32; i++) { if (num % i == 0) { ratio = i; break; } } } else if (den < 64) { ratio = 64; for (int i = 2; i < 64; i++) { if (den % i == 0) { ratio = i; break; } } } else if (den < 128) { int x = den; int y = num; int z = x + y; for (int i = 1; i < 30; i++) { z = x + y; x = y; y = z; } ratio = z; } else { ratio = den + num + 10; } return ratio; } }

The new version of the code is as follows: public class newV{ public static int snippet(int num, int den) { int ratio; if (num < 0 || den < 0) { ratio = -1; } else if (den == 0 || num == 0) { ratio = 0; } else if (den > 200 || num > 200) { ratio = 200; } else if (den < 2) { ratio = 2 * num; } else if (den < 4) { ratio = num - den; } else if (den < 8) { if (num < den) { ratio = num; } else { ratio = den; } } else if (den < 16) { if (num > den) { ratio = num; } else { ratio = den; } } else if (den < 32) { ratio = 32; for (int i = 2; i < 32; i++) { if (num % i == 0) { ratio = i; break; } } } else if (den < 64) { ratio = 64; for (int i = 2; i < 64; i++) { if (den % i == 0) { ratio = i; break; } } } else if (den < 128) { int x = den; int y = num; int z = x + y; for (int i = 1; i < 30; i++) { z = x + y; x = y; y = z; } ratio = y; } else { ratio = den + num + 10; } return ratio; } }

When I use IMP-S to test the code, IMP-S can provide correct results. However, when I use DSE and ARDiff to test the program, the tools report errors as follows: `***** ------------------------------------ARDIFF-----------------------------------


An error/exception occurred when instrumenting the files or running the equivalence checking. Please report this issue to us.

java.io.IOException: Compilation error: Compilation error: cannot find symbol symbol: variable ratio location: class demo.benchmarks.Airy.Sign.Eq.instrumented.IoldVARDiffcannot find symbol symbol: variable ratio location: class demo.benchmarks.Airy.Sign.Eq.instrumented.IoldVARDiff at equiv.checking.Utils.compile(Utils.java:69) at equiv.checking.Instrumentation.saveNewProcedure(Instrumentation.java:312) at DSE.DSE.runEquivalenceChecking(DSE.java:272) at GradDiff.GradDiff.runTool(GradDiff.java:90) at Runner.Runner.runTool(Runner.java:163) at Runner.Runner.main(Runner.java:472)`

The detection instructions I used are:java -Djava.library.path=jpf-git/jpf-symbc/lib -jar target/artifacts/Implementation_jar/Implementation.jar --path1 /project/ARDiff/benchmarks/Airy/Sign/Eq/oldV.java --path2 /project/ARDiff/benchmarks/Airy/Sign/Eq/newV.java --tool A --s coral --b 3

I replaced the files in the /benchmarks/Airy/Sign/Eq directory of the test suite with my own code. Therefore, the error message indicates that the error occurred in the demo.benchmarks.Airy.Sign.Eq directory.

The error message indicates that the symbol "ratio" was not found. I attempted to redefine "ratio" within the function snippet instead of as a standalone entity. Here is an example of how it is done: 'public class oldV{ public static int snippet(int num, int den,int ratio) { if (num < 0 || den < 0) { ratio = -1; } else if (den == 0 || num == 0) { ratio = 0; } else if (den > 200 || num > 200) { ratio = 200; } else if (den < 2) { ratio = 2 * num; } else if (den < 4) { ratio = num - den; } else if (den < 8) { if (num < den) { ratio = num; } else { ratio = den; } } else if (den < 16) { if (num > den) { ratio = num; } else { ratio = den; } } else if (den < 32) { ratio = 32; for (int i = 2; i < 32; i++) { if (num % i == 0) { ratio = i; break; } } } else if (den < 64) { ratio = 64; for (int i = 2; i < 64; i++) { if (den % i == 0) { ratio = i; break; } } } else if (den < 128) { int x = den; int y = num; int z = x + y; for (int i = 1; i < 30; i++) { z = x + y; x = y; y = z; } ratio = z; } else { ratio = den + num + 10; } return ratio; } }'

After making this modification, ARDiff no longer reports this error. Do you happen to know the reason behind this problem?

LuMingYinDetect commented 5 months ago

Additionally, when I tested a more complex program using IRDiff, IMP-S, and DSE, none of the three tools were able to detect the code correctly. Below is the old version of the code: public class oldV{ public static int client(int den, int num) { int ratio = 0; if (den == 0 || num == 0) { ratio = 0; } else if (den < 0) { System.out.println("den < 0"); int N = 3; int max, min; int t1 = 1, t2 = 1; int j = 1; for (; j <= N - 1; j++) t1 *= 10;

        for (; j <= N; j++)
            t2 *= 10;
        min = t1;
        max = t2 - 1;

        int i = min;
        for (i = min; i <= max; i++) {
            int sum = 0;
            int temp_i = i;
            while (temp_i != 0) {
                int t = 1;
                int temp = temp_i % 10;
                for (int k = 1; k <= N; k++) {
                    t *= temp;
                }
                sum += t;
                temp_i /= 10;
            }
            if (i == sum) {
                break;
            }
        }

        int half = (min + max) / 2;
        if (i > half) {
            ratio = i;
        } else {
            ratio = 0;
        }

        int k = 0;
        for (k = i; k <= max; k++) {
            int sum = 0;
            int temp_k = k;
            while (temp_k != 0) {
                int t = 1;
                int temp = temp_k % 10;
                for (int l = 1; l <= N; l++) {
                    t *= temp;
                }
                sum += t;
                temp_k /= 10;
            }
            if (k == sum) {
                break;
            }
        }
        if (153 > half) {
            ratio = i;
        } else {
            ratio = 0;
        }

    } else if (den < 4) {
        System.out.println("den < 4");
        int[] arr = { 4, 3, 2, 1 };
        int[] tem = { 1, 2, 3, 4 };
        int len = 4;
        int i, j, key;
        if (len > den)
            for (i = 1; i < len; i++) {
                key = arr[i];
                j = i - 1;
                while ((j >= 0) && (arr[j] > key)) {
                    arr[j + 1] = arr[j] + den;
                    j--;
                }
                arr[j + 1] = key + den;
            }
        else
            for (i = 1; i < len; i++) {
                key = tem[i];
                j = i - 1;
                while ((j >= 0) && (tem[j] < key)) {
                    tem[j + 1] = tem[j] + den;
                    j--;
                }
                tem[j + 1] = key + den;
            }
        ratio = 4;

    } else if (den < 16) {
        if (den < num) {
            int flag1 = 10;
            int d = 0;
            int temp = den;
            int i = 0;
            for (i = 0; i < flag1; i++) {
                ratio = 0;
                for (int j = 0; j < den; j++) {
                    temp=temp-1;
                    d = temp;
                    for (int k = 0; k < d; k++)
                        for (int l = k + 1; l < d; l++) {
                            ratio = ratio + l;
                        }
                }
                if (ratio > num)
                    break;
            }
            if (i < flag1)
                ratio = ratio - 10;
            else
                ratio = num;
        } else {
            int[] a = { 1, 2, 3, 4, 5, 5, 6 };
            int length = 7;
            int val_max = -1;
            int time_max = 0;
            int time_tmp = 0;
            ratio = 0;
            for (int i = 0; i < length; i++) {
                time_tmp = 0;
                for (int j = 0; j < length; j++) {
                    if (a[i] == a[j]) {
                        time_tmp += 1;
                    }
                    if (time_tmp > time_max) {
                        time_max = time_tmp;
                        val_max = a[i];
                    }
                }
            }
            ratio = 2 * val_max;
        }
        ratio = num;

    } else if (den < 64) {
        if (den < num) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                }
            }
            ratio = ratio;
        } else {
            ratio = 64;
            int temp = 0;
            int temp2 = 0;
            int temp3 = 0;
            int i = 2;
            for (; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    while (ratio > 0) {
                        temp = ratio;
                        if (temp > 12)
                            for (int j = 0; j < temp; j++) {
                                temp2 = temp;
                                int flage = temp2 % 2;
                                if (flage != 0) {
                                    while (temp2 != 0) {
                                        temp--;
                                    }
                                } else {
                                    temp3 = flage;
                                }
                            }
                        else
                            for (int j = 0; j < temp; j++)
                                temp2 = temp2 + i;
                        ratio--;
                    }
                }
            }
            if (den % 63 == 0) {
                ratio = i;
            }
        }

        ratio = den;

    } else if (den < 128) {
        System.out.println("den < 128");
        int x = den, y = num, z = x + y;
        if (y % 2 != 0) {
            if (y < 22)
                for (int i = 1; i < 10; i++) {
                    z = x + y;
                    x = y;
                    y = z;
                }
            else
                for (int i = 1; i < 20; i++) {
                    z = x + y;
                    x = y;
                    y = z;
                }
            ratio = z;
        } else {
            int temp = y / 2;
            int flag = temp;
            if (flag > 12)
                for (int i = 0; i < temp; i++) {
                    ratio = ratio + i;
                    int temp4 = 0;
                    if (i % 2 == 0) {
                        for (int j = 0; j < temp; j++) {
                            if (j % 3 != 0) {
                                temp4 += 1;
                            } else {
                                temp4 -= 1;
                            }
                        }
                    } else {
                        temp4 += 0;
                    }
                }
        }
        ratio = 11;

    } else {
        ratio = 11;
    }
    return ratio;
}

}

The new version of the code is as follows: public class newV{ public static int client(int den, int num) { int ratio = 0; if (den == 0 || num == 0) { ratio = 0; } else if (den < 0) { System.out.println("den < 0"); int N = 3; int max, min; int t1 = 1, t2 = 1; int j = 1; for (; j <= N - 1; j++) t1 *= 10;

        for (; j <= N; j++)
            t2 *= 10;
        min = t1;
        max = t2 - 1;

        int i = min;
        for (i = min; i <= max; i++) {
            int sum = 0;
            int temp_i = i;
            while (temp_i != 0) {
                int t = 1;
                int temp = temp_i % 10;
                for (int k = 1; k <= N; k++) {
                    t *= temp;
                }
                sum += t;
                temp_i /= 10;
            }
            if (i == sum) {
                break;
            }
        }

        int half = (min + max) / 2;
        if (i > half) {
            ratio = i;
        } else {
            ratio = 0;
        }

        int k = 0;
        for (k = i; k <= max; k++) {
            int sum = 0;
            int temp_k = k;
            while (temp_k != 0) {
                int t = 1;
                int temp = temp_k % 10;
                for (int l = 1; l <= N; l++) {
                    t *= temp;
                }
                sum += t;
                temp_k /= 10;
            }
            if (k == sum) {
                break;
            }
        }
        if (153 > half) {
            ratio = i;
        } else {
            ratio = 0;
        }

    } else if (den < 4) {
        System.out.println("den < 4");
        int[] arr = { 4, 3, 2, 1 };
        int[] tem = { 1, 2, 3, 4 };
        int len = 4;
        int i, j, key;
        if (len > den)
            for (i = 1; i < len; i++) {
                key = arr[i];
                j = i - 1;
                while ((j >= 0) && (arr[j] > key)) {
                    arr[j + 1] = arr[j] + den;
                    j--;
                }
                arr[j + 1] = key + den;
            }
        else
            for (i = 1; i < len; i++) {
                key = tem[i];
                j = i - 1;
                while ((j >= 0) && (tem[j] < key)) {
                    tem[j + 1] = tem[j] + den;
                    j--;
                }
                tem[j + 1] = key + den;
            }
        ratio = 4;

    } else if (den < 16) {
        if (num > den) {
            int flag1 = 10;
            int d = 0;
            int temp = den;
            int i = 0;
            for (i = 0; i < flag1; i++) {
                ratio = 0;
                for (int j = 0; j < den; j++) {
                    temp=temp-1;
                    d = temp;
                    for (int k = 0; k < d; k++)
                        for (int l = k + 1; l < d; l++) {
                            ratio = ratio + l;
                        }
                }
                if (ratio > num)
                    break;
            }
            if (i < flag1)
                ratio = ratio - 10;
            else
                ratio = num;
        } else {
            int[] a = { 1, 2, 3, 4, 5, 5, 6 };
            int length = 7;
            int val_max = -1;
            int time_max = 0;
            int time_tmp = 0;
            ratio = 0;
            for (int i = 0; i < length; i++) {
                time_tmp = 0;
                for (int j = 0; j < length; j++) {
                    if (a[i] == a[j]) {
                        time_tmp += 1;
                    }
                    if (time_tmp > time_max) {
                        time_max = time_tmp;
                        val_max = a[i];
                    }
                }
            }
            ratio = 2 * val_max;
        }
        ratio = num;

    } else if (den < 64) {
        if (den < num) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                }
            }
            ratio = ratio;
        } else {
            ratio = 64;
            int temp = 0;
            int temp2 = 0;
            int temp3 = 0;
            int i = 2;
            for (; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    while (ratio > 0) {
                        temp = ratio;
                        if (temp > 12)
                            for (int j = 0; j < temp; j++) {
                                temp2 = temp;
                                int flage = temp2 % 2;
                                if (flage != 0) {
                                    while (temp2 != 0) {
                                        temp--;
                                    }
                                } else {
                                    temp3 = flage;
                                }
                            }
                        else
                            for (int j = 0; j < temp; j++)
                                temp2 = temp2 + i;
                        ratio--;
                    }
                }
            }
            if (den % 63 == 0) {
                ratio = i;
            }
        }

        ratio = den;

    } else if (den < 128) {
        System.out.println("den < 128");
        int x = den, y = num, z = x + y;
        if (y % 2 != 0) {
            if (y < 22)
                for (int i = 1; i < 10; i++) {
                    z = x + y;
                    x = y;
                    y = z;
                }
            else
                for (int i = 1; i < 20; i++) {
                    z = x + y;
                    x = y;
                    y = z;
                }
            ratio = z;
        } else {
            int temp = y / 2;
            int flag = temp;
            if (flag > 12)
                for (int i = 0; i < temp; i++) {
                    ratio = ratio + i;
                    int temp4 = 0;
                    if (i % 2 == 0) {
                        for (int j = 0; j < temp; j++) {
                            if (j % 3 != 0) {
                                temp4 += 1;
                            } else {
                                temp4 -= 1;
                            }
                        }
                    } else {
                        temp4 += 0;
                    }
                }
        }
        ratio = 11;

    } else {
        ratio = 11;
    }
    return ratio;
}

}

The error message is as follows: DSE: [NOTE] If you want to have a complete summary (exercise all behaviors), make sure your bound is big enough.


------------------------------------DSE-----------------------------------


An error/exception occurred when instrumenting the files or running the equivalence checking. Please report this issue to us.

java.io.IOException: Compilation error: Compilation error: ';' expected';' expected';' expected';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement at equiv.checking.Utils.compile(Utils.java:69) at equiv.checking.Instrumentation.saveNewProcedure(Instrumentation.java:312) at DSE.DSE.runEquivalenceChecking(DSE.java:272) at DSE.DSE.runTool(DSE.java:164) at Runner.Runner.runTool(Runner.java:129) at Runner.Runner.main(Runner.java:472)

ARDiff:


------------------------------------ARDIFF-----------------------------------


An error/exception occurred when instrumenting the files or running the equivalence checking. Please report this issue to us.

java.io.IOException: Compilation error: Compilation error: ';' expected';' expected';' expected';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected expectednot a statement';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement';' expected';' expected';' expected expectednot a statement at equiv.checking.Utils.compile(Utils.java:69) at equiv.checking.Instrumentation.saveNewProcedure(Instrumentation.java:312) at DSE.DSE.runEquivalenceChecking(DSE.java:272) at GradDiff.GradDiff.runTool(GradDiff.java:90) at Runner.Runner.runTool(Runner.java:163) at Runner.Runner.main(Runner.java:472)

IMP-S:


------------------------------------IMP-S-----------------------------------


An error/exception occurred when instrumenting the files or running the equivalence checking. Please report this issue to us.

java.io.IOException: Compilation error: Compilation error: method client in class demo.benchmarks.Airy.Sign.Eq.instrumented.IoldVImp cannot be applied to given types; required: int,int found: int,int,int reason: actual and formal argument lists differ in length at equiv.checking.Utils.compile(Utils.java:69) at equiv.checking.Instrumentation.saveNewProcedure(Instrumentation.java:312) at IMPs.ImpactedS.runEquivalenceChecking(ImpactedS.java:240) at IMPs.ImpactedS.runTool(ImpactedS.java:147) at Runner.Runner.runTool(Runner.java:185) at Runner.Runner.main(Runner.java:472)

How can this issue be resolved?Thank you for taking the time out of your busy schedule to help me with this issue! Looking forward to your reply.

LuMingYinDetect commented 5 months ago

I'm sorry for the garbled code I provided you with in the four versions. Let me repost them here. Old version code of the first program:

public class oldV{
    public static int snippet(int num, int den) {
        int ratio;
        if (num < 0 || den < 0) {
            ratio = -1;
        } else if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den > 200 || num > 200) {
            ratio = 200;
        } else if (den < 2) {
            ratio = 2 * num;
        } else if (den < 4) {
            ratio = num - den;
        } else if (den < 8) {
            if (num < den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 16) {
            if (num > den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 32) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 64) {
            ratio = 64;
            for (int i = 2; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 128) {
            int x = den;
            int y = num;
            int z = x + y;
            for (int i = 1; i < 30; i++) {
                z = x + y;
                x = y;
                y = z;
            }
            ratio = z;
        } else {
            ratio = den + num + 10;
        }
        return ratio;
    }
}

New version code of the first program:

public class newV{
    public static int snippet(int num, int den) {
        int ratio;
        if (num < 0 || den < 0) {
            ratio = -1;
        } else if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den > 200 || num > 200) {
            ratio = 200;
        } else if (den < 2) {
            ratio = 2 * num;
        } else if (den < 4) {
            ratio = num - den;
        } else if (den < 8) {
            if (num < den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 16) {
            if (num > den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 32) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 64) {
            ratio = 64;
            for (int i = 2; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 128) {
            int x = den;
            int y = num;
            int z = x + y;
            for (int i = 1; i < 30; i++) {
                z = x + y;
                x = y;
                y = z;
            }
            ratio = y;
        } else {
            ratio = den + num + 10;
        }
        return ratio;
    }
}

Old version code of the second program:

public class oldV{
    public static int client(int den, int num) {
        int ratio = 0;
        if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den < 0) {
            System.out.println("den < 0");
            int N = 3;
            int max, min;
            int t1 = 1, t2 = 1;
            int j = 1;
            for (; j <= N - 1; j++)
                t1 *= 10;

            for (; j <= N; j++)
                t2 *= 10;
            min = t1;
            max = t2 - 1;

            int i = min;
            for (i = min; i <= max; i++) {
                int sum = 0;
                int temp_i = i;
                while (temp_i != 0) {
                    int t = 1;
                    int temp = temp_i % 10;
                    for (int k = 1; k <= N; k++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_i /= 10;
                }
                if (i == sum) {
                    break;
                }
            }

            int half = (min + max) / 2;
            if (i > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

            int k = 0;
            for (k = i; k <= max; k++) {
                int sum = 0;
                int temp_k = k;
                while (temp_k != 0) {
                    int t = 1;
                    int temp = temp_k % 10;
                    for (int l = 1; l <= N; l++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_k /= 10;
                }
                if (k == sum) {
                    break;
                }
            }
            if (153 > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

        } else if (den < 4) {
            System.out.println("den < 4");
            int[] arr = { 4, 3, 2, 1 };
            int[] tem = { 1, 2, 3, 4 };
            int len = 4;
            int i, j, key;
            if (len > den)
                for (i = 1; i < len; i++) {
                    key = arr[i];
                    j = i - 1;
                    while ((j >= 0) && (arr[j] > key)) {
                        arr[j + 1] = arr[j] + den;
                        j--;
                    }
                    arr[j + 1] = key + den;
                }
            else
                for (i = 1; i < len; i++) {
                    key = tem[i];
                    j = i - 1;
                    while ((j >= 0) && (tem[j] < key)) {
                        tem[j + 1] = tem[j] + den;
                        j--;
                    }
                    tem[j + 1] = key + den;
                }
            ratio = 4;

        } else if (den < 16) {
            if (den < num) {
                int flag1 = 10;
                int d = 0;
                int temp = den;
                int i = 0;
                for (i = 0; i < flag1; i++) {
                    ratio = 0;
                    for (int j = 0; j < den; j++) {
                        temp=temp-1;
                        d = temp;
                        for (int k = 0; k < d; k++)
                            for (int l = k + 1; l < d; l++) {
                                ratio = ratio + l;
                            }
                    }
                    if (ratio > num)
                        break;
                }
                if (i < flag1)
                    ratio = ratio - 10;
                else
                    ratio = num;
            } else {
                int[] a = { 1, 2, 3, 4, 5, 5, 6 };
                int length = 7;
                int val_max = -1;
                int time_max = 0;
                int time_tmp = 0;
                ratio = 0;
                for (int i = 0; i < length; i++) {
                    time_tmp = 0;
                    for (int j = 0; j < length; j++) {
                        if (a[i] == a[j]) {
                            time_tmp += 1;
                        }
                        if (time_tmp > time_max) {
                            time_max = time_tmp;
                            val_max = a[i];
                        }
                    }
                }
                ratio = 2 * val_max;
            }
            ratio = num;

        } else if (den < 64) {
            if (den < num) {
                ratio = 32;
                for (int i = 2; i < 32; i++) {
                    if (num % i == 0) {
                        ratio = i;
                    }
                }
                ratio = ratio;
            } else {
                ratio = 64;
                int temp = 0;
                int temp2 = 0;
                int temp3 = 0;
                int i = 2;
                for (; i < 64; i++) {
                    if (den % i == 0) {
                        ratio = i;
                        while (ratio > 0) {
                            temp = ratio;
                            if (temp > 12)
                                for (int j = 0; j < temp; j++) {
                                    temp2 = temp;
                                    int flage = temp2 % 2;
                                    if (flage != 0) {
                                        while (temp2 != 0) {
                                            temp--;
                                        }
                                    } else {
                                        temp3 = flage;
                                    }
                                }
                            else
                                for (int j = 0; j < temp; j++)
                                    temp2 = temp2 + i;
                            ratio--;
                        }
                    }
                }
                if (den % 63 == 0) {
                    ratio = i;
                }
            }

            ratio = den;

        } else if (den < 128) {
            System.out.println("den < 128");
            int x = den, y = num, z = x + y;
            if (y % 2 != 0) {
                if (y < 22)
                    for (int i = 1; i < 10; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                else
                    for (int i = 1; i < 20; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                ratio = z;
            } else {
                int temp = y / 2;
                int flag = temp;
                if (flag > 12)
                    for (int i = 0; i < temp; i++) {
                        ratio = ratio + i;
                        int temp4 = 0;
                        if (i % 2 == 0) {
                            for (int j = 0; j < temp; j++) {
                                if (j % 3 != 0) {
                                    temp4 += 1;
                                } else {
                                    temp4 -= 1;
                                }
                            }
                        } else {
                            temp4 += 0;
                        }
                    }
            }
            ratio = 11;

        } else {
            ratio = 11;
        }
        return ratio;
    }
}

New version code of the second program:

public class newV{
    public static int client(int den, int num) {
        int ratio = 0;
        if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den < 0) {
            System.out.println("den < 0");
            int N = 3;
            int max, min;
            int t1 = 1, t2 = 1;
            int j = 1;
            for (; j <= N - 1; j++)
                t1 *= 10;

            for (; j <= N; j++)
                t2 *= 10;
            min = t1;
            max = t2 - 1;

            int i = min;
            for (i = min; i <= max; i++) {
                int sum = 0;
                int temp_i = i;
                while (temp_i != 0) {
                    int t = 1;
                    int temp = temp_i % 10;
                    for (int k = 1; k <= N; k++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_i /= 10;
                }
                if (i == sum) {
                    break;
                }
            }

            int half = (min + max) / 2;
            if (i > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

            int k = 0;
            for (k = i; k <= max; k++) {
                int sum = 0;
                int temp_k = k;
                while (temp_k != 0) {
                    int t = 1;
                    int temp = temp_k % 10;
                    for (int l = 1; l <= N; l++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_k /= 10;
                }
                if (k == sum) {
                    break;
                }
            }
            if (153 > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

        } else if (den < 4) {
            System.out.println("den < 4");
            int[] arr = { 4, 3, 2, 1 };
            int[] tem = { 1, 2, 3, 4 };
            int len = 4;
            int i, j, key;
            if (len > den)
                for (i = 1; i < len; i++) {
                    key = arr[i];
                    j = i - 1;
                    while ((j >= 0) && (arr[j] > key)) {
                        arr[j + 1] = arr[j] + den;
                        j--;
                    }
                    arr[j + 1] = key + den;
                }
            else
                for (i = 1; i < len; i++) {
                    key = tem[i];
                    j = i - 1;
                    while ((j >= 0) && (tem[j] < key)) {
                        tem[j + 1] = tem[j] + den;
                        j--;
                    }
                    tem[j + 1] = key + den;
                }
            ratio = 4;

        } else if (den < 16) {
            if (num > den) {
                int flag1 = 10;
                int d = 0;
                int temp = den;
                int i = 0;
                for (i = 0; i < flag1; i++) {
                    ratio = 0;
                    for (int j = 0; j < den; j++) {
                        temp=temp-1;
                        d = temp;
                        for (int k = 0; k < d; k++)
                            for (int l = k + 1; l < d; l++) {
                                ratio = ratio + l;
                            }
                    }
                    if (ratio > num)
                        break;
                }
                if (i < flag1)
                    ratio = ratio - 10;
                else
                    ratio = num;
            } else {
                int[] a = { 1, 2, 3, 4, 5, 5, 6 };
                int length = 7;
                int val_max = -1;
                int time_max = 0;
                int time_tmp = 0;
                ratio = 0;
                for (int i = 0; i < length; i++) {
                    time_tmp = 0;
                    for (int j = 0; j < length; j++) {
                        if (a[i] == a[j]) {
                            time_tmp += 1;
                        }
                        if (time_tmp > time_max) {
                            time_max = time_tmp;
                            val_max = a[i];
                        }
                    }
                }
                ratio = 2 * val_max;
            }
            ratio = num;

        } else if (den < 64) {
            if (den < num) {
                ratio = 32;
                for (int i = 2; i < 32; i++) {
                    if (num % i == 0) {
                        ratio = i;
                    }
                }
                ratio = ratio;
            } else {
                ratio = 64;
                int temp = 0;
                int temp2 = 0;
                int temp3 = 0;
                int i = 2;
                for (; i < 64; i++) {
                    if (den % i == 0) {
                        ratio = i;
                        while (ratio > 0) {
                            temp = ratio;
                            if (temp > 12)
                                for (int j = 0; j < temp; j++) {
                                    temp2 = temp;
                                    int flage = temp2 % 2;
                                    if (flage != 0) {
                                        while (temp2 != 0) {
                                            temp--;
                                        }
                                    } else {
                                        temp3 = flage;
                                    }
                                }
                            else
                                for (int j = 0; j < temp; j++)
                                    temp2 = temp2 + i;
                            ratio--;
                        }
                    }
                }
                if (den % 63 == 0) {
                    ratio = i;
                }
            }

            ratio = den;

        } else if (den < 128) {
            System.out.println("den < 128");
            int x = den, y = num, z = x + y;
            if (y % 2 != 0) {
                if (y < 22)
                    for (int i = 1; i < 10; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                else
                    for (int i = 1; i < 20; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                ratio = z;
            } else {
                int temp = y / 2;
                int flag = temp;
                if (flag > 12)
                    for (int i = 0; i < temp; i++) {
                        ratio = ratio + i;
                        int temp4 = 0;
                        if (i % 2 == 0) {
                            for (int j = 0; j < temp; j++) {
                                if (j % 3 != 0) {
                                    temp4 += 1;
                                } else {
                                    temp4 -= 1;
                                }
                            }
                        } else {
                            temp4 += 0;
                        }
                    }
            }
            ratio = 11;

        } else {
            ratio = 11;
        }
        return ratio;
    }
}
LuMingYinDetect commented 5 months ago

When I changed the variable "ratio" in the first program to be defined as a parameter in the function, the issue disappeared. However, this approach does not work for the second program. The old version of the first program with the modified parameter "ratio" is as follows:

public class oldV{
    public static int snippet(int num, int den,int ratio) {
        if (num < 0 || den < 0) {
            ratio = -1;
        } else if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den > 200 || num > 200) {
            ratio = 200;
        } else if (den < 2) {
            ratio = 2 * num;
        } else if (den < 4) {
            ratio = num - den;
        } else if (den < 8) {
            if (num < den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 16) {
            if (num > den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 32) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 64) {
            ratio = 64;
            for (int i = 2; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 128) {
            int x = den;
            int y = num;
            int z = x + y;
            for (int i = 1; i < 30; i++) {
                z = x + y;
                x = y;
                y = z;
            }
            ratio = z;
        } else {
            ratio = den + num + 10;
        }
        return ratio;
    }
}

The new version of the first program with the modified parameter "ratio" is as follows:

public class newV{
    public static int snippet(int num, int den,int ratio) {
        if (num < 0 || den < 0) {
            ratio = -1;
        } else if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den > 200 || num > 200) {
            ratio = 200;
        } else if (den < 2) {
            ratio = 2 * num;
        } else if (den < 4) {
            ratio = num - den;
        } else if (den < 8) {
            if (num < den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 16) {
            if (num > den) {
                ratio = num;
            } else {
                ratio = den;
            }
        } else if (den < 32) {
            ratio = 32;
            for (int i = 2; i < 32; i++) {
                if (num % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 64) {
            ratio = 64;
            for (int i = 2; i < 64; i++) {
                if (den % i == 0) {
                    ratio = i;
                    break;
                }
            }
        } else if (den < 128) {
            int x = den;
            int y = num;
            int z = x + y;
            for (int i = 1; i < 30; i++) {
                z = x + y;
                x = y;
                y = z;
            }
            ratio = y;
        } else {
            ratio = den + num + 10;
        }
        return ratio;
    }
}
shrBadihi commented 5 months ago

For the issue with the first program, the current version of ARDiff will not redefine the variables if they are in the common block (e.g., ration). That results in "cannot find symbol". The work around for this is what you did.

Looking at the error for the second program, it seems the issue is with the instrumentation. required: int,int found: int,int,int reason: actual and formal argument lists differ in length

I would suggest to copy the second program in the new directory (currently you are using Airy/Sign/Eg for both). The inconsistencies might come from using the temp files of the first program for the second one. Remove all the tool-created folders.

LuMingYinDetect commented 5 months ago

For the issue with the first program, the current version of ARDiff will not redefine the variables if they are in the common block (e.g., ration). That results in "cannot find symbol". The work around for this is what you did.

Looking at the error for the second program, it seems the issue is with the instrumentation. required: int,int found: int,int,int reason: actual and formal argument lists differ in length

I would suggest to copy the second program in the new directory (currently you are using Airy/Sign/Eg for both). The inconsistencies might come from using the temp files of the first program for the second one. Remove all the tool-created folders.

Thank you for your patient explanation! Since the ratio variable is also declared within a function body in my second program, I first moved the ratio variable from the function body to the function parameters. Below is the modified code for the old version:

public class oldV{
    public static int client(int den, int num,int ratio) {
        if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den < 0) {
            System.out.println("den < 0");
            int N = 3;
            int max, min;
            int t1 = 1, t2 = 1;
            int j = 1;
            for (; j <= N - 1; j++)
                t1 *= 10;

            for (; j <= N; j++)
                t2 *= 10;
            min = t1;
            max = t2 - 1;

            int i = min;
            for (i = min; i <= max; i++) {
                int sum = 0;
                int temp_i = i;
                while (temp_i != 0) {
                    int t = 1;
                    int temp = temp_i % 10;
                    for (int k = 1; k <= N; k++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_i /= 10;
                }
                if (i == sum) {
                    break;
                }
            }

            int half = (min + max) / 2;
            if (i > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

            int k = 0;
            for (k = i; k <= max; k++) {
                int sum = 0;
                int temp_k = k;
                while (temp_k != 0) {
                    int t = 1;
                    int temp = temp_k % 10;
                    for (int l = 1; l <= N; l++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_k /= 10;
                }
                if (k == sum) {
                    break;
                }
            }
            if (153 > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

        } else if (den < 4) {
            System.out.println("den < 4");
            int[] arr = { 4, 3, 2, 1 };
            int[] tem = { 1, 2, 3, 4 };
            int len = 4;
            int i, j, key;
            if (len > den)
                for (i = 1; i < len; i++) {
                    key = arr[i];
                    j = i - 1;
                    while ((j >= 0) && (arr[j] > key)) {
                        arr[j + 1] = arr[j] + den;
                        j--;
                    }
                    arr[j + 1] = key + den;
                }
            else
                for (i = 1; i < len; i++) {
                    key = tem[i];
                    j = i - 1;
                    while ((j >= 0) && (tem[j] < key)) {
                        tem[j + 1] = tem[j] + den;
                        j--;
                    }
                    tem[j + 1] = key + den;
                }
            ratio = 4;

        } else if (den < 16) {
            if (den < num) {
                int flag1 = 10;
                int d = 0;
                int temp = den;
                int i = 0;
                for (i = 0; i < flag1; i++) {
                    ratio = 0;
                    for (int j = 0; j < den; j++) {
                        temp=temp-1;
                        d = temp;
                        for (int k = 0; k < d; k++)
                            for (int l = k + 1; l < d; l++) {
                                ratio = ratio + l;
                            }
                    }
                    if (ratio > num)
                        break;
                }
                if (i < flag1)
                    ratio = ratio - 10;
                else
                    ratio = num;
            } else {
                int[] a = { 1, 2, 3, 4, 5, 5, 6 };
                int length = 7;
                int val_max = -1;
                int time_max = 0;
                int time_tmp = 0;
                ratio = 0;
                for (int i = 0; i < length; i++) {
                    time_tmp = 0;
                    for (int j = 0; j < length; j++) {
                        if (a[i] == a[j]) {
                            time_tmp += 1;
                        }
                        if (time_tmp > time_max) {
                            time_max = time_tmp;
                            val_max = a[i];
                        }
                    }
                }
                ratio = 2 * val_max;
            }
            ratio = num;

        } else if (den < 64) {
            if (den < num) {
                ratio = 32;
                for (int i = 2; i < 32; i++) {
                    if (num % i == 0) {
                        ratio = i;
                    }
                }
                ratio = ratio;
            } else {
                ratio = 64;
                int temp = 0;
                int temp2 = 0;
                int temp3 = 0;
                int i = 2;
                for (; i < 64; i++) {
                    if (den % i == 0) {
                        ratio = i;
                        while (ratio > 0) {
                            temp = ratio;
                            if (temp > 12)
                                for (int j = 0; j < temp; j++) {
                                    temp2 = temp;
                                    int flage = temp2 % 2;
                                    if (flage != 0) {
                                        while (temp2 != 0) {
                                            temp--;
                                        }
                                    } else {
                                        temp3 = flage;
                                    }
                                }
                            else
                                for (int j = 0; j < temp; j++)
                                    temp2 = temp2 + i;
                            ratio--;
                        }
                    }
                }
                if (den % 63 == 0) {
                    ratio = i;
                }
            }

            ratio = den;

        } else if (den < 128) {
            System.out.println("den < 128");
            int x = den, y = num, z = x + y;
            if (y % 2 != 0) {
                if (y < 22)
                    for (int i = 1; i < 10; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                else
                    for (int i = 1; i < 20; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                ratio = z;
            } else {
                int temp = y / 2;
                int flag = temp;
                if (flag > 12)
                    for (int i = 0; i < temp; i++) {
                        ratio = ratio + i;
                        int temp4 = 0;
                        if (i % 2 == 0) {
                            for (int j = 0; j < temp; j++) {
                                if (j % 3 != 0) {
                                    temp4 += 1;
                                } else {
                                    temp4 -= 1;
                                }
                            }
                        } else {
                            temp4 += 0;
                        }
                    }
            }
            ratio = 11;

        } else {
            ratio = 11;
        }
        return ratio;
    }
}

The modified new version of the code is as follows:

public class newV{
    public static int client(int den, int num,int ratio) {
        if (den == 0 || num == 0) {
            ratio = 0;
        } else if (den < 0) {
            System.out.println("den < 0");
            int N = 3;
            int max, min;
            int t1 = 1, t2 = 1;
            int j = 1;
            for (; j <= N - 1; j++)
                t1 *= 10;

            for (; j <= N; j++)
                t2 *= 10;
            min = t1;
            max = t2 - 1;

            int i = min;
            for (i = min; i <= max; i++) {
                int sum = 0;
                int temp_i = i;
                while (temp_i != 0) {
                    int t = 1;
                    int temp = temp_i % 10;
                    for (int k = 1; k <= N; k++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_i /= 10;
                }
                if (i == sum) {
                    break;
                }
            }

            int half = (min + max) / 2;
            if (i > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

            int k = 0;
            for (k = i; k <= max; k++) {
                int sum = 0;
                int temp_k = k;
                while (temp_k != 0) {
                    int t = 1;
                    int temp = temp_k % 10;
                    for (int l = 1; l <= N; l++) {
                        t *= temp;
                    }
                    sum += t;
                    temp_k /= 10;
                }
                if (k == sum) {
                    break;
                }
            }
            if (153 > half) {
                ratio = i;
            } else {
                ratio = 0;
            }

        } else if (den < 4) {
            System.out.println("den < 4");
            int[] arr = { 4, 3, 2, 1 };
            int[] tem = { 1, 2, 3, 4 };
            int len = 4;
            int i, j, key;
            if (len > den)
                for (i = 1; i < len; i++) {
                    key = arr[i];
                    j = i - 1;
                    while ((j >= 0) && (arr[j] > key)) {
                        arr[j + 1] = arr[j] + den;
                        j--;
                    }
                    arr[j + 1] = key + den;
                }
            else
                for (i = 1; i < len; i++) {
                    key = tem[i];
                    j = i - 1;
                    while ((j >= 0) && (tem[j] < key)) {
                        tem[j + 1] = tem[j] + den;
                        j--;
                    }
                    tem[j + 1] = key + den;
                }
            ratio = 4;

        } else if (den < 16) {
            if (num > den) {
                int flag1 = 10;
                int d = 0;
                int temp = den;
                int i = 0;
                for (i = 0; i < flag1; i++) {
                    ratio = 0;
                    for (int j = 0; j < den; j++) {
                        temp=temp-1;
                        d = temp;
                        for (int k = 0; k < d; k++)
                            for (int l = k + 1; l < d; l++) {
                                ratio = ratio + l;
                            }
                    }
                    if (ratio > num)
                        break;
                }
                if (i < flag1)
                    ratio = ratio - 10;
                else
                    ratio = num;
            } else {
                int[] a = { 1, 2, 3, 4, 5, 5, 6 };
                int length = 7;
                int val_max = -1;
                int time_max = 0;
                int time_tmp = 0;
                ratio = 0;
                for (int i = 0; i < length; i++) {
                    time_tmp = 0;
                    for (int j = 0; j < length; j++) {
                        if (a[i] == a[j]) {
                            time_tmp += 1;
                        }
                        if (time_tmp > time_max) {
                            time_max = time_tmp;
                            val_max = a[i];
                        }
                    }
                }
                ratio = 2 * val_max;
            }
            ratio = num;

        } else if (den < 64) {
            if (den < num) {
                ratio = 32;
                for (int i = 2; i < 32; i++) {
                    if (num % i == 0) {
                        ratio = i;
                    }
                }
                ratio = ratio;
            } else {
                ratio = 64;
                int temp = 0;
                int temp2 = 0;
                int temp3 = 0;
                int i = 2;
                for (; i < 64; i++) {
                    if (den % i == 0) {
                        ratio = i;
                        while (ratio > 0) {
                            temp = ratio;
                            if (temp > 12)
                                for (int j = 0; j < temp; j++) {
                                    temp2 = temp;
                                    int flage = temp2 % 2;
                                    if (flage != 0) {
                                        while (temp2 != 0) {
                                            temp--;
                                        }
                                    } else {
                                        temp3 = flage;
                                    }
                                }
                            else
                                for (int j = 0; j < temp; j++)
                                    temp2 = temp2 + i;
                            ratio--;
                        }
                    }
                }
                if (den % 63 == 0) {
                    ratio = i;
                }
            }

            ratio = den;

        } else if (den < 128) {
            System.out.println("den < 128");
            int x = den, y = num, z = x + y;
            if (y % 2 != 0) {
                if (y < 22)
                    for (int i = 1; i < 10; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                else
                    for (int i = 1; i < 20; i++) {
                        z = x + y;
                        x = y;
                        y = z;
                    }
                ratio = z;
            } else {
                int temp = y / 2;
                int flag = temp;
                if (flag > 12)
                    for (int i = 0; i < temp; i++) {
                        ratio = ratio + i;
                        int temp4 = 0;
                        if (i % 2 == 0) {
                            for (int j = 0; j < temp; j++) {
                                if (j % 3 != 0) {
                                    temp4 += 1;
                                } else {
                                    temp4 -= 1;
                                }
                            }
                        } else {
                            temp4 += 0;
                        }
                    }
            }
            ratio = 11;

        } else {
            ratio = 11;
        }
        return ratio;
    }
}

Afterwards, I created an empty folder and moved the files oldV.java and newV.java into it.Then, I proceeded to use ARDiff to detect the differences between the old and new versions of the code. The detection command is as follows:

java -Djava.library.path=jpf-git/jpf-symbc/lib -jar target/artifacts/Implementation_jar/Implementation.jar --path1 /project/ARDiff/benchmarks/Airy/Sign/Test/oldV.java --path2 /project/ARDiff/benchmarks/Airy/Sign/Test/newV.java --tool A --s coral --b 3

ARDiff execution failed with the following error message:

*****************************************************************************
------------------------------------ARDIFF-----------------------------------
*****************************************************************************
An error/exception occurred when instrumenting the files or running the equivalence checking. Please report this issue to us.

java.lang.NullPointerException
        at equiv.checking.Instrumentation.valueBasedOnType(Instrumentation.java:115)
        at equiv.checking.Instrumentation.getMainProcedure(Instrumentation.java:206)
        at DSE.DSE.runEquivalenceChecking(DSE.java:268)
        at GradDiff.GradDiff.runTool(GradDiff.java:90)
        at Runner.Runner.runTool(Runner.java:163)
        at Runner.Runner.main(Runner.java:472)

DSE and IMP-S encountered the same issue, as shown below:

*****************************************************************************
------------------------------------IMP-S-----------------------------------
*****************************************************************************
An error/exception occurred when instrumenting the files or running the equivalence checking. Please report this issue to us.

java.lang.NullPointerException
        at equiv.checking.Instrumentation.valueBasedOnType(Instrumentation.java:115)
        at equiv.checking.Instrumentation.getMainProcedure(Instrumentation.java:206)
        at IMPs.ImpactedS.runEquivalenceChecking(ImpactedS.java:235)
        at IMPs.ImpactedS.runTool(ImpactedS.java:147)
        at Runner.Runner.runTool(Runner.java:185)
        at Runner.Runner.main(Runner.java:472)

Do you know what might be causing this issue? Looking forward to your response.