1#!/usr/bin/env python 2# Copyright (c) 2016 Facebook, Inc. 3# Licensed under the Apache License, Version 2.0 (the "License") 4 5import ctypes as ct 6import unittest 7from bcc import BPF 8 9class TestSharedTable(unittest.TestCase): 10 def test_close_extern(self): 11 b1 = BPF(text="""BPF_TABLE_PUBLIC("array", int, int, table1, 10);""") 12 13 with BPF(text="""BPF_TABLE("extern", int, int, table1, 10);""") as b2: 14 t2 = b2["table1"] 15 t2[ct.c_int(1)] = ct.c_int(10) 16 self.assertEqual(len(t2), 10) 17 18 t1 = b1["table1"] 19 self.assertEqual(t1[ct.c_int(1)].value, 10) 20 self.assertEqual(len(t1), 10) 21 22if __name__ == "__main__": 23 unittest.main() 24