• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright (c) PLUMgrid, Inc.
3# Licensed under the Apache License, Version 2.0 (the "License")
4
5from ctypes import c_uint, c_ulong, Structure
6from bcc import BPF
7from time import sleep
8import sys
9from unittest import main, TestCase
10from utils import mayFail
11
12arg1 = sys.argv.pop(1)
13arg2 = ""
14if len(sys.argv) > 1:
15  arg2 = sys.argv.pop(1)
16
17
18class TestBlkRequest(TestCase):
19    @mayFail("This fails on github actions environment, and needs to be fixed")
20    def setUp(self):
21        b = BPF(arg1, arg2, debug=0)
22        self.latency = b.get_table("latency", c_uint, c_ulong)
23        b.attach_kprobe(event="blk_start_request",
24                fn_name="probe_blk_start_request")
25        b.attach_kprobe(event="blk_update_request",
26                fn_name="probe_blk_update_request")
27
28    def test_blk1(self):
29        import subprocess
30        import os
31        # use /opt instead of /tmp so that it hits a real disk
32        for i in range(0, 2):
33            subprocess.call(["dd", "if=/dev/zero", "of=/opt/trace3.txt",
34                             "count=1024", "bs=4096"])
35            subprocess.call(["sync"])
36        os.unlink("/opt/trace3.txt")
37        for key, leaf in self.latency.items():
38            print("latency %u:" % key.value, "count %u" % leaf.value)
39        sys.stdout.flush()
40        self.assertEqual(len(list(self.latency.keys())), len(self.latency))
41
42if __name__ == "__main__":
43    main()
44