Browse Source

Allow creating more than one nasmtest per instruction

Fabian 3 years ago
parent
commit
b97c5661f5
1 changed files with 30 additions and 20 deletions
  1. 30 20
      tests/nasm/create_tests.js

+ 30 - 20
tests/nasm/create_tests.js

@@ -1,8 +1,8 @@
 #!/usr/bin/env node
 "use strict";
 
-// TODO
-// - multiple random tests
+// number of tests per instruction
+const NO_TESTS = 1;
 
 const assert = require("assert").strict;
 const fs = require("fs");
@@ -40,28 +40,37 @@ function generate_tests()
 
         for(const config of configurations)
         {
-            for(const code of create_nasm(op, config))
+            for(let nth_test = 0; nth_test < NO_TESTS; nth_test++)
             {
-                const filename = "gen_" + format_opcode(op.opcode) + "_" + (op.fixed_g || 0) + "_" + i + ".asm";
-                const dirname = build_folder + filename;
-
-                let old_code = undefined;
-
-                try
-                {
-                    old_code = fs.readFileSync(dirname, { encoding: "ascii" });
-                }
-                catch(e)
+                if(nth_test > 0 && op.opcode === 0x8D)
                 {
+                    // is already tested exhaustively in first run
+                    continue;
                 }
 
-                if(old_code !== code)
+                for(const code of create_nasm(op, config, nth_test))
                 {
-                    console.log("Creating %s", filename);
-                    fs.writeFileSync(dirname, code);
+                    const filename = "gen_" + format_opcode(op.opcode) + "_" + (op.fixed_g || 0) + "_" + i + ".asm";
+                    const dirname = build_folder + filename;
+
+                    let old_code = undefined;
+
+                    try
+                    {
+                        old_code = fs.readFileSync(dirname, { encoding: "ascii" });
+                    }
+                    catch(e)
+                    {
+                    }
+
+                    if(old_code !== code)
+                    {
+                        console.log("Creating %s", filename);
+                        fs.writeFileSync(dirname, code);
+                    }
+
+                    i++;
                 }
-
-                i++;
             }
         }
     }
@@ -142,9 +151,8 @@ function create_nasm_modrm_combinations_32()
 }
 
 
-function create_nasm(op, config)
+function create_nasm(op, config, nth_test)
 {
-    const op_rand = new Prand(op.opcode);
     if(op.prefix || op.skip)
     {
         return [];
@@ -174,6 +182,8 @@ function create_nasm(op, config)
         }
     }
 
+    const op_rand = new Prand(op.opcode + nth_test * 0x10000);
+
     const size = (op.os || op.opcode % 2 === 1) ? config.size : 8;
     const is_modrm = op.e || op.fixed_g !== undefined;