• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2#
3# USAGE: test_usdt.py
4#
5# Copyright 2018 Facebook, Inc
6# Licensed under the Apache License, Version 2.0 (the "License")
7
8from __future__ import print_function
9from bcc import BPF
10from unittest import main, skipUnless, TestCase
11from utils import kernel_version_ge
12import distutils.version
13import os, resource
14
15@skipUnless(not kernel_version_ge(5, 11), "Since d5299b67dd59 \"bpf: Memcg-based memory accounting for bpf maps\""\
16                                          ",map mem has been counted against memcg, not rlimit")
17class TestRlimitMemlock(TestCase):
18    def testRlimitMemlock(self):
19        text = """
20BPF_HASH(unused, u64, u64, 65536);
21int test() { return 0; }
22"""
23        # save the original memlock limits
24        memlock_limit = resource.getrlimit(resource.RLIMIT_MEMLOCK)
25
26        # set a small RLIMIT_MEMLOCK limit
27        resource.setrlimit(resource.RLIMIT_MEMLOCK, (4096, 4096))
28
29        # below will fail
30        failed = 0
31        try:
32            b = BPF(text=text, allow_rlimit=False)
33        except:
34            failed = 1
35        self.assertEqual(failed, 1)
36
37        # below should succeed
38        b = BPF(text=text, allow_rlimit=True)
39
40        # reset to the original memlock limits
41        resource.setrlimit(resource.RLIMIT_MEMLOCK, memlock_limit)
42
43if __name__ == "__main__":
44    main()
45