File: test_shared_table.py

package info (click to toggle)
bpfcc 0.18.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 12,368 kB
  • sloc: ansic: 132,727; python: 36,226; cpp: 26,973; sh: 710; yacc: 525; makefile: 141; lex: 94
file content (23 lines) | stat: -rw-r--r-- 694 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# Copyright (c) 2016 Facebook, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")

import ctypes as ct
import unittest
from bcc import BPF

class TestSharedTable(unittest.TestCase):
    def test_close_extern(self):
        b1 = BPF(text="""BPF_TABLE_PUBLIC("array", int, int, table1, 10);""")

        with BPF(text="""BPF_TABLE("extern", int, int, table1, 10);""") as b2:
            t2 = b2["table1"]
            t2[ct.c_int(1)] = ct.c_int(10)
            self.assertEqual(len(t2), 10)

        t1 = b1["table1"]
        self.assertEqual(t1[ct.c_int(1)].value, 10)
        self.assertEqual(len(t1), 10)

if __name__ == "__main__":
    unittest.main()