]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - fuzzer.sh
Oops.
[xonotic/gmqcc.git] / fuzzer.sh
index 4a6c566b8af3072b1fe2e1c61790eeeb2e6323c3..933b0ff5021ffcdbb86e9445a7ea9cc2a298a013 100755 (executable)
--- a/fuzzer.sh
+++ b/fuzzer.sh
@@ -75,7 +75,7 @@ build_constant() {
        esac
        nextvar
        compiletime=$randomselect_choice
-       runtime="$var=$randomselect_choice"
+       runtime="CHECK($1, $var, $randomselect_choice, $randomselect_choice)"
        vars="$1 $var"
 }
 
@@ -115,8 +115,8 @@ build_random_expression() {
                randomselect "vector / vector float"
                #randomselect "float % float float"
                randomselect "vector >< vector vector"
-               randomselect "float >> float float"
-               randomselect "float << float float"
+               #randomselect "float >> float float"
+               #randomselect "float << float float"
                randomselect "float < float float"
                randomselect "float > float float"
                randomselect "float <=> float float"
@@ -166,21 +166,21 @@ build_random_expression() {
                        nextvar
                        case "$op" in
                                '/'|'%')
-                                       check="if(!${expr2_vars##* }) { print(\"DIVISION BY ZERO\\n\"); return 1; }$NL$TAB"
+                                       check="if(!${expr2_vars##* }) { print(\"DIVISION BY ZERO\\n\"); return; }$NL$TAB"
                                        ;;
                                *)
                                        check=
                                        ;;
                        esac
                        compiletime="($expr1_compiletime)$op($expr2_compiletime)"
-                       runtime="$expr1_runtime;$NL$TAB$expr2_runtime;$NL$TAB$check$var=(${expr1_vars##* }$op${expr2_vars##* })"
+                       runtime="$expr1_runtime;$NL$TAB$expr2_runtime;$NL$TAB$check""CHECK($type, $var, ${expr1_vars##* }$op${expr2_vars##* }, $compiletime)"
                        vars="$expr1_vars;$NL$expr2_vars;$NL$type $var"
                        ;;
                *)
                        build_random_expression "$((depth - 1))" "$randomselect_choice"
                        nextvar
                        compiletime="$op($compiletime)"
-                       runtime="$runtime;$NL$TAB$var=($op${vars##* })"
+                       runtime="$runtime;$NL$TAB""CHECK($type, $var, $op${vars##* }, $compiletime)"
                        vars="$vars;$NL$type $var"
                        ;;
        esac
@@ -198,7 +198,7 @@ while :; do
                        ;;
        esac
        newvars
-       build_random_expression 2 "$type"
+       build_random_expression 3 "$type"
        cat <<EOF >foo.qc
 void print(...) = #1;
 string ftos(float) = #2;
@@ -210,22 +210,29 @@ var string s = "s";
 var float f = 134217728;
 var vector v = '-134217728 17 0.03125';
 $vars;
-float check() {
-       $runtime;
-       $type result = ($compiletime);
-       print("Runtime: ", $conv(${vars##* }), "\\n");
-       print("Compile-time: ", $conv(result), "\\n");
-       return ${vars##* } == result;
+void check_float(string var_name, string expr_short, string expr_long, float a, float b) {
+       print(var_name, " = ", expr_short, "  // ", ftos(a), "\n");
+       if (a != b)
+               print(var_name, " != ", expr_long, "  // ", ftos(b), "\nFAIL\n");
+}
+void check_vector(string var_name, string expr_short, string expr_long, vector a, vector b) {
+       print(var_name, " = ", expr_short, "  // ", vtos(a), "\n");
+       if (a != b)
+               print(var_name, " != ", expr_long, "  // ", vtos(b), "\nFAIL\n");
 }
+void check_string(string var_name, string expr_short, string expr_long, string a, string b) {
+       print(var_name, " = ", expr_short, "  // ", a, "\n");
+       if (a != b)
+               print(var_name, " != ", expr_long, "  // ", b, "\nFAIL\n");
+}
+#define CHECK(type,var,expr_short,expr_long) \\
+       var = (expr_short); \\
+       check_##type(#var, #expr_short, #expr_long, var, expr_long)
 void main() {
-       if (check()) {
-               print("OK\\n");
-       } else {
-               print("FAIL\\n");
-       }
+       $runtime;
 }
 EOF
-       if ./gmqcc -std=gmqcc -Wall foo.qc; then
+       if ./gmqcc -std=gmqcc -fftepp -Wall foo.qc; then
                if ./qcvm progs.dat | tee /dev/stderr | grep FAIL >/dev/null; then
                        nl foo.qc
                        echo "Compiler is broken AGAIN."