2019-04-16 13:57:05 -04:00
|
|
|
#!/usr/bin/env python
|
2020-01-02 15:13:47 -05:00
|
|
|
# Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2018-09-24 18:12:52 -04:00
|
|
|
import sys
|
|
|
|
import os
|
2019-05-30 16:40:40 -04:00
|
|
|
import unittest
|
2019-09-11 16:47:42 -04:00
|
|
|
import benchmark
|
2019-06-03 12:35:55 -04:00
|
|
|
from test_util import DenoTestCase, run_tests
|
2019-05-30 16:40:40 -04:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-01-20 09:49:18 -05:00
|
|
|
def test_strace_parse2(self):
|
|
|
|
with open(
|
|
|
|
os.path.join(sys.path[0], "testdata/strace_summary2.out"),
|
|
|
|
"r") as f:
|
|
|
|
summary = benchmark.strace_parse(f.read())
|
|
|
|
# first syscall line
|
|
|
|
assert summary["futex"]["calls"] == 449
|
|
|
|
assert summary["futex"]["errors"] == 94
|
|
|
|
# summary line
|
|
|
|
assert summary["total"]["calls"] == 821
|
|
|
|
|
2019-05-30 16:40:40 -04:00
|
|
|
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
|
2019-09-02 17:07:11 -04:00
|
|
|
assert binary_size_dict["CLI_SNAPSHOT.bin"] > 0
|
2019-05-30 16:40:40 -04:00
|
|
|
|
|
|
|
@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
|
2019-04-16 13:57:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2019-06-03 12:35:55 -04:00
|
|
|
run_tests()
|