Пример #1
0
def test_MakeDriver_CompileDriver_hello_world():
    """And end-to-end test."""
    testcase = deepsmith_pb2.Testcase(
        inputs={
            "lsize": "1,1,1",
            "gsize": "1,1,1",
            "src": "kernel void A(global int* a) {a[get_global_id(0)] += 10;}",
        })
    driver = cldrive.MakeDriver(testcase, True)
    with tempfile.TemporaryDirectory() as d:
        binary = cldrive.CompileDriver(driver,
                                       pathlib.Path(d) / "exe",
                                       0,
                                       0,
                                       timeout_seconds=60)
        proc = oclgrind.Exec([str(binary)])
    assert "[cldrive] Platform:" in proc.stderr
    assert "[cldrive] Device:" in proc.stderr
    assert "[cldrive] OpenCL optimizations: on\n" in proc.stderr
    assert '[cldrive] Kernel: "A"\n' in proc.stderr
    assert "done.\n" in proc.stderr
    assert proc.stdout.split("\n")[-2] == (
        "global int * a: 10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 "
        "22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 "
        "46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 "
        "70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 "
        "94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 "
        "114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 "
        "132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 "
        "150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 "
        "168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 "
        "186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 "
        "204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 "
        "222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 "
        "240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255")
Пример #2
0
 def Exec(self,
          argv: typing.List[str],
          env: typing.Dict[str, str] = None) -> subprocess.Popen:
     """Execute a command in the device environment."""
     return oclgrind.Exec([
         '--max-errors', '1', '--uninitialized', '--data-races',
         '--uniform-writes', '--uniform-writes'
     ] + argv,
                          env=env)
Пример #3
0
 def Exec(
   self,
   argv: typing.List[str],
   stdin: typing.Optional[str] = None,
   env: typing.Dict[str, str] = None,
 ) -> subprocess.Popen:
   """Execute a command in the device environment."""
   return oclgrind.Exec(
     [
       "--max-errors",
       "1",
       "--uninitialized",
       "--data-races",
       "--uniform-writes",
       "--uniform-writes",
     ]
     + argv,
     stdin=stdin,
     env=env,
   )
Пример #4
0
def test_Exec_version():
    """Test that the version of oclgrind is as expected."""
    proc = oclgrind.Exec(['--version'])
    # This test will of course fail if the @oclgrind package is updated.
    assert proc.stdout == VERSION
Пример #5
0
def test_Exec_opencl_working_app():
    """Run a binary which checks for oclgrind device availability."""
    proc = oclgrind.Exec([str(OCLGRIND_WORKING_BIN)])
    print(proc.stderr)
    assert "done" in proc.stderr
    assert proc.returncode == 0
Пример #6
0
def test_GenerateDeadcodeMutations_fuzz_test_batch(i: int):
  """Fuzz test the mutation generator.

  For each round of testing:
    Generate a batch of mutated kernels.
    For each mutated kernel:
      Create a DeepSmith testcase to compile and run the kernel.
      Drive the testcase using oclgrind.
      Ensure that the testcase completes.
  """
  del i  # unused

  # Select random parameters for test.
  kernels = [random.choice(KERNELS)] + [
    k for k in KERNELS if random.random() < 0.5
  ]
  seed = random.randint(0, 1e9)
  num_permutations_of_kernel = random.randint(1, 5)
  num_mutations_per_kernel_min = random.randint(1, 5)
  num_mutations_per_kernel_max = num_mutations_per_kernel_min + random.randint(
    1, 5
  )
  num_mutations_per_kernel = (
    num_mutations_per_kernel_min,
    num_mutations_per_kernel_max,
  )

  app.Log(
    1,
    "num_kernels=%d, seed=%d, num_permutations_of_kernel=%d, "
    "num_mutations_per_kernel=%s",
    len(kernels),
    seed,
    num_permutations_of_kernel,
    num_mutations_per_kernel,
  )

  # Generate a batch of mutations.
  generator = dci.GenerateDeadcodeMutations(
    kernels=kernels,
    rand=np.random.RandomState(seed),
    num_permutations_of_kernel=num_permutations_of_kernel,
    num_mutations_per_kernel=num_mutations_per_kernel,
  )

  for i, mutated_kernel in enumerate(generator):
    app.Log(1, "Testing mutated kernel: %s", mutated_kernel)

    # Create a DeepSmith testcase for the mutated kernel.
    testcase = deepsmith_pb2.Testcase(
      inputs={"lsize": "1,1,1", "gsize": "1,1,1", "src": mutated_kernel,}
    )

    # Make a driver for the testcase.
    driver = cldrive.MakeDriver(testcase, optimizations=True)

    with tempfile.TemporaryDirectory(prefix="phd_") as d:
      # Compile the driver.
      binary = cldrive.CompileDriver(
        driver, pathlib.Path(d) / "exe", 0, 0, timeout_seconds=60
      )
      # Execute the driver.
      proc = oclgrind.Exec([str(binary)])

    app.Log(1, "Testcase driver output: '%s'", proc.stderr.rstrip())
    assert not proc.returncode
    assert "[cldrive] Platform:" in proc.stderr
    assert "[cldrive] Device:" in proc.stderr
    assert "[cldrive] OpenCL optimizations: on\n" in proc.stderr
    assert '[cldrive] Kernel: "' in proc.stderr
    assert "done.\n" in proc.stderr

  # Sanity check that the correct number of kernels have been generated.
  app.Log(1, "Generated %d mutations", i + 1)
  assert i + 1 == len(kernels) * num_permutations_of_kernel