summaryrefslogtreecommitdiff
path: root/tools/benchmark_test.py
blob: cdaad1e1fde86f6dbffc30259c012754022eb079 (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
import sys
import os
import benchmark


def strace_parse_test():
    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 thread_count_test(deno_path):
    thread_count_dict = benchmark.run_thread_count_benchmark(deno_path)
    assert "set_timeout" in thread_count_dict
    assert thread_count_dict["set_timeout"] > 1


def syscall_count_test(deno_path):
    syscall_count_dict = benchmark.run_syscall_count_benchmark(deno_path)
    assert "hello" in syscall_count_dict
    assert syscall_count_dict["hello"] > 1


def benchmark_test(deno_path):
    strace_parse_test()
    if "linux" in sys.platform:
        thread_count_test(deno_path)
        syscall_count_test(deno_path)