summaryrefslogtreecommitdiff
path: root/tools/benchmark_test.py
blob: 28d81264732a3e12c58dcf0ffb1be5732ed6dbea (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
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
#!/usr/bin/env python
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import sys
import os
import unittest
import benchmark
from test_util import DenoTestCase, run_tests


class TestBenchmark(DenoTestCase):
    def test_strace_parse(self):
        with open(
                os.path.join(sys.path[0], "testdata/strace_summary.out"),
                "r") as f:
            summary = benchmark.strace_parse(f.read())
            # first syscall line
            assert summary["munmap"]["calls"] == 60
            assert summary["munmap"]["errors"] == 0
            # line with errors
            assert summary["mkdir"]["errors"] == 2
            # last syscall line
            assert summary["prlimit64"]["calls"] == 2
            assert summary["prlimit64"]["% time"] == 0
            # summary line
            assert summary["total"]["calls"] == 704

    def test_max_mem_parse(self):
        with open(os.path.join(sys.path[0], "testdata/time.out"), "r") as f:
            data = f.read()
            assert benchmark.find_max_mem_in_bytes(data) == 120380 * 1024

    def test_binary_size(self):
        binary_size_dict = benchmark.get_binary_sizes(self.build_dir)
        assert binary_size_dict["deno"] > 0
        assert binary_size_dict["CLI_SNAPSHOT.js"] > 0
        assert binary_size_dict["CLI_SNAPSHOT.js.map"] > 0
        assert binary_size_dict["CLI_SNAPSHOT.bin"] > 0

    @unittest.skipIf("linux" not in sys.platform,
                     "strace only supported on linux")
    def test_strace(self):
        new_data = {}
        benchmark.run_strace_benchmarks(self.deno_exe, new_data)
        assert "thread_count" in new_data
        assert "syscall_count" in new_data

        s = new_data["thread_count"]
        assert "hello" in s
        assert s["hello"] > 1

        s = new_data["syscall_count"]
        assert "hello" in s
        assert s["hello"] > 1


if __name__ == '__main__':
    # FIME this doesn't appear to be the case.
    # This test assumes tools/http_server.py is running in the background.
    run_tests()