summaryrefslogtreecommitdiff
path: root/test/unit/utils.py
blob: 6aa00aa4f4398e310ee9bcce36000ceb660a9fd6 (plain)
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
import os
import unittest
from scripts.test.shared import WASM_OPT, run_process, options


class BinaryenTestCase(unittest.TestCase):
    def input_path(self, filename):
        return os.path.join(options.binaryen_test, 'unit', 'input', filename)

    def roundtrip(self, filename, opts=[]):
        path = self.input_path(filename)
        p = run_process(WASM_OPT + ['-g', '-o', 'a.wasm', path] + opts)
        self.assertEqual(p.returncode, 0)
        with open(path, 'rb') as f:
            with open('a.wasm', 'rb') as g:
                self.assertEqual(g.read(), f.read())

    def disassemble(self, filename):
        path = self.input_path(filename)
        p = run_process(WASM_OPT + ['--print', '-o', os.devnull, path], check=False,
                        capture_output=True)
        self.assertEqual(p.returncode, 0)
        self.assertEqual(p.stderr, '')
        return p.stdout

    def check_features(self, filename, features, opts=[]):
        path = self.input_path(filename)
        cmd = WASM_OPT + ['--print-features', '-o', os.devnull, path] + opts
        p = run_process(cmd, check=False, capture_output=True)
        self.assertEqual(p.returncode, 0)
        self.assertEqual(p.stderr, '')
        self.assertEqual(p.stdout.split('\n')[:-1],
                         ['--enable-' + f for f in features])